Devin Heitmueller | ca3355a | 2010-07-04 18:42:11 -0300 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c), 2004-2005,2007-2010 Trident Microsystems, Inc. |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | |
| 8 | * Redistributions of source code must retain the above copyright notice, |
| 9 | this list of conditions and the following disclaimer. |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | this list of conditions and the following disclaimer in the documentation |
| 12 | and/or other materials provided with the distribution. |
| 13 | * Neither the name of Trident Microsystems nor Hauppauge Computer Works |
| 14 | nor the names of its contributors may be used to endorse or promote |
| 15 | products derived from this software without specific prior written |
| 16 | permission. |
| 17 | |
| 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | POSSIBILITY OF SUCH DAMAGE. |
Devin Heitmueller | ca3355a | 2010-07-04 18:42:11 -0300 | [diff] [blame] | 29 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 30 | DRXJ specific implementation of DRX driver |
| 31 | authors: Dragan Savic, Milos Nikolic, Mihajlo Katona, Tao Ding, Paul Janssen |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 32 | |
| 33 | The Linux DVB Driver for Micronas DRX39xx family (drx3933j) was |
| 34 | written by Devin Heitmueller <devin.heitmueller@kernellabs.com> |
| 35 | |
| 36 | This program is free software; you can redistribute it and/or modify |
| 37 | it under the terms of the GNU General Public License as published by |
| 38 | the Free Software Foundation; either version 2 of the License, or |
| 39 | (at your option) any later version. |
| 40 | |
| 41 | This program is distributed in the hope that it will be useful, |
| 42 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 43 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 44 | |
| 45 | GNU General Public License for more details. |
| 46 | |
| 47 | You should have received a copy of the GNU General Public License |
| 48 | along with this program; if not, write to the Free Software |
| 49 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 50 | */ |
| 51 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 52 | /*----------------------------------------------------------------------------- |
| 53 | INCLUDE FILES |
| 54 | ----------------------------------------------------------------------------*/ |
| 55 | |
Mauro Carvalho Chehab | 935c665 | 2014-01-17 11:36:17 -0300 | [diff] [blame] | 56 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 57 | |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 58 | #include <linux/module.h> |
| 59 | #include <linux/init.h> |
| 60 | #include <linux/string.h> |
| 61 | #include <linux/slab.h> |
Gianluca Gennari | 90d9c3e | 2014-03-11 10:41:47 -0300 | [diff] [blame] | 62 | #include <asm/div64.h> |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 63 | |
| 64 | #include "dvb_frontend.h" |
| 65 | #include "drx39xxj.h" |
| 66 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 67 | #include "drxj.h" |
| 68 | #include "drxj_map.h" |
| 69 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 70 | /*============================================================================*/ |
| 71 | /*=== DEFINES ================================================================*/ |
| 72 | /*============================================================================*/ |
| 73 | |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 74 | #define DRX39XX_MAIN_FIRMWARE "dvb-fe-drxj-mc-1.0.8.fw" |
| 75 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 76 | /** |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 77 | * \brief Maximum u32 value. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 78 | */ |
| 79 | #ifndef MAX_U32 |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 80 | #define MAX_U32 ((u32) (0xFFFFFFFFL)) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 81 | #endif |
| 82 | |
| 83 | /* Customer configurable hardware settings, etc */ |
| 84 | #ifndef MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH |
| 85 | #define MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH 0x02 |
| 86 | #endif |
| 87 | |
| 88 | #ifndef MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH |
| 89 | #define MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH 0x02 |
| 90 | #endif |
| 91 | |
| 92 | #ifndef MPEG_OUTPUT_CLK_DRIVE_STRENGTH |
| 93 | #define MPEG_OUTPUT_CLK_DRIVE_STRENGTH 0x06 |
| 94 | #endif |
| 95 | |
| 96 | #ifndef OOB_CRX_DRIVE_STRENGTH |
| 97 | #define OOB_CRX_DRIVE_STRENGTH 0x02 |
| 98 | #endif |
| 99 | |
| 100 | #ifndef OOB_DRX_DRIVE_STRENGTH |
| 101 | #define OOB_DRX_DRIVE_STRENGTH 0x02 |
| 102 | #endif |
| 103 | /**** START DJCOMBO patches to DRXJ registermap constants *********************/ |
| 104 | /**** registermap 200706071303 from drxj **************************************/ |
| 105 | #define ATV_TOP_CR_AMP_TH_FM 0x0 |
| 106 | #define ATV_TOP_CR_AMP_TH_L 0xA |
| 107 | #define ATV_TOP_CR_AMP_TH_LP 0xA |
| 108 | #define ATV_TOP_CR_AMP_TH_BG 0x8 |
| 109 | #define ATV_TOP_CR_AMP_TH_DK 0x8 |
| 110 | #define ATV_TOP_CR_AMP_TH_I 0x8 |
| 111 | #define ATV_TOP_CR_CONT_CR_D_MN 0x18 |
| 112 | #define ATV_TOP_CR_CONT_CR_D_FM 0x0 |
| 113 | #define ATV_TOP_CR_CONT_CR_D_L 0x20 |
| 114 | #define ATV_TOP_CR_CONT_CR_D_LP 0x20 |
| 115 | #define ATV_TOP_CR_CONT_CR_D_BG 0x18 |
| 116 | #define ATV_TOP_CR_CONT_CR_D_DK 0x18 |
| 117 | #define ATV_TOP_CR_CONT_CR_D_I 0x18 |
| 118 | #define ATV_TOP_CR_CONT_CR_I_MN 0x80 |
| 119 | #define ATV_TOP_CR_CONT_CR_I_FM 0x0 |
| 120 | #define ATV_TOP_CR_CONT_CR_I_L 0x80 |
| 121 | #define ATV_TOP_CR_CONT_CR_I_LP 0x80 |
| 122 | #define ATV_TOP_CR_CONT_CR_I_BG 0x80 |
| 123 | #define ATV_TOP_CR_CONT_CR_I_DK 0x80 |
| 124 | #define ATV_TOP_CR_CONT_CR_I_I 0x80 |
| 125 | #define ATV_TOP_CR_CONT_CR_P_MN 0x4 |
| 126 | #define ATV_TOP_CR_CONT_CR_P_FM 0x0 |
| 127 | #define ATV_TOP_CR_CONT_CR_P_L 0x4 |
| 128 | #define ATV_TOP_CR_CONT_CR_P_LP 0x4 |
| 129 | #define ATV_TOP_CR_CONT_CR_P_BG 0x4 |
| 130 | #define ATV_TOP_CR_CONT_CR_P_DK 0x4 |
| 131 | #define ATV_TOP_CR_CONT_CR_P_I 0x4 |
| 132 | #define ATV_TOP_CR_OVM_TH_MN 0xA0 |
| 133 | #define ATV_TOP_CR_OVM_TH_FM 0x0 |
| 134 | #define ATV_TOP_CR_OVM_TH_L 0xA0 |
| 135 | #define ATV_TOP_CR_OVM_TH_LP 0xA0 |
| 136 | #define ATV_TOP_CR_OVM_TH_BG 0xA0 |
| 137 | #define ATV_TOP_CR_OVM_TH_DK 0xA0 |
| 138 | #define ATV_TOP_CR_OVM_TH_I 0xA0 |
| 139 | #define ATV_TOP_EQU0_EQU_C0_FM 0x0 |
| 140 | #define ATV_TOP_EQU0_EQU_C0_L 0x3 |
| 141 | #define ATV_TOP_EQU0_EQU_C0_LP 0x3 |
| 142 | #define ATV_TOP_EQU0_EQU_C0_BG 0x7 |
| 143 | #define ATV_TOP_EQU0_EQU_C0_DK 0x0 |
| 144 | #define ATV_TOP_EQU0_EQU_C0_I 0x3 |
| 145 | #define ATV_TOP_EQU1_EQU_C1_FM 0x0 |
| 146 | #define ATV_TOP_EQU1_EQU_C1_L 0x1F6 |
| 147 | #define ATV_TOP_EQU1_EQU_C1_LP 0x1F6 |
| 148 | #define ATV_TOP_EQU1_EQU_C1_BG 0x197 |
| 149 | #define ATV_TOP_EQU1_EQU_C1_DK 0x198 |
| 150 | #define ATV_TOP_EQU1_EQU_C1_I 0x1F6 |
| 151 | #define ATV_TOP_EQU2_EQU_C2_FM 0x0 |
| 152 | #define ATV_TOP_EQU2_EQU_C2_L 0x28 |
| 153 | #define ATV_TOP_EQU2_EQU_C2_LP 0x28 |
| 154 | #define ATV_TOP_EQU2_EQU_C2_BG 0xC5 |
| 155 | #define ATV_TOP_EQU2_EQU_C2_DK 0xB0 |
| 156 | #define ATV_TOP_EQU2_EQU_C2_I 0x28 |
| 157 | #define ATV_TOP_EQU3_EQU_C3_FM 0x0 |
| 158 | #define ATV_TOP_EQU3_EQU_C3_L 0x192 |
| 159 | #define ATV_TOP_EQU3_EQU_C3_LP 0x192 |
| 160 | #define ATV_TOP_EQU3_EQU_C3_BG 0x12E |
| 161 | #define ATV_TOP_EQU3_EQU_C3_DK 0x18E |
| 162 | #define ATV_TOP_EQU3_EQU_C3_I 0x192 |
| 163 | #define ATV_TOP_STD_MODE_MN 0x0 |
| 164 | #define ATV_TOP_STD_MODE_FM 0x1 |
| 165 | #define ATV_TOP_STD_MODE_L 0x0 |
| 166 | #define ATV_TOP_STD_MODE_LP 0x0 |
| 167 | #define ATV_TOP_STD_MODE_BG 0x0 |
| 168 | #define ATV_TOP_STD_MODE_DK 0x0 |
| 169 | #define ATV_TOP_STD_MODE_I 0x0 |
| 170 | #define ATV_TOP_STD_VID_POL_MN 0x0 |
| 171 | #define ATV_TOP_STD_VID_POL_FM 0x0 |
| 172 | #define ATV_TOP_STD_VID_POL_L 0x2 |
| 173 | #define ATV_TOP_STD_VID_POL_LP 0x2 |
| 174 | #define ATV_TOP_STD_VID_POL_BG 0x0 |
| 175 | #define ATV_TOP_STD_VID_POL_DK 0x0 |
| 176 | #define ATV_TOP_STD_VID_POL_I 0x0 |
| 177 | #define ATV_TOP_VID_AMP_MN 0x380 |
| 178 | #define ATV_TOP_VID_AMP_FM 0x0 |
| 179 | #define ATV_TOP_VID_AMP_L 0xF50 |
| 180 | #define ATV_TOP_VID_AMP_LP 0xF50 |
| 181 | #define ATV_TOP_VID_AMP_BG 0x380 |
| 182 | #define ATV_TOP_VID_AMP_DK 0x394 |
| 183 | #define ATV_TOP_VID_AMP_I 0x3D8 |
| 184 | #define IQM_CF_OUT_ENA_OFDM__M 0x4 |
| 185 | #define IQM_FS_ADJ_SEL_B_QAM 0x1 |
| 186 | #define IQM_FS_ADJ_SEL_B_OFF 0x0 |
| 187 | #define IQM_FS_ADJ_SEL_B_VSB 0x2 |
| 188 | #define IQM_RC_ADJ_SEL_B_OFF 0x0 |
| 189 | #define IQM_RC_ADJ_SEL_B_QAM 0x1 |
| 190 | #define IQM_RC_ADJ_SEL_B_VSB 0x2 |
| 191 | /**** END DJCOMBO patches to DRXJ registermap *********************************/ |
| 192 | |
| 193 | #include "drx_driver_version.h" |
| 194 | |
Mauro Carvalho Chehab | 7ef6675 | 2014-01-16 11:08:15 -0300 | [diff] [blame] | 195 | /* #define DRX_DEBUG */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 196 | #ifdef DRX_DEBUG |
| 197 | #include <stdio.h> |
| 198 | #endif |
| 199 | |
| 200 | /*----------------------------------------------------------------------------- |
| 201 | ENUMS |
| 202 | ----------------------------------------------------------------------------*/ |
| 203 | |
| 204 | /*----------------------------------------------------------------------------- |
| 205 | DEFINES |
| 206 | ----------------------------------------------------------------------------*/ |
| 207 | #ifndef DRXJ_WAKE_UP_KEY |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 208 | #define DRXJ_WAKE_UP_KEY (demod->my_i2c_dev_addr->i2c_addr) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 209 | #endif |
| 210 | |
| 211 | /** |
| 212 | * \def DRXJ_DEF_I2C_ADDR |
| 213 | * \brief Default I2C addres of a demodulator instance. |
| 214 | */ |
| 215 | #define DRXJ_DEF_I2C_ADDR (0x52) |
| 216 | |
| 217 | /** |
| 218 | * \def DRXJ_DEF_DEMOD_DEV_ID |
| 219 | * \brief Default device identifier of a demodultor instance. |
| 220 | */ |
| 221 | #define DRXJ_DEF_DEMOD_DEV_ID (1) |
| 222 | |
| 223 | /** |
| 224 | * \def DRXJ_SCAN_TIMEOUT |
| 225 | * \brief Timeout value for waiting on demod lock during channel scan (millisec). |
| 226 | */ |
| 227 | #define DRXJ_SCAN_TIMEOUT 1000 |
| 228 | |
| 229 | /** |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 230 | * \def HI_I2C_DELAY |
| 231 | * \brief HI timing delay for I2C timing (in nano seconds) |
| 232 | * |
| 233 | * Used to compute HI_CFG_DIV |
| 234 | */ |
| 235 | #define HI_I2C_DELAY 42 |
| 236 | |
| 237 | /** |
| 238 | * \def HI_I2C_BRIDGE_DELAY |
| 239 | * \brief HI timing delay for I2C timing (in nano seconds) |
| 240 | * |
| 241 | * Used to compute HI_CFG_BDL |
| 242 | */ |
| 243 | #define HI_I2C_BRIDGE_DELAY 750 |
| 244 | |
| 245 | /** |
| 246 | * \brief Time Window for MER and SER Measurement in Units of Segment duration. |
| 247 | */ |
| 248 | #define VSB_TOP_MEASUREMENT_PERIOD 64 |
| 249 | #define SYMBOLS_PER_SEGMENT 832 |
| 250 | |
| 251 | /** |
| 252 | * \brief bit rate and segment rate constants used for SER and BER. |
| 253 | */ |
| 254 | /* values taken from the QAM microcode */ |
| 255 | #define DRXJ_QAM_SL_SIG_POWER_QAM_UNKNOWN 0 |
| 256 | #define DRXJ_QAM_SL_SIG_POWER_QPSK 32768 |
| 257 | #define DRXJ_QAM_SL_SIG_POWER_QAM8 24576 |
| 258 | #define DRXJ_QAM_SL_SIG_POWER_QAM16 40960 |
| 259 | #define DRXJ_QAM_SL_SIG_POWER_QAM32 20480 |
| 260 | #define DRXJ_QAM_SL_SIG_POWER_QAM64 43008 |
| 261 | #define DRXJ_QAM_SL_SIG_POWER_QAM128 20992 |
| 262 | #define DRXJ_QAM_SL_SIG_POWER_QAM256 43520 |
| 263 | /** |
| 264 | * \brief Min supported symbolrates. |
| 265 | */ |
| 266 | #ifndef DRXJ_QAM_SYMBOLRATE_MIN |
| 267 | #define DRXJ_QAM_SYMBOLRATE_MIN (520000) |
| 268 | #endif |
| 269 | |
| 270 | /** |
| 271 | * \brief Max supported symbolrates. |
| 272 | */ |
| 273 | #ifndef DRXJ_QAM_SYMBOLRATE_MAX |
| 274 | #define DRXJ_QAM_SYMBOLRATE_MAX (7233000) |
| 275 | #endif |
| 276 | |
| 277 | /** |
| 278 | * \def DRXJ_QAM_MAX_WAITTIME |
| 279 | * \brief Maximal wait time for QAM auto constellation in ms |
| 280 | */ |
| 281 | #ifndef DRXJ_QAM_MAX_WAITTIME |
| 282 | #define DRXJ_QAM_MAX_WAITTIME 900 |
| 283 | #endif |
| 284 | |
| 285 | #ifndef DRXJ_QAM_FEC_LOCK_WAITTIME |
| 286 | #define DRXJ_QAM_FEC_LOCK_WAITTIME 150 |
| 287 | #endif |
| 288 | |
| 289 | #ifndef DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME |
| 290 | #define DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME 200 |
| 291 | #endif |
| 292 | |
| 293 | /** |
| 294 | * \def SCU status and results |
| 295 | * \brief SCU |
| 296 | */ |
| 297 | #define DRX_SCU_READY 0 |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 298 | #define DRXJ_MAX_WAITTIME 100 /* ms */ |
| 299 | #define FEC_RS_MEASUREMENT_PERIOD 12894 /* 1 sec */ |
| 300 | #define FEC_RS_MEASUREMENT_PRESCALE 1 /* n sec */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 301 | |
| 302 | /** |
| 303 | * \def DRX_AUD_MAX_DEVIATION |
| 304 | * \brief Needed for calculation of prescale feature in AUD |
| 305 | */ |
| 306 | #ifndef DRXJ_AUD_MAX_FM_DEVIATION |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 307 | #define DRXJ_AUD_MAX_FM_DEVIATION 100 /* kHz */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 308 | #endif |
| 309 | |
| 310 | /** |
| 311 | * \brief Needed for calculation of NICAM prescale feature in AUD |
| 312 | */ |
| 313 | #ifndef DRXJ_AUD_MAX_NICAM_PRESCALE |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 314 | #define DRXJ_AUD_MAX_NICAM_PRESCALE (9) /* dB */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 315 | #endif |
| 316 | |
| 317 | /** |
| 318 | * \brief Needed for calculation of NICAM prescale feature in AUD |
| 319 | */ |
| 320 | #ifndef DRXJ_AUD_MAX_WAITTIME |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 321 | #define DRXJ_AUD_MAX_WAITTIME 250 /* ms */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 322 | #endif |
| 323 | |
| 324 | /* ATV config changed flags */ |
Mauro Carvalho Chehab | 7ef6675 | 2014-01-16 11:08:15 -0300 | [diff] [blame] | 325 | #define DRXJ_ATV_CHANGED_COEF (0x00000001UL) |
| 326 | #define DRXJ_ATV_CHANGED_PEAK_FLT (0x00000008UL) |
| 327 | #define DRXJ_ATV_CHANGED_NOISE_FLT (0x00000010UL) |
| 328 | #define DRXJ_ATV_CHANGED_OUTPUT (0x00000020UL) |
| 329 | #define DRXJ_ATV_CHANGED_SIF_ATT (0x00000040UL) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 330 | |
| 331 | /* UIO define */ |
| 332 | #define DRX_UIO_MODE_FIRMWARE_SMA DRX_UIO_MODE_FIRMWARE0 |
| 333 | #define DRX_UIO_MODE_FIRMWARE_SAW DRX_UIO_MODE_FIRMWARE1 |
| 334 | |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 335 | /* |
| 336 | * MICROCODE RELATED DEFINES |
| 337 | */ |
| 338 | |
| 339 | /* Magic word for checking correct Endianess of microcode data */ |
| 340 | #define DRX_UCODE_MAGIC_WORD ((((u16)'H')<<8)+((u16)'L')) |
| 341 | |
| 342 | /* CRC flag in ucode header, flags field. */ |
| 343 | #define DRX_UCODE_CRC_FLAG (0x0001) |
| 344 | |
| 345 | /* |
| 346 | * Maximum size of buffer used to verify the microcode. |
| 347 | * Must be an even number |
| 348 | */ |
| 349 | #define DRX_UCODE_MAX_BUF_SIZE (DRXDAP_MAX_RCHUNKSIZE) |
| 350 | |
| 351 | #if DRX_UCODE_MAX_BUF_SIZE & 1 |
| 352 | #error DRX_UCODE_MAX_BUF_SIZE must be an even number |
| 353 | #endif |
| 354 | |
| 355 | /* |
| 356 | * Power mode macros |
| 357 | */ |
| 358 | |
| 359 | #define DRX_ISPOWERDOWNMODE(mode) ((mode == DRX_POWER_MODE_9) || \ |
| 360 | (mode == DRX_POWER_MODE_10) || \ |
| 361 | (mode == DRX_POWER_MODE_11) || \ |
| 362 | (mode == DRX_POWER_MODE_12) || \ |
| 363 | (mode == DRX_POWER_MODE_13) || \ |
| 364 | (mode == DRX_POWER_MODE_14) || \ |
| 365 | (mode == DRX_POWER_MODE_15) || \ |
| 366 | (mode == DRX_POWER_MODE_16) || \ |
| 367 | (mode == DRX_POWER_DOWN)) |
| 368 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 369 | /* Pin safe mode macro */ |
| 370 | #define DRXJ_PIN_SAFE_MODE 0x0000 |
| 371 | /*============================================================================*/ |
| 372 | /*=== GLOBAL VARIABLEs =======================================================*/ |
| 373 | /*============================================================================*/ |
| 374 | /** |
| 375 | */ |
| 376 | |
| 377 | /** |
| 378 | * \brief Temporary register definitions. |
| 379 | * (register definitions that are not yet available in register master) |
| 380 | */ |
| 381 | |
| 382 | /******************************************************************************/ |
| 383 | /* Audio block 0x103 is write only. To avoid shadowing in driver accessing */ |
| 384 | /* RAM adresses directly. This must be READ ONLY to avoid problems. */ |
| 385 | /* Writing to the interface adresses is more than only writing the RAM */ |
| 386 | /* locations */ |
| 387 | /******************************************************************************/ |
| 388 | /** |
| 389 | * \brief RAM location of MODUS registers |
| 390 | */ |
| 391 | #define AUD_DEM_RAM_MODUS_HI__A 0x10204A3 |
| 392 | #define AUD_DEM_RAM_MODUS_HI__M 0xF000 |
| 393 | |
| 394 | #define AUD_DEM_RAM_MODUS_LO__A 0x10204A4 |
| 395 | #define AUD_DEM_RAM_MODUS_LO__M 0x0FFF |
| 396 | |
| 397 | /** |
| 398 | * \brief RAM location of I2S config registers |
| 399 | */ |
| 400 | #define AUD_DEM_RAM_I2S_CONFIG1__A 0x10204B1 |
| 401 | #define AUD_DEM_RAM_I2S_CONFIG2__A 0x10204B2 |
| 402 | |
| 403 | /** |
| 404 | * \brief RAM location of DCO config registers |
| 405 | */ |
| 406 | #define AUD_DEM_RAM_DCO_B_HI__A 0x1020461 |
| 407 | #define AUD_DEM_RAM_DCO_B_LO__A 0x1020462 |
| 408 | #define AUD_DEM_RAM_DCO_A_HI__A 0x1020463 |
| 409 | #define AUD_DEM_RAM_DCO_A_LO__A 0x1020464 |
| 410 | |
| 411 | /** |
| 412 | * \brief RAM location of Threshold registers |
| 413 | */ |
| 414 | #define AUD_DEM_RAM_NICAM_THRSHLD__A 0x102045A |
| 415 | #define AUD_DEM_RAM_A2_THRSHLD__A 0x10204BB |
| 416 | #define AUD_DEM_RAM_BTSC_THRSHLD__A 0x10204A6 |
| 417 | |
| 418 | /** |
| 419 | * \brief RAM location of Carrier Threshold registers |
| 420 | */ |
| 421 | #define AUD_DEM_RAM_CM_A_THRSHLD__A 0x10204AF |
| 422 | #define AUD_DEM_RAM_CM_B_THRSHLD__A 0x10204B0 |
| 423 | |
| 424 | /** |
| 425 | * \brief FM Matrix register fix |
| 426 | */ |
Mauro Carvalho Chehab | 7ef6675 | 2014-01-16 11:08:15 -0300 | [diff] [blame] | 427 | #ifdef AUD_DEM_WR_FM_MATRIX__A |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 428 | #undef AUD_DEM_WR_FM_MATRIX__A |
| 429 | #endif |
| 430 | #define AUD_DEM_WR_FM_MATRIX__A 0x105006F |
| 431 | |
| 432 | /*============================================================================*/ |
| 433 | /** |
| 434 | * \brief Defines required for audio |
| 435 | */ |
| 436 | #define AUD_VOLUME_ZERO_DB 115 |
| 437 | #define AUD_VOLUME_DB_MIN -60 |
| 438 | #define AUD_VOLUME_DB_MAX 12 |
| 439 | #define AUD_CARRIER_STRENGTH_QP_0DB 0x4000 |
| 440 | #define AUD_CARRIER_STRENGTH_QP_0DB_LOG10T100 421 |
| 441 | #define AUD_MAX_AVC_REF_LEVEL 15 |
| 442 | #define AUD_I2S_FREQUENCY_MAX 48000UL |
| 443 | #define AUD_I2S_FREQUENCY_MIN 12000UL |
| 444 | #define AUD_RDS_ARRAY_SIZE 18 |
| 445 | |
| 446 | /** |
| 447 | * \brief Needed for calculation of prescale feature in AUD |
| 448 | */ |
| 449 | #ifndef DRX_AUD_MAX_FM_DEVIATION |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 450 | #define DRX_AUD_MAX_FM_DEVIATION (100) /* kHz */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 451 | #endif |
| 452 | |
| 453 | /** |
| 454 | * \brief Needed for calculation of NICAM prescale feature in AUD |
| 455 | */ |
| 456 | #ifndef DRX_AUD_MAX_NICAM_PRESCALE |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 457 | #define DRX_AUD_MAX_NICAM_PRESCALE (9) /* dB */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 458 | #endif |
| 459 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 460 | /*============================================================================*/ |
| 461 | /* Values for I2S Master/Slave pin configurations */ |
| 462 | #define SIO_PDR_I2S_CL_CFG_MODE__MASTER 0x0004 |
| 463 | #define SIO_PDR_I2S_CL_CFG_DRIVE__MASTER 0x0008 |
| 464 | #define SIO_PDR_I2S_CL_CFG_MODE__SLAVE 0x0004 |
| 465 | #define SIO_PDR_I2S_CL_CFG_DRIVE__SLAVE 0x0000 |
| 466 | |
| 467 | #define SIO_PDR_I2S_DA_CFG_MODE__MASTER 0x0003 |
| 468 | #define SIO_PDR_I2S_DA_CFG_DRIVE__MASTER 0x0008 |
| 469 | #define SIO_PDR_I2S_DA_CFG_MODE__SLAVE 0x0003 |
| 470 | #define SIO_PDR_I2S_DA_CFG_DRIVE__SLAVE 0x0008 |
| 471 | |
| 472 | #define SIO_PDR_I2S_WS_CFG_MODE__MASTER 0x0004 |
| 473 | #define SIO_PDR_I2S_WS_CFG_DRIVE__MASTER 0x0008 |
| 474 | #define SIO_PDR_I2S_WS_CFG_MODE__SLAVE 0x0004 |
| 475 | #define SIO_PDR_I2S_WS_CFG_DRIVE__SLAVE 0x0000 |
| 476 | |
| 477 | /*============================================================================*/ |
| 478 | /*=== REGISTER ACCESS MACROS =================================================*/ |
| 479 | /*============================================================================*/ |
| 480 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 481 | /** |
| 482 | * This macro is used to create byte arrays for block writes. |
| 483 | * Block writes speed up I2C traffic between host and demod. |
| 484 | * The macro takes care of the required byte order in a 16 bits word. |
| 485 | * x -> lowbyte(x), highbyte(x) |
| 486 | */ |
Mauro Carvalho Chehab | 7ef6675 | 2014-01-16 11:08:15 -0300 | [diff] [blame] | 487 | #define DRXJ_16TO8(x) ((u8) (((u16)x) & 0xFF)), \ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 488 | ((u8)((((u16)x)>>8)&0xFF)) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 489 | /** |
| 490 | * This macro is used to convert byte array to 16 bit register value for block read. |
| 491 | * Block read speed up I2C traffic between host and demod. |
| 492 | * The macro takes care of the required byte order in a 16 bits word. |
| 493 | */ |
Mauro Carvalho Chehab | 7ef6675 | 2014-01-16 11:08:15 -0300 | [diff] [blame] | 494 | #define DRXJ_8TO16(x) ((u16) (x[0] | (x[1] << 8))) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 495 | |
| 496 | /*============================================================================*/ |
| 497 | /*=== MISC DEFINES ===========================================================*/ |
| 498 | /*============================================================================*/ |
| 499 | |
| 500 | /*============================================================================*/ |
| 501 | /*=== HI COMMAND RELATED DEFINES =============================================*/ |
| 502 | /*============================================================================*/ |
| 503 | |
| 504 | /** |
| 505 | * \brief General maximum number of retries for ucode command interfaces |
| 506 | */ |
| 507 | #define DRXJ_MAX_RETRIES (100) |
| 508 | |
| 509 | /*============================================================================*/ |
| 510 | /*=== STANDARD RELATED MACROS ================================================*/ |
| 511 | /*============================================================================*/ |
| 512 | |
Mauro Carvalho Chehab | adc0e25 | 2014-01-16 15:56:51 -0300 | [diff] [blame] | 513 | #define DRXJ_ISATVSTD(std) ((std == DRX_STANDARD_PAL_SECAM_BG) || \ |
Mauro Carvalho Chehab | 7ef6675 | 2014-01-16 11:08:15 -0300 | [diff] [blame] | 514 | (std == DRX_STANDARD_PAL_SECAM_DK) || \ |
| 515 | (std == DRX_STANDARD_PAL_SECAM_I) || \ |
| 516 | (std == DRX_STANDARD_PAL_SECAM_L) || \ |
| 517 | (std == DRX_STANDARD_PAL_SECAM_LP) || \ |
| 518 | (std == DRX_STANDARD_NTSC) || \ |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 519 | (std == DRX_STANDARD_FM)) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 520 | |
Mauro Carvalho Chehab | adc0e25 | 2014-01-16 15:56:51 -0300 | [diff] [blame] | 521 | #define DRXJ_ISQAMSTD(std) ((std == DRX_STANDARD_ITU_A) || \ |
Mauro Carvalho Chehab | 7ef6675 | 2014-01-16 11:08:15 -0300 | [diff] [blame] | 522 | (std == DRX_STANDARD_ITU_B) || \ |
| 523 | (std == DRX_STANDARD_ITU_C) || \ |
| 524 | (std == DRX_STANDARD_ITU_D)) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 525 | |
| 526 | /*----------------------------------------------------------------------------- |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 527 | GLOBAL VARIABLES |
| 528 | ----------------------------------------------------------------------------*/ |
| 529 | /* |
| 530 | * DRXJ DAP structures |
| 531 | */ |
| 532 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 533 | static int drxdap_fasi_read_block(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 534 | u32 addr, |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 535 | u16 datasize, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 536 | u8 *data, u32 flags); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 537 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 538 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 539 | static int drxj_dap_read_modify_write_reg16(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 540 | u32 waddr, |
| 541 | u32 raddr, |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 542 | u16 wdata, u16 *rdata); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 543 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 544 | static int drxj_dap_read_reg16(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 545 | u32 addr, |
| 546 | u16 *data, u32 flags); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 547 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 548 | static int drxdap_fasi_read_reg32(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 549 | u32 addr, |
| 550 | u32 *data, u32 flags); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 551 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 552 | static int drxdap_fasi_write_block(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 553 | u32 addr, |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 554 | u16 datasize, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 555 | u8 *data, u32 flags); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 556 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 557 | static int drxj_dap_write_reg16(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 558 | u32 addr, |
| 559 | u16 data, u32 flags); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 560 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 561 | static int drxdap_fasi_write_reg32(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 562 | u32 addr, |
| 563 | u32 data, u32 flags); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 564 | |
Mauro Carvalho Chehab | 0147314 | 2014-03-09 10:33:19 -0300 | [diff] [blame] | 565 | static struct drxj_data drxj_data_g = { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 566 | false, /* has_lna : true if LNA (aka PGA) present */ |
| 567 | false, /* has_oob : true if OOB supported */ |
| 568 | false, /* has_ntsc: true if NTSC supported */ |
| 569 | false, /* has_btsc: true if BTSC supported */ |
| 570 | false, /* has_smatx: true if SMA_TX pin is available */ |
| 571 | false, /* has_smarx: true if SMA_RX pin is available */ |
| 572 | false, /* has_gpio : true if GPIO pin is available */ |
| 573 | false, /* has_irqn : true if IRQN pin is available */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 574 | 0, /* mfx A1/A2/A... */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 575 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 576 | /* tuner settings */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 577 | false, /* tuner mirrors RF signal */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 578 | /* standard/channel settings */ |
| 579 | DRX_STANDARD_UNKNOWN, /* current standard */ |
| 580 | DRX_CONSTELLATION_AUTO, /* constellation */ |
| 581 | 0, /* frequency in KHz */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 582 | DRX_BANDWIDTH_UNKNOWN, /* curr_bandwidth */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 583 | DRX_MIRROR_NO, /* mirror */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 584 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 585 | /* signal quality information: */ |
| 586 | /* default values taken from the QAM Programming guide */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 587 | /* fec_bits_desired should not be less than 4000000 */ |
| 588 | 4000000, /* fec_bits_desired */ |
| 589 | 5, /* fec_vd_plen */ |
| 590 | 4, /* qam_vd_prescale */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 591 | 0xFFFF, /* qamVDPeriod */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 592 | 204 * 8, /* fec_rs_plen annex A */ |
| 593 | 1, /* fec_rs_prescale */ |
| 594 | FEC_RS_MEASUREMENT_PERIOD, /* fec_rs_period */ |
| 595 | true, /* reset_pkt_err_acc */ |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 596 | 0, /* pkt_err_acc_start */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 597 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 598 | /* HI configuration */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 599 | 0, /* hi_cfg_timing_div */ |
| 600 | 0, /* hi_cfg_bridge_delay */ |
| 601 | 0, /* hi_cfg_wake_up_key */ |
| 602 | 0, /* hi_cfg_ctrl */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 603 | 0, /* HICfgTimeout */ |
| 604 | /* UIO configuartion */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 605 | DRX_UIO_MODE_DISABLE, /* uio_sma_rx_mode */ |
| 606 | DRX_UIO_MODE_DISABLE, /* uio_sma_tx_mode */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 607 | DRX_UIO_MODE_DISABLE, /* uioASELMode */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 608 | DRX_UIO_MODE_DISABLE, /* uio_irqn_mode */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 609 | /* FS setting */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 610 | 0UL, /* iqm_fs_rate_ofs */ |
| 611 | false, /* pos_image */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 612 | /* RC setting */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 613 | 0UL, /* iqm_rc_rate_ofs */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 614 | /* AUD information */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 615 | /* false, * flagSetAUDdone */ |
| 616 | /* false, * detectedRDS */ |
| 617 | /* true, * flagASDRequest */ |
| 618 | /* false, * flagHDevClear */ |
| 619 | /* false, * flagHDevSet */ |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 620 | /* (u16) 0xFFF, * rdsLastCount */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 621 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 622 | /* ATV configuartion */ |
| 623 | 0UL, /* flags cfg changes */ |
| 624 | /* shadow of ATV_TOP_EQU0__A */ |
| 625 | {-5, |
| 626 | ATV_TOP_EQU0_EQU_C0_FM, |
| 627 | ATV_TOP_EQU0_EQU_C0_L, |
| 628 | ATV_TOP_EQU0_EQU_C0_LP, |
| 629 | ATV_TOP_EQU0_EQU_C0_BG, |
| 630 | ATV_TOP_EQU0_EQU_C0_DK, |
| 631 | ATV_TOP_EQU0_EQU_C0_I}, |
| 632 | /* shadow of ATV_TOP_EQU1__A */ |
| 633 | {-50, |
| 634 | ATV_TOP_EQU1_EQU_C1_FM, |
| 635 | ATV_TOP_EQU1_EQU_C1_L, |
| 636 | ATV_TOP_EQU1_EQU_C1_LP, |
| 637 | ATV_TOP_EQU1_EQU_C1_BG, |
| 638 | ATV_TOP_EQU1_EQU_C1_DK, |
| 639 | ATV_TOP_EQU1_EQU_C1_I}, |
| 640 | /* shadow of ATV_TOP_EQU2__A */ |
| 641 | {210, |
| 642 | ATV_TOP_EQU2_EQU_C2_FM, |
| 643 | ATV_TOP_EQU2_EQU_C2_L, |
| 644 | ATV_TOP_EQU2_EQU_C2_LP, |
| 645 | ATV_TOP_EQU2_EQU_C2_BG, |
| 646 | ATV_TOP_EQU2_EQU_C2_DK, |
| 647 | ATV_TOP_EQU2_EQU_C2_I}, |
| 648 | /* shadow of ATV_TOP_EQU3__A */ |
| 649 | {-160, |
| 650 | ATV_TOP_EQU3_EQU_C3_FM, |
| 651 | ATV_TOP_EQU3_EQU_C3_L, |
| 652 | ATV_TOP_EQU3_EQU_C3_LP, |
| 653 | ATV_TOP_EQU3_EQU_C3_BG, |
| 654 | ATV_TOP_EQU3_EQU_C3_DK, |
| 655 | ATV_TOP_EQU3_EQU_C3_I}, |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 656 | false, /* flag: true=bypass */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 657 | ATV_TOP_VID_PEAK__PRE, /* shadow of ATV_TOP_VID_PEAK__A */ |
| 658 | ATV_TOP_NOISE_TH__PRE, /* shadow of ATV_TOP_NOISE_TH__A */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 659 | true, /* flag CVBS ouput enable */ |
| 660 | false, /* flag SIF ouput enable */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 661 | DRXJ_SIF_ATTENUATION_0DB, /* current SIF att setting */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 662 | { /* qam_rf_agc_cfg */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 663 | DRX_STANDARD_ITU_B, /* standard */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 664 | DRX_AGC_CTRL_AUTO, /* ctrl_mode */ |
| 665 | 0, /* output_level */ |
| 666 | 0, /* min_output_level */ |
| 667 | 0xFFFF, /* max_output_level */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 668 | 0x0000, /* speed */ |
| 669 | 0x0000, /* top */ |
| 670 | 0x0000 /* c.o.c. */ |
| 671 | }, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 672 | { /* qam_if_agc_cfg */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 673 | DRX_STANDARD_ITU_B, /* standard */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 674 | DRX_AGC_CTRL_AUTO, /* ctrl_mode */ |
| 675 | 0, /* output_level */ |
| 676 | 0, /* min_output_level */ |
| 677 | 0xFFFF, /* max_output_level */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 678 | 0x0000, /* speed */ |
| 679 | 0x0000, /* top (don't care) */ |
| 680 | 0x0000 /* c.o.c. (don't care) */ |
| 681 | }, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 682 | { /* vsb_rf_agc_cfg */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 683 | DRX_STANDARD_8VSB, /* standard */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 684 | DRX_AGC_CTRL_AUTO, /* ctrl_mode */ |
| 685 | 0, /* output_level */ |
| 686 | 0, /* min_output_level */ |
| 687 | 0xFFFF, /* max_output_level */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 688 | 0x0000, /* speed */ |
| 689 | 0x0000, /* top (don't care) */ |
| 690 | 0x0000 /* c.o.c. (don't care) */ |
| 691 | }, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 692 | { /* vsb_if_agc_cfg */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 693 | DRX_STANDARD_8VSB, /* standard */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 694 | DRX_AGC_CTRL_AUTO, /* ctrl_mode */ |
| 695 | 0, /* output_level */ |
| 696 | 0, /* min_output_level */ |
| 697 | 0xFFFF, /* max_output_level */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 698 | 0x0000, /* speed */ |
| 699 | 0x0000, /* top (don't care) */ |
| 700 | 0x0000 /* c.o.c. (don't care) */ |
| 701 | }, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 702 | 0, /* qam_pga_cfg */ |
| 703 | 0, /* vsb_pga_cfg */ |
| 704 | { /* qam_pre_saw_cfg */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 705 | DRX_STANDARD_ITU_B, /* standard */ |
| 706 | 0, /* reference */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 707 | false /* use_pre_saw */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 708 | }, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 709 | { /* vsb_pre_saw_cfg */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 710 | DRX_STANDARD_8VSB, /* standard */ |
| 711 | 0, /* reference */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 712 | false /* use_pre_saw */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 713 | }, |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 714 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 715 | /* Version information */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 716 | #ifndef _CH_ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 717 | { |
| 718 | "01234567890", /* human readable version microcode */ |
| 719 | "01234567890" /* human readable version device specific code */ |
| 720 | }, |
| 721 | { |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 722 | { /* struct drx_version for microcode */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 723 | DRX_MODULE_UNKNOWN, |
| 724 | (char *)(NULL), |
| 725 | 0, |
| 726 | 0, |
| 727 | 0, |
| 728 | (char *)(NULL) |
| 729 | }, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 730 | { /* struct drx_version for device specific code */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 731 | DRX_MODULE_UNKNOWN, |
| 732 | (char *)(NULL), |
| 733 | 0, |
| 734 | 0, |
| 735 | 0, |
| 736 | (char *)(NULL) |
| 737 | } |
| 738 | }, |
| 739 | { |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 740 | { /* struct drx_version_list for microcode */ |
| 741 | (struct drx_version *) (NULL), |
| 742 | (struct drx_version_list *) (NULL) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 743 | }, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 744 | { /* struct drx_version_list for device specific code */ |
| 745 | (struct drx_version *) (NULL), |
| 746 | (struct drx_version_list *) (NULL) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 747 | } |
| 748 | }, |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 749 | #endif |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 750 | false, /* smart_ant_inverted */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 751 | /* Tracking filter setting for OOB */ |
| 752 | { |
| 753 | 12000, |
| 754 | 9300, |
| 755 | 6600, |
| 756 | 5280, |
| 757 | 3700, |
| 758 | 3000, |
| 759 | 2000, |
| 760 | 0}, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 761 | false, /* oob_power_on */ |
| 762 | 0, /* mpeg_ts_static_bitrate */ |
| 763 | false, /* disable_te_ihandling */ |
| 764 | false, /* bit_reverse_mpeg_outout */ |
| 765 | DRXJ_MPEGOUTPUT_CLOCK_RATE_AUTO, /* mpeg_output_clock_rate */ |
| 766 | DRXJ_MPEG_START_WIDTH_1CLKCYC, /* mpeg_start_width */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 767 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 768 | /* Pre SAW & Agc configuration for ATV */ |
| 769 | { |
| 770 | DRX_STANDARD_NTSC, /* standard */ |
| 771 | 7, /* reference */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 772 | true /* use_pre_saw */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 773 | }, |
| 774 | { /* ATV RF-AGC */ |
| 775 | DRX_STANDARD_NTSC, /* standard */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 776 | DRX_AGC_CTRL_AUTO, /* ctrl_mode */ |
| 777 | 0, /* output_level */ |
| 778 | 0, /* min_output_level (d.c.) */ |
| 779 | 0, /* max_output_level (d.c.) */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 780 | 3, /* speed */ |
| 781 | 9500, /* top */ |
| 782 | 4000 /* cut-off current */ |
| 783 | }, |
| 784 | { /* ATV IF-AGC */ |
| 785 | DRX_STANDARD_NTSC, /* standard */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 786 | DRX_AGC_CTRL_AUTO, /* ctrl_mode */ |
| 787 | 0, /* output_level */ |
| 788 | 0, /* min_output_level (d.c.) */ |
| 789 | 0, /* max_output_level (d.c.) */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 790 | 3, /* speed */ |
| 791 | 2400, /* top */ |
| 792 | 0 /* c.o.c. (d.c.) */ |
| 793 | }, |
| 794 | 140, /* ATV PGA config */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 795 | 0, /* curr_symbol_rate */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 796 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 797 | false, /* pdr_safe_mode */ |
| 798 | SIO_PDR_GPIO_CFG__PRE, /* pdr_safe_restore_val_gpio */ |
| 799 | SIO_PDR_VSYNC_CFG__PRE, /* pdr_safe_restore_val_v_sync */ |
| 800 | SIO_PDR_SMA_RX_CFG__PRE, /* pdr_safe_restore_val_sma_rx */ |
| 801 | SIO_PDR_SMA_TX_CFG__PRE, /* pdr_safe_restore_val_sma_tx */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 802 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 803 | 4, /* oob_pre_saw */ |
| 804 | DRXJ_OOB_LO_POW_MINUS10DB, /* oob_lo_pow */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 805 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 806 | false /* aud_data, only first member */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 807 | }, |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 808 | }; |
| 809 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 810 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 811 | * \var drxj_default_addr_g |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 812 | * \brief Default I2C address and device identifier. |
| 813 | */ |
Mauro Carvalho Chehab | 0147314 | 2014-03-09 10:33:19 -0300 | [diff] [blame] | 814 | static struct i2c_device_addr drxj_default_addr_g = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 815 | DRXJ_DEF_I2C_ADDR, /* i2c address */ |
| 816 | DRXJ_DEF_DEMOD_DEV_ID /* device id */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 817 | }; |
| 818 | |
| 819 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 820 | * \var drxj_default_comm_attr_g |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 821 | * \brief Default common attributes of a drxj demodulator instance. |
| 822 | */ |
Mauro Carvalho Chehab | 0147314 | 2014-03-09 10:33:19 -0300 | [diff] [blame] | 823 | static struct drx_common_attr drxj_default_comm_attr_g = { |
Mauro Carvalho Chehab | b48293d | 2014-01-18 11:13:02 -0300 | [diff] [blame] | 824 | NULL, /* ucode file */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 825 | true, /* ucode verify switch */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 826 | {0}, /* version record */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 827 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 828 | 44000, /* IF in kHz in case no tuner instance is used */ |
| 829 | (151875 - 0), /* system clock frequency in kHz */ |
| 830 | 0, /* oscillator frequency kHz */ |
| 831 | 0, /* oscillator deviation in ppm, signed */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 832 | false, /* If true mirror frequency spectrum */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 833 | { |
| 834 | /* MPEG output configuration */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 835 | true, /* If true, enable MPEG ouput */ |
| 836 | false, /* If true, insert RS byte */ |
Mauro Carvalho Chehab | a5e7a67 | 2014-03-03 06:13:17 -0300 | [diff] [blame] | 837 | false, /* If true, parallel out otherwise serial */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 838 | false, /* If true, invert DATA signals */ |
| 839 | false, /* If true, invert ERR signal */ |
| 840 | false, /* If true, invert STR signals */ |
| 841 | false, /* If true, invert VAL signals */ |
| 842 | false, /* If true, invert CLK signals */ |
| 843 | true, /* If true, static MPEG clockrate will |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 844 | be used, otherwise clockrate will |
| 845 | adapt to the bitrate of the TS */ |
| 846 | 19392658UL, /* Maximum bitrate in b/s in case |
| 847 | static clockrate is selected */ |
| 848 | DRX_MPEG_STR_WIDTH_1 /* MPEG Start width in clock cycles */ |
| 849 | }, |
| 850 | /* Initilisations below can be ommited, they require no user input and |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 851 | are initialy 0, NULL or false. The compiler will initialize them to these |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 852 | values when ommited. */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 853 | false, /* is_opened */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 854 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 855 | /* SCAN */ |
| 856 | NULL, /* no scan params yet */ |
| 857 | 0, /* current scan index */ |
| 858 | 0, /* next scan frequency */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 859 | false, /* scan ready flag */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 860 | 0, /* max channels to scan */ |
| 861 | 0, /* nr of channels scanned */ |
| 862 | NULL, /* default scan function */ |
| 863 | NULL, /* default context pointer */ |
| 864 | 0, /* millisec to wait for demod lock */ |
| 865 | DRXJ_DEMOD_LOCK, /* desired lock */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 866 | false, |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 867 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 868 | /* Power management */ |
| 869 | DRX_POWER_UP, |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 870 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 871 | /* Tuner */ |
| 872 | 1, /* nr of I2C port to wich tuner is */ |
| 873 | 0L, /* minimum RF input frequency, in kHz */ |
| 874 | 0L, /* maximum RF input frequency, in kHz */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 875 | false, /* Rf Agc Polarity */ |
| 876 | false, /* If Agc Polarity */ |
| 877 | false, /* tuner slow mode */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 878 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 879 | { /* current channel (all 0) */ |
| 880 | 0UL /* channel.frequency */ |
| 881 | }, |
| 882 | DRX_STANDARD_UNKNOWN, /* current standard */ |
| 883 | DRX_STANDARD_UNKNOWN, /* previous standard */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 884 | DRX_STANDARD_UNKNOWN, /* di_cache_standard */ |
| 885 | false, /* use_bootloader */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 886 | 0UL, /* capabilities */ |
| 887 | 0 /* mfx */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 888 | }; |
| 889 | |
| 890 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 891 | * \var drxj_default_demod_g |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 892 | * \brief Default drxj demodulator instance. |
| 893 | */ |
Mauro Carvalho Chehab | 0147314 | 2014-03-09 10:33:19 -0300 | [diff] [blame] | 894 | static struct drx_demod_instance drxj_default_demod_g = { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 895 | &drxj_default_addr_g, /* i2c address & device id */ |
| 896 | &drxj_default_comm_attr_g, /* demod common attributes */ |
| 897 | &drxj_data_g /* demod device specific attributes */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 898 | }; |
| 899 | |
| 900 | /** |
| 901 | * \brief Default audio data structure for DRK demodulator instance. |
| 902 | * |
| 903 | * This structure is DRXK specific. |
| 904 | * |
| 905 | */ |
Fengguang Wu | c4cfb29 | 2014-03-09 09:08:30 -0300 | [diff] [blame] | 906 | static struct drx_aud_data drxj_default_aud_data_g = { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 907 | false, /* audio_is_active */ |
| 908 | DRX_AUD_STANDARD_AUTO, /* audio_standard */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 909 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 910 | /* i2sdata */ |
| 911 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 912 | false, /* output_enable */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 913 | 48000, /* frequency */ |
| 914 | DRX_I2S_MODE_MASTER, /* mode */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 915 | DRX_I2S_WORDLENGTH_32, /* word_length */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 916 | DRX_I2S_POLARITY_RIGHT, /* polarity */ |
| 917 | DRX_I2S_FORMAT_WS_WITH_DATA /* format */ |
| 918 | }, |
| 919 | /* volume */ |
| 920 | { |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 921 | true, /* mute; */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 922 | 0, /* volume */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 923 | DRX_AUD_AVC_OFF, /* avc_mode */ |
| 924 | 0, /* avc_ref_level */ |
| 925 | DRX_AUD_AVC_MAX_GAIN_12DB, /* avc_max_gain */ |
| 926 | DRX_AUD_AVC_MAX_ATTEN_24DB, /* avc_max_atten */ |
| 927 | 0, /* strength_left */ |
| 928 | 0 /* strength_right */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 929 | }, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 930 | DRX_AUD_AUTO_SOUND_SELECT_ON_CHANGE_ON, /* auto_sound */ |
| 931 | /* ass_thresholds */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 932 | { |
| 933 | 440, /* A2 */ |
| 934 | 12, /* BTSC */ |
| 935 | 700, /* NICAM */ |
| 936 | }, |
| 937 | /* carrier */ |
| 938 | { |
| 939 | /* a */ |
| 940 | { |
| 941 | 42, /* thres */ |
| 942 | DRX_NO_CARRIER_NOISE, /* opt */ |
| 943 | 0, /* shift */ |
| 944 | 0 /* dco */ |
| 945 | }, |
| 946 | /* b */ |
| 947 | { |
| 948 | 42, /* thres */ |
| 949 | DRX_NO_CARRIER_MUTE, /* opt */ |
| 950 | 0, /* shift */ |
| 951 | 0 /* dco */ |
| 952 | }, |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 953 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 954 | }, |
| 955 | /* mixer */ |
| 956 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 957 | DRX_AUD_SRC_STEREO_OR_A, /* source_i2s */ |
| 958 | DRX_AUD_I2S_MATRIX_STEREO, /* matrix_i2s */ |
| 959 | DRX_AUD_FM_MATRIX_SOUND_A /* matrix_fm */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 960 | }, |
| 961 | DRX_AUD_DEVIATION_NORMAL, /* deviation */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 962 | DRX_AUD_AVSYNC_OFF, /* av_sync */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 963 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 964 | /* prescale */ |
| 965 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 966 | DRX_AUD_MAX_FM_DEVIATION, /* fm_deviation */ |
| 967 | DRX_AUD_MAX_NICAM_PRESCALE /* nicam_gain */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 968 | }, |
| 969 | DRX_AUD_FM_DEEMPH_75US, /* deemph */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 970 | DRX_BTSC_STEREO, /* btsc_detect */ |
| 971 | 0, /* rds_data_counter */ |
| 972 | false /* rds_data_present */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 973 | }; |
| 974 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 975 | /*----------------------------------------------------------------------------- |
| 976 | STRUCTURES |
| 977 | ----------------------------------------------------------------------------*/ |
Mauro Carvalho Chehab | 60d3603 | 2014-01-17 07:00:31 -0300 | [diff] [blame] | 978 | struct drxjeq_stat { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 979 | u16 eq_mse; |
| 980 | u8 eq_mode; |
| 981 | u8 eq_ctrl; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 982 | u8 eq_stat; |
| 983 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 984 | |
| 985 | /* HI command */ |
Mauro Carvalho Chehab | 60d3603 | 2014-01-17 07:00:31 -0300 | [diff] [blame] | 986 | struct drxj_hi_cmd { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 987 | u16 cmd; |
| 988 | u16 param1; |
| 989 | u16 param2; |
| 990 | u16 param3; |
| 991 | u16 param4; |
| 992 | u16 param5; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 993 | u16 param6; |
| 994 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 995 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 996 | /*============================================================================*/ |
| 997 | /*=== MICROCODE RELATED STRUCTURES ===========================================*/ |
| 998 | /*============================================================================*/ |
| 999 | |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 1000 | /** |
| 1001 | * struct drxu_code_block_hdr - Structure of the microcode block headers |
| 1002 | * |
| 1003 | * @addr: Destination address of the data in this block |
| 1004 | * @size: Size of the block data following this header counted in |
| 1005 | * 16 bits words |
| 1006 | * @CRC: CRC value of the data block, only valid if CRC flag is |
| 1007 | * set. |
| 1008 | */ |
Mauro Carvalho Chehab | 60d3603 | 2014-01-17 07:00:31 -0300 | [diff] [blame] | 1009 | struct drxu_code_block_hdr { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1010 | u32 addr; |
| 1011 | u16 size; |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 1012 | u16 flags; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 1013 | u16 CRC; |
| 1014 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1015 | |
| 1016 | /*----------------------------------------------------------------------------- |
| 1017 | FUNCTIONS |
| 1018 | ----------------------------------------------------------------------------*/ |
| 1019 | /* Some prototypes */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 1020 | static int |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1021 | hi_command(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 60d3603 | 2014-01-17 07:00:31 -0300 | [diff] [blame] | 1022 | const struct drxj_hi_cmd *cmd, u16 *result); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1023 | |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 1024 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 1025 | ctrl_lock_status(struct drx_demod_instance *demod, enum drx_lock_status *lock_stat); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1026 | |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 1027 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 1028 | ctrl_power_mode(struct drx_demod_instance *demod, enum drx_power_mode *mode); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1029 | |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 1030 | static int power_down_aud(struct drx_demod_instance *demod); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1031 | |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 1032 | static int |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 1033 | ctrl_set_cfg_pre_saw(struct drx_demod_instance *demod, struct drxj_cfg_pre_saw *pre_saw); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1034 | |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 1035 | static int |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 1036 | ctrl_set_cfg_afe_gain(struct drx_demod_instance *demod, struct drxj_cfg_afe_gain *afe_gain); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1037 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1038 | /*============================================================================*/ |
| 1039 | /*============================================================================*/ |
| 1040 | /*== HELPER FUNCTIONS ==*/ |
| 1041 | /*============================================================================*/ |
| 1042 | /*============================================================================*/ |
| 1043 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1044 | |
| 1045 | /*============================================================================*/ |
| 1046 | |
| 1047 | /* |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1048 | * \fn u32 frac28(u32 N, u32 D) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1049 | * \brief Compute: (1<<28)*N/D |
| 1050 | * \param N 32 bits |
| 1051 | * \param D 32 bits |
| 1052 | * \return (1<<28)*N/D |
| 1053 | * This function is used to avoid floating-point calculations as they may |
| 1054 | * not be present on the target platform. |
| 1055 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1056 | * frac28 performs an unsigned 28/28 bits division to 32-bit fixed point |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1057 | * fraction used for setting the Frequency Shifter registers. |
| 1058 | * N and D can hold numbers up to width: 28-bits. |
| 1059 | * The 4 bits integer part and the 28 bits fractional part are calculated. |
| 1060 | |
| 1061 | * Usage condition: ((1<<28)*n)/d < ((1<<32)-1) => (n/d) < 15.999 |
| 1062 | |
| 1063 | * N: 0...(1<<28)-1 = 268435454 |
| 1064 | * D: 0...(1<<28)-1 |
| 1065 | * Q: 0...(1<<32)-1 |
| 1066 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1067 | static u32 frac28(u32 N, u32 D) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1068 | { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1069 | int i = 0; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1070 | u32 Q1 = 0; |
| 1071 | u32 R0 = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1072 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1073 | R0 = (N % D) << 4; /* 32-28 == 4 shifts possible at max */ |
| 1074 | Q1 = N / D; /* integer part, only the 4 least significant bits |
| 1075 | will be visible in the result */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1076 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1077 | /* division using radix 16, 7 nibbles in the result */ |
| 1078 | for (i = 0; i < 7; i++) { |
| 1079 | Q1 = (Q1 << 4) | R0 / D; |
| 1080 | R0 = (R0 % D) << 4; |
| 1081 | } |
| 1082 | /* rounding */ |
| 1083 | if ((R0 >> 3) >= D) |
| 1084 | Q1++; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1085 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1086 | return Q1; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1090 | * \fn u32 log1_times100( u32 x) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1091 | * \brief Compute: 100*log10(x) |
| 1092 | * \param x 32 bits |
| 1093 | * \return 100*log10(x) |
| 1094 | * |
| 1095 | * 100*log10(x) |
| 1096 | * = 100*(log2(x)/log2(10))) |
| 1097 | * = (100*(2^15)*log2(x))/((2^15)*log2(10)) |
| 1098 | * = ((200*(2^15)*log2(x))/((2^15)*log2(10)))/2 |
| 1099 | * = ((200*(2^15)*(log2(x/y)+log2(y)))/((2^15)*log2(10)))/2 |
| 1100 | * = ((200*(2^15)*log2(x/y))+(200*(2^15)*log2(y)))/((2^15)*log2(10)))/2 |
| 1101 | * |
| 1102 | * where y = 2^k and 1<= (x/y) < 2 |
| 1103 | */ |
| 1104 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1105 | static u32 log1_times100(u32 x) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1106 | { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1107 | static const u8 scale = 15; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1108 | static const u8 index_width = 5; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1109 | /* |
| 1110 | log2lut[n] = (1<<scale) * 200 * log2( 1.0 + ( (1.0/(1<<INDEXWIDTH)) * n )) |
| 1111 | 0 <= n < ((1<<INDEXWIDTH)+1) |
| 1112 | */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1113 | |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1114 | static const u32 log2lut[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1115 | 0, /* 0.000000 */ |
| 1116 | 290941, /* 290941.300628 */ |
| 1117 | 573196, /* 573196.476418 */ |
| 1118 | 847269, /* 847269.179851 */ |
| 1119 | 1113620, /* 1113620.489452 */ |
| 1120 | 1372674, /* 1372673.576986 */ |
| 1121 | 1624818, /* 1624817.752104 */ |
| 1122 | 1870412, /* 1870411.981536 */ |
| 1123 | 2109788, /* 2109787.962654 */ |
| 1124 | 2343253, /* 2343252.817465 */ |
| 1125 | 2571091, /* 2571091.461923 */ |
| 1126 | 2793569, /* 2793568.696416 */ |
| 1127 | 3010931, /* 3010931.055901 */ |
| 1128 | 3223408, /* 3223408.452106 */ |
| 1129 | 3431216, /* 3431215.635215 */ |
| 1130 | 3634553, /* 3634553.498355 */ |
| 1131 | 3833610, /* 3833610.244726 */ |
| 1132 | 4028562, /* 4028562.434393 */ |
| 1133 | 4219576, /* 4219575.925308 */ |
| 1134 | 4406807, /* 4406806.721144 */ |
| 1135 | 4590402, /* 4590401.736809 */ |
| 1136 | 4770499, /* 4770499.491025 */ |
| 1137 | 4947231, /* 4947230.734179 */ |
| 1138 | 5120719, /* 5120719.018555 */ |
| 1139 | 5291081, /* 5291081.217197 */ |
| 1140 | 5458428, /* 5458427.996830 */ |
| 1141 | 5622864, /* 5622864.249668 */ |
| 1142 | 5784489, /* 5784489.488298 */ |
| 1143 | 5943398, /* 5943398.207380 */ |
| 1144 | 6099680, /* 6099680.215452 */ |
| 1145 | 6253421, /* 6253420.939751 */ |
| 1146 | 6404702, /* 6404701.706649 */ |
| 1147 | 6553600, /* 6553600.000000 */ |
| 1148 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1149 | |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1150 | u8 i = 0; |
| 1151 | u32 y = 0; |
| 1152 | u32 d = 0; |
| 1153 | u32 k = 0; |
| 1154 | u32 r = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1155 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1156 | if (x == 0) |
Mauro Carvalho Chehab | 64e49cb | 2014-01-17 06:28:28 -0300 | [diff] [blame] | 1157 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1158 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1159 | /* Scale x (normalize) */ |
| 1160 | /* computing y in log(x/y) = log(x) - log(y) */ |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1161 | if ((x & (((u32) (-1)) << (scale + 1))) == 0) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1162 | for (k = scale; k > 0; k--) { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1163 | if (x & (((u32) 1) << scale)) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1164 | break; |
| 1165 | x <<= 1; |
| 1166 | } |
| 1167 | } else { |
| 1168 | for (k = scale; k < 31; k++) { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1169 | if ((x & (((u32) (-1)) << (scale + 1))) == 0) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1170 | break; |
| 1171 | x >>= 1; |
| 1172 | } |
| 1173 | } |
| 1174 | /* |
| 1175 | Now x has binary point between bit[scale] and bit[scale-1] |
| 1176 | and 1.0 <= x < 2.0 */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1177 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1178 | /* correction for divison: log(x) = log(x/y)+log(y) */ |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1179 | y = k * ((((u32) 1) << scale) * 200); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1180 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1181 | /* remove integer part */ |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1182 | x &= ((((u32) 1) << scale) - 1); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1183 | /* get index */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1184 | i = (u8) (x >> (scale - index_width)); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1185 | /* compute delta (x-a) */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1186 | d = x & ((((u32) 1) << (scale - index_width)) - 1); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1187 | /* compute log, multiplication ( d* (.. )) must be within range ! */ |
| 1188 | y += log2lut[i] + |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1189 | ((d * (log2lut[i + 1] - log2lut[i])) >> (scale - index_width)); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1190 | /* Conver to log10() */ |
| 1191 | y /= 108853; /* (log2(10) << scale) */ |
| 1192 | r = (y >> 1); |
| 1193 | /* rounding */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 1194 | if (y & ((u32)1)) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1195 | r++; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1196 | |
Mauro Carvalho Chehab | 64e49cb | 2014-01-17 06:28:28 -0300 | [diff] [blame] | 1197 | return r; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1198 | |
| 1199 | } |
| 1200 | |
| 1201 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1202 | * \fn u32 frac_times1e6( u16 N, u32 D) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1203 | * \brief Compute: (N/D) * 1000000. |
| 1204 | * \param N nominator 16-bits. |
| 1205 | * \param D denominator 32-bits. |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1206 | * \return u32 |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1207 | * \retval ((N/D) * 1000000), 32 bits |
| 1208 | * |
| 1209 | * No check on D=0! |
| 1210 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1211 | static u32 frac_times1e6(u32 N, u32 D) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1212 | { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1213 | u32 remainder = 0; |
| 1214 | u32 frac = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1215 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1216 | /* |
| 1217 | frac = (N * 1000000) / D |
| 1218 | To let it fit in a 32 bits computation: |
| 1219 | frac = (N * (1000000 >> 4)) / (D >> 4) |
| 1220 | This would result in a problem in case D < 16 (div by 0). |
| 1221 | So we do it more elaborate as shown below. |
| 1222 | */ |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1223 | frac = (((u32) N) * (1000000 >> 4)) / D; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1224 | frac <<= 4; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1225 | remainder = (((u32) N) * (1000000 >> 4)) % D; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1226 | remainder <<= 4; |
| 1227 | frac += remainder / D; |
| 1228 | remainder = remainder % D; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 1229 | if ((remainder * 2) > D) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1230 | frac++; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1231 | |
Mauro Carvalho Chehab | 64e49cb | 2014-01-17 06:28:28 -0300 | [diff] [blame] | 1232 | return frac; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | /*============================================================================*/ |
| 1236 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1237 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1238 | /** |
| 1239 | * \brief Values for NICAM prescaler gain. Computed from dB to integer |
| 1240 | * and rounded. For calc used formula: 16*10^(prescaleGain[dB]/20). |
| 1241 | * |
| 1242 | */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 1243 | static const u16 nicam_presc_table_val[43] = { |
| 1244 | 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1245 | 5, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16, |
| 1246 | 18, 20, 23, 25, 28, 32, 36, 40, 45, |
| 1247 | 51, 57, 64, 71, 80, 90, 101, 113, 127 |
| 1248 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1249 | |
| 1250 | /*============================================================================*/ |
| 1251 | /*== END HELPER FUNCTIONS ==*/ |
| 1252 | /*============================================================================*/ |
| 1253 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1254 | /*============================================================================*/ |
| 1255 | /*============================================================================*/ |
| 1256 | /*== DRXJ DAP FUNCTIONS ==*/ |
| 1257 | /*============================================================================*/ |
| 1258 | /*============================================================================*/ |
| 1259 | |
| 1260 | /* |
| 1261 | This layer takes care of some device specific register access protocols: |
| 1262 | -conversion to short address format |
| 1263 | -access to audio block |
| 1264 | This layer is placed between the drx_dap_fasi and the rest of the drxj |
| 1265 | specific implementation. This layer can use address map knowledge whereas |
| 1266 | dap_fasi may not use memory map knowledge. |
| 1267 | |
| 1268 | * For audio currently only 16 bits read and write register access is |
| 1269 | supported. More is not needed. RMW and 32 or 8 bit access on audio |
| 1270 | registers will have undefined behaviour. Flags (RMW, CRC reset, broadcast |
| 1271 | single/multi master) will be ignored. |
| 1272 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1273 | TODO: check ignoring single/multimaster is ok for AUD access ? |
| 1274 | */ |
| 1275 | |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 1276 | #define DRXJ_ISAUDWRITE(addr) (((((addr)>>16)&1) == 1) ? true : false) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1277 | #define DRXJ_DAP_AUDTRIF_TIMEOUT 80 /* millisec */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1278 | /*============================================================================*/ |
| 1279 | |
| 1280 | /** |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 1281 | * \fn bool is_handled_by_aud_tr_if( u32 addr ) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1282 | * \brief Check if this address is handled by the audio token ring interface. |
| 1283 | * \param addr |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 1284 | * \return bool |
| 1285 | * \retval true Yes, handled by audio token ring interface |
| 1286 | * \retval false No, not handled by audio token ring interface |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1287 | * |
| 1288 | */ |
| 1289 | static |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 1290 | bool is_handled_by_aud_tr_if(u32 addr) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1291 | { |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 1292 | bool retval = false; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1293 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1294 | if ((DRXDAP_FASI_ADDR2BLOCK(addr) == 4) && |
| 1295 | (DRXDAP_FASI_ADDR2BANK(addr) > 1) && |
| 1296 | (DRXDAP_FASI_ADDR2BANK(addr) < 6)) { |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 1297 | retval = true; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1298 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1299 | |
Mauro Carvalho Chehab | 64e49cb | 2014-01-17 06:28:28 -0300 | [diff] [blame] | 1300 | return retval; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | /*============================================================================*/ |
| 1304 | |
Mauro Carvalho Chehab | 73b3fc3 | 2014-01-27 02:14:14 -0300 | [diff] [blame] | 1305 | int drxbsp_i2c_write_read(struct i2c_device_addr *w_dev_addr, |
| 1306 | u16 w_count, |
| 1307 | u8 *wData, |
| 1308 | struct i2c_device_addr *r_dev_addr, |
| 1309 | u16 r_count, u8 *r_data) |
| 1310 | { |
| 1311 | struct drx39xxj_state *state; |
| 1312 | struct i2c_msg msg[2]; |
| 1313 | unsigned int num_msgs; |
| 1314 | |
| 1315 | if (w_dev_addr == NULL) { |
| 1316 | /* Read only */ |
| 1317 | state = r_dev_addr->user_data; |
| 1318 | msg[0].addr = r_dev_addr->i2c_addr >> 1; |
| 1319 | msg[0].flags = I2C_M_RD; |
| 1320 | msg[0].buf = r_data; |
| 1321 | msg[0].len = r_count; |
| 1322 | num_msgs = 1; |
| 1323 | } else if (r_dev_addr == NULL) { |
| 1324 | /* Write only */ |
| 1325 | state = w_dev_addr->user_data; |
| 1326 | msg[0].addr = w_dev_addr->i2c_addr >> 1; |
| 1327 | msg[0].flags = 0; |
| 1328 | msg[0].buf = wData; |
| 1329 | msg[0].len = w_count; |
| 1330 | num_msgs = 1; |
| 1331 | } else { |
| 1332 | /* Both write and read */ |
| 1333 | state = w_dev_addr->user_data; |
| 1334 | msg[0].addr = w_dev_addr->i2c_addr >> 1; |
| 1335 | msg[0].flags = 0; |
| 1336 | msg[0].buf = wData; |
| 1337 | msg[0].len = w_count; |
| 1338 | msg[1].addr = r_dev_addr->i2c_addr >> 1; |
| 1339 | msg[1].flags = I2C_M_RD; |
| 1340 | msg[1].buf = r_data; |
| 1341 | msg[1].len = r_count; |
| 1342 | num_msgs = 2; |
| 1343 | } |
| 1344 | |
| 1345 | if (state->i2c == NULL) { |
| 1346 | pr_err("i2c was zero, aborting\n"); |
| 1347 | return 0; |
| 1348 | } |
| 1349 | if (i2c_transfer(state->i2c, msg, num_msgs) != num_msgs) { |
| 1350 | pr_warn("drx3933: I2C write/read failed\n"); |
| 1351 | return -EREMOTEIO; |
| 1352 | } |
| 1353 | |
Mauro Carvalho Chehab | 73b3fc3 | 2014-01-27 02:14:14 -0300 | [diff] [blame] | 1354 | #ifdef DJH_DEBUG |
Shuah Khan | 1ad77b5 | 2014-02-28 18:23:02 -0300 | [diff] [blame] | 1355 | if (w_dev_addr == NULL || r_dev_addr == NULL) |
| 1356 | return 0; |
Mauro Carvalho Chehab | 73b3fc3 | 2014-01-27 02:14:14 -0300 | [diff] [blame] | 1357 | |
Shuah Khan | 1ad77b5 | 2014-02-28 18:23:02 -0300 | [diff] [blame] | 1358 | state = w_dev_addr->user_data; |
| 1359 | |
| 1360 | if (state->i2c == NULL) |
| 1361 | return 0; |
| 1362 | |
| 1363 | msg[0].addr = w_dev_addr->i2c_addr; |
| 1364 | msg[0].flags = 0; |
| 1365 | msg[0].buf = wData; |
| 1366 | msg[0].len = w_count; |
| 1367 | msg[1].addr = r_dev_addr->i2c_addr; |
| 1368 | msg[1].flags = I2C_M_RD; |
| 1369 | msg[1].buf = r_data; |
| 1370 | msg[1].len = r_count; |
| 1371 | num_msgs = 2; |
Mauro Carvalho Chehab | 73b3fc3 | 2014-01-27 02:14:14 -0300 | [diff] [blame] | 1372 | |
Shuah Khan | 6c955b8 | 2014-02-28 18:23:00 -0300 | [diff] [blame] | 1373 | pr_debug("drx3933 i2c operation addr=%x i2c=%p, wc=%x rc=%x\n", |
Mauro Carvalho Chehab | 73b3fc3 | 2014-01-27 02:14:14 -0300 | [diff] [blame] | 1374 | w_dev_addr->i2c_addr, state->i2c, w_count, r_count); |
| 1375 | |
| 1376 | if (i2c_transfer(state->i2c, msg, 2) != 2) { |
| 1377 | pr_warn("drx3933: I2C write/read failed\n"); |
| 1378 | return -EREMOTEIO; |
| 1379 | } |
| 1380 | #endif |
| 1381 | return 0; |
| 1382 | } |
| 1383 | |
| 1384 | /*============================================================================*/ |
| 1385 | |
| 1386 | /****************************** |
| 1387 | * |
| 1388 | * int drxdap_fasi_read_block ( |
| 1389 | * struct i2c_device_addr *dev_addr, -- address of I2C device |
| 1390 | * u32 addr, -- address of chip register/memory |
| 1391 | * u16 datasize, -- number of bytes to read |
| 1392 | * u8 *data, -- data to receive |
| 1393 | * u32 flags) -- special device flags |
| 1394 | * |
| 1395 | * Read block data from chip address. Because the chip is word oriented, |
| 1396 | * the number of bytes to read must be even. |
| 1397 | * |
| 1398 | * Make sure that the buffer to receive the data is large enough. |
| 1399 | * |
| 1400 | * Although this function expects an even number of bytes, it is still byte |
| 1401 | * oriented, and the data read back is NOT translated to the endianness of |
| 1402 | * the target platform. |
| 1403 | * |
| 1404 | * Output: |
| 1405 | * - 0 if reading was successful |
| 1406 | * in that case: data read is in *data. |
| 1407 | * - -EIO if anything went wrong |
| 1408 | * |
| 1409 | ******************************/ |
| 1410 | |
| 1411 | static int drxdap_fasi_read_block(struct i2c_device_addr *dev_addr, |
| 1412 | u32 addr, |
| 1413 | u16 datasize, |
| 1414 | u8 *data, u32 flags) |
| 1415 | { |
| 1416 | u8 buf[4]; |
| 1417 | u16 bufx; |
| 1418 | int rc; |
| 1419 | u16 overhead_size = 0; |
| 1420 | |
| 1421 | /* Check parameters ******************************************************* */ |
| 1422 | if (dev_addr == NULL) |
| 1423 | return -EINVAL; |
| 1424 | |
| 1425 | overhead_size = (IS_I2C_10BIT(dev_addr->i2c_addr) ? 2 : 1) + |
| 1426 | (DRXDAP_FASI_LONG_FORMAT(addr) ? 4 : 2); |
| 1427 | |
| 1428 | if ((DRXDAP_FASI_OFFSET_TOO_LARGE(addr)) || |
| 1429 | ((!(DRXDAPFASI_LONG_ADDR_ALLOWED)) && |
| 1430 | DRXDAP_FASI_LONG_FORMAT(addr)) || |
| 1431 | (overhead_size > (DRXDAP_MAX_WCHUNKSIZE)) || |
| 1432 | ((datasize != 0) && (data == NULL)) || ((datasize & 1) == 1)) { |
| 1433 | return -EINVAL; |
| 1434 | } |
| 1435 | |
| 1436 | /* ReadModifyWrite & mode flag bits are not allowed */ |
| 1437 | flags &= (~DRXDAP_FASI_RMW & ~DRXDAP_FASI_MODEFLAGS); |
| 1438 | #if DRXDAP_SINGLE_MASTER |
| 1439 | flags |= DRXDAP_FASI_SINGLE_MASTER; |
| 1440 | #endif |
| 1441 | |
| 1442 | /* Read block from I2C **************************************************** */ |
| 1443 | do { |
| 1444 | u16 todo = (datasize < DRXDAP_MAX_RCHUNKSIZE ? |
| 1445 | datasize : DRXDAP_MAX_RCHUNKSIZE); |
| 1446 | |
| 1447 | bufx = 0; |
| 1448 | |
| 1449 | addr &= ~DRXDAP_FASI_FLAGS; |
| 1450 | addr |= flags; |
| 1451 | |
| 1452 | #if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 1) && (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1)) |
| 1453 | /* short format address preferred but long format otherwise */ |
| 1454 | if (DRXDAP_FASI_LONG_FORMAT(addr)) { |
| 1455 | #endif |
| 1456 | #if (DRXDAPFASI_LONG_ADDR_ALLOWED == 1) |
| 1457 | buf[bufx++] = (u8) (((addr << 1) & 0xFF) | 0x01); |
| 1458 | buf[bufx++] = (u8) ((addr >> 16) & 0xFF); |
| 1459 | buf[bufx++] = (u8) ((addr >> 24) & 0xFF); |
| 1460 | buf[bufx++] = (u8) ((addr >> 7) & 0xFF); |
| 1461 | #endif |
| 1462 | #if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 1) && (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1)) |
| 1463 | } else { |
| 1464 | #endif |
| 1465 | #if (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1) |
| 1466 | buf[bufx++] = (u8) ((addr << 1) & 0xFF); |
| 1467 | buf[bufx++] = |
| 1468 | (u8) (((addr >> 16) & 0x0F) | |
| 1469 | ((addr >> 18) & 0xF0)); |
| 1470 | #endif |
| 1471 | #if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 1) && (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1)) |
| 1472 | } |
| 1473 | #endif |
| 1474 | |
| 1475 | #if DRXDAP_SINGLE_MASTER |
| 1476 | /* |
| 1477 | * In single master mode, split the read and write actions. |
| 1478 | * No special action is needed for write chunks here. |
| 1479 | */ |
Mauro Carvalho Chehab | db5657c | 2014-03-09 09:32:58 -0300 | [diff] [blame] | 1480 | rc = drxbsp_i2c_write_read(dev_addr, bufx, buf, |
| 1481 | NULL, 0, NULL); |
Mauro Carvalho Chehab | 73b3fc3 | 2014-01-27 02:14:14 -0300 | [diff] [blame] | 1482 | if (rc == 0) |
Mauro Carvalho Chehab | db5657c | 2014-03-09 09:32:58 -0300 | [diff] [blame] | 1483 | rc = drxbsp_i2c_write_read(NULL, 0, NULL, dev_addr, todo, data); |
Mauro Carvalho Chehab | 73b3fc3 | 2014-01-27 02:14:14 -0300 | [diff] [blame] | 1484 | #else |
| 1485 | /* In multi master mode, do everything in one RW action */ |
| 1486 | rc = drxbsp_i2c_write_read(dev_addr, bufx, buf, dev_addr, todo, |
| 1487 | data); |
| 1488 | #endif |
| 1489 | data += todo; |
| 1490 | addr += (todo >> 1); |
| 1491 | datasize -= todo; |
| 1492 | } while (datasize && rc == 0); |
| 1493 | |
| 1494 | return rc; |
| 1495 | } |
| 1496 | |
| 1497 | |
| 1498 | /****************************** |
| 1499 | * |
| 1500 | * int drxdap_fasi_read_reg16 ( |
| 1501 | * struct i2c_device_addr *dev_addr, -- address of I2C device |
| 1502 | * u32 addr, -- address of chip register/memory |
| 1503 | * u16 *data, -- data to receive |
| 1504 | * u32 flags) -- special device flags |
| 1505 | * |
| 1506 | * Read one 16-bit register or memory location. The data received back is |
| 1507 | * converted back to the target platform's endianness. |
| 1508 | * |
| 1509 | * Output: |
| 1510 | * - 0 if reading was successful |
| 1511 | * in that case: read data is at *data |
| 1512 | * - -EIO if anything went wrong |
| 1513 | * |
| 1514 | ******************************/ |
| 1515 | |
| 1516 | static int drxdap_fasi_read_reg16(struct i2c_device_addr *dev_addr, |
| 1517 | u32 addr, |
| 1518 | u16 *data, u32 flags) |
| 1519 | { |
| 1520 | u8 buf[sizeof(*data)]; |
| 1521 | int rc; |
| 1522 | |
| 1523 | if (!data) |
| 1524 | return -EINVAL; |
| 1525 | |
| 1526 | rc = drxdap_fasi_read_block(dev_addr, addr, sizeof(*data), buf, flags); |
| 1527 | *data = buf[0] + (((u16) buf[1]) << 8); |
| 1528 | return rc; |
| 1529 | } |
| 1530 | |
| 1531 | /****************************** |
| 1532 | * |
| 1533 | * int drxdap_fasi_read_reg32 ( |
| 1534 | * struct i2c_device_addr *dev_addr, -- address of I2C device |
| 1535 | * u32 addr, -- address of chip register/memory |
| 1536 | * u32 *data, -- data to receive |
| 1537 | * u32 flags) -- special device flags |
| 1538 | * |
| 1539 | * Read one 32-bit register or memory location. The data received back is |
| 1540 | * converted back to the target platform's endianness. |
| 1541 | * |
| 1542 | * Output: |
| 1543 | * - 0 if reading was successful |
| 1544 | * in that case: read data is at *data |
| 1545 | * - -EIO if anything went wrong |
| 1546 | * |
| 1547 | ******************************/ |
| 1548 | |
| 1549 | static int drxdap_fasi_read_reg32(struct i2c_device_addr *dev_addr, |
| 1550 | u32 addr, |
| 1551 | u32 *data, u32 flags) |
| 1552 | { |
| 1553 | u8 buf[sizeof(*data)]; |
| 1554 | int rc; |
| 1555 | |
| 1556 | if (!data) |
| 1557 | return -EINVAL; |
| 1558 | |
| 1559 | rc = drxdap_fasi_read_block(dev_addr, addr, sizeof(*data), buf, flags); |
| 1560 | *data = (((u32) buf[0]) << 0) + |
| 1561 | (((u32) buf[1]) << 8) + |
| 1562 | (((u32) buf[2]) << 16) + (((u32) buf[3]) << 24); |
| 1563 | return rc; |
| 1564 | } |
| 1565 | |
| 1566 | /****************************** |
| 1567 | * |
| 1568 | * int drxdap_fasi_write_block ( |
| 1569 | * struct i2c_device_addr *dev_addr, -- address of I2C device |
| 1570 | * u32 addr, -- address of chip register/memory |
| 1571 | * u16 datasize, -- number of bytes to read |
| 1572 | * u8 *data, -- data to receive |
| 1573 | * u32 flags) -- special device flags |
| 1574 | * |
| 1575 | * Write block data to chip address. Because the chip is word oriented, |
| 1576 | * the number of bytes to write must be even. |
| 1577 | * |
| 1578 | * Although this function expects an even number of bytes, it is still byte |
| 1579 | * oriented, and the data being written is NOT translated from the endianness of |
| 1580 | * the target platform. |
| 1581 | * |
| 1582 | * Output: |
| 1583 | * - 0 if writing was successful |
| 1584 | * - -EIO if anything went wrong |
| 1585 | * |
| 1586 | ******************************/ |
| 1587 | |
| 1588 | static int drxdap_fasi_write_block(struct i2c_device_addr *dev_addr, |
| 1589 | u32 addr, |
| 1590 | u16 datasize, |
| 1591 | u8 *data, u32 flags) |
| 1592 | { |
| 1593 | u8 buf[DRXDAP_MAX_WCHUNKSIZE]; |
| 1594 | int st = -EIO; |
| 1595 | int first_err = 0; |
| 1596 | u16 overhead_size = 0; |
| 1597 | u16 block_size = 0; |
| 1598 | |
| 1599 | /* Check parameters ******************************************************* */ |
| 1600 | if (dev_addr == NULL) |
| 1601 | return -EINVAL; |
| 1602 | |
| 1603 | overhead_size = (IS_I2C_10BIT(dev_addr->i2c_addr) ? 2 : 1) + |
| 1604 | (DRXDAP_FASI_LONG_FORMAT(addr) ? 4 : 2); |
| 1605 | |
| 1606 | if ((DRXDAP_FASI_OFFSET_TOO_LARGE(addr)) || |
| 1607 | ((!(DRXDAPFASI_LONG_ADDR_ALLOWED)) && |
| 1608 | DRXDAP_FASI_LONG_FORMAT(addr)) || |
| 1609 | (overhead_size > (DRXDAP_MAX_WCHUNKSIZE)) || |
| 1610 | ((datasize != 0) && (data == NULL)) || ((datasize & 1) == 1)) |
| 1611 | return -EINVAL; |
| 1612 | |
| 1613 | flags &= DRXDAP_FASI_FLAGS; |
| 1614 | flags &= ~DRXDAP_FASI_MODEFLAGS; |
| 1615 | #if DRXDAP_SINGLE_MASTER |
| 1616 | flags |= DRXDAP_FASI_SINGLE_MASTER; |
| 1617 | #endif |
| 1618 | |
| 1619 | /* Write block to I2C ***************************************************** */ |
| 1620 | block_size = ((DRXDAP_MAX_WCHUNKSIZE) - overhead_size) & ~1; |
| 1621 | do { |
| 1622 | u16 todo = 0; |
| 1623 | u16 bufx = 0; |
| 1624 | |
| 1625 | /* Buffer device address */ |
| 1626 | addr &= ~DRXDAP_FASI_FLAGS; |
| 1627 | addr |= flags; |
| 1628 | #if (((DRXDAPFASI_LONG_ADDR_ALLOWED) == 1) && ((DRXDAPFASI_SHORT_ADDR_ALLOWED) == 1)) |
| 1629 | /* short format address preferred but long format otherwise */ |
| 1630 | if (DRXDAP_FASI_LONG_FORMAT(addr)) { |
| 1631 | #endif |
| 1632 | #if ((DRXDAPFASI_LONG_ADDR_ALLOWED) == 1) |
| 1633 | buf[bufx++] = (u8) (((addr << 1) & 0xFF) | 0x01); |
| 1634 | buf[bufx++] = (u8) ((addr >> 16) & 0xFF); |
| 1635 | buf[bufx++] = (u8) ((addr >> 24) & 0xFF); |
| 1636 | buf[bufx++] = (u8) ((addr >> 7) & 0xFF); |
| 1637 | #endif |
| 1638 | #if (((DRXDAPFASI_LONG_ADDR_ALLOWED) == 1) && ((DRXDAPFASI_SHORT_ADDR_ALLOWED) == 1)) |
| 1639 | } else { |
| 1640 | #endif |
| 1641 | #if ((DRXDAPFASI_SHORT_ADDR_ALLOWED) == 1) |
| 1642 | buf[bufx++] = (u8) ((addr << 1) & 0xFF); |
| 1643 | buf[bufx++] = |
| 1644 | (u8) (((addr >> 16) & 0x0F) | |
| 1645 | ((addr >> 18) & 0xF0)); |
| 1646 | #endif |
| 1647 | #if (((DRXDAPFASI_LONG_ADDR_ALLOWED) == 1) && ((DRXDAPFASI_SHORT_ADDR_ALLOWED) == 1)) |
| 1648 | } |
| 1649 | #endif |
| 1650 | |
| 1651 | /* |
| 1652 | In single master mode block_size can be 0. In such a case this I2C |
| 1653 | sequense will be visible: (1) write address {i2c addr, |
| 1654 | 4 bytes chip address} (2) write data {i2c addr, 4 bytes data } |
| 1655 | (3) write address (4) write data etc... |
| 1656 | Addres must be rewriten because HI is reset after data transport and |
| 1657 | expects an address. |
| 1658 | */ |
| 1659 | todo = (block_size < datasize ? block_size : datasize); |
| 1660 | if (todo == 0) { |
| 1661 | u16 overhead_size_i2c_addr = 0; |
| 1662 | u16 data_block_size = 0; |
| 1663 | |
| 1664 | overhead_size_i2c_addr = |
| 1665 | (IS_I2C_10BIT(dev_addr->i2c_addr) ? 2 : 1); |
| 1666 | data_block_size = |
| 1667 | (DRXDAP_MAX_WCHUNKSIZE - overhead_size_i2c_addr) & ~1; |
| 1668 | |
| 1669 | /* write device address */ |
| 1670 | st = drxbsp_i2c_write_read(dev_addr, |
| 1671 | (u16) (bufx), |
| 1672 | buf, |
| 1673 | (struct i2c_device_addr *)(NULL), |
| 1674 | 0, (u8 *)(NULL)); |
| 1675 | |
| 1676 | if ((st != 0) && (first_err == 0)) { |
| 1677 | /* at the end, return the first error encountered */ |
| 1678 | first_err = st; |
| 1679 | } |
| 1680 | bufx = 0; |
| 1681 | todo = |
| 1682 | (data_block_size < |
| 1683 | datasize ? data_block_size : datasize); |
| 1684 | } |
| 1685 | memcpy(&buf[bufx], data, todo); |
| 1686 | /* write (address if can do and) data */ |
| 1687 | st = drxbsp_i2c_write_read(dev_addr, |
| 1688 | (u16) (bufx + todo), |
| 1689 | buf, |
| 1690 | (struct i2c_device_addr *)(NULL), |
| 1691 | 0, (u8 *)(NULL)); |
| 1692 | |
| 1693 | if ((st != 0) && (first_err == 0)) { |
| 1694 | /* at the end, return the first error encountered */ |
| 1695 | first_err = st; |
| 1696 | } |
| 1697 | datasize -= todo; |
| 1698 | data += todo; |
| 1699 | addr += (todo >> 1); |
| 1700 | } while (datasize); |
| 1701 | |
| 1702 | return first_err; |
| 1703 | } |
| 1704 | |
| 1705 | /****************************** |
| 1706 | * |
| 1707 | * int drxdap_fasi_write_reg16 ( |
| 1708 | * struct i2c_device_addr *dev_addr, -- address of I2C device |
| 1709 | * u32 addr, -- address of chip register/memory |
| 1710 | * u16 data, -- data to send |
| 1711 | * u32 flags) -- special device flags |
| 1712 | * |
| 1713 | * Write one 16-bit register or memory location. The data being written is |
| 1714 | * converted from the target platform's endianness to little endian. |
| 1715 | * |
| 1716 | * Output: |
| 1717 | * - 0 if writing was successful |
| 1718 | * - -EIO if anything went wrong |
| 1719 | * |
| 1720 | ******************************/ |
| 1721 | |
| 1722 | static int drxdap_fasi_write_reg16(struct i2c_device_addr *dev_addr, |
| 1723 | u32 addr, |
| 1724 | u16 data, u32 flags) |
| 1725 | { |
| 1726 | u8 buf[sizeof(data)]; |
| 1727 | |
| 1728 | buf[0] = (u8) ((data >> 0) & 0xFF); |
| 1729 | buf[1] = (u8) ((data >> 8) & 0xFF); |
| 1730 | |
| 1731 | return drxdap_fasi_write_block(dev_addr, addr, sizeof(data), buf, flags); |
| 1732 | } |
| 1733 | |
| 1734 | /****************************** |
| 1735 | * |
| 1736 | * int drxdap_fasi_read_modify_write_reg16 ( |
| 1737 | * struct i2c_device_addr *dev_addr, -- address of I2C device |
| 1738 | * u32 waddr, -- address of chip register/memory |
| 1739 | * u32 raddr, -- chip address to read back from |
| 1740 | * u16 wdata, -- data to send |
| 1741 | * u16 *rdata) -- data to receive back |
| 1742 | * |
| 1743 | * Write 16-bit data, then read back the original contents of that location. |
| 1744 | * Requires long addressing format to be allowed. |
| 1745 | * |
| 1746 | * Before sending data, the data is converted to little endian. The |
| 1747 | * data received back is converted back to the target platform's endianness. |
| 1748 | * |
| 1749 | * WARNING: This function is only guaranteed to work if there is one |
| 1750 | * master on the I2C bus. |
| 1751 | * |
| 1752 | * Output: |
| 1753 | * - 0 if reading was successful |
| 1754 | * in that case: read back data is at *rdata |
| 1755 | * - -EIO if anything went wrong |
| 1756 | * |
| 1757 | ******************************/ |
| 1758 | |
| 1759 | static int drxdap_fasi_read_modify_write_reg16(struct i2c_device_addr *dev_addr, |
| 1760 | u32 waddr, |
| 1761 | u32 raddr, |
| 1762 | u16 wdata, u16 *rdata) |
| 1763 | { |
| 1764 | int rc = -EIO; |
| 1765 | |
| 1766 | #if (DRXDAPFASI_LONG_ADDR_ALLOWED == 1) |
| 1767 | if (rdata == NULL) |
| 1768 | return -EINVAL; |
| 1769 | |
| 1770 | rc = drxdap_fasi_write_reg16(dev_addr, waddr, wdata, DRXDAP_FASI_RMW); |
| 1771 | if (rc == 0) |
| 1772 | rc = drxdap_fasi_read_reg16(dev_addr, raddr, rdata, 0); |
| 1773 | #endif |
| 1774 | |
| 1775 | return rc; |
| 1776 | } |
| 1777 | |
| 1778 | /****************************** |
| 1779 | * |
| 1780 | * int drxdap_fasi_write_reg32 ( |
| 1781 | * struct i2c_device_addr *dev_addr, -- address of I2C device |
| 1782 | * u32 addr, -- address of chip register/memory |
| 1783 | * u32 data, -- data to send |
| 1784 | * u32 flags) -- special device flags |
| 1785 | * |
| 1786 | * Write one 32-bit register or memory location. The data being written is |
| 1787 | * converted from the target platform's endianness to little endian. |
| 1788 | * |
| 1789 | * Output: |
| 1790 | * - 0 if writing was successful |
| 1791 | * - -EIO if anything went wrong |
| 1792 | * |
| 1793 | ******************************/ |
| 1794 | |
| 1795 | static int drxdap_fasi_write_reg32(struct i2c_device_addr *dev_addr, |
| 1796 | u32 addr, |
| 1797 | u32 data, u32 flags) |
| 1798 | { |
| 1799 | u8 buf[sizeof(data)]; |
| 1800 | |
| 1801 | buf[0] = (u8) ((data >> 0) & 0xFF); |
| 1802 | buf[1] = (u8) ((data >> 8) & 0xFF); |
| 1803 | buf[2] = (u8) ((data >> 16) & 0xFF); |
| 1804 | buf[3] = (u8) ((data >> 24) & 0xFF); |
| 1805 | |
| 1806 | return drxdap_fasi_write_block(dev_addr, addr, sizeof(data), buf, flags); |
| 1807 | } |
| 1808 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1809 | /*============================================================================*/ |
| 1810 | |
| 1811 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1812 | * \fn int drxj_dap_rm_write_reg16short |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1813 | * \brief Read modify write 16 bits audio register using short format only. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1814 | * \param dev_addr |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1815 | * \param waddr Address to write to |
| 1816 | * \param raddr Address to read from (usually SIO_HI_RA_RAM_S0_RMWBUF__A) |
| 1817 | * \param wdata Data to write |
| 1818 | * \param rdata Buffer for data to read |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 1819 | * \return int |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1820 | * \retval 0 Succes |
| 1821 | * \retval -EIO Timeout, I2C error, illegal bank |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1822 | * |
| 1823 | * 16 bits register read modify write access using short addressing format only. |
| 1824 | * Requires knowledge of the registermap, thus device dependent. |
| 1825 | * Using DAP FASI directly to avoid endless recursion of RMWs to audio registers. |
| 1826 | * |
| 1827 | */ |
| 1828 | |
| 1829 | /* TODO correct define should be #if ( DRXDAPFASI_SHORT_ADDR_ALLOWED==1 ) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1830 | See comments drxj_dap_read_modify_write_reg16 */ |
Mauro Carvalho Chehab | 7ef6675 | 2014-01-16 11:08:15 -0300 | [diff] [blame] | 1831 | #if (DRXDAPFASI_LONG_ADDR_ALLOWED == 0) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1832 | static int drxj_dap_rm_write_reg16short(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 1833 | u32 waddr, |
| 1834 | u32 raddr, |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1835 | u16 wdata, u16 *rdata) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1836 | { |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 1837 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1838 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 1839 | if (rdata == NULL) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1840 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1841 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1842 | /* Set RMW flag */ |
Mauro Carvalho Chehab | 80bff4b | 2014-01-27 02:24:25 -0300 | [diff] [blame] | 1843 | rc = drxdap_fasi_write_reg16(dev_addr, |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1844 | SIO_HI_RA_RAM_S0_FLG_ACC__A, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1845 | SIO_HI_RA_RAM_S0_FLG_ACC_S0_RWM__M, |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1846 | 0x0000); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1847 | if (rc == 0) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1848 | /* Write new data: triggers RMW */ |
Mauro Carvalho Chehab | 80bff4b | 2014-01-27 02:24:25 -0300 | [diff] [blame] | 1849 | rc = drxdap_fasi_write_reg16(dev_addr, waddr, wdata, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1850 | 0x0000); |
| 1851 | } |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1852 | if (rc == 0) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1853 | /* Read old data */ |
Mauro Carvalho Chehab | 80bff4b | 2014-01-27 02:24:25 -0300 | [diff] [blame] | 1854 | rc = drxdap_fasi_read_reg16(dev_addr, raddr, rdata, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1855 | 0x0000); |
| 1856 | } |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1857 | if (rc == 0) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1858 | /* Reset RMW flag */ |
Mauro Carvalho Chehab | 80bff4b | 2014-01-27 02:24:25 -0300 | [diff] [blame] | 1859 | rc = drxdap_fasi_write_reg16(dev_addr, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1860 | SIO_HI_RA_RAM_S0_FLG_ACC__A, |
| 1861 | 0, 0x0000); |
| 1862 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1863 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1864 | return rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1865 | } |
| 1866 | #endif |
| 1867 | |
| 1868 | /*============================================================================*/ |
| 1869 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1870 | static int drxj_dap_read_modify_write_reg16(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 1871 | u32 waddr, |
| 1872 | u32 raddr, |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 1873 | u16 wdata, u16 *rdata) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1874 | { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1875 | /* TODO: correct short/long addressing format decision, |
| 1876 | now long format has higher prio then short because short also |
| 1877 | needs virt bnks (not impl yet) for certain audio registers */ |
Mauro Carvalho Chehab | 7ef6675 | 2014-01-16 11:08:15 -0300 | [diff] [blame] | 1878 | #if (DRXDAPFASI_LONG_ADDR_ALLOWED == 1) |
Mauro Carvalho Chehab | 80bff4b | 2014-01-27 02:24:25 -0300 | [diff] [blame] | 1879 | return drxdap_fasi_read_modify_write_reg16(dev_addr, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1880 | waddr, |
| 1881 | raddr, wdata, rdata); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1882 | #else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1883 | return drxj_dap_rm_write_reg16short(dev_addr, waddr, raddr, wdata, rdata); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1884 | #endif |
| 1885 | } |
| 1886 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1887 | |
| 1888 | /*============================================================================*/ |
| 1889 | |
| 1890 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1891 | * \fn int drxj_dap_read_aud_reg16 |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1892 | * \brief Read 16 bits audio register |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1893 | * \param dev_addr |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1894 | * \param addr |
| 1895 | * \param data |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 1896 | * \return int |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1897 | * \retval 0 Succes |
| 1898 | * \retval -EIO Timeout, I2C error, illegal bank |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1899 | * |
| 1900 | * 16 bits register read access via audio token ring interface. |
| 1901 | * |
| 1902 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1903 | static int drxj_dap_read_aud_reg16(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 1904 | u32 addr, u16 *data) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1905 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1906 | u32 start_timer = 0; |
| 1907 | u32 current_timer = 0; |
| 1908 | u32 delta_timer = 0; |
| 1909 | u16 tr_status = 0; |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1910 | int stat = -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1911 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1912 | /* No read possible for bank 3, return with error */ |
| 1913 | if (DRXDAP_FASI_ADDR2BANK(addr) == 3) { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1914 | stat = -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1915 | } else { |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 1916 | const u32 write_bit = ((dr_xaddr_t) 1) << 16; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1917 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1918 | /* Force reset write bit */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1919 | addr &= (~write_bit); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1920 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1921 | /* Set up read */ |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 1922 | start_timer = jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1923 | do { |
| 1924 | /* RMW to aud TR IF until request is granted or timeout */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1925 | stat = drxj_dap_read_modify_write_reg16(dev_addr, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1926 | addr, |
| 1927 | SIO_HI_RA_RAM_S0_RMWBUF__A, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1928 | 0x0000, &tr_status); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1929 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1930 | if (stat != 0) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1931 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1932 | |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 1933 | current_timer = jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1934 | delta_timer = current_timer - start_timer; |
| 1935 | if (delta_timer > DRXJ_DAP_AUDTRIF_TIMEOUT) { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1936 | stat = -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1937 | break; |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 1938 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1939 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1940 | } while (((tr_status & AUD_TOP_TR_CTR_FIFO_LOCK__M) == |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1941 | AUD_TOP_TR_CTR_FIFO_LOCK_LOCKED) || |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1942 | ((tr_status & AUD_TOP_TR_CTR_FIFO_FULL__M) == |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1943 | AUD_TOP_TR_CTR_FIFO_FULL_FULL)); |
| 1944 | } /* if ( DRXDAP_FASI_ADDR2BANK(addr)!=3 ) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1945 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1946 | /* Wait for read ready status or timeout */ |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1947 | if (stat == 0) { |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 1948 | start_timer = jiffies_to_msecs(jiffies); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1949 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1950 | while ((tr_status & AUD_TOP_TR_CTR_FIFO_RD_RDY__M) != |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1951 | AUD_TOP_TR_CTR_FIFO_RD_RDY_READY) { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1952 | stat = drxj_dap_read_reg16(dev_addr, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1953 | AUD_TOP_TR_CTR__A, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1954 | &tr_status, 0x0000); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1955 | if (stat != 0) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1956 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1957 | |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 1958 | current_timer = jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1959 | delta_timer = current_timer - start_timer; |
| 1960 | if (delta_timer > DRXJ_DAP_AUDTRIF_TIMEOUT) { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1961 | stat = -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1962 | break; |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 1963 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1964 | } /* while ( ... ) */ |
| 1965 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1966 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1967 | /* Read value */ |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1968 | if (stat == 0) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1969 | stat = drxj_dap_read_modify_write_reg16(dev_addr, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1970 | AUD_TOP_TR_RD_REG__A, |
| 1971 | SIO_HI_RA_RAM_S0_RMWBUF__A, |
| 1972 | 0x0000, data); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1973 | return stat; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | /*============================================================================*/ |
| 1977 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1978 | static int drxj_dap_read_reg16(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 1979 | u32 addr, |
| 1980 | u16 *data, u32 flags) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1981 | { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1982 | int stat = -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1983 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1984 | /* Check param */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 1985 | if ((dev_addr == NULL) || (data == NULL)) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 1986 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1987 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 1988 | if (is_handled_by_aud_tr_if(addr)) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1989 | stat = drxj_dap_read_aud_reg16(dev_addr, addr, data); |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 1990 | else |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 1991 | stat = drxdap_fasi_read_reg16(dev_addr, addr, data, flags); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1992 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 1993 | return stat; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1994 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1995 | /*============================================================================*/ |
| 1996 | |
| 1997 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 1998 | * \fn int drxj_dap_write_aud_reg16 |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 1999 | * \brief Write 16 bits audio register |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2000 | * \param dev_addr |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2001 | * \param addr |
| 2002 | * \param data |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 2003 | * \return int |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2004 | * \retval 0 Succes |
| 2005 | * \retval -EIO Timeout, I2C error, illegal bank |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2006 | * |
| 2007 | * 16 bits register write access via audio token ring interface. |
| 2008 | * |
| 2009 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2010 | static int drxj_dap_write_aud_reg16(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2011 | u32 addr, u16 data) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2012 | { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2013 | int stat = -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2014 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2015 | /* No write possible for bank 2, return with error */ |
| 2016 | if (DRXDAP_FASI_ADDR2BANK(addr) == 2) { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2017 | stat = -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2018 | } else { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2019 | u32 start_timer = 0; |
| 2020 | u32 current_timer = 0; |
| 2021 | u32 delta_timer = 0; |
| 2022 | u16 tr_status = 0; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2023 | const u32 write_bit = ((dr_xaddr_t) 1) << 16; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2024 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2025 | /* Force write bit */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2026 | addr |= write_bit; |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 2027 | start_timer = jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2028 | do { |
| 2029 | /* RMW to aud TR IF until request is granted or timeout */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2030 | stat = drxj_dap_read_modify_write_reg16(dev_addr, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2031 | addr, |
| 2032 | SIO_HI_RA_RAM_S0_RMWBUF__A, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2033 | data, &tr_status); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2034 | if (stat != 0) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2035 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2036 | |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 2037 | current_timer = jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2038 | delta_timer = current_timer - start_timer; |
| 2039 | if (delta_timer > DRXJ_DAP_AUDTRIF_TIMEOUT) { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2040 | stat = -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2041 | break; |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 2042 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2043 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2044 | } while (((tr_status & AUD_TOP_TR_CTR_FIFO_LOCK__M) == |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2045 | AUD_TOP_TR_CTR_FIFO_LOCK_LOCKED) || |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2046 | ((tr_status & AUD_TOP_TR_CTR_FIFO_FULL__M) == |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2047 | AUD_TOP_TR_CTR_FIFO_FULL_FULL)); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2048 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2049 | } /* if ( DRXDAP_FASI_ADDR2BANK(addr)!=2 ) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2050 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2051 | return stat; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | /*============================================================================*/ |
| 2055 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2056 | static int drxj_dap_write_reg16(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2057 | u32 addr, |
| 2058 | u16 data, u32 flags) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2059 | { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2060 | int stat = -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2061 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2062 | /* Check param */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2063 | if (dev_addr == NULL) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2064 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2065 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2066 | if (is_handled_by_aud_tr_if(addr)) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2067 | stat = drxj_dap_write_aud_reg16(dev_addr, addr, data); |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2068 | else |
Mauro Carvalho Chehab | 80bff4b | 2014-01-27 02:24:25 -0300 | [diff] [blame] | 2069 | stat = drxdap_fasi_write_reg16(dev_addr, |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2070 | addr, data, flags); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2071 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2072 | return stat; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | /*============================================================================*/ |
| 2076 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2077 | /* Free data ram in SIO HI */ |
| 2078 | #define SIO_HI_RA_RAM_USR_BEGIN__A 0x420040 |
| 2079 | #define SIO_HI_RA_RAM_USR_END__A 0x420060 |
| 2080 | |
| 2081 | #define DRXJ_HI_ATOMIC_BUF_START (SIO_HI_RA_RAM_USR_BEGIN__A) |
| 2082 | #define DRXJ_HI_ATOMIC_BUF_END (SIO_HI_RA_RAM_USR_BEGIN__A + 7) |
| 2083 | #define DRXJ_HI_ATOMIC_READ SIO_HI_RA_RAM_PAR_3_ACP_RW_READ |
| 2084 | #define DRXJ_HI_ATOMIC_WRITE SIO_HI_RA_RAM_PAR_3_ACP_RW_WRITE |
| 2085 | |
| 2086 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2087 | * \fn int drxj_dap_atomic_read_write_block() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2088 | * \brief Basic access routine for atomic read or write access |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2089 | * \param dev_addr pointer to i2c dev address |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2090 | * \param addr destination/source address |
| 2091 | * \param datasize size of data buffer in bytes |
| 2092 | * \param data pointer to data buffer |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 2093 | * \return int |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2094 | * \retval 0 Succes |
| 2095 | * \retval -EIO Timeout, I2C error, illegal bank |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2096 | * |
| 2097 | */ |
| 2098 | static |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2099 | int drxj_dap_atomic_read_write_block(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2100 | u32 addr, |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2101 | u16 datasize, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2102 | u8 *data, bool read_flag) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2103 | { |
Mauro Carvalho Chehab | 60d3603 | 2014-01-17 07:00:31 -0300 | [diff] [blame] | 2104 | struct drxj_hi_cmd hi_cmd; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2105 | int rc; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2106 | u16 word; |
| 2107 | u16 dummy = 0; |
| 2108 | u16 i = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2109 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2110 | /* Parameter check */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2111 | if (!data || !dev_addr || ((datasize % 2)) || ((datasize / 2) > 8)) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2112 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2113 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2114 | /* Set up HI parameters to read or write n bytes */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2115 | hi_cmd.cmd = SIO_HI_RA_RAM_CMD_ATOMIC_COPY; |
| 2116 | hi_cmd.param1 = |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2117 | (u16) ((DRXDAP_FASI_ADDR2BLOCK(DRXJ_HI_ATOMIC_BUF_START) << 6) + |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2118 | DRXDAP_FASI_ADDR2BANK(DRXJ_HI_ATOMIC_BUF_START)); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2119 | hi_cmd.param2 = |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2120 | (u16) DRXDAP_FASI_ADDR2OFFSET(DRXJ_HI_ATOMIC_BUF_START); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2121 | hi_cmd.param3 = (u16) ((datasize / 2) - 1); |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2122 | if (!read_flag) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2123 | hi_cmd.param3 |= DRXJ_HI_ATOMIC_WRITE; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2124 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2125 | hi_cmd.param3 |= DRXJ_HI_ATOMIC_READ; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2126 | hi_cmd.param4 = (u16) ((DRXDAP_FASI_ADDR2BLOCK(addr) << 6) + |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2127 | DRXDAP_FASI_ADDR2BANK(addr)); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2128 | hi_cmd.param5 = (u16) DRXDAP_FASI_ADDR2OFFSET(addr); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2129 | |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 2130 | if (!read_flag) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2131 | /* write data to buffer */ |
| 2132 | for (i = 0; i < (datasize / 2); i++) { |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2133 | |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2134 | word = ((u16) data[2 * i]); |
| 2135 | word += (((u16) data[(2 * i) + 1]) << 8); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2136 | drxj_dap_write_reg16(dev_addr, |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 2137 | (DRXJ_HI_ATOMIC_BUF_START + i), |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2138 | word, 0); |
| 2139 | } |
| 2140 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2141 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2142 | rc = hi_command(dev_addr, &hi_cmd, &dummy); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2143 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2144 | pr_err("error %d\n", rc); |
| 2145 | goto rw_error; |
| 2146 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2147 | |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 2148 | if (read_flag) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2149 | /* read data from buffer */ |
| 2150 | for (i = 0; i < (datasize / 2); i++) { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2151 | drxj_dap_read_reg16(dev_addr, |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 2152 | (DRXJ_HI_ATOMIC_BUF_START + i), |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2153 | &word, 0); |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2154 | data[2 * i] = (u8) (word & 0xFF); |
| 2155 | data[(2 * i) + 1] = (u8) (word >> 8); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2156 | } |
| 2157 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2158 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2159 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2160 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2161 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2162 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2163 | |
| 2164 | } |
| 2165 | |
| 2166 | /*============================================================================*/ |
| 2167 | |
| 2168 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2169 | * \fn int drxj_dap_atomic_read_reg32() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2170 | * \brief Atomic read of 32 bits words |
| 2171 | */ |
| 2172 | static |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2173 | int drxj_dap_atomic_read_reg32(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2174 | u32 addr, |
| 2175 | u32 *data, u32 flags) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2176 | { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2177 | u8 buf[sizeof(*data)]; |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2178 | int rc = -EIO; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2179 | u32 word = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2180 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2181 | if (!data) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2182 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2183 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2184 | rc = drxj_dap_atomic_read_write_block(dev_addr, addr, |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2185 | sizeof(*data), buf, true); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2186 | |
Mauro Carvalho Chehab | b1d0a59 | 2014-01-16 16:34:03 -0300 | [diff] [blame] | 2187 | if (rc < 0) |
| 2188 | return 0; |
| 2189 | |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2190 | word = (u32) buf[3]; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2191 | word <<= 8; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2192 | word |= (u32) buf[2]; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2193 | word <<= 8; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2194 | word |= (u32) buf[1]; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2195 | word <<= 8; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2196 | word |= (u32) buf[0]; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2197 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2198 | *data = word; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2199 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2200 | return rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2201 | } |
| 2202 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2203 | /*============================================================================*/ |
| 2204 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2205 | /*============================================================================*/ |
| 2206 | /*== END DRXJ DAP FUNCTIONS ==*/ |
| 2207 | /*============================================================================*/ |
| 2208 | |
| 2209 | /*============================================================================*/ |
| 2210 | /*============================================================================*/ |
| 2211 | /*== HOST INTERFACE FUNCTIONS ==*/ |
| 2212 | /*============================================================================*/ |
| 2213 | /*============================================================================*/ |
| 2214 | |
| 2215 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2216 | * \fn int hi_cfg_command() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2217 | * \brief Configure HI with settings stored in the demod structure. |
| 2218 | * \param demod Demodulator. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 2219 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2220 | * |
| 2221 | * This routine was created because to much orthogonal settings have |
| 2222 | * been put into one HI API function (configure). Especially the I2C bridge |
| 2223 | * enable/disable should not need re-configuration of the HI. |
| 2224 | * |
| 2225 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2226 | static int hi_cfg_command(const struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2227 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 2228 | struct drxj_data *ext_attr = (struct drxj_data *) (NULL); |
Mauro Carvalho Chehab | 60d3603 | 2014-01-17 07:00:31 -0300 | [diff] [blame] | 2229 | struct drxj_hi_cmd hi_cmd; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2230 | u16 result = 0; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2231 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2232 | |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 2233 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2234 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2235 | hi_cmd.cmd = SIO_HI_RA_RAM_CMD_CONFIG; |
| 2236 | hi_cmd.param1 = SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY; |
| 2237 | hi_cmd.param2 = ext_attr->hi_cfg_timing_div; |
| 2238 | hi_cmd.param3 = ext_attr->hi_cfg_bridge_delay; |
| 2239 | hi_cmd.param4 = ext_attr->hi_cfg_wake_up_key; |
| 2240 | hi_cmd.param5 = ext_attr->hi_cfg_ctrl; |
| 2241 | hi_cmd.param6 = ext_attr->hi_cfg_transmit; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2242 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2243 | rc = hi_command(demod->my_i2c_dev_addr, &hi_cmd, &result); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2244 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2245 | pr_err("error %d\n", rc); |
| 2246 | goto rw_error; |
| 2247 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2248 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2249 | /* Reset power down flag (set one call only) */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2250 | ext_attr->hi_cfg_ctrl &= (~(SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ)); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2251 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2252 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2253 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2254 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2255 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2259 | * \fn int hi_command() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2260 | * \brief Configure HI with settings stored in the demod structure. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2261 | * \param dev_addr I2C address. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2262 | * \param cmd HI command. |
| 2263 | * \param result HI command result. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 2264 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2265 | * |
| 2266 | * Sends command to HI |
| 2267 | * |
| 2268 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 2269 | static int |
Mauro Carvalho Chehab | 60d3603 | 2014-01-17 07:00:31 -0300 | [diff] [blame] | 2270 | hi_command(struct i2c_device_addr *dev_addr, const struct drxj_hi_cmd *cmd, u16 *result) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2271 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2272 | u16 wait_cmd = 0; |
| 2273 | u16 nr_retries = 0; |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 2274 | bool powerdown_cmd = false; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2275 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2276 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2277 | /* Write parameters */ |
| 2278 | switch (cmd->cmd) { |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2279 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2280 | case SIO_HI_RA_RAM_CMD_CONFIG: |
| 2281 | case SIO_HI_RA_RAM_CMD_ATOMIC_COPY: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2282 | rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_6__A, cmd->param6, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2283 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2284 | pr_err("error %d\n", rc); |
| 2285 | goto rw_error; |
| 2286 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2287 | rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_5__A, cmd->param5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2288 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2289 | pr_err("error %d\n", rc); |
| 2290 | goto rw_error; |
| 2291 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2292 | rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_4__A, cmd->param4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2293 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2294 | pr_err("error %d\n", rc); |
| 2295 | goto rw_error; |
| 2296 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2297 | rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_3__A, cmd->param3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2298 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2299 | pr_err("error %d\n", rc); |
| 2300 | goto rw_error; |
| 2301 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2302 | /* fallthrough */ |
| 2303 | case SIO_HI_RA_RAM_CMD_BRDCTRL: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2304 | rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_2__A, cmd->param2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2305 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2306 | pr_err("error %d\n", rc); |
| 2307 | goto rw_error; |
| 2308 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2309 | rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_1__A, cmd->param1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2310 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2311 | pr_err("error %d\n", rc); |
| 2312 | goto rw_error; |
| 2313 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2314 | /* fallthrough */ |
| 2315 | case SIO_HI_RA_RAM_CMD_NULL: |
| 2316 | /* No parameters */ |
| 2317 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2318 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2319 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2320 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2321 | break; |
| 2322 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2323 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2324 | /* Write command */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2325 | rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_CMD__A, cmd->cmd, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2326 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2327 | pr_err("error %d\n", rc); |
| 2328 | goto rw_error; |
| 2329 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2330 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2331 | if ((cmd->cmd) == SIO_HI_RA_RAM_CMD_RESET) |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 2332 | msleep(1); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2333 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2334 | /* Detect power down to ommit reading result */ |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 2335 | powerdown_cmd = (bool) ((cmd->cmd == SIO_HI_RA_RAM_CMD_CONFIG) && |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2336 | (((cmd-> |
| 2337 | param5) & SIO_HI_RA_RAM_PAR_5_CFG_SLEEP__M) |
| 2338 | == SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ)); |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 2339 | if (!powerdown_cmd) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2340 | /* Wait until command rdy */ |
| 2341 | do { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2342 | nr_retries++; |
| 2343 | if (nr_retries > DRXJ_MAX_RETRIES) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2344 | pr_err("timeout\n"); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2345 | goto rw_error; |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 2346 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2347 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2348 | rc = drxj_dap_read_reg16(dev_addr, SIO_HI_RA_RAM_CMD__A, &wait_cmd, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2349 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2350 | pr_err("error %d\n", rc); |
| 2351 | goto rw_error; |
| 2352 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2353 | } while (wait_cmd != 0); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2354 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2355 | /* Read result */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2356 | rc = drxj_dap_read_reg16(dev_addr, SIO_HI_RA_RAM_RES__A, result, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2357 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2358 | pr_err("error %d\n", rc); |
| 2359 | goto rw_error; |
| 2360 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2361 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2362 | } |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 2363 | /* if ( powerdown_cmd == true ) */ |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2364 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2365 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2366 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | /** |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2370 | * \fn int init_hi( const struct drx_demod_instance *demod ) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2371 | * \brief Initialise and configurate HI. |
| 2372 | * \param demod pointer to demod data. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 2373 | * \return int Return status. |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2374 | * \retval 0 Success. |
| 2375 | * \retval -EIO Failure. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2376 | * |
| 2377 | * Needs to know Psys (System Clock period) and Posc (Osc Clock period) |
| 2378 | * Need to store configuration in driver because of the way I2C |
| 2379 | * bridging is controlled. |
| 2380 | * |
| 2381 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2382 | static int init_hi(const struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2383 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 2384 | struct drxj_data *ext_attr = (struct drxj_data *) (NULL); |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2385 | struct drx_common_attr *common_attr = (struct drx_common_attr *) (NULL); |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 2386 | struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL); |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2387 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2388 | |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 2389 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2390 | common_attr = (struct drx_common_attr *) demod->my_common_attr; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2391 | dev_addr = demod->my_i2c_dev_addr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2392 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2393 | /* PATCH for bug 5003, HI ucode v3.1.0 */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2394 | rc = drxj_dap_write_reg16(dev_addr, 0x4301D7, 0x801, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2395 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2396 | pr_err("error %d\n", rc); |
| 2397 | goto rw_error; |
| 2398 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2399 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2400 | /* Timing div, 250ns/Psys */ |
| 2401 | /* Timing div, = ( delay (nano seconds) * sysclk (kHz) )/ 1000 */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2402 | ext_attr->hi_cfg_timing_div = |
| 2403 | (u16) ((common_attr->sys_clock_freq / 1000) * HI_I2C_DELAY) / 1000; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2404 | /* Clipping */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2405 | if ((ext_attr->hi_cfg_timing_div) > SIO_HI_RA_RAM_PAR_2_CFG_DIV__M) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2406 | ext_attr->hi_cfg_timing_div = SIO_HI_RA_RAM_PAR_2_CFG_DIV__M; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2407 | /* Bridge delay, uses oscilator clock */ |
| 2408 | /* Delay = ( delay (nano seconds) * oscclk (kHz) )/ 1000 */ |
| 2409 | /* SDA brdige delay */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2410 | ext_attr->hi_cfg_bridge_delay = |
| 2411 | (u16) ((common_attr->osc_clock_freq / 1000) * HI_I2C_BRIDGE_DELAY) / |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2412 | 1000; |
| 2413 | /* Clipping */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2414 | if ((ext_attr->hi_cfg_bridge_delay) > SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2415 | ext_attr->hi_cfg_bridge_delay = SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2416 | /* SCL bridge delay, same as SDA for now */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2417 | ext_attr->hi_cfg_bridge_delay += ((ext_attr->hi_cfg_bridge_delay) << |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2418 | SIO_HI_RA_RAM_PAR_3_CFG_DBL_SCL__B); |
| 2419 | /* Wakeup key, setting the read flag (as suggest in the documentation) does |
| 2420 | not always result into a working solution (barebones worked VI2C failed). |
| 2421 | Not setting the bit works in all cases . */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2422 | ext_attr->hi_cfg_wake_up_key = DRXJ_WAKE_UP_KEY; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2423 | /* port/bridge/power down ctrl */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2424 | ext_attr->hi_cfg_ctrl = (SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2425 | /* transit mode time out delay and watch dog divider */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2426 | ext_attr->hi_cfg_transmit = SIO_HI_RA_RAM_PAR_6__PRE; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2427 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2428 | rc = hi_cfg_command(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2429 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2430 | pr_err("error %d\n", rc); |
| 2431 | goto rw_error; |
| 2432 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2433 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2434 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2435 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2436 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2437 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2438 | } |
| 2439 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2440 | /*============================================================================*/ |
| 2441 | /*== END HOST INTERFACE FUNCTIONS ==*/ |
| 2442 | /*============================================================================*/ |
| 2443 | |
| 2444 | /*============================================================================*/ |
| 2445 | /*============================================================================*/ |
| 2446 | /*== AUXILIARY FUNCTIONS ==*/ |
| 2447 | /*============================================================================*/ |
| 2448 | /*============================================================================*/ |
| 2449 | |
| 2450 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2451 | * \fn int get_device_capabilities() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2452 | * \brief Get and store device capabilities. |
| 2453 | * \param demod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 2454 | * \return int. |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2455 | * \return 0 Success |
| 2456 | * \retval -EIO Failure |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2457 | * |
| 2458 | * Depending on pulldowns on MDx pins the following internals are set: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2459 | * * common_attr->osc_clock_freq |
| 2460 | * * ext_attr->has_lna |
| 2461 | * * ext_attr->has_ntsc |
| 2462 | * * ext_attr->has_btsc |
| 2463 | * * ext_attr->has_oob |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2464 | * |
| 2465 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2466 | static int get_device_capabilities(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2467 | { |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2468 | struct drx_common_attr *common_attr = (struct drx_common_attr *) (NULL); |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 2469 | struct drxj_data *ext_attr = (struct drxj_data *) NULL; |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 2470 | struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2471 | u16 sio_pdr_ohw_cfg = 0; |
| 2472 | u32 sio_top_jtagid_lo = 0; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2473 | u16 bid = 0; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2474 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2475 | |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2476 | common_attr = (struct drx_common_attr *) demod->my_common_attr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 2477 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2478 | dev_addr = demod->my_i2c_dev_addr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2479 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2480 | rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2481 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2482 | pr_err("error %d\n", rc); |
| 2483 | goto rw_error; |
| 2484 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2485 | rc = drxj_dap_read_reg16(dev_addr, SIO_PDR_OHW_CFG__A, &sio_pdr_ohw_cfg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2486 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2487 | pr_err("error %d\n", rc); |
| 2488 | goto rw_error; |
| 2489 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2490 | rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2491 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2492 | pr_err("error %d\n", rc); |
| 2493 | goto rw_error; |
| 2494 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2495 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2496 | switch ((sio_pdr_ohw_cfg & SIO_PDR_OHW_CFG_FREF_SEL__M)) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2497 | case 0: |
| 2498 | /* ignore (bypass ?) */ |
| 2499 | break; |
| 2500 | case 1: |
| 2501 | /* 27 MHz */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2502 | common_attr->osc_clock_freq = 27000; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2503 | break; |
| 2504 | case 2: |
| 2505 | /* 20.25 MHz */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2506 | common_attr->osc_clock_freq = 20250; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2507 | break; |
| 2508 | case 3: |
| 2509 | /* 4 MHz */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2510 | common_attr->osc_clock_freq = 4000; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2511 | break; |
| 2512 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2513 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2514 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2515 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2516 | /* |
| 2517 | Determine device capabilities |
| 2518 | Based on pinning v47 |
| 2519 | */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2520 | rc = drxdap_fasi_read_reg32(dev_addr, SIO_TOP_JTAGID_LO__A, &sio_top_jtagid_lo, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2521 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2522 | pr_err("error %d\n", rc); |
| 2523 | goto rw_error; |
| 2524 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2525 | ext_attr->mfx = (u8) ((sio_top_jtagid_lo >> 29) & 0xF); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2526 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2527 | switch ((sio_top_jtagid_lo >> 12) & 0xFF) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2528 | case 0x31: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2529 | rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2530 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2531 | pr_err("error %d\n", rc); |
| 2532 | goto rw_error; |
| 2533 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2534 | rc = drxj_dap_read_reg16(dev_addr, SIO_PDR_UIO_IN_HI__A, &bid, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2535 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2536 | pr_err("error %d\n", rc); |
| 2537 | goto rw_error; |
| 2538 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2539 | bid = (bid >> 10) & 0xf; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2540 | rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2541 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2542 | pr_err("error %d\n", rc); |
| 2543 | goto rw_error; |
| 2544 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2545 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2546 | ext_attr->has_lna = true; |
| 2547 | ext_attr->has_ntsc = false; |
| 2548 | ext_attr->has_btsc = false; |
| 2549 | ext_attr->has_oob = false; |
| 2550 | ext_attr->has_smatx = true; |
| 2551 | ext_attr->has_smarx = false; |
| 2552 | ext_attr->has_gpio = false; |
| 2553 | ext_attr->has_irqn = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2554 | break; |
| 2555 | case 0x33: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2556 | ext_attr->has_lna = false; |
| 2557 | ext_attr->has_ntsc = false; |
| 2558 | ext_attr->has_btsc = false; |
| 2559 | ext_attr->has_oob = false; |
| 2560 | ext_attr->has_smatx = true; |
| 2561 | ext_attr->has_smarx = false; |
| 2562 | ext_attr->has_gpio = false; |
| 2563 | ext_attr->has_irqn = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2564 | break; |
| 2565 | case 0x45: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2566 | ext_attr->has_lna = true; |
| 2567 | ext_attr->has_ntsc = true; |
| 2568 | ext_attr->has_btsc = false; |
| 2569 | ext_attr->has_oob = false; |
| 2570 | ext_attr->has_smatx = true; |
| 2571 | ext_attr->has_smarx = true; |
| 2572 | ext_attr->has_gpio = true; |
| 2573 | ext_attr->has_irqn = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2574 | break; |
| 2575 | case 0x46: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2576 | ext_attr->has_lna = false; |
| 2577 | ext_attr->has_ntsc = true; |
| 2578 | ext_attr->has_btsc = false; |
| 2579 | ext_attr->has_oob = false; |
| 2580 | ext_attr->has_smatx = true; |
| 2581 | ext_attr->has_smarx = true; |
| 2582 | ext_attr->has_gpio = true; |
| 2583 | ext_attr->has_irqn = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2584 | break; |
| 2585 | case 0x41: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2586 | ext_attr->has_lna = true; |
| 2587 | ext_attr->has_ntsc = true; |
| 2588 | ext_attr->has_btsc = true; |
| 2589 | ext_attr->has_oob = false; |
| 2590 | ext_attr->has_smatx = true; |
| 2591 | ext_attr->has_smarx = true; |
| 2592 | ext_attr->has_gpio = true; |
| 2593 | ext_attr->has_irqn = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2594 | break; |
| 2595 | case 0x43: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2596 | ext_attr->has_lna = false; |
| 2597 | ext_attr->has_ntsc = true; |
| 2598 | ext_attr->has_btsc = true; |
| 2599 | ext_attr->has_oob = false; |
| 2600 | ext_attr->has_smatx = true; |
| 2601 | ext_attr->has_smarx = true; |
| 2602 | ext_attr->has_gpio = true; |
| 2603 | ext_attr->has_irqn = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2604 | break; |
| 2605 | case 0x32: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2606 | ext_attr->has_lna = true; |
| 2607 | ext_attr->has_ntsc = false; |
| 2608 | ext_attr->has_btsc = false; |
| 2609 | ext_attr->has_oob = true; |
| 2610 | ext_attr->has_smatx = true; |
| 2611 | ext_attr->has_smarx = true; |
| 2612 | ext_attr->has_gpio = true; |
| 2613 | ext_attr->has_irqn = true; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2614 | break; |
| 2615 | case 0x34: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2616 | ext_attr->has_lna = false; |
| 2617 | ext_attr->has_ntsc = true; |
| 2618 | ext_attr->has_btsc = true; |
| 2619 | ext_attr->has_oob = true; |
| 2620 | ext_attr->has_smatx = true; |
| 2621 | ext_attr->has_smarx = true; |
| 2622 | ext_attr->has_gpio = true; |
| 2623 | ext_attr->has_irqn = true; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2624 | break; |
| 2625 | case 0x42: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2626 | ext_attr->has_lna = true; |
| 2627 | ext_attr->has_ntsc = true; |
| 2628 | ext_attr->has_btsc = true; |
| 2629 | ext_attr->has_oob = true; |
| 2630 | ext_attr->has_smatx = true; |
| 2631 | ext_attr->has_smarx = true; |
| 2632 | ext_attr->has_gpio = true; |
| 2633 | ext_attr->has_irqn = true; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2634 | break; |
| 2635 | case 0x44: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2636 | ext_attr->has_lna = false; |
| 2637 | ext_attr->has_ntsc = true; |
| 2638 | ext_attr->has_btsc = true; |
| 2639 | ext_attr->has_oob = true; |
| 2640 | ext_attr->has_smatx = true; |
| 2641 | ext_attr->has_smarx = true; |
| 2642 | ext_attr->has_gpio = true; |
| 2643 | ext_attr->has_irqn = true; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2644 | break; |
| 2645 | default: |
| 2646 | /* Unknown device variant */ |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2647 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2648 | break; |
| 2649 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2650 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2651 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2652 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2653 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2654 | } |
| 2655 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2656 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2657 | * \fn int power_up_device() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2658 | * \brief Power up device. |
| 2659 | * \param demod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 2660 | * \return int. |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2661 | * \return 0 Success |
| 2662 | * \retval -EIO Failure, I2C or max retries reached |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2663 | * |
| 2664 | */ |
| 2665 | |
| 2666 | #ifndef DRXJ_MAX_RETRIES_POWERUP |
| 2667 | #define DRXJ_MAX_RETRIES_POWERUP 10 |
| 2668 | #endif |
| 2669 | |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2670 | static int power_up_device(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2671 | { |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 2672 | struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL); |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 2673 | u8 data = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2674 | u16 retry_count = 0; |
| 2675 | struct i2c_device_addr wake_up_addr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2676 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2677 | dev_addr = demod->my_i2c_dev_addr; |
| 2678 | wake_up_addr.i2c_addr = DRXJ_WAKE_UP_KEY; |
| 2679 | wake_up_addr.i2c_dev_id = dev_addr->i2c_dev_id; |
| 2680 | wake_up_addr.user_data = dev_addr->user_data; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2681 | /* |
| 2682 | * I2C access may fail in this case: no ack |
| 2683 | * dummy write must be used to wake uop device, dummy read must be used to |
| 2684 | * reset HI state machine (avoiding actual writes) |
| 2685 | */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2686 | do { |
| 2687 | data = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2688 | drxbsp_i2c_write_read(&wake_up_addr, 1, &data, |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 2689 | (struct i2c_device_addr *)(NULL), 0, |
| 2690 | (u8 *)(NULL)); |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 2691 | msleep(10); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2692 | retry_count++; |
| 2693 | } while ((drxbsp_i2c_write_read |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 2694 | ((struct i2c_device_addr *) (NULL), 0, (u8 *)(NULL), dev_addr, 1, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2695 | &data) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2696 | != 0) && (retry_count < DRXJ_MAX_RETRIES_POWERUP)); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2697 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2698 | /* Need some recovery time .... */ |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 2699 | msleep(10); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2700 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2701 | if (retry_count == DRXJ_MAX_RETRIES_POWERUP) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2702 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2703 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2704 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | /*----------------------------------------------------------------------------*/ |
| 2708 | /* MPEG Output Configuration Functions - begin */ |
| 2709 | /*----------------------------------------------------------------------------*/ |
| 2710 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2711 | * \fn int ctrl_set_cfg_mpeg_output() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2712 | * \brief Set MPEG output configuration of the device. |
| 2713 | * \param devmod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2714 | * \param cfg_data Pointer to mpeg output configuaration. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 2715 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2716 | * |
| 2717 | * Configure MPEG output parameters. |
| 2718 | * |
| 2719 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 2720 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2721 | ctrl_set_cfg_mpeg_output(struct drx_demod_instance *demod, struct drx_cfg_mpeg_output *cfg_data) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2722 | { |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 2723 | struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL); |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 2724 | struct drxj_data *ext_attr = (struct drxj_data *) (NULL); |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2725 | struct drx_common_attr *common_attr = (struct drx_common_attr *) (NULL); |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2726 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2727 | u16 fec_oc_reg_mode = 0; |
| 2728 | u16 fec_oc_reg_ipr_mode = 0; |
| 2729 | u16 fec_oc_reg_ipr_invert = 0; |
| 2730 | u32 max_bit_rate = 0; |
| 2731 | u32 rcn_rate = 0; |
| 2732 | u32 nr_bits = 0; |
| 2733 | u16 sio_pdr_md_cfg = 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2734 | /* data mask for the output data byte */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2735 | u16 invert_data_mask = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2736 | FEC_OC_IPR_INVERT_MD7__M | FEC_OC_IPR_INVERT_MD6__M | |
| 2737 | FEC_OC_IPR_INVERT_MD5__M | FEC_OC_IPR_INVERT_MD4__M | |
| 2738 | FEC_OC_IPR_INVERT_MD3__M | FEC_OC_IPR_INVERT_MD2__M | |
| 2739 | FEC_OC_IPR_INVERT_MD1__M | FEC_OC_IPR_INVERT_MD0__M; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2740 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2741 | /* check arguments */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2742 | if ((demod == NULL) || (cfg_data == NULL)) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2743 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2744 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2745 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 2746 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 2747 | common_attr = (struct drx_common_attr *) demod->my_common_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2748 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2749 | if (cfg_data->enable_mpeg_output == true) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2750 | /* quick and dirty patch to set MPEG incase current std is not |
| 2751 | producing MPEG */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2752 | switch (ext_attr->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2753 | case DRX_STANDARD_8VSB: |
| 2754 | case DRX_STANDARD_ITU_A: |
| 2755 | case DRX_STANDARD_ITU_B: |
| 2756 | case DRX_STANDARD_ITU_C: |
| 2757 | break; |
| 2758 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2759 | return 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2760 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2761 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2762 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_OCR_INVERT__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2763 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2764 | pr_err("error %d\n", rc); |
| 2765 | goto rw_error; |
| 2766 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2767 | switch (ext_attr->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2768 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2769 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_FCT_USAGE__A, 7, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2770 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2771 | pr_err("error %d\n", rc); |
| 2772 | goto rw_error; |
| 2773 | } /* 2048 bytes fifo ram */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2774 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_TMD_CTL_UPD_RATE__A, 10, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2775 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2776 | pr_err("error %d\n", rc); |
| 2777 | goto rw_error; |
| 2778 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2779 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_TMD_INT_UPD_RATE__A, 10, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2780 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2781 | pr_err("error %d\n", rc); |
| 2782 | goto rw_error; |
| 2783 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2784 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_AVR_PARM_A__A, 5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2785 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2786 | pr_err("error %d\n", rc); |
| 2787 | goto rw_error; |
| 2788 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2789 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_AVR_PARM_B__A, 7, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2790 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2791 | pr_err("error %d\n", rc); |
| 2792 | goto rw_error; |
| 2793 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2794 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_RCN_GAIN__A, 10, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2795 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2796 | pr_err("error %d\n", rc); |
| 2797 | goto rw_error; |
| 2798 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2799 | /* Low Water Mark for synchronization */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2800 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_LWM__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2801 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2802 | pr_err("error %d\n", rc); |
| 2803 | goto rw_error; |
| 2804 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2805 | /* High Water Mark for synchronization */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2806 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_HWM__A, 5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2807 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2808 | pr_err("error %d\n", rc); |
| 2809 | goto rw_error; |
| 2810 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2811 | break; |
| 2812 | case DRX_STANDARD_ITU_A: |
| 2813 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2814 | switch (ext_attr->constellation) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2815 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2816 | nr_bits = 8; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2817 | break; |
| 2818 | case DRX_CONSTELLATION_QAM128: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2819 | nr_bits = 7; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2820 | break; |
| 2821 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2822 | nr_bits = 6; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2823 | break; |
| 2824 | case DRX_CONSTELLATION_QAM32: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2825 | nr_bits = 5; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2826 | break; |
| 2827 | case DRX_CONSTELLATION_QAM16: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2828 | nr_bits = 4; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2829 | break; |
| 2830 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2831 | return -EIO; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2832 | } /* ext_attr->constellation */ |
| 2833 | /* max_bit_rate = symbol_rate * nr_bits * coef */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2834 | /* coef = 188/204 */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2835 | max_bit_rate = |
| 2836 | (ext_attr->curr_symbol_rate / 8) * nr_bits * 188; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2837 | /* pass through b/c Annex A/c need following settings */ |
| 2838 | case DRX_STANDARD_ITU_B: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2839 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_FCT_USAGE__A, FEC_OC_FCT_USAGE__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2840 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2841 | pr_err("error %d\n", rc); |
| 2842 | goto rw_error; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2843 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2844 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_TMD_CTL_UPD_RATE__A, FEC_OC_TMD_CTL_UPD_RATE__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2845 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2846 | pr_err("error %d\n", rc); |
| 2847 | goto rw_error; |
| 2848 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2849 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_TMD_INT_UPD_RATE__A, 5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2850 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2851 | pr_err("error %d\n", rc); |
| 2852 | goto rw_error; |
| 2853 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2854 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_AVR_PARM_A__A, FEC_OC_AVR_PARM_A__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2855 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2856 | pr_err("error %d\n", rc); |
| 2857 | goto rw_error; |
| 2858 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2859 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_AVR_PARM_B__A, FEC_OC_AVR_PARM_B__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2860 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2861 | pr_err("error %d\n", rc); |
| 2862 | goto rw_error; |
| 2863 | } |
| 2864 | if (cfg_data->static_clk == true) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2865 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_RCN_GAIN__A, 0xD, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2866 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2867 | pr_err("error %d\n", rc); |
| 2868 | goto rw_error; |
| 2869 | } |
| 2870 | } else { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2871 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_RCN_GAIN__A, FEC_OC_RCN_GAIN__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2872 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2873 | pr_err("error %d\n", rc); |
| 2874 | goto rw_error; |
| 2875 | } |
| 2876 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2877 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_LWM__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2878 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2879 | pr_err("error %d\n", rc); |
| 2880 | goto rw_error; |
| 2881 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2882 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_HWM__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2883 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2884 | pr_err("error %d\n", rc); |
| 2885 | goto rw_error; |
| 2886 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2887 | break; |
| 2888 | default: |
| 2889 | break; |
| 2890 | } /* swtich (standard) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2891 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2892 | /* Check insertion of the Reed-Solomon parity bytes */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2893 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_MODE__A, &fec_oc_reg_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2894 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2895 | pr_err("error %d\n", rc); |
| 2896 | goto rw_error; |
| 2897 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 2898 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_IPR_MODE__A, &fec_oc_reg_ipr_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2899 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 2900 | pr_err("error %d\n", rc); |
| 2901 | goto rw_error; |
| 2902 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2903 | if (cfg_data->insert_rs_byte == true) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2904 | /* enable parity symbol forward */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2905 | fec_oc_reg_mode |= FEC_OC_MODE_PARITY__M; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2906 | /* MVAL disable during parity bytes */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2907 | fec_oc_reg_ipr_mode |= FEC_OC_IPR_MODE_MVAL_DIS_PAR__M; |
| 2908 | switch (ext_attr->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2909 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2910 | rcn_rate = 0x004854D3; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2911 | break; |
| 2912 | case DRX_STANDARD_ITU_B: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2913 | fec_oc_reg_mode |= FEC_OC_MODE_TRANSPARENT__M; |
| 2914 | switch (ext_attr->constellation) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2915 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2916 | rcn_rate = 0x008945E7; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2917 | break; |
| 2918 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2919 | rcn_rate = 0x005F64D4; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2920 | break; |
| 2921 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2922 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2923 | } |
| 2924 | break; |
| 2925 | case DRX_STANDARD_ITU_A: |
| 2926 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2927 | /* insert_rs_byte = true -> coef = 188/188 -> 1, RS bits are in MPEG output */ |
| 2928 | rcn_rate = |
| 2929 | (frac28 |
| 2930 | (max_bit_rate, |
| 2931 | (u32) (common_attr->sys_clock_freq / 8))) / |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2932 | 188; |
| 2933 | break; |
| 2934 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2935 | return -EIO; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2936 | } /* ext_attr->standard */ |
| 2937 | } else { /* insert_rs_byte == false */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2938 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2939 | /* disable parity symbol forward */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2940 | fec_oc_reg_mode &= (~FEC_OC_MODE_PARITY__M); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2941 | /* MVAL enable during parity bytes */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2942 | fec_oc_reg_ipr_mode &= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M); |
| 2943 | switch (ext_attr->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2944 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2945 | rcn_rate = 0x0041605C; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2946 | break; |
| 2947 | case DRX_STANDARD_ITU_B: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2948 | fec_oc_reg_mode &= (~FEC_OC_MODE_TRANSPARENT__M); |
| 2949 | switch (ext_attr->constellation) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2950 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2951 | rcn_rate = 0x0082D6A0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2952 | break; |
| 2953 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2954 | rcn_rate = 0x005AEC1A; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2955 | break; |
| 2956 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2957 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2958 | } |
| 2959 | break; |
| 2960 | case DRX_STANDARD_ITU_A: |
| 2961 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2962 | /* insert_rs_byte = false -> coef = 188/204, RS bits not in MPEG output */ |
| 2963 | rcn_rate = |
| 2964 | (frac28 |
| 2965 | (max_bit_rate, |
| 2966 | (u32) (common_attr->sys_clock_freq / 8))) / |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2967 | 204; |
| 2968 | break; |
| 2969 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 2970 | return -EIO; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2971 | } /* ext_attr->standard */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2972 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2973 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2974 | if (cfg_data->enable_parallel == true) { /* MPEG data output is paralel -> clear ipr_mode[0] */ |
| 2975 | fec_oc_reg_ipr_mode &= (~(FEC_OC_IPR_MODE_SERIAL__M)); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2976 | } else { /* MPEG data output is serial -> set ipr_mode[0] */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2977 | fec_oc_reg_ipr_mode |= FEC_OC_IPR_MODE_SERIAL__M; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2978 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2979 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 2980 | /* Control slective inversion of output bits */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2981 | if (cfg_data->invert_data == true) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2982 | fec_oc_reg_ipr_invert |= invert_data_mask; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2983 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2984 | fec_oc_reg_ipr_invert &= (~(invert_data_mask)); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2985 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2986 | if (cfg_data->invert_err == true) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2987 | fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MERR__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2988 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2989 | fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MERR__M)); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2990 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2991 | if (cfg_data->invert_str == true) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2992 | fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MSTRT__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2993 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2994 | fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MSTRT__M)); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 2995 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2996 | if (cfg_data->invert_val == true) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2997 | fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MVAL__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 2998 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 2999 | fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MVAL__M)); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3000 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3001 | if (cfg_data->invert_clk == true) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3002 | fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MCLK__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3003 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3004 | fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MCLK__M)); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3005 | |
Mauro Carvalho Chehab | 41b5cc0 | 2014-03-02 11:01:11 -0300 | [diff] [blame] | 3006 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3007 | if (cfg_data->static_clk == true) { /* Static mode */ |
| 3008 | u32 dto_rate = 0; |
| 3009 | u32 bit_rate = 0; |
| 3010 | u16 fec_oc_dto_burst_len = 0; |
| 3011 | u16 fec_oc_dto_period = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3012 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3013 | fec_oc_dto_burst_len = FEC_OC_DTO_BURST_LEN__PRE; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3014 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3015 | switch (ext_attr->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3016 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3017 | fec_oc_dto_period = 4; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3018 | if (cfg_data->insert_rs_byte == true) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3019 | fec_oc_dto_burst_len = 208; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3020 | break; |
| 3021 | case DRX_STANDARD_ITU_A: |
| 3022 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3023 | u32 symbol_rate_th = 6400000; |
| 3024 | if (cfg_data->insert_rs_byte == true) { |
| 3025 | fec_oc_dto_burst_len = 204; |
| 3026 | symbol_rate_th = 5900000; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3027 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3028 | if (ext_attr->curr_symbol_rate >= |
| 3029 | symbol_rate_th) { |
| 3030 | fec_oc_dto_period = 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3031 | } else { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3032 | fec_oc_dto_period = 1; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3033 | } |
| 3034 | } |
| 3035 | break; |
| 3036 | case DRX_STANDARD_ITU_B: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3037 | fec_oc_dto_period = 1; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3038 | if (cfg_data->insert_rs_byte == true) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3039 | fec_oc_dto_burst_len = 128; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3040 | break; |
| 3041 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3042 | fec_oc_dto_period = 1; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3043 | if (cfg_data->insert_rs_byte == true) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3044 | fec_oc_dto_burst_len = 204; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3045 | break; |
| 3046 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3047 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3048 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3049 | bit_rate = |
| 3050 | common_attr->sys_clock_freq * 1000 / (fec_oc_dto_period + |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3051 | 2); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3052 | dto_rate = |
| 3053 | frac28(bit_rate, common_attr->sys_clock_freq * 1000); |
| 3054 | dto_rate >>= 3; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3055 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_RATE_HI__A, (u16)((dto_rate >> 16) & FEC_OC_DTO_RATE_HI__M), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3056 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3057 | pr_err("error %d\n", rc); |
| 3058 | goto rw_error; |
| 3059 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3060 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_RATE_LO__A, (u16)(dto_rate & FEC_OC_DTO_RATE_LO_RATE_LO__M), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3061 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3062 | pr_err("error %d\n", rc); |
| 3063 | goto rw_error; |
| 3064 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3065 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_MODE__A, FEC_OC_DTO_MODE_DYNAMIC__M | FEC_OC_DTO_MODE_OFFSET_ENABLE__M, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3066 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3067 | pr_err("error %d\n", rc); |
| 3068 | goto rw_error; |
| 3069 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3070 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_FCT_MODE__A, FEC_OC_FCT_MODE_RAT_ENA__M | FEC_OC_FCT_MODE_VIRT_ENA__M, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3071 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3072 | pr_err("error %d\n", rc); |
| 3073 | goto rw_error; |
| 3074 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3075 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_BURST_LEN__A, fec_oc_dto_burst_len, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3076 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3077 | pr_err("error %d\n", rc); |
| 3078 | goto rw_error; |
| 3079 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3080 | if (ext_attr->mpeg_output_clock_rate != DRXJ_MPEGOUTPUT_CLOCK_RATE_AUTO) |
| 3081 | fec_oc_dto_period = ext_attr->mpeg_output_clock_rate - 1; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3082 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_PERIOD__A, fec_oc_dto_period, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3083 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3084 | pr_err("error %d\n", rc); |
| 3085 | goto rw_error; |
| 3086 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3087 | } else { /* Dynamic mode */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3088 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3089 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_MODE__A, FEC_OC_DTO_MODE_DYNAMIC__M, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3090 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3091 | pr_err("error %d\n", rc); |
| 3092 | goto rw_error; |
| 3093 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3094 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_FCT_MODE__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3095 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3096 | pr_err("error %d\n", rc); |
| 3097 | goto rw_error; |
| 3098 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3099 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3100 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3101 | rc = drxdap_fasi_write_reg32(dev_addr, FEC_OC_RCN_CTL_RATE_LO__A, rcn_rate, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3102 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3103 | pr_err("error %d\n", rc); |
| 3104 | goto rw_error; |
| 3105 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3106 | |
| 3107 | /* Write appropriate registers with requested configuration */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3108 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_MODE__A, fec_oc_reg_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3109 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3110 | pr_err("error %d\n", rc); |
| 3111 | goto rw_error; |
| 3112 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3113 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_IPR_MODE__A, fec_oc_reg_ipr_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3114 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3115 | pr_err("error %d\n", rc); |
| 3116 | goto rw_error; |
| 3117 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3118 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_IPR_INVERT__A, fec_oc_reg_ipr_invert, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3119 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3120 | pr_err("error %d\n", rc); |
| 3121 | goto rw_error; |
| 3122 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3123 | |
| 3124 | /* enabling for both parallel and serial now */ |
| 3125 | /* Write magic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3126 | rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0xFABA, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3127 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3128 | pr_err("error %d\n", rc); |
| 3129 | goto rw_error; |
| 3130 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3131 | /* Set MPEG TS pads to outputmode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3132 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MSTRT_CFG__A, 0x0013, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3133 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3134 | pr_err("error %d\n", rc); |
| 3135 | goto rw_error; |
| 3136 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3137 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MERR_CFG__A, 0x0013, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3138 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3139 | pr_err("error %d\n", rc); |
| 3140 | goto rw_error; |
| 3141 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3142 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MCLK_CFG__A, MPEG_OUTPUT_CLK_DRIVE_STRENGTH << SIO_PDR_MCLK_CFG_DRIVE__B | 0x03 << SIO_PDR_MCLK_CFG_MODE__B, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3143 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3144 | pr_err("error %d\n", rc); |
| 3145 | goto rw_error; |
| 3146 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3147 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MVAL_CFG__A, 0x0013, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3148 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3149 | pr_err("error %d\n", rc); |
| 3150 | goto rw_error; |
| 3151 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3152 | sio_pdr_md_cfg = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3153 | MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH << |
| 3154 | SIO_PDR_MD0_CFG_DRIVE__B | 0x03 << SIO_PDR_MD0_CFG_MODE__B; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3155 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD0_CFG__A, sio_pdr_md_cfg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3156 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3157 | pr_err("error %d\n", rc); |
| 3158 | goto rw_error; |
| 3159 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3160 | if (cfg_data->enable_parallel == true) { /* MPEG data output is paralel -> set MD1 to MD7 to output mode */ |
| 3161 | sio_pdr_md_cfg = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3162 | MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH << |
| 3163 | SIO_PDR_MD0_CFG_DRIVE__B | 0x03 << |
| 3164 | SIO_PDR_MD0_CFG_MODE__B; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3165 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD0_CFG__A, sio_pdr_md_cfg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3166 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3167 | pr_err("error %d\n", rc); |
| 3168 | goto rw_error; |
| 3169 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3170 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD1_CFG__A, sio_pdr_md_cfg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3171 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3172 | pr_err("error %d\n", rc); |
| 3173 | goto rw_error; |
| 3174 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3175 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD2_CFG__A, sio_pdr_md_cfg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3176 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3177 | pr_err("error %d\n", rc); |
| 3178 | goto rw_error; |
| 3179 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3180 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD3_CFG__A, sio_pdr_md_cfg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3181 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3182 | pr_err("error %d\n", rc); |
| 3183 | goto rw_error; |
| 3184 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3185 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD4_CFG__A, sio_pdr_md_cfg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3186 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3187 | pr_err("error %d\n", rc); |
| 3188 | goto rw_error; |
| 3189 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3190 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD5_CFG__A, sio_pdr_md_cfg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3191 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3192 | pr_err("error %d\n", rc); |
| 3193 | goto rw_error; |
| 3194 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3195 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD6_CFG__A, sio_pdr_md_cfg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3196 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3197 | pr_err("error %d\n", rc); |
| 3198 | goto rw_error; |
| 3199 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3200 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD7_CFG__A, sio_pdr_md_cfg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3201 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3202 | pr_err("error %d\n", rc); |
| 3203 | goto rw_error; |
| 3204 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3205 | } else { /* MPEG data output is serial -> set MD1 to MD7 to tri-state */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3206 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD1_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3207 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3208 | pr_err("error %d\n", rc); |
| 3209 | goto rw_error; |
| 3210 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3211 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD2_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3212 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3213 | pr_err("error %d\n", rc); |
| 3214 | goto rw_error; |
| 3215 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3216 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD3_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3217 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3218 | pr_err("error %d\n", rc); |
| 3219 | goto rw_error; |
| 3220 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3221 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD4_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3222 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3223 | pr_err("error %d\n", rc); |
| 3224 | goto rw_error; |
| 3225 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3226 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD5_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3227 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3228 | pr_err("error %d\n", rc); |
| 3229 | goto rw_error; |
| 3230 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3231 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD6_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3232 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3233 | pr_err("error %d\n", rc); |
| 3234 | goto rw_error; |
| 3235 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3236 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD7_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3237 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3238 | pr_err("error %d\n", rc); |
| 3239 | goto rw_error; |
| 3240 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3241 | } |
| 3242 | /* Enable Monitor Bus output over MPEG pads and ctl input */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3243 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MON_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3244 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3245 | pr_err("error %d\n", rc); |
| 3246 | goto rw_error; |
| 3247 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3248 | /* Write nomagic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3249 | rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3250 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3251 | pr_err("error %d\n", rc); |
| 3252 | goto rw_error; |
| 3253 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3254 | } else { |
| 3255 | /* Write magic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3256 | rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0xFABA, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3257 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3258 | pr_err("error %d\n", rc); |
| 3259 | goto rw_error; |
| 3260 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3261 | /* Set MPEG TS pads to inputmode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3262 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MSTRT_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3263 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3264 | pr_err("error %d\n", rc); |
| 3265 | goto rw_error; |
| 3266 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3267 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MERR_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3268 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3269 | pr_err("error %d\n", rc); |
| 3270 | goto rw_error; |
| 3271 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3272 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MCLK_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3273 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3274 | pr_err("error %d\n", rc); |
| 3275 | goto rw_error; |
| 3276 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3277 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MVAL_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3278 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3279 | pr_err("error %d\n", rc); |
| 3280 | goto rw_error; |
| 3281 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3282 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD0_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3283 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3284 | pr_err("error %d\n", rc); |
| 3285 | goto rw_error; |
| 3286 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3287 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD1_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3288 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3289 | pr_err("error %d\n", rc); |
| 3290 | goto rw_error; |
| 3291 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3292 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD2_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3293 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3294 | pr_err("error %d\n", rc); |
| 3295 | goto rw_error; |
| 3296 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3297 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD3_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3298 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3299 | pr_err("error %d\n", rc); |
| 3300 | goto rw_error; |
| 3301 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3302 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD4_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3303 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3304 | pr_err("error %d\n", rc); |
| 3305 | goto rw_error; |
| 3306 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3307 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD5_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3308 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3309 | pr_err("error %d\n", rc); |
| 3310 | goto rw_error; |
| 3311 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3312 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD6_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3313 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3314 | pr_err("error %d\n", rc); |
| 3315 | goto rw_error; |
| 3316 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3317 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD7_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3318 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3319 | pr_err("error %d\n", rc); |
| 3320 | goto rw_error; |
| 3321 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3322 | /* Enable Monitor Bus output over MPEG pads and ctl input */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3323 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MON_CFG__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3324 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3325 | pr_err("error %d\n", rc); |
| 3326 | goto rw_error; |
| 3327 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3328 | /* Write nomagic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3329 | rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3330 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3331 | pr_err("error %d\n", rc); |
| 3332 | goto rw_error; |
| 3333 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3334 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3335 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3336 | /* save values for restore after re-acquire */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3337 | common_attr->mpeg_cfg.enable_mpeg_output = cfg_data->enable_mpeg_output; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3338 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3339 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3340 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3341 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | /*----------------------------------------------------------------------------*/ |
| 3345 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3346 | |
| 3347 | /*----------------------------------------------------------------------------*/ |
| 3348 | /* MPEG Output Configuration Functions - end */ |
| 3349 | /*----------------------------------------------------------------------------*/ |
| 3350 | |
| 3351 | /*----------------------------------------------------------------------------*/ |
| 3352 | /* miscellaneous configuartions - begin */ |
| 3353 | /*----------------------------------------------------------------------------*/ |
| 3354 | |
| 3355 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3356 | * \fn int set_mpegtei_handling() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3357 | * \brief Activate MPEG TEI handling settings. |
| 3358 | * \param devmod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 3359 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3360 | * |
| 3361 | * This routine should be called during a set channel of QAM/VSB |
| 3362 | * |
| 3363 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 3364 | static int set_mpegtei_handling(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3365 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3366 | struct drxj_data *ext_attr = (struct drxj_data *) (NULL); |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 3367 | struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL); |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3368 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3369 | u16 fec_oc_dpr_mode = 0; |
| 3370 | u16 fec_oc_snc_mode = 0; |
| 3371 | u16 fec_oc_ems_mode = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3372 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3373 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3374 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3375 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3376 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_DPR_MODE__A, &fec_oc_dpr_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3377 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3378 | pr_err("error %d\n", rc); |
| 3379 | goto rw_error; |
| 3380 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3381 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_SNC_MODE__A, &fec_oc_snc_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3382 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3383 | pr_err("error %d\n", rc); |
| 3384 | goto rw_error; |
| 3385 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3386 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_EMS_MODE__A, &fec_oc_ems_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3387 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3388 | pr_err("error %d\n", rc); |
| 3389 | goto rw_error; |
| 3390 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3391 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3392 | /* reset to default, allow TEI bit to be changed */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3393 | fec_oc_dpr_mode &= (~FEC_OC_DPR_MODE_ERR_DISABLE__M); |
| 3394 | fec_oc_snc_mode &= (~(FEC_OC_SNC_MODE_ERROR_CTL__M | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3395 | FEC_OC_SNC_MODE_CORR_DISABLE__M)); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3396 | fec_oc_ems_mode &= (~FEC_OC_EMS_MODE_MODE__M); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3397 | |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 3398 | if (ext_attr->disable_te_ihandling) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3399 | /* do not change TEI bit */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3400 | fec_oc_dpr_mode |= FEC_OC_DPR_MODE_ERR_DISABLE__M; |
| 3401 | fec_oc_snc_mode |= FEC_OC_SNC_MODE_CORR_DISABLE__M | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3402 | ((0x2) << (FEC_OC_SNC_MODE_ERROR_CTL__B)); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3403 | fec_oc_ems_mode |= ((0x01) << (FEC_OC_EMS_MODE_MODE__B)); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3404 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3405 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3406 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DPR_MODE__A, fec_oc_dpr_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3407 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3408 | pr_err("error %d\n", rc); |
| 3409 | goto rw_error; |
| 3410 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3411 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_MODE__A, fec_oc_snc_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3412 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3413 | pr_err("error %d\n", rc); |
| 3414 | goto rw_error; |
| 3415 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3416 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_EMS_MODE__A, fec_oc_ems_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3417 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3418 | pr_err("error %d\n", rc); |
| 3419 | goto rw_error; |
| 3420 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3421 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3422 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3423 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3424 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | /*----------------------------------------------------------------------------*/ |
| 3428 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3429 | * \fn int bit_reverse_mpeg_output() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3430 | * \brief Set MPEG output bit-endian settings. |
| 3431 | * \param devmod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 3432 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3433 | * |
| 3434 | * This routine should be called during a set channel of QAM/VSB |
| 3435 | * |
| 3436 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 3437 | static int bit_reverse_mpeg_output(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3438 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3439 | struct drxj_data *ext_attr = (struct drxj_data *) (NULL); |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 3440 | struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL); |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3441 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3442 | u16 fec_oc_ipr_mode = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3443 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3444 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3445 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3446 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3447 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_IPR_MODE__A, &fec_oc_ipr_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3448 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3449 | pr_err("error %d\n", rc); |
| 3450 | goto rw_error; |
| 3451 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3452 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3453 | /* reset to default (normal bit order) */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3454 | fec_oc_ipr_mode &= (~FEC_OC_IPR_MODE_REVERSE_ORDER__M); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3455 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3456 | if (ext_attr->bit_reverse_mpeg_outout) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3457 | fec_oc_ipr_mode |= FEC_OC_IPR_MODE_REVERSE_ORDER__M; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3458 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3459 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_IPR_MODE__A, fec_oc_ipr_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3460 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3461 | pr_err("error %d\n", rc); |
| 3462 | goto rw_error; |
| 3463 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3464 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3465 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3466 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3467 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | /*----------------------------------------------------------------------------*/ |
| 3471 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3472 | * \fn int set_mpeg_start_width() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3473 | * \brief Set MPEG start width. |
| 3474 | * \param devmod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 3475 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3476 | * |
| 3477 | * This routine should be called during a set channel of QAM/VSB |
| 3478 | * |
| 3479 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 3480 | static int set_mpeg_start_width(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3481 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3482 | struct drxj_data *ext_attr = (struct drxj_data *) (NULL); |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 3483 | struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL); |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 3484 | struct drx_common_attr *common_attr = (struct drx_common_attr *) NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3485 | int rc; |
| 3486 | u16 fec_oc_comm_mb = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3487 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3488 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3489 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3490 | common_attr = demod->my_common_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3491 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3492 | if ((common_attr->mpeg_cfg.static_clk == true) |
| 3493 | && (common_attr->mpeg_cfg.enable_parallel == false)) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3494 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_COMM_MB__A, &fec_oc_comm_mb, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3495 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3496 | pr_err("error %d\n", rc); |
| 3497 | goto rw_error; |
| 3498 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3499 | fec_oc_comm_mb &= ~FEC_OC_COMM_MB_CTL_ON; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3500 | if (ext_attr->mpeg_start_width == DRXJ_MPEG_START_WIDTH_8CLKCYC) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3501 | fec_oc_comm_mb |= FEC_OC_COMM_MB_CTL_ON; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3502 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_COMM_MB__A, fec_oc_comm_mb, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3503 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3504 | pr_err("error %d\n", rc); |
| 3505 | goto rw_error; |
| 3506 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3507 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3508 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3509 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3510 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3511 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3512 | } |
| 3513 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3514 | /*----------------------------------------------------------------------------*/ |
| 3515 | /* miscellaneous configuartions - end */ |
| 3516 | /*----------------------------------------------------------------------------*/ |
| 3517 | |
| 3518 | /*----------------------------------------------------------------------------*/ |
| 3519 | /* UIO Configuration Functions - begin */ |
| 3520 | /*----------------------------------------------------------------------------*/ |
| 3521 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3522 | * \fn int ctrl_set_uio_cfg() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3523 | * \brief Configure modus oprandi UIO. |
| 3524 | * \param demod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3525 | * \param uio_cfg Pointer to a configuration setting for a certain UIO. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 3526 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3527 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 3528 | static int ctrl_set_uio_cfg(struct drx_demod_instance *demod, struct drxuio_cfg *uio_cfg) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3529 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3530 | struct drxj_data *ext_attr = (struct drxj_data *) (NULL); |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3531 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3532 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3533 | if ((uio_cfg == NULL) || (demod == NULL)) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3534 | return -EINVAL; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3535 | |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3536 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3537 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3538 | /* Write magic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3539 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3540 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3541 | pr_err("error %d\n", rc); |
| 3542 | goto rw_error; |
| 3543 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3544 | switch (uio_cfg->uio) { |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3545 | /*====================================================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3546 | case DRX_UIO1: |
| 3547 | /* DRX_UIO1: SMA_TX UIO-1 */ |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 3548 | if (!ext_attr->has_smatx) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3549 | return -EIO; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3550 | switch (uio_cfg->mode) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3551 | case DRX_UIO_MODE_FIRMWARE_SMA: /* falltrough */ |
| 3552 | case DRX_UIO_MODE_FIRMWARE_SAW: /* falltrough */ |
| 3553 | case DRX_UIO_MODE_READWRITE: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3554 | ext_attr->uio_sma_tx_mode = uio_cfg->mode; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3555 | break; |
| 3556 | case DRX_UIO_MODE_DISABLE: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3557 | ext_attr->uio_sma_tx_mode = uio_cfg->mode; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3558 | /* pad configuration register is set 0 - input mode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3559 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_TX_CFG__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3560 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3561 | pr_err("error %d\n", rc); |
| 3562 | goto rw_error; |
| 3563 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3564 | break; |
| 3565 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3566 | return -EINVAL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3567 | } /* switch ( uio_cfg->mode ) */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3568 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3569 | /*====================================================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3570 | case DRX_UIO2: |
| 3571 | /* DRX_UIO2: SMA_RX UIO-2 */ |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 3572 | if (!ext_attr->has_smarx) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3573 | return -EIO; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3574 | switch (uio_cfg->mode) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3575 | case DRX_UIO_MODE_FIRMWARE0: /* falltrough */ |
| 3576 | case DRX_UIO_MODE_READWRITE: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3577 | ext_attr->uio_sma_rx_mode = uio_cfg->mode; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3578 | break; |
| 3579 | case DRX_UIO_MODE_DISABLE: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3580 | ext_attr->uio_sma_rx_mode = uio_cfg->mode; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3581 | /* pad configuration register is set 0 - input mode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3582 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_RX_CFG__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3583 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3584 | pr_err("error %d\n", rc); |
| 3585 | goto rw_error; |
| 3586 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3587 | break; |
| 3588 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3589 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3590 | break; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3591 | } /* switch ( uio_cfg->mode ) */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3592 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3593 | /*====================================================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3594 | case DRX_UIO3: |
| 3595 | /* DRX_UIO3: GPIO UIO-3 */ |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 3596 | if (!ext_attr->has_gpio) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3597 | return -EIO; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3598 | switch (uio_cfg->mode) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3599 | case DRX_UIO_MODE_FIRMWARE0: /* falltrough */ |
| 3600 | case DRX_UIO_MODE_READWRITE: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3601 | ext_attr->uio_gpio_mode = uio_cfg->mode; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3602 | break; |
| 3603 | case DRX_UIO_MODE_DISABLE: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3604 | ext_attr->uio_gpio_mode = uio_cfg->mode; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3605 | /* pad configuration register is set 0 - input mode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3606 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_GPIO_CFG__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3607 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3608 | pr_err("error %d\n", rc); |
| 3609 | goto rw_error; |
| 3610 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3611 | break; |
| 3612 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3613 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3614 | break; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3615 | } /* switch ( uio_cfg->mode ) */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3616 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3617 | /*====================================================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3618 | case DRX_UIO4: |
| 3619 | /* DRX_UIO4: IRQN UIO-4 */ |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 3620 | if (!ext_attr->has_irqn) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3621 | return -EIO; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3622 | switch (uio_cfg->mode) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3623 | case DRX_UIO_MODE_READWRITE: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3624 | ext_attr->uio_irqn_mode = uio_cfg->mode; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3625 | break; |
| 3626 | case DRX_UIO_MODE_DISABLE: |
| 3627 | /* pad configuration register is set 0 - input mode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3628 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_IRQN_CFG__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3629 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3630 | pr_err("error %d\n", rc); |
| 3631 | goto rw_error; |
| 3632 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3633 | ext_attr->uio_irqn_mode = uio_cfg->mode; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3634 | break; |
| 3635 | case DRX_UIO_MODE_FIRMWARE0: /* falltrough */ |
| 3636 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3637 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3638 | break; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3639 | } /* switch ( uio_cfg->mode ) */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3640 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3641 | /*====================================================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3642 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3643 | return -EINVAL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3644 | } /* switch ( uio_cfg->uio ) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3645 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3646 | /* Write magic word to disable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3647 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3648 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3649 | pr_err("error %d\n", rc); |
| 3650 | goto rw_error; |
| 3651 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3652 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3653 | return 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3654 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3655 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3656 | } |
| 3657 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3658 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3659 | * \fn int ctrl_uio_write() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3660 | * \brief Write to a UIO. |
| 3661 | * \param demod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3662 | * \param uio_data Pointer to data container for a certain UIO. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 3663 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3664 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 3665 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 3666 | ctrl_uio_write(struct drx_demod_instance *demod, struct drxuio_data *uio_data) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3667 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3668 | struct drxj_data *ext_attr = (struct drxj_data *) (NULL); |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3669 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3670 | u16 pin_cfg_value = 0; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 3671 | u16 value = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3672 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3673 | if ((uio_data == NULL) || (demod == NULL)) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3674 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3675 | |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3676 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3677 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3678 | /* Write magic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3679 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3680 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3681 | pr_err("error %d\n", rc); |
| 3682 | goto rw_error; |
| 3683 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3684 | switch (uio_data->uio) { |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3685 | /*====================================================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3686 | case DRX_UIO1: |
| 3687 | /* DRX_UIO1: SMA_TX UIO-1 */ |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 3688 | if (!ext_attr->has_smatx) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3689 | return -EIO; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3690 | if ((ext_attr->uio_sma_tx_mode != DRX_UIO_MODE_READWRITE) |
| 3691 | && (ext_attr->uio_sma_tx_mode != DRX_UIO_MODE_FIRMWARE_SAW)) { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3692 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3693 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3694 | pin_cfg_value = 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3695 | /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3696 | pin_cfg_value |= 0x0113; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3697 | /* io_pad_cfg_mode output mode is drive always */ |
| 3698 | /* io_pad_cfg_drive is set to power 2 (23 mA) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3699 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3700 | /* write to io pad configuration register - output mode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3701 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_TX_CFG__A, pin_cfg_value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3702 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3703 | pr_err("error %d\n", rc); |
| 3704 | goto rw_error; |
| 3705 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3706 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3707 | /* use corresponding bit in io data output registar */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3708 | rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, &value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3709 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3710 | pr_err("error %d\n", rc); |
| 3711 | goto rw_error; |
| 3712 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3713 | if (!uio_data->value) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3714 | value &= 0x7FFF; /* write zero to 15th bit - 1st UIO */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3715 | else |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3716 | value |= 0x8000; /* write one to 15th bit - 1st UIO */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3717 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3718 | /* write back to io data output register */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3719 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3720 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3721 | pr_err("error %d\n", rc); |
| 3722 | goto rw_error; |
| 3723 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3724 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3725 | /*======================================================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3726 | case DRX_UIO2: |
| 3727 | /* DRX_UIO2: SMA_RX UIO-2 */ |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 3728 | if (!ext_attr->has_smarx) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3729 | return -EIO; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3730 | if (ext_attr->uio_sma_rx_mode != DRX_UIO_MODE_READWRITE) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3731 | return -EIO; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3732 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3733 | pin_cfg_value = 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3734 | /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3735 | pin_cfg_value |= 0x0113; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3736 | /* io_pad_cfg_mode output mode is drive always */ |
| 3737 | /* io_pad_cfg_drive is set to power 2 (23 mA) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3738 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3739 | /* write to io pad configuration register - output mode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3740 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_RX_CFG__A, pin_cfg_value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3741 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3742 | pr_err("error %d\n", rc); |
| 3743 | goto rw_error; |
| 3744 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3745 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3746 | /* use corresponding bit in io data output registar */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3747 | rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, &value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3748 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3749 | pr_err("error %d\n", rc); |
| 3750 | goto rw_error; |
| 3751 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3752 | if (!uio_data->value) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3753 | value &= 0xBFFF; /* write zero to 14th bit - 2nd UIO */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3754 | else |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3755 | value |= 0x4000; /* write one to 14th bit - 2nd UIO */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3756 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3757 | /* write back to io data output register */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3758 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3759 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3760 | pr_err("error %d\n", rc); |
| 3761 | goto rw_error; |
| 3762 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3763 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3764 | /*====================================================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3765 | case DRX_UIO3: |
| 3766 | /* DRX_UIO3: ASEL UIO-3 */ |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 3767 | if (!ext_attr->has_gpio) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3768 | return -EIO; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3769 | if (ext_attr->uio_gpio_mode != DRX_UIO_MODE_READWRITE) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3770 | return -EIO; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3771 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3772 | pin_cfg_value = 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3773 | /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3774 | pin_cfg_value |= 0x0113; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3775 | /* io_pad_cfg_mode output mode is drive always */ |
| 3776 | /* io_pad_cfg_drive is set to power 2 (23 mA) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3777 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3778 | /* write to io pad configuration register - output mode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3779 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_GPIO_CFG__A, pin_cfg_value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3780 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3781 | pr_err("error %d\n", rc); |
| 3782 | goto rw_error; |
| 3783 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3784 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3785 | /* use corresponding bit in io data output registar */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3786 | rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_HI__A, &value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3787 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3788 | pr_err("error %d\n", rc); |
| 3789 | goto rw_error; |
| 3790 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3791 | if (!uio_data->value) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3792 | value &= 0xFFFB; /* write zero to 2nd bit - 3rd UIO */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3793 | else |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3794 | value |= 0x0004; /* write one to 2nd bit - 3rd UIO */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3795 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3796 | /* write back to io data output register */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3797 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_HI__A, value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3798 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3799 | pr_err("error %d\n", rc); |
| 3800 | goto rw_error; |
| 3801 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3802 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3803 | /*=====================================================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3804 | case DRX_UIO4: |
| 3805 | /* DRX_UIO4: IRQN UIO-4 */ |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 3806 | if (!ext_attr->has_irqn) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3807 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3808 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3809 | if (ext_attr->uio_irqn_mode != DRX_UIO_MODE_READWRITE) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3810 | return -EIO; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3811 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3812 | pin_cfg_value = 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3813 | /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3814 | pin_cfg_value |= 0x0113; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3815 | /* io_pad_cfg_mode output mode is drive always */ |
| 3816 | /* io_pad_cfg_drive is set to power 2 (23 mA) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3817 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3818 | /* write to io pad configuration register - output mode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3819 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_IRQN_CFG__A, pin_cfg_value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3820 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3821 | pr_err("error %d\n", rc); |
| 3822 | goto rw_error; |
| 3823 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3824 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3825 | /* use corresponding bit in io data output registar */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3826 | rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, &value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3827 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3828 | pr_err("error %d\n", rc); |
| 3829 | goto rw_error; |
| 3830 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3831 | if (uio_data->value == false) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3832 | value &= 0xEFFF; /* write zero to 12th bit - 4th UIO */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3833 | else |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3834 | value |= 0x1000; /* write one to 12th bit - 4th UIO */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3835 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3836 | /* write back to io data output register */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3837 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, value, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3838 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3839 | pr_err("error %d\n", rc); |
| 3840 | goto rw_error; |
| 3841 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3842 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3843 | /*=====================================================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3844 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3845 | return -EINVAL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3846 | } /* switch ( uio_data->uio ) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3847 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3848 | /* Write magic word to disable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3849 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3850 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3851 | pr_err("error %d\n", rc); |
| 3852 | goto rw_error; |
| 3853 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3854 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3855 | return 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3856 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3857 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3858 | } |
| 3859 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3860 | /*---------------------------------------------------------------------------*/ |
| 3861 | /* UIO Configuration Functions - end */ |
| 3862 | /*---------------------------------------------------------------------------*/ |
| 3863 | |
| 3864 | /*----------------------------------------------------------------------------*/ |
| 3865 | /* I2C Bridge Functions - begin */ |
| 3866 | /*----------------------------------------------------------------------------*/ |
| 3867 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3868 | * \fn int ctrl_i2c_bridge() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3869 | * \brief Open or close the I2C switch to tuner. |
| 3870 | * \param demod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3871 | * \param bridge_closed Pointer to bool indication if bridge is closed not. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 3872 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3873 | |
| 3874 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 3875 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 3876 | ctrl_i2c_bridge(struct drx_demod_instance *demod, bool *bridge_closed) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3877 | { |
Mauro Carvalho Chehab | 60d3603 | 2014-01-17 07:00:31 -0300 | [diff] [blame] | 3878 | struct drxj_hi_cmd hi_cmd; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 3879 | u16 result = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3880 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3881 | /* check arguments */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3882 | if (bridge_closed == NULL) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3883 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3884 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3885 | hi_cmd.cmd = SIO_HI_RA_RAM_CMD_BRDCTRL; |
| 3886 | hi_cmd.param1 = SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3887 | if (*bridge_closed) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3888 | hi_cmd.param2 = SIO_HI_RA_RAM_PAR_2_BRD_CFG_CLOSED; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3889 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3890 | hi_cmd.param2 = SIO_HI_RA_RAM_PAR_2_BRD_CFG_OPEN; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3891 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3892 | return hi_command(demod->my_i2c_dev_addr, &hi_cmd, &result); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3893 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3894 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3895 | /*----------------------------------------------------------------------------*/ |
| 3896 | /* I2C Bridge Functions - end */ |
| 3897 | /*----------------------------------------------------------------------------*/ |
| 3898 | |
| 3899 | /*----------------------------------------------------------------------------*/ |
| 3900 | /* Smart antenna Functions - begin */ |
| 3901 | /*----------------------------------------------------------------------------*/ |
| 3902 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3903 | * \fn int smart_ant_init() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3904 | * \brief Initialize Smart Antenna. |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 3905 | * \param pointer to struct drx_demod_instance. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 3906 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3907 | * |
| 3908 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 3909 | static int smart_ant_init(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3910 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3911 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3912 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 3913 | struct drxuio_cfg uio_cfg = { DRX_UIO1, DRX_UIO_MODE_FIRMWARE_SMA }; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3914 | int rc; |
| 3915 | u16 data = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3916 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3917 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3918 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3919 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3920 | /* Write magic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3921 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3922 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3923 | pr_err("error %d\n", rc); |
| 3924 | goto rw_error; |
| 3925 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3926 | /* init smart antenna */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3927 | rc = drxj_dap_read_reg16(dev_addr, SIO_SA_TX_COMMAND__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3928 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3929 | pr_err("error %d\n", rc); |
| 3930 | goto rw_error; |
| 3931 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3932 | if (ext_attr->smart_ant_inverted) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3933 | rc = drxj_dap_write_reg16(dev_addr, SIO_SA_TX_COMMAND__A, (data | SIO_SA_TX_COMMAND_TX_INVERT__M) | SIO_SA_TX_COMMAND_TX_ENABLE__M, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3934 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3935 | pr_err("error %d\n", rc); |
| 3936 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3937 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3938 | } else { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3939 | rc = drxj_dap_write_reg16(dev_addr, SIO_SA_TX_COMMAND__A, (data & (~SIO_SA_TX_COMMAND_TX_INVERT__M)) | SIO_SA_TX_COMMAND_TX_ENABLE__M, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3940 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3941 | pr_err("error %d\n", rc); |
| 3942 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3943 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3944 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3945 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3946 | /* config SMA_TX pin to smart antenna mode */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3947 | rc = ctrl_set_uio_cfg(demod, &uio_cfg); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3948 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3949 | pr_err("error %d\n", rc); |
| 3950 | goto rw_error; |
| 3951 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3952 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_TX_CFG__A, 0x13, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3953 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3954 | pr_err("error %d\n", rc); |
| 3955 | goto rw_error; |
| 3956 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3957 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_TX_GPIO_FNC__A, 0x03, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3958 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3959 | pr_err("error %d\n", rc); |
| 3960 | goto rw_error; |
| 3961 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3962 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3963 | /* Write magic word to disable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3964 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3965 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3966 | pr_err("error %d\n", rc); |
| 3967 | goto rw_error; |
| 3968 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3969 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3970 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3971 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3972 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3973 | } |
| 3974 | |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 3975 | static int scu_command(struct i2c_device_addr *dev_addr, struct drxjscu_cmd *cmd) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3976 | { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3977 | int rc; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3978 | u16 cur_cmd = 0; |
Mauro Carvalho Chehab | ceea5e2 | 2014-01-26 15:55:57 -0300 | [diff] [blame] | 3979 | unsigned long timeout; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3980 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3981 | /* Check param */ |
| 3982 | if (cmd == NULL) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3983 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3984 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3985 | /* Wait until SCU command interface is ready to receive command */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3986 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_COMMAND__A, &cur_cmd, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3987 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3988 | pr_err("error %d\n", rc); |
| 3989 | goto rw_error; |
| 3990 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 3991 | if (cur_cmd != DRX_SCU_READY) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3992 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 3993 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 3994 | switch (cmd->parameter_len) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 3995 | case 5: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 3996 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_PARAM_4__A, *(cmd->parameter + 4), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 3997 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 3998 | pr_err("error %d\n", rc); |
| 3999 | goto rw_error; |
| 4000 | } /* fallthrough */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4001 | case 4: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4002 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_PARAM_3__A, *(cmd->parameter + 3), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4003 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4004 | pr_err("error %d\n", rc); |
| 4005 | goto rw_error; |
| 4006 | } /* fallthrough */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4007 | case 3: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4008 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_PARAM_2__A, *(cmd->parameter + 2), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4009 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4010 | pr_err("error %d\n", rc); |
| 4011 | goto rw_error; |
| 4012 | } /* fallthrough */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4013 | case 2: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4014 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_PARAM_1__A, *(cmd->parameter + 1), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4015 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4016 | pr_err("error %d\n", rc); |
| 4017 | goto rw_error; |
| 4018 | } /* fallthrough */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4019 | case 1: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4020 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_PARAM_0__A, *(cmd->parameter + 0), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4021 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4022 | pr_err("error %d\n", rc); |
| 4023 | goto rw_error; |
| 4024 | } /* fallthrough */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4025 | case 0: |
| 4026 | /* do nothing */ |
| 4027 | break; |
| 4028 | default: |
| 4029 | /* this number of parameters is not supported */ |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4030 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4031 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4032 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_COMMAND__A, cmd->command, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4033 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4034 | pr_err("error %d\n", rc); |
| 4035 | goto rw_error; |
| 4036 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4037 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4038 | /* Wait until SCU has processed command */ |
Mauro Carvalho Chehab | ceea5e2 | 2014-01-26 15:55:57 -0300 | [diff] [blame] | 4039 | timeout = jiffies + msecs_to_jiffies(DRXJ_MAX_WAITTIME); |
| 4040 | while (time_is_after_jiffies(timeout)) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4041 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_COMMAND__A, &cur_cmd, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4042 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4043 | pr_err("error %d\n", rc); |
| 4044 | goto rw_error; |
| 4045 | } |
Mauro Carvalho Chehab | ceea5e2 | 2014-01-26 15:55:57 -0300 | [diff] [blame] | 4046 | if (cur_cmd == DRX_SCU_READY) |
| 4047 | break; |
| 4048 | usleep_range(1000, 2000); |
| 4049 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4050 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4051 | if (cur_cmd != DRX_SCU_READY) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4052 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4053 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4054 | /* read results */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4055 | if ((cmd->result_len > 0) && (cmd->result != NULL)) { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 4056 | s16 err; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4057 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4058 | switch (cmd->result_len) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4059 | case 4: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4060 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_PARAM_3__A, cmd->result + 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4061 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4062 | pr_err("error %d\n", rc); |
| 4063 | goto rw_error; |
| 4064 | } /* fallthrough */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4065 | case 3: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4066 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_PARAM_2__A, cmd->result + 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4067 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4068 | pr_err("error %d\n", rc); |
| 4069 | goto rw_error; |
| 4070 | } /* fallthrough */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4071 | case 2: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4072 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_PARAM_1__A, cmd->result + 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4073 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4074 | pr_err("error %d\n", rc); |
| 4075 | goto rw_error; |
| 4076 | } /* fallthrough */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4077 | case 1: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4078 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_PARAM_0__A, cmd->result + 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4079 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4080 | pr_err("error %d\n", rc); |
| 4081 | goto rw_error; |
| 4082 | } /* fallthrough */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4083 | case 0: |
| 4084 | /* do nothing */ |
| 4085 | break; |
| 4086 | default: |
| 4087 | /* this number of parameters is not supported */ |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4088 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4089 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4090 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4091 | /* Check if an error was reported by SCU */ |
| 4092 | err = cmd->result[0]; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4093 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4094 | /* check a few fixed error codes */ |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 4095 | if ((err == (s16) SCU_RAM_PARAM_0_RESULT_UNKSTD) |
| 4096 | || (err == (s16) SCU_RAM_PARAM_0_RESULT_UNKCMD) |
| 4097 | || (err == (s16) SCU_RAM_PARAM_0_RESULT_INVPAR) |
| 4098 | || (err == (s16) SCU_RAM_PARAM_0_RESULT_SIZE) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4099 | ) { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4100 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4101 | } |
| 4102 | /* here it is assumed that negative means error, and positive no error */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4103 | else if (err < 0) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4104 | return -EIO; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4105 | else |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4106 | return 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4107 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4108 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4109 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4110 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4111 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4112 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4113 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4114 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4115 | /** |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4116 | * \fn int DRXJ_DAP_SCUAtomicReadWriteBlock() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4117 | * \brief Basic access routine for SCU atomic read or write access |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4118 | * \param dev_addr pointer to i2c dev address |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4119 | * \param addr destination/source address |
| 4120 | * \param datasize size of data buffer in bytes |
| 4121 | * \param data pointer to data buffer |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4122 | * \return int |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4123 | * \retval 0 Succes |
| 4124 | * \retval -EIO Timeout, I2C error, illegal bank |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4125 | * |
| 4126 | */ |
| 4127 | #define ADDR_AT_SCU_SPACE(x) ((x - 0x82E000) * 2) |
| 4128 | static |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4129 | int drxj_dap_scu_atomic_read_write_block(struct i2c_device_addr *dev_addr, u32 addr, u16 datasize, /* max 30 bytes because the limit of SCU parameter */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4130 | u8 *data, bool read_flag) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4131 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 4132 | struct drxjscu_cmd scu_cmd; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4133 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4134 | u16 set_param_parameters[15]; |
| 4135 | u16 cmd_result[15]; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4136 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4137 | /* Parameter check */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4138 | if (!data || !dev_addr || (datasize % 2) || ((datasize / 2) > 16)) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4139 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4140 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4141 | set_param_parameters[1] = (u16) ADDR_AT_SCU_SPACE(addr); |
| 4142 | if (read_flag) { /* read */ |
| 4143 | set_param_parameters[0] = ((~(0x0080)) & datasize); |
| 4144 | scu_cmd.parameter_len = 2; |
| 4145 | scu_cmd.result_len = datasize / 2 + 2; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4146 | } else { |
| 4147 | int i = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4148 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4149 | set_param_parameters[0] = 0x0080 | datasize; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4150 | for (i = 0; i < (datasize / 2); i++) { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4151 | set_param_parameters[i + 2] = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4152 | (data[2 * i] | (data[(2 * i) + 1] << 8)); |
| 4153 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4154 | scu_cmd.parameter_len = datasize / 2 + 2; |
| 4155 | scu_cmd.result_len = 1; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4156 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4157 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4158 | scu_cmd.command = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4159 | SCU_RAM_COMMAND_STANDARD_TOP | |
| 4160 | SCU_RAM_COMMAND_CMD_AUX_SCU_ATOMIC_ACCESS; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4161 | scu_cmd.result = cmd_result; |
| 4162 | scu_cmd.parameter = set_param_parameters; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4163 | rc = scu_command(dev_addr, &scu_cmd); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4164 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4165 | pr_err("error %d\n", rc); |
| 4166 | goto rw_error; |
| 4167 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4168 | |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 4169 | if (read_flag) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4170 | int i = 0; |
| 4171 | /* read data from buffer */ |
| 4172 | for (i = 0; i < (datasize / 2); i++) { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4173 | data[2 * i] = (u8) (scu_cmd.result[i + 2] & 0xFF); |
| 4174 | data[(2 * i) + 1] = (u8) (scu_cmd.result[i + 2] >> 8); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4175 | } |
| 4176 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4177 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4178 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4179 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4180 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4181 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4182 | |
| 4183 | } |
| 4184 | |
| 4185 | /*============================================================================*/ |
| 4186 | |
| 4187 | /** |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4188 | * \fn int DRXJ_DAP_AtomicReadReg16() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4189 | * \brief Atomic read of 16 bits words |
| 4190 | */ |
| 4191 | static |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4192 | int drxj_dap_scu_atomic_read_reg16(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4193 | u32 addr, |
| 4194 | u16 *data, u32 flags) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4195 | { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 4196 | u8 buf[2]; |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4197 | int rc = -EIO; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 4198 | u16 word = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4199 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4200 | if (!data) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4201 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4202 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4203 | rc = drxj_dap_scu_atomic_read_write_block(dev_addr, addr, 2, buf, true); |
Mauro Carvalho Chehab | b1d0a59 | 2014-01-16 16:34:03 -0300 | [diff] [blame] | 4204 | if (rc < 0) |
| 4205 | return rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4206 | |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 4207 | word = (u16) (buf[0] + (buf[1] << 8)); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4208 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4209 | *data = word; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4210 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4211 | return rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4212 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4213 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4214 | /*============================================================================*/ |
| 4215 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4216 | * \fn int drxj_dap_scu_atomic_write_reg16() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4217 | * \brief Atomic read of 16 bits words |
| 4218 | */ |
| 4219 | static |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4220 | int drxj_dap_scu_atomic_write_reg16(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4221 | u32 addr, |
| 4222 | u16 data, u32 flags) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4223 | { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 4224 | u8 buf[2]; |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4225 | int rc = -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4226 | |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 4227 | buf[0] = (u8) (data & 0xff); |
| 4228 | buf[1] = (u8) ((data >> 8) & 0xff); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4229 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4230 | rc = drxj_dap_scu_atomic_read_write_block(dev_addr, addr, 2, buf, false); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4231 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4232 | return rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4233 | } |
| 4234 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4235 | /* -------------------------------------------------------------------------- */ |
| 4236 | /** |
| 4237 | * \brief Measure result of ADC synchronisation |
| 4238 | * \param demod demod instance |
| 4239 | * \param count (returned) count |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4240 | * \return int. |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4241 | * \retval 0 Success |
| 4242 | * \retval -EIO Failure: I2C error |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4243 | * |
| 4244 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4245 | static int adc_sync_measurement(struct drx_demod_instance *demod, u16 *count) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4246 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4247 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4248 | int rc; |
| 4249 | u16 data = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4250 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4251 | dev_addr = demod->my_i2c_dev_addr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4252 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4253 | /* Start measurement */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4254 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_COMM_EXEC__A, IQM_AF_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4255 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4256 | pr_err("error %d\n", rc); |
| 4257 | goto rw_error; |
| 4258 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4259 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_START_LOCK__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4260 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4261 | pr_err("error %d\n", rc); |
| 4262 | goto rw_error; |
| 4263 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4264 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4265 | /* Wait at least 3*128*(1/sysclk) <<< 1 millisec */ |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 4266 | msleep(1); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4267 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4268 | *count = 0; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4269 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_PHASE0__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4270 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4271 | pr_err("error %d\n", rc); |
| 4272 | goto rw_error; |
| 4273 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4274 | if (data == 127) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4275 | *count = *count + 1; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4276 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_PHASE1__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4277 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4278 | pr_err("error %d\n", rc); |
| 4279 | goto rw_error; |
| 4280 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4281 | if (data == 127) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4282 | *count = *count + 1; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4283 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_PHASE2__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4284 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4285 | pr_err("error %d\n", rc); |
| 4286 | goto rw_error; |
| 4287 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4288 | if (data == 127) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4289 | *count = *count + 1; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4290 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4291 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4292 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4293 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | /** |
| 4297 | * \brief Synchronize analog and digital clock domains |
| 4298 | * \param demod demod instance |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4299 | * \return int. |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4300 | * \retval 0 Success |
| 4301 | * \retval -EIO Failure: I2C error or failure to synchronize |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4302 | * |
| 4303 | * An IQM reset will also reset the results of this synchronization. |
| 4304 | * After an IQM reset this routine needs to be called again. |
| 4305 | * |
| 4306 | */ |
| 4307 | |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4308 | static int adc_synchronization(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4309 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4310 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4311 | int rc; |
| 4312 | u16 count = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4313 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4314 | dev_addr = demod->my_i2c_dev_addr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4315 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4316 | rc = adc_sync_measurement(demod, &count); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4317 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4318 | pr_err("error %d\n", rc); |
| 4319 | goto rw_error; |
| 4320 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4321 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4322 | if (count == 1) { |
| 4323 | /* Try sampling on a diffrent edge */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4324 | u16 clk_neg = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4325 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4326 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_CLKNEG__A, &clk_neg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4327 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4328 | pr_err("error %d\n", rc); |
| 4329 | goto rw_error; |
| 4330 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4331 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4332 | clk_neg ^= IQM_AF_CLKNEG_CLKNEGDATA__M; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4333 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_CLKNEG__A, clk_neg, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4334 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4335 | pr_err("error %d\n", rc); |
| 4336 | goto rw_error; |
| 4337 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4338 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4339 | rc = adc_sync_measurement(demod, &count); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4340 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4341 | pr_err("error %d\n", rc); |
| 4342 | goto rw_error; |
| 4343 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4344 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4345 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4346 | /* TODO: implement fallback scenarios */ |
| 4347 | if (count < 2) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4348 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4349 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4350 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4351 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4352 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4353 | } |
| 4354 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4355 | /*============================================================================*/ |
| 4356 | /*== END AUXILIARY FUNCTIONS ==*/ |
| 4357 | /*============================================================================*/ |
| 4358 | |
| 4359 | /*============================================================================*/ |
| 4360 | /*============================================================================*/ |
| 4361 | /*== 8VSB & QAM COMMON DATAPATH FUNCTIONS ==*/ |
| 4362 | /*============================================================================*/ |
| 4363 | /*============================================================================*/ |
| 4364 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4365 | * \fn int init_agc () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4366 | * \brief Initialize AGC for all standards. |
| 4367 | * \param demod instance of demodulator. |
| 4368 | * \param channel pointer to channel data. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4369 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4370 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4371 | static int init_agc(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4372 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4373 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4374 | struct drx_common_attr *common_attr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 4375 | struct drxj_data *ext_attr = NULL; |
| 4376 | struct drxj_cfg_agc *p_agc_rf_settings = NULL; |
| 4377 | struct drxj_cfg_agc *p_agc_if_settings = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4378 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4379 | u16 ingain_tgt_max = 0; |
| 4380 | u16 clp_dir_to = 0; |
| 4381 | u16 sns_sum_max = 0; |
| 4382 | u16 clp_sum_max = 0; |
| 4383 | u16 sns_dir_to = 0; |
| 4384 | u16 ki_innergain_min = 0; |
| 4385 | u16 agc_ki = 0; |
| 4386 | u16 ki_max = 0; |
| 4387 | u16 if_iaccu_hi_tgt_min = 0; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 4388 | u16 data = 0; |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 4389 | u16 agc_ki_dgain = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4390 | u16 ki_min = 0; |
| 4391 | u16 clp_ctrl_mode = 0; |
| 4392 | u16 agc_rf = 0; |
| 4393 | u16 agc_if = 0; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4394 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4395 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4396 | common_attr = (struct drx_common_attr *) demod->my_common_attr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 4397 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4398 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4399 | switch (ext_attr->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4400 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4401 | clp_sum_max = 1023; |
| 4402 | clp_dir_to = (u16) (-9); |
| 4403 | sns_sum_max = 1023; |
| 4404 | sns_dir_to = (u16) (-9); |
| 4405 | ki_innergain_min = (u16) (-32768); |
| 4406 | ki_max = 0x032C; |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 4407 | agc_ki_dgain = 0xC; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4408 | if_iaccu_hi_tgt_min = 2047; |
| 4409 | ki_min = 0x0117; |
| 4410 | ingain_tgt_max = 16383; |
| 4411 | clp_ctrl_mode = 0; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4412 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MINGAIN__A, 0x7fff, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4413 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4414 | pr_err("error %d\n", rc); |
| 4415 | goto rw_error; |
| 4416 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4417 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MAXGAIN__A, 0x0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4418 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4419 | pr_err("error %d\n", rc); |
| 4420 | goto rw_error; |
| 4421 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4422 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_SUM__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4423 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4424 | pr_err("error %d\n", rc); |
| 4425 | goto rw_error; |
| 4426 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4427 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_CYCCNT__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4428 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4429 | pr_err("error %d\n", rc); |
| 4430 | goto rw_error; |
| 4431 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4432 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_DIR_WD__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4433 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4434 | pr_err("error %d\n", rc); |
| 4435 | goto rw_error; |
| 4436 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4437 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_DIR_STP__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4438 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4439 | pr_err("error %d\n", rc); |
| 4440 | goto rw_error; |
| 4441 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4442 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_SUM__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4443 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4444 | pr_err("error %d\n", rc); |
| 4445 | goto rw_error; |
| 4446 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4447 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_CYCCNT__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4448 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4449 | pr_err("error %d\n", rc); |
| 4450 | goto rw_error; |
| 4451 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4452 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_DIR_WD__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4453 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4454 | pr_err("error %d\n", rc); |
| 4455 | goto rw_error; |
| 4456 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4457 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_DIR_STP__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4458 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4459 | pr_err("error %d\n", rc); |
| 4460 | goto rw_error; |
| 4461 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4462 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN__A, 1024, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4463 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4464 | pr_err("error %d\n", rc); |
| 4465 | goto rw_error; |
| 4466 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4467 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_VSB_AGC_POW_TGT__A, 22600, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4468 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4469 | pr_err("error %d\n", rc); |
| 4470 | goto rw_error; |
| 4471 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4472 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN_TGT__A, 13200, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4473 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4474 | pr_err("error %d\n", rc); |
| 4475 | goto rw_error; |
| 4476 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4477 | p_agc_if_settings = &(ext_attr->vsb_if_agc_cfg); |
| 4478 | p_agc_rf_settings = &(ext_attr->vsb_rf_agc_cfg); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4479 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4480 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4481 | case DRX_STANDARD_ITU_A: |
| 4482 | case DRX_STANDARD_ITU_C: |
| 4483 | case DRX_STANDARD_ITU_B: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4484 | ingain_tgt_max = 5119; |
| 4485 | clp_sum_max = 1023; |
| 4486 | clp_dir_to = (u16) (-5); |
| 4487 | sns_sum_max = 127; |
| 4488 | sns_dir_to = (u16) (-3); |
| 4489 | ki_innergain_min = 0; |
| 4490 | ki_max = 0x0657; |
| 4491 | if_iaccu_hi_tgt_min = 2047; |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 4492 | agc_ki_dgain = 0x7; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4493 | ki_min = 0x0117; |
| 4494 | clp_ctrl_mode = 0; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4495 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MINGAIN__A, 0x7fff, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4496 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4497 | pr_err("error %d\n", rc); |
| 4498 | goto rw_error; |
| 4499 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4500 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MAXGAIN__A, 0x0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4501 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4502 | pr_err("error %d\n", rc); |
| 4503 | goto rw_error; |
| 4504 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4505 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_SUM__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4506 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4507 | pr_err("error %d\n", rc); |
| 4508 | goto rw_error; |
| 4509 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4510 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_CYCCNT__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4511 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4512 | pr_err("error %d\n", rc); |
| 4513 | goto rw_error; |
| 4514 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4515 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_DIR_WD__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4516 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4517 | pr_err("error %d\n", rc); |
| 4518 | goto rw_error; |
| 4519 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4520 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_DIR_STP__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4521 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4522 | pr_err("error %d\n", rc); |
| 4523 | goto rw_error; |
| 4524 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4525 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_SUM__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4526 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4527 | pr_err("error %d\n", rc); |
| 4528 | goto rw_error; |
| 4529 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4530 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_CYCCNT__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4531 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4532 | pr_err("error %d\n", rc); |
| 4533 | goto rw_error; |
| 4534 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4535 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_DIR_WD__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4536 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4537 | pr_err("error %d\n", rc); |
| 4538 | goto rw_error; |
| 4539 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4540 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_DIR_STP__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4541 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4542 | pr_err("error %d\n", rc); |
| 4543 | goto rw_error; |
| 4544 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4545 | p_agc_if_settings = &(ext_attr->qam_if_agc_cfg); |
| 4546 | p_agc_rf_settings = &(ext_attr->qam_rf_agc_cfg); |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4547 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN_TGT__A, p_agc_if_settings->top, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4548 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4549 | pr_err("error %d\n", rc); |
| 4550 | goto rw_error; |
| 4551 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4552 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4553 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_AGC_KI__A, &agc_ki, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4554 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4555 | pr_err("error %d\n", rc); |
| 4556 | goto rw_error; |
| 4557 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4558 | agc_ki &= 0xf000; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4559 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI__A, agc_ki, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4560 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4561 | pr_err("error %d\n", rc); |
| 4562 | goto rw_error; |
| 4563 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4564 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4565 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4566 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4567 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4568 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4569 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4570 | /* for new AGC interface */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4571 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN_TGT_MIN__A, p_agc_if_settings->top, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4572 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4573 | pr_err("error %d\n", rc); |
| 4574 | goto rw_error; |
| 4575 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4576 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN__A, p_agc_if_settings->top, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4577 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4578 | pr_err("error %d\n", rc); |
| 4579 | goto rw_error; |
| 4580 | } /* Gain fed from inner to outer AGC */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4581 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN_TGT_MAX__A, ingain_tgt_max, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4582 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4583 | pr_err("error %d\n", rc); |
| 4584 | goto rw_error; |
| 4585 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4586 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT_MIN__A, if_iaccu_hi_tgt_min, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4587 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4588 | pr_err("error %d\n", rc); |
| 4589 | goto rw_error; |
| 4590 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4591 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_IF_IACCU_HI__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4592 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4593 | pr_err("error %d\n", rc); |
| 4594 | goto rw_error; |
| 4595 | } /* set to p_agc_settings->top before */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4596 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_IF_IACCU_LO__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4597 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4598 | pr_err("error %d\n", rc); |
| 4599 | goto rw_error; |
| 4600 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4601 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_RF_IACCU_HI__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4602 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4603 | pr_err("error %d\n", rc); |
| 4604 | goto rw_error; |
| 4605 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4606 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_RF_IACCU_LO__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4607 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4608 | pr_err("error %d\n", rc); |
| 4609 | goto rw_error; |
| 4610 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4611 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_RF_MAX__A, 32767, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4612 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4613 | pr_err("error %d\n", rc); |
| 4614 | goto rw_error; |
| 4615 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4616 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_SUM_MAX__A, clp_sum_max, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4617 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4618 | pr_err("error %d\n", rc); |
| 4619 | goto rw_error; |
| 4620 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4621 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_SUM_MAX__A, sns_sum_max, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4622 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4623 | pr_err("error %d\n", rc); |
| 4624 | goto rw_error; |
| 4625 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4626 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_INNERGAIN_MIN__A, ki_innergain_min, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4627 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4628 | pr_err("error %d\n", rc); |
| 4629 | goto rw_error; |
| 4630 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4631 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_FAST_SNS_CTRL_DELAY__A, 50, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4632 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4633 | pr_err("error %d\n", rc); |
| 4634 | goto rw_error; |
| 4635 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4636 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_CYCLEN__A, 500, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4637 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4638 | pr_err("error %d\n", rc); |
| 4639 | goto rw_error; |
| 4640 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4641 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_CYCLEN__A, 500, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4642 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4643 | pr_err("error %d\n", rc); |
| 4644 | goto rw_error; |
| 4645 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4646 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A, 20, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4647 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4648 | pr_err("error %d\n", rc); |
| 4649 | goto rw_error; |
| 4650 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4651 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MIN__A, ki_min, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4652 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4653 | pr_err("error %d\n", rc); |
| 4654 | goto rw_error; |
| 4655 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4656 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MAX__A, ki_max, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4657 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4658 | pr_err("error %d\n", rc); |
| 4659 | goto rw_error; |
| 4660 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4661 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_RED__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4662 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4663 | pr_err("error %d\n", rc); |
| 4664 | goto rw_error; |
| 4665 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4666 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_SUM_MIN__A, 8, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4667 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4668 | pr_err("error %d\n", rc); |
| 4669 | goto rw_error; |
| 4670 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4671 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_CYCLEN__A, 500, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4672 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4673 | pr_err("error %d\n", rc); |
| 4674 | goto rw_error; |
| 4675 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4676 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_DIR_TO__A, clp_dir_to, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4677 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4678 | pr_err("error %d\n", rc); |
| 4679 | goto rw_error; |
| 4680 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4681 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_SUM_MIN__A, 8, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4682 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4683 | pr_err("error %d\n", rc); |
| 4684 | goto rw_error; |
| 4685 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4686 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_DIR_TO__A, sns_dir_to, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4687 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4688 | pr_err("error %d\n", rc); |
| 4689 | goto rw_error; |
| 4690 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4691 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, 50, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4692 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4693 | pr_err("error %d\n", rc); |
| 4694 | goto rw_error; |
| 4695 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4696 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_CTRL_MODE__A, clp_ctrl_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4697 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4698 | pr_err("error %d\n", rc); |
| 4699 | goto rw_error; |
| 4700 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4701 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4702 | agc_rf = 0x800 + p_agc_rf_settings->cut_off_current; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4703 | if (common_attr->tuner_rf_agc_pol == true) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4704 | agc_rf = 0x87ff - agc_rf; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4705 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4706 | agc_if = 0x800; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4707 | if (common_attr->tuner_if_agc_pol == true) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4708 | agc_rf = 0x87ff - agc_rf; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4709 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4710 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_AGC_RF__A, agc_rf, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4711 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4712 | pr_err("error %d\n", rc); |
| 4713 | goto rw_error; |
| 4714 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4715 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_AGC_IF__A, agc_if, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4716 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4717 | pr_err("error %d\n", rc); |
| 4718 | goto rw_error; |
| 4719 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4720 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4721 | /* Set/restore Ki DGAIN factor */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4722 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_AGC_KI__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4723 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4724 | pr_err("error %d\n", rc); |
| 4725 | goto rw_error; |
| 4726 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4727 | data &= ~SCU_RAM_AGC_KI_DGAIN__M; |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 4728 | data |= (agc_ki_dgain << SCU_RAM_AGC_KI_DGAIN__B); |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4729 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4730 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4731 | pr_err("error %d\n", rc); |
| 4732 | goto rw_error; |
| 4733 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4734 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4735 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4736 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4737 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4738 | } |
| 4739 | |
| 4740 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4741 | * \fn int set_frequency () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4742 | * \brief Set frequency shift. |
| 4743 | * \param demod instance of demodulator. |
| 4744 | * \param channel pointer to channel data. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4745 | * \param tuner_freq_offset residual frequency from tuner. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4746 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4747 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4748 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4749 | set_frequency(struct drx_demod_instance *demod, |
| 4750 | struct drx_channel *channel, s32 tuner_freq_offset) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4751 | { |
Mauro Carvalho Chehab | 4d7bb0e | 2014-01-16 11:49:13 -0300 | [diff] [blame] | 4752 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 4753 | struct drxj_data *ext_attr = demod->my_ext_attr; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4754 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4755 | s32 sampling_frequency = 0; |
| 4756 | s32 frequency_shift = 0; |
| 4757 | s32 if_freq_actual = 0; |
Mauro Carvalho Chehab | 4d7bb0e | 2014-01-16 11:49:13 -0300 | [diff] [blame] | 4758 | s32 rf_freq_residual = -1 * tuner_freq_offset; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4759 | s32 adc_freq = 0; |
| 4760 | s32 intermediate_freq = 0; |
| 4761 | u32 iqm_fs_rate_ofs = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4762 | bool adc_flip = true; |
| 4763 | bool select_pos_image = false; |
Mauro Carvalho Chehab | 4d7bb0e | 2014-01-16 11:49:13 -0300 | [diff] [blame] | 4764 | bool rf_mirror; |
| 4765 | bool tuner_mirror; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4766 | bool image_to_select = true; |
| 4767 | s32 fm_frequency_shift = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4768 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4769 | rf_mirror = (ext_attr->mirror == DRX_MIRROR_YES) ? true : false; |
| 4770 | tuner_mirror = demod->my_common_attr->mirror_freq_spect ? false : true; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4771 | /* |
| 4772 | Program frequency shifter |
| 4773 | No need to account for mirroring on RF |
| 4774 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4775 | switch (ext_attr->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4776 | case DRX_STANDARD_ITU_A: /* fallthrough */ |
| 4777 | case DRX_STANDARD_ITU_C: /* fallthrough */ |
| 4778 | case DRX_STANDARD_PAL_SECAM_LP: /* fallthrough */ |
| 4779 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4780 | select_pos_image = true; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4781 | break; |
| 4782 | case DRX_STANDARD_FM: |
| 4783 | /* After IQM FS sound carrier must appear at 4 Mhz in spect. |
| 4784 | Sound carrier is already 3Mhz above centre frequency due |
| 4785 | to tuner setting so now add an extra shift of 1MHz... */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4786 | fm_frequency_shift = 1000; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4787 | case DRX_STANDARD_ITU_B: /* fallthrough */ |
| 4788 | case DRX_STANDARD_NTSC: /* fallthrough */ |
| 4789 | case DRX_STANDARD_PAL_SECAM_BG: /* fallthrough */ |
| 4790 | case DRX_STANDARD_PAL_SECAM_DK: /* fallthrough */ |
| 4791 | case DRX_STANDARD_PAL_SECAM_I: /* fallthrough */ |
| 4792 | case DRX_STANDARD_PAL_SECAM_L: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4793 | select_pos_image = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4794 | break; |
| 4795 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4796 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4797 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4798 | intermediate_freq = demod->my_common_attr->intermediate_freq; |
| 4799 | sampling_frequency = demod->my_common_attr->sys_clock_freq / 3; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4800 | if (tuner_mirror) |
| 4801 | if_freq_actual = intermediate_freq + rf_freq_residual + fm_frequency_shift; |
| 4802 | else |
| 4803 | if_freq_actual = intermediate_freq - rf_freq_residual - fm_frequency_shift; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4804 | if (if_freq_actual > sampling_frequency / 2) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4805 | /* adc mirrors */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4806 | adc_freq = sampling_frequency - if_freq_actual; |
| 4807 | adc_flip = true; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4808 | } else { |
| 4809 | /* adc doesn't mirror */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4810 | adc_freq = if_freq_actual; |
| 4811 | adc_flip = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4812 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4813 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4814 | frequency_shift = adc_freq; |
| 4815 | image_to_select = |
| 4816 | (bool) (rf_mirror ^ tuner_mirror ^ adc_flip ^ select_pos_image); |
| 4817 | iqm_fs_rate_ofs = frac28(frequency_shift, sampling_frequency); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4818 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4819 | if (image_to_select) |
| 4820 | iqm_fs_rate_ofs = ~iqm_fs_rate_ofs + 1; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4821 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4822 | /* Program frequency shifter with tuner offset compensation */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4823 | /* frequency_shift += tuner_freq_offset; TODO */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4824 | rc = drxdap_fasi_write_reg32(dev_addr, IQM_FS_RATE_OFS_LO__A, iqm_fs_rate_ofs, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4825 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4826 | pr_err("error %d\n", rc); |
| 4827 | goto rw_error; |
| 4828 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4829 | ext_attr->iqm_fs_rate_ofs = iqm_fs_rate_ofs; |
| 4830 | ext_attr->pos_image = (bool) (rf_mirror ^ tuner_mirror ^ select_pos_image); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4831 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4832 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4833 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4834 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4835 | } |
| 4836 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4837 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4838 | * \fn int get_acc_pkt_err() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4839 | * \brief Retrieve signal strength for VSB and QAM. |
| 4840 | * \param demod Pointer to demod instance |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4841 | * \param packet_err Pointer to packet error |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4842 | * \return int. |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4843 | * \retval 0 sig_strength contains valid data. |
| 4844 | * \retval -EINVAL sig_strength is NULL. |
| 4845 | * \retval -EIO Erroneous data, sig_strength contains invalid data. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4846 | */ |
| 4847 | #ifdef DRXJ_SIGNAL_ACCUM_ERR |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4848 | static int get_acc_pkt_err(struct drx_demod_instance *demod, u16 *packet_err) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4849 | { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4850 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4851 | static u16 pkt_err; |
| 4852 | static u16 last_pkt_err; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 4853 | u16 data = 0; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 4854 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4855 | struct i2c_device_addr *dev_addr = NULL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4856 | |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 4857 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4858 | dev_addr = demod->my_i2c_dev_addr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4859 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4860 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4861 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4862 | pr_err("error %d\n", rc); |
| 4863 | goto rw_error; |
| 4864 | } |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 4865 | if (ext_attr->reset_pkt_err_acc) { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4866 | last_pkt_err = data; |
| 4867 | pkt_err = 0; |
| 4868 | ext_attr->reset_pkt_err_acc = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4869 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4870 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4871 | if (data < last_pkt_err) { |
| 4872 | pkt_err += 0xffff - last_pkt_err; |
| 4873 | pkt_err += data; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4874 | } else { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4875 | pkt_err += (data - last_pkt_err); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4876 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4877 | *packet_err = pkt_err; |
| 4878 | last_pkt_err = data; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4879 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4880 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4881 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4882 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4883 | } |
| 4884 | #endif |
| 4885 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4886 | |
| 4887 | /*============================================================================*/ |
| 4888 | |
| 4889 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4890 | * \fn int set_agc_rf () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4891 | * \brief Configure RF AGC |
| 4892 | * \param demod instance of demodulator. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4893 | * \param agc_settings AGC configuration structure |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4894 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4895 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 4896 | static int |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 4897 | set_agc_rf(struct drx_demod_instance *demod, struct drxj_cfg_agc *agc_settings, bool atomic) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4898 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4899 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 4900 | struct drxj_data *ext_attr = NULL; |
| 4901 | struct drxj_cfg_agc *p_agc_settings = NULL; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4902 | struct drx_common_attr *common_attr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4903 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4904 | drx_write_reg16func_t scu_wr16 = NULL; |
| 4905 | drx_read_reg16func_t scu_rr16 = NULL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4906 | |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 4907 | common_attr = (struct drx_common_attr *) demod->my_common_attr; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4908 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 4909 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4910 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4911 | if (atomic) { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4912 | scu_rr16 = drxj_dap_scu_atomic_read_reg16; |
| 4913 | scu_wr16 = drxj_dap_scu_atomic_write_reg16; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4914 | } else { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4915 | scu_rr16 = drxj_dap_read_reg16; |
| 4916 | scu_wr16 = drxj_dap_write_reg16; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4917 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4918 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4919 | /* Configure AGC only if standard is currently active */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4920 | if ((ext_attr->standard == agc_settings->standard) || |
| 4921 | (DRXJ_ISQAMSTD(ext_attr->standard) && |
| 4922 | DRXJ_ISQAMSTD(agc_settings->standard)) || |
| 4923 | (DRXJ_ISATVSTD(ext_attr->standard) && |
| 4924 | DRXJ_ISATVSTD(agc_settings->standard))) { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 4925 | u16 data = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4926 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4927 | switch (agc_settings->ctrl_mode) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4928 | case DRX_AGC_CTRL_AUTO: |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4929 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4930 | /* Enable RF AGC DAC */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4931 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4932 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4933 | pr_err("error %d\n", rc); |
| 4934 | goto rw_error; |
| 4935 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4936 | data |= IQM_AF_STDBY_STDBY_TAGC_RF_A2_ACTIVE; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 4937 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4938 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4939 | pr_err("error %d\n", rc); |
| 4940 | goto rw_error; |
| 4941 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4942 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4943 | /* Enable SCU RF AGC loop */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4944 | rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4945 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4946 | pr_err("error %d\n", rc); |
| 4947 | goto rw_error; |
| 4948 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4949 | data &= ~SCU_RAM_AGC_KI_RF__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4950 | if (ext_attr->standard == DRX_STANDARD_8VSB) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4951 | data |= (2 << SCU_RAM_AGC_KI_RF__B); |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4952 | else if (DRXJ_ISQAMSTD(ext_attr->standard)) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4953 | data |= (5 << SCU_RAM_AGC_KI_RF__B); |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4954 | else |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4955 | data |= (4 << SCU_RAM_AGC_KI_RF__B); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4956 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4957 | if (common_attr->tuner_rf_agc_pol) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4958 | data |= SCU_RAM_AGC_KI_INV_RF_POL__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4959 | else |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4960 | data &= ~SCU_RAM_AGC_KI_INV_RF_POL__M; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4961 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4962 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4963 | pr_err("error %d\n", rc); |
| 4964 | goto rw_error; |
| 4965 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4966 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4967 | /* Set speed ( using complementary reduction value ) */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4968 | rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI_RED__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4969 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4970 | pr_err("error %d\n", rc); |
| 4971 | goto rw_error; |
| 4972 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4973 | data &= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 4974 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI_RED__A, (~(agc_settings->speed << SCU_RAM_AGC_KI_RED_RAGC_RED__B) & SCU_RAM_AGC_KI_RED_RAGC_RED__M) | data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4975 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4976 | pr_err("error %d\n", rc); |
| 4977 | goto rw_error; |
| 4978 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4979 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4980 | if (agc_settings->standard == DRX_STANDARD_8VSB) |
| 4981 | p_agc_settings = &(ext_attr->vsb_if_agc_cfg); |
| 4982 | else if (DRXJ_ISQAMSTD(agc_settings->standard)) |
| 4983 | p_agc_settings = &(ext_attr->qam_if_agc_cfg); |
| 4984 | else if (DRXJ_ISATVSTD(agc_settings->standard)) |
| 4985 | p_agc_settings = &(ext_attr->atv_if_agc_cfg); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4986 | else |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4987 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 4988 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 4989 | /* Set TOP, only if IF-AGC is in AUTO mode */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 4990 | if (p_agc_settings->ctrl_mode == DRX_AGC_CTRL_AUTO) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4991 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, agc_settings->top, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4992 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4993 | pr_err("error %d\n", rc); |
| 4994 | goto rw_error; |
| 4995 | } |
| 4996 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, agc_settings->top, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 4997 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 4998 | pr_err("error %d\n", rc); |
| 4999 | goto rw_error; |
| 5000 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5001 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5002 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5003 | /* Cut-Off current */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5004 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_RF_IACCU_HI_CO__A, agc_settings->cut_off_current, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5005 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5006 | pr_err("error %d\n", rc); |
| 5007 | goto rw_error; |
| 5008 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5009 | break; |
| 5010 | case DRX_AGC_CTRL_USER: |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5011 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5012 | /* Enable RF AGC DAC */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5013 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5014 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5015 | pr_err("error %d\n", rc); |
| 5016 | goto rw_error; |
| 5017 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5018 | data |= IQM_AF_STDBY_STDBY_TAGC_RF_A2_ACTIVE; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5019 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5020 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5021 | pr_err("error %d\n", rc); |
| 5022 | goto rw_error; |
| 5023 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5024 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5025 | /* Disable SCU RF AGC loop */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5026 | rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5027 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5028 | pr_err("error %d\n", rc); |
| 5029 | goto rw_error; |
| 5030 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5031 | data &= ~SCU_RAM_AGC_KI_RF__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 5032 | if (common_attr->tuner_rf_agc_pol) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5033 | data |= SCU_RAM_AGC_KI_INV_RF_POL__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 5034 | else |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5035 | data &= ~SCU_RAM_AGC_KI_INV_RF_POL__M; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5036 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5037 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5038 | pr_err("error %d\n", rc); |
| 5039 | goto rw_error; |
| 5040 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5041 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5042 | /* Write value to output pin */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5043 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_RF_IACCU_HI__A, agc_settings->output_level, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5044 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5045 | pr_err("error %d\n", rc); |
| 5046 | goto rw_error; |
| 5047 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5048 | break; |
| 5049 | case DRX_AGC_CTRL_OFF: |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5050 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5051 | /* Disable RF AGC DAC */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5052 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5053 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5054 | pr_err("error %d\n", rc); |
| 5055 | goto rw_error; |
| 5056 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5057 | data &= (~IQM_AF_STDBY_STDBY_TAGC_RF_A2_ACTIVE); |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5058 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5059 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5060 | pr_err("error %d\n", rc); |
| 5061 | goto rw_error; |
| 5062 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5063 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5064 | /* Disable SCU RF AGC loop */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5065 | rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5066 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5067 | pr_err("error %d\n", rc); |
| 5068 | goto rw_error; |
| 5069 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5070 | data &= ~SCU_RAM_AGC_KI_RF__M; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5071 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5072 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5073 | pr_err("error %d\n", rc); |
| 5074 | goto rw_error; |
| 5075 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5076 | break; |
| 5077 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5078 | return -EINVAL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5079 | } /* switch ( agcsettings->ctrl_mode ) */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5080 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5081 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5082 | /* Store rf agc settings */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5083 | switch (agc_settings->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5084 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5085 | ext_attr->vsb_rf_agc_cfg = *agc_settings; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5086 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5087 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5088 | case DRX_STANDARD_ITU_A: |
| 5089 | case DRX_STANDARD_ITU_B: |
| 5090 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5091 | ext_attr->qam_rf_agc_cfg = *agc_settings; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5092 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5093 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5094 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5095 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5096 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5097 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5098 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5099 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5100 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5101 | } |
| 5102 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5103 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5104 | * \fn int set_agc_if () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5105 | * \brief Configure If AGC |
| 5106 | * \param demod instance of demodulator. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5107 | * \param agc_settings AGC configuration structure |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 5108 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5109 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 5110 | static int |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 5111 | set_agc_if(struct drx_demod_instance *demod, struct drxj_cfg_agc *agc_settings, bool atomic) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5112 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5113 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 5114 | struct drxj_data *ext_attr = NULL; |
| 5115 | struct drxj_cfg_agc *p_agc_settings = NULL; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 5116 | struct drx_common_attr *common_attr = NULL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5117 | drx_write_reg16func_t scu_wr16 = NULL; |
| 5118 | drx_read_reg16func_t scu_rr16 = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5119 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5120 | |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 5121 | common_attr = (struct drx_common_attr *) demod->my_common_attr; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5122 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 5123 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5124 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5125 | if (atomic) { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5126 | scu_rr16 = drxj_dap_scu_atomic_read_reg16; |
| 5127 | scu_wr16 = drxj_dap_scu_atomic_write_reg16; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5128 | } else { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5129 | scu_rr16 = drxj_dap_read_reg16; |
| 5130 | scu_wr16 = drxj_dap_write_reg16; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5131 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5132 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5133 | /* Configure AGC only if standard is currently active */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5134 | if ((ext_attr->standard == agc_settings->standard) || |
| 5135 | (DRXJ_ISQAMSTD(ext_attr->standard) && |
| 5136 | DRXJ_ISQAMSTD(agc_settings->standard)) || |
| 5137 | (DRXJ_ISATVSTD(ext_attr->standard) && |
| 5138 | DRXJ_ISATVSTD(agc_settings->standard))) { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 5139 | u16 data = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5140 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5141 | switch (agc_settings->ctrl_mode) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5142 | case DRX_AGC_CTRL_AUTO: |
| 5143 | /* Enable IF AGC DAC */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5144 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5145 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5146 | pr_err("error %d\n", rc); |
| 5147 | goto rw_error; |
| 5148 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5149 | data |= IQM_AF_STDBY_STDBY_TAGC_IF_A2_ACTIVE; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5150 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5151 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5152 | pr_err("error %d\n", rc); |
| 5153 | goto rw_error; |
| 5154 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5155 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5156 | /* Enable SCU IF AGC loop */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5157 | rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5158 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5159 | pr_err("error %d\n", rc); |
| 5160 | goto rw_error; |
| 5161 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5162 | data &= ~SCU_RAM_AGC_KI_IF_AGC_DISABLE__M; |
| 5163 | data &= ~SCU_RAM_AGC_KI_IF__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 5164 | if (ext_attr->standard == DRX_STANDARD_8VSB) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5165 | data |= (3 << SCU_RAM_AGC_KI_IF__B); |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 5166 | else if (DRXJ_ISQAMSTD(ext_attr->standard)) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5167 | data |= (6 << SCU_RAM_AGC_KI_IF__B); |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 5168 | else |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5169 | data |= (5 << SCU_RAM_AGC_KI_IF__B); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5170 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 5171 | if (common_attr->tuner_if_agc_pol) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5172 | data |= SCU_RAM_AGC_KI_INV_IF_POL__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 5173 | else |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5174 | data &= ~SCU_RAM_AGC_KI_INV_IF_POL__M; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5175 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5176 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5177 | pr_err("error %d\n", rc); |
| 5178 | goto rw_error; |
| 5179 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5180 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5181 | /* Set speed (using complementary reduction value) */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5182 | rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI_RED__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5183 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5184 | pr_err("error %d\n", rc); |
| 5185 | goto rw_error; |
| 5186 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5187 | data &= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5188 | rc = (*scu_wr16) (dev_addr, SCU_RAM_AGC_KI_RED__A, (~(agc_settings->speed << SCU_RAM_AGC_KI_RED_IAGC_RED__B) & SCU_RAM_AGC_KI_RED_IAGC_RED__M) | data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5189 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5190 | pr_err("error %d\n", rc); |
| 5191 | goto rw_error; |
| 5192 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5193 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5194 | if (agc_settings->standard == DRX_STANDARD_8VSB) |
| 5195 | p_agc_settings = &(ext_attr->vsb_rf_agc_cfg); |
| 5196 | else if (DRXJ_ISQAMSTD(agc_settings->standard)) |
| 5197 | p_agc_settings = &(ext_attr->qam_rf_agc_cfg); |
| 5198 | else if (DRXJ_ISATVSTD(agc_settings->standard)) |
| 5199 | p_agc_settings = &(ext_attr->atv_rf_agc_cfg); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5200 | else |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5201 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5202 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5203 | /* Restore TOP */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5204 | if (p_agc_settings->ctrl_mode == DRX_AGC_CTRL_AUTO) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5205 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, p_agc_settings->top, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5206 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5207 | pr_err("error %d\n", rc); |
| 5208 | goto rw_error; |
| 5209 | } |
| 5210 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, p_agc_settings->top, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5211 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5212 | pr_err("error %d\n", rc); |
| 5213 | goto rw_error; |
| 5214 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5215 | } else { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5216 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5217 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5218 | pr_err("error %d\n", rc); |
| 5219 | goto rw_error; |
| 5220 | } |
| 5221 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5222 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5223 | pr_err("error %d\n", rc); |
| 5224 | goto rw_error; |
| 5225 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5226 | } |
| 5227 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5228 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5229 | case DRX_AGC_CTRL_USER: |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5230 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5231 | /* Enable IF AGC DAC */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5232 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5233 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5234 | pr_err("error %d\n", rc); |
| 5235 | goto rw_error; |
| 5236 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5237 | data |= IQM_AF_STDBY_STDBY_TAGC_IF_A2_ACTIVE; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5238 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5239 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5240 | pr_err("error %d\n", rc); |
| 5241 | goto rw_error; |
| 5242 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5243 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5244 | /* Disable SCU IF AGC loop */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5245 | rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5246 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5247 | pr_err("error %d\n", rc); |
| 5248 | goto rw_error; |
| 5249 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5250 | data &= ~SCU_RAM_AGC_KI_IF_AGC_DISABLE__M; |
| 5251 | data |= SCU_RAM_AGC_KI_IF_AGC_DISABLE__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 5252 | if (common_attr->tuner_if_agc_pol) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5253 | data |= SCU_RAM_AGC_KI_INV_IF_POL__M; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 5254 | else |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5255 | data &= ~SCU_RAM_AGC_KI_INV_IF_POL__M; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5256 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5257 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5258 | pr_err("error %d\n", rc); |
| 5259 | goto rw_error; |
| 5260 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5261 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5262 | /* Write value to output pin */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5263 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, agc_settings->output_level, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5264 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5265 | pr_err("error %d\n", rc); |
| 5266 | goto rw_error; |
| 5267 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5268 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5269 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5270 | case DRX_AGC_CTRL_OFF: |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5271 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5272 | /* Disable If AGC DAC */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5273 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5274 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5275 | pr_err("error %d\n", rc); |
| 5276 | goto rw_error; |
| 5277 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5278 | data &= (~IQM_AF_STDBY_STDBY_TAGC_IF_A2_ACTIVE); |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5279 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5280 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5281 | pr_err("error %d\n", rc); |
| 5282 | goto rw_error; |
| 5283 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5284 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5285 | /* Disable SCU IF AGC loop */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5286 | rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5287 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5288 | pr_err("error %d\n", rc); |
| 5289 | goto rw_error; |
| 5290 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5291 | data &= ~SCU_RAM_AGC_KI_IF_AGC_DISABLE__M; |
| 5292 | data |= SCU_RAM_AGC_KI_IF_AGC_DISABLE__M; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5293 | rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5294 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5295 | pr_err("error %d\n", rc); |
| 5296 | goto rw_error; |
| 5297 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5298 | break; |
| 5299 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5300 | return -EINVAL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5301 | } /* switch ( agcsettings->ctrl_mode ) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5302 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5303 | /* always set the top to support configurations without if-loop */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5304 | rc = (*scu_wr16) (dev_addr, SCU_RAM_AGC_INGAIN_TGT_MIN__A, agc_settings->top, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5305 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5306 | pr_err("error %d\n", rc); |
| 5307 | goto rw_error; |
| 5308 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5309 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5310 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5311 | /* Store if agc settings */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5312 | switch (agc_settings->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5313 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5314 | ext_attr->vsb_if_agc_cfg = *agc_settings; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5315 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5316 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5317 | case DRX_STANDARD_ITU_A: |
| 5318 | case DRX_STANDARD_ITU_B: |
| 5319 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5320 | ext_attr->qam_if_agc_cfg = *agc_settings; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5321 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5322 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5323 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5324 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5325 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5326 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5327 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5328 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5329 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5330 | } |
| 5331 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5332 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5333 | * \fn int set_iqm_af () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5334 | * \brief Configure IQM AF registers |
| 5335 | * \param demod instance of demodulator. |
| 5336 | * \param active |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 5337 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5338 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 5339 | static int set_iqm_af(struct drx_demod_instance *demod, bool active) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5340 | { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 5341 | u16 data = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5342 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5343 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5344 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5345 | dev_addr = demod->my_i2c_dev_addr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5346 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5347 | /* Configure IQM */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5348 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5349 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5350 | pr_err("error %d\n", rc); |
| 5351 | goto rw_error; |
| 5352 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 5353 | if (!active) |
| 5354 | data &= ((~IQM_AF_STDBY_STDBY_ADC_A2_ACTIVE) & (~IQM_AF_STDBY_STDBY_AMP_A2_ACTIVE) & (~IQM_AF_STDBY_STDBY_PD_A2_ACTIVE) & (~IQM_AF_STDBY_STDBY_TAGC_IF_A2_ACTIVE) & (~IQM_AF_STDBY_STDBY_TAGC_RF_A2_ACTIVE)); |
| 5355 | else |
| 5356 | data |= (IQM_AF_STDBY_STDBY_ADC_A2_ACTIVE | IQM_AF_STDBY_STDBY_AMP_A2_ACTIVE | IQM_AF_STDBY_STDBY_PD_A2_ACTIVE | IQM_AF_STDBY_STDBY_TAGC_IF_A2_ACTIVE | IQM_AF_STDBY_STDBY_TAGC_RF_A2_ACTIVE); |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5357 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5358 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5359 | pr_err("error %d\n", rc); |
| 5360 | goto rw_error; |
| 5361 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5362 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5363 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5364 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5365 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | /*============================================================================*/ |
| 5369 | /*== END 8VSB & QAM COMMON DATAPATH FUNCTIONS ==*/ |
| 5370 | /*============================================================================*/ |
| 5371 | |
| 5372 | /*============================================================================*/ |
| 5373 | /*============================================================================*/ |
| 5374 | /*== 8VSB DATAPATH FUNCTIONS ==*/ |
| 5375 | /*============================================================================*/ |
| 5376 | /*============================================================================*/ |
| 5377 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5378 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5379 | * \fn int power_down_vsb () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5380 | * \brief Powr down QAM related blocks. |
| 5381 | * \param demod instance of demodulator. |
| 5382 | * \param channel pointer to channel data. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 5383 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5384 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 5385 | static int power_down_vsb(struct drx_demod_instance *demod, bool primary) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5386 | { |
Mauro Carvalho Chehab | 4d7bb0e | 2014-01-16 11:49:13 -0300 | [diff] [blame] | 5387 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 5388 | struct drxjscu_cmd cmd_scu = { /* command */ 0, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5389 | /* parameter_len */ 0, |
| 5390 | /* result_len */ 0, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5391 | /* *parameter */ NULL, |
| 5392 | /* *result */ NULL |
| 5393 | }; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 5394 | struct drx_cfg_mpeg_output cfg_mpeg_output; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5395 | int rc; |
| 5396 | u16 cmd_result = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5397 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5398 | /* |
| 5399 | STOP demodulator |
| 5400 | reset of FEC and VSB HW |
| 5401 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5402 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_VSB | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5403 | SCU_RAM_COMMAND_CMD_DEMOD_STOP; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5404 | cmd_scu.parameter_len = 0; |
| 5405 | cmd_scu.result_len = 1; |
| 5406 | cmd_scu.parameter = NULL; |
| 5407 | cmd_scu.result = &cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5408 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5409 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5410 | pr_err("error %d\n", rc); |
| 5411 | goto rw_error; |
| 5412 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5413 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5414 | /* stop all comm_exec */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5415 | rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5416 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5417 | pr_err("error %d\n", rc); |
| 5418 | goto rw_error; |
| 5419 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5420 | rc = drxj_dap_write_reg16(dev_addr, VSB_COMM_EXEC__A, VSB_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5421 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5422 | pr_err("error %d\n", rc); |
| 5423 | goto rw_error; |
| 5424 | } |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 5425 | if (primary) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5426 | rc = drxj_dap_write_reg16(dev_addr, IQM_COMM_EXEC__A, IQM_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5427 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5428 | pr_err("error %d\n", rc); |
| 5429 | goto rw_error; |
| 5430 | } |
| 5431 | rc = set_iqm_af(demod, false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5432 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5433 | pr_err("error %d\n", rc); |
| 5434 | goto rw_error; |
| 5435 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5436 | } else { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5437 | rc = drxj_dap_write_reg16(dev_addr, IQM_FS_COMM_EXEC__A, IQM_FS_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5438 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5439 | pr_err("error %d\n", rc); |
| 5440 | goto rw_error; |
| 5441 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5442 | rc = drxj_dap_write_reg16(dev_addr, IQM_FD_COMM_EXEC__A, IQM_FD_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5443 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5444 | pr_err("error %d\n", rc); |
| 5445 | goto rw_error; |
| 5446 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5447 | rc = drxj_dap_write_reg16(dev_addr, IQM_RC_COMM_EXEC__A, IQM_RC_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5448 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5449 | pr_err("error %d\n", rc); |
| 5450 | goto rw_error; |
| 5451 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5452 | rc = drxj_dap_write_reg16(dev_addr, IQM_RT_COMM_EXEC__A, IQM_RT_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5453 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5454 | pr_err("error %d\n", rc); |
| 5455 | goto rw_error; |
| 5456 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5457 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_COMM_EXEC__A, IQM_CF_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5458 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5459 | pr_err("error %d\n", rc); |
| 5460 | goto rw_error; |
| 5461 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5462 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5463 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5464 | cfg_mpeg_output.enable_mpeg_output = false; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5465 | rc = ctrl_set_cfg_mpeg_output(demod, &cfg_mpeg_output); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5466 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5467 | pr_err("error %d\n", rc); |
| 5468 | goto rw_error; |
| 5469 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5470 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5471 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5472 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5473 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5474 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5475 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5476 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5477 | * \fn int set_vsb_leak_n_gain () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5478 | * \brief Set ATSC demod. |
| 5479 | * \param demod instance of demodulator. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 5480 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5481 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 5482 | static int set_vsb_leak_n_gain(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5483 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5484 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5485 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5486 | |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 5487 | const u8 vsb_ffe_leak_gain_ram0[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5488 | DRXJ_16TO8(0x8), /* FFETRAINLKRATIO1 */ |
| 5489 | DRXJ_16TO8(0x8), /* FFETRAINLKRATIO2 */ |
| 5490 | DRXJ_16TO8(0x8), /* FFETRAINLKRATIO3 */ |
| 5491 | DRXJ_16TO8(0xf), /* FFETRAINLKRATIO4 */ |
| 5492 | DRXJ_16TO8(0xf), /* FFETRAINLKRATIO5 */ |
| 5493 | DRXJ_16TO8(0xf), /* FFETRAINLKRATIO6 */ |
| 5494 | DRXJ_16TO8(0xf), /* FFETRAINLKRATIO7 */ |
| 5495 | DRXJ_16TO8(0xf), /* FFETRAINLKRATIO8 */ |
| 5496 | DRXJ_16TO8(0xf), /* FFETRAINLKRATIO9 */ |
| 5497 | DRXJ_16TO8(0x8), /* FFETRAINLKRATIO10 */ |
| 5498 | DRXJ_16TO8(0x8), /* FFETRAINLKRATIO11 */ |
| 5499 | DRXJ_16TO8(0x8), /* FFETRAINLKRATIO12 */ |
| 5500 | DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO1 */ |
| 5501 | DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO2 */ |
| 5502 | DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO3 */ |
| 5503 | DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO4 */ |
| 5504 | DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO5 */ |
| 5505 | DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO6 */ |
| 5506 | DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO7 */ |
| 5507 | DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO8 */ |
| 5508 | DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO9 */ |
| 5509 | DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO10 */ |
| 5510 | DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO11 */ |
| 5511 | DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO12 */ |
| 5512 | DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO1 */ |
| 5513 | DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO2 */ |
| 5514 | DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO3 */ |
| 5515 | DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO4 */ |
| 5516 | DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO5 */ |
| 5517 | DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO6 */ |
| 5518 | DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO7 */ |
| 5519 | DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO8 */ |
| 5520 | DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO9 */ |
| 5521 | DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO10 */ |
| 5522 | DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO11 */ |
| 5523 | DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO12 */ |
| 5524 | DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO1 */ |
| 5525 | DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO2 */ |
| 5526 | DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO3 */ |
| 5527 | DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO4 */ |
| 5528 | DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO5 */ |
| 5529 | DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO6 */ |
| 5530 | DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO7 */ |
| 5531 | DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO8 */ |
| 5532 | DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO9 */ |
| 5533 | DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO10 */ |
| 5534 | DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO11 */ |
| 5535 | DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO12 */ |
| 5536 | DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO1 */ |
| 5537 | DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO2 */ |
| 5538 | DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO3 */ |
| 5539 | DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO4 */ |
| 5540 | DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO5 */ |
| 5541 | DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO6 */ |
| 5542 | DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO7 */ |
| 5543 | DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO8 */ |
| 5544 | DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO9 */ |
| 5545 | DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO10 */ |
| 5546 | DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO11 */ |
| 5547 | DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO12 */ |
| 5548 | DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO1 */ |
| 5549 | DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO2 */ |
| 5550 | DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO3 */ |
| 5551 | DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO4 */ |
| 5552 | DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO5 */ |
| 5553 | DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO6 */ |
| 5554 | DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO7 */ |
| 5555 | DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO8 */ |
| 5556 | DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO9 */ |
| 5557 | DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO10 */ |
| 5558 | DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO11 */ |
| 5559 | DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO12 */ |
| 5560 | DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO1 */ |
| 5561 | DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO2 */ |
| 5562 | DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO3 */ |
| 5563 | DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO4 */ |
| 5564 | DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO5 */ |
| 5565 | DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO6 */ |
| 5566 | DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO7 */ |
| 5567 | DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO8 */ |
| 5568 | DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO9 */ |
| 5569 | DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO10 */ |
| 5570 | DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO11 */ |
| 5571 | DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO12 */ |
| 5572 | DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO1 */ |
| 5573 | DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO2 */ |
| 5574 | DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO3 */ |
| 5575 | DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO4 */ |
| 5576 | DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO5 */ |
| 5577 | DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO6 */ |
| 5578 | DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO7 */ |
| 5579 | DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO8 */ |
| 5580 | DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO9 */ |
| 5581 | DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO10 */ |
| 5582 | DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO11 */ |
| 5583 | DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO12 */ |
| 5584 | DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO1 */ |
| 5585 | DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO2 */ |
| 5586 | DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO3 */ |
| 5587 | DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO4 */ |
| 5588 | DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO5 */ |
| 5589 | DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO6 */ |
| 5590 | DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO7 */ |
| 5591 | DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO8 */ |
| 5592 | DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO9 */ |
| 5593 | DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO10 */ |
| 5594 | DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO11 */ |
| 5595 | DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO12 */ |
| 5596 | DRXJ_16TO8(0x2020), /* FIRTRAINGAIN1 */ |
| 5597 | DRXJ_16TO8(0x2020), /* FIRTRAINGAIN2 */ |
| 5598 | DRXJ_16TO8(0x2020), /* FIRTRAINGAIN3 */ |
| 5599 | DRXJ_16TO8(0x4040), /* FIRTRAINGAIN4 */ |
| 5600 | DRXJ_16TO8(0x4040), /* FIRTRAINGAIN5 */ |
| 5601 | DRXJ_16TO8(0x4040), /* FIRTRAINGAIN6 */ |
| 5602 | DRXJ_16TO8(0x4040), /* FIRTRAINGAIN7 */ |
| 5603 | DRXJ_16TO8(0x4040), /* FIRTRAINGAIN8 */ |
| 5604 | DRXJ_16TO8(0x4040), /* FIRTRAINGAIN9 */ |
| 5605 | DRXJ_16TO8(0x2020), /* FIRTRAINGAIN10 */ |
| 5606 | DRXJ_16TO8(0x2020), /* FIRTRAINGAIN11 */ |
| 5607 | DRXJ_16TO8(0x2020), /* FIRTRAINGAIN12 */ |
| 5608 | DRXJ_16TO8(0x0808), /* FIRRCA1GAIN1 */ |
| 5609 | DRXJ_16TO8(0x0808), /* FIRRCA1GAIN2 */ |
| 5610 | DRXJ_16TO8(0x0808), /* FIRRCA1GAIN3 */ |
| 5611 | DRXJ_16TO8(0x1010), /* FIRRCA1GAIN4 */ |
| 5612 | DRXJ_16TO8(0x1010), /* FIRRCA1GAIN5 */ |
| 5613 | DRXJ_16TO8(0x1010), /* FIRRCA1GAIN6 */ |
| 5614 | DRXJ_16TO8(0x1010), /* FIRRCA1GAIN7 */ |
| 5615 | DRXJ_16TO8(0x1010) /* FIRRCA1GAIN8 */ |
| 5616 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5617 | |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 5618 | const u8 vsb_ffe_leak_gain_ram1[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5619 | DRXJ_16TO8(0x1010), /* FIRRCA1GAIN9 */ |
| 5620 | DRXJ_16TO8(0x0808), /* FIRRCA1GAIN10 */ |
| 5621 | DRXJ_16TO8(0x0808), /* FIRRCA1GAIN11 */ |
| 5622 | DRXJ_16TO8(0x0808), /* FIRRCA1GAIN12 */ |
| 5623 | DRXJ_16TO8(0x0808), /* FIRRCA2GAIN1 */ |
| 5624 | DRXJ_16TO8(0x0808), /* FIRRCA2GAIN2 */ |
| 5625 | DRXJ_16TO8(0x0808), /* FIRRCA2GAIN3 */ |
| 5626 | DRXJ_16TO8(0x1010), /* FIRRCA2GAIN4 */ |
| 5627 | DRXJ_16TO8(0x1010), /* FIRRCA2GAIN5 */ |
| 5628 | DRXJ_16TO8(0x1010), /* FIRRCA2GAIN6 */ |
| 5629 | DRXJ_16TO8(0x1010), /* FIRRCA2GAIN7 */ |
| 5630 | DRXJ_16TO8(0x1010), /* FIRRCA2GAIN8 */ |
| 5631 | DRXJ_16TO8(0x1010), /* FIRRCA2GAIN9 */ |
| 5632 | DRXJ_16TO8(0x0808), /* FIRRCA2GAIN10 */ |
| 5633 | DRXJ_16TO8(0x0808), /* FIRRCA2GAIN11 */ |
| 5634 | DRXJ_16TO8(0x0808), /* FIRRCA2GAIN12 */ |
| 5635 | DRXJ_16TO8(0x0303), /* FIRDDM1GAIN1 */ |
| 5636 | DRXJ_16TO8(0x0303), /* FIRDDM1GAIN2 */ |
| 5637 | DRXJ_16TO8(0x0303), /* FIRDDM1GAIN3 */ |
| 5638 | DRXJ_16TO8(0x0606), /* FIRDDM1GAIN4 */ |
| 5639 | DRXJ_16TO8(0x0606), /* FIRDDM1GAIN5 */ |
| 5640 | DRXJ_16TO8(0x0606), /* FIRDDM1GAIN6 */ |
| 5641 | DRXJ_16TO8(0x0606), /* FIRDDM1GAIN7 */ |
| 5642 | DRXJ_16TO8(0x0606), /* FIRDDM1GAIN8 */ |
| 5643 | DRXJ_16TO8(0x0606), /* FIRDDM1GAIN9 */ |
| 5644 | DRXJ_16TO8(0x0303), /* FIRDDM1GAIN10 */ |
| 5645 | DRXJ_16TO8(0x0303), /* FIRDDM1GAIN11 */ |
| 5646 | DRXJ_16TO8(0x0303), /* FIRDDM1GAIN12 */ |
| 5647 | DRXJ_16TO8(0x0303), /* FIRDDM2GAIN1 */ |
| 5648 | DRXJ_16TO8(0x0303), /* FIRDDM2GAIN2 */ |
| 5649 | DRXJ_16TO8(0x0303), /* FIRDDM2GAIN3 */ |
| 5650 | DRXJ_16TO8(0x0505), /* FIRDDM2GAIN4 */ |
| 5651 | DRXJ_16TO8(0x0505), /* FIRDDM2GAIN5 */ |
| 5652 | DRXJ_16TO8(0x0505), /* FIRDDM2GAIN6 */ |
| 5653 | DRXJ_16TO8(0x0505), /* FIRDDM2GAIN7 */ |
| 5654 | DRXJ_16TO8(0x0505), /* FIRDDM2GAIN8 */ |
| 5655 | DRXJ_16TO8(0x0505), /* FIRDDM2GAIN9 */ |
| 5656 | DRXJ_16TO8(0x0303), /* FIRDDM2GAIN10 */ |
| 5657 | DRXJ_16TO8(0x0303), /* FIRDDM2GAIN11 */ |
| 5658 | DRXJ_16TO8(0x0303), /* FIRDDM2GAIN12 */ |
| 5659 | DRXJ_16TO8(0x001f), /* DFETRAINLKRATIO */ |
| 5660 | DRXJ_16TO8(0x01ff), /* DFERCA1TRAINLKRATIO */ |
| 5661 | DRXJ_16TO8(0x01ff), /* DFERCA1DATALKRATIO */ |
| 5662 | DRXJ_16TO8(0x004f), /* DFERCA2TRAINLKRATIO */ |
| 5663 | DRXJ_16TO8(0x004f), /* DFERCA2DATALKRATIO */ |
| 5664 | DRXJ_16TO8(0x01ff), /* DFEDDM1TRAINLKRATIO */ |
| 5665 | DRXJ_16TO8(0x01ff), /* DFEDDM1DATALKRATIO */ |
| 5666 | DRXJ_16TO8(0x0352), /* DFEDDM2TRAINLKRATIO */ |
| 5667 | DRXJ_16TO8(0x0352), /* DFEDDM2DATALKRATIO */ |
| 5668 | DRXJ_16TO8(0x0000), /* DFETRAINGAIN */ |
| 5669 | DRXJ_16TO8(0x2020), /* DFERCA1GAIN */ |
| 5670 | DRXJ_16TO8(0x1010), /* DFERCA2GAIN */ |
| 5671 | DRXJ_16TO8(0x1818), /* DFEDDM1GAIN */ |
| 5672 | DRXJ_16TO8(0x1212) /* DFEDDM2GAIN */ |
| 5673 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5674 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5675 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5676 | rc = drxdap_fasi_write_block(dev_addr, VSB_SYSCTRL_RAM0_FFETRAINLKRATIO1__A, sizeof(vsb_ffe_leak_gain_ram0), ((u8 *)vsb_ffe_leak_gain_ram0), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5677 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5678 | pr_err("error %d\n", rc); |
| 5679 | goto rw_error; |
| 5680 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5681 | rc = drxdap_fasi_write_block(dev_addr, VSB_SYSCTRL_RAM1_FIRRCA1GAIN9__A, sizeof(vsb_ffe_leak_gain_ram1), ((u8 *)vsb_ffe_leak_gain_ram1), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5682 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5683 | pr_err("error %d\n", rc); |
| 5684 | goto rw_error; |
| 5685 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5686 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5687 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5688 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5689 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5690 | } |
| 5691 | |
| 5692 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5693 | * \fn int set_vsb() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5694 | * \brief Set 8VSB demod. |
| 5695 | * \param demod instance of demodulator. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 5696 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5697 | * |
| 5698 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 5699 | static int set_vsb(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5700 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5701 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5702 | int rc; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 5703 | struct drx_common_attr *common_attr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 5704 | struct drxjscu_cmd cmd_scu; |
| 5705 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5706 | u16 cmd_result = 0; |
| 5707 | u16 cmd_param = 0; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 5708 | const u8 vsb_taps_re[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5709 | DRXJ_16TO8(-2), /* re0 */ |
| 5710 | DRXJ_16TO8(4), /* re1 */ |
| 5711 | DRXJ_16TO8(1), /* re2 */ |
| 5712 | DRXJ_16TO8(-4), /* re3 */ |
| 5713 | DRXJ_16TO8(1), /* re4 */ |
| 5714 | DRXJ_16TO8(4), /* re5 */ |
| 5715 | DRXJ_16TO8(-3), /* re6 */ |
| 5716 | DRXJ_16TO8(-3), /* re7 */ |
| 5717 | DRXJ_16TO8(6), /* re8 */ |
| 5718 | DRXJ_16TO8(1), /* re9 */ |
| 5719 | DRXJ_16TO8(-9), /* re10 */ |
| 5720 | DRXJ_16TO8(3), /* re11 */ |
| 5721 | DRXJ_16TO8(12), /* re12 */ |
| 5722 | DRXJ_16TO8(-9), /* re13 */ |
| 5723 | DRXJ_16TO8(-15), /* re14 */ |
| 5724 | DRXJ_16TO8(17), /* re15 */ |
| 5725 | DRXJ_16TO8(19), /* re16 */ |
| 5726 | DRXJ_16TO8(-29), /* re17 */ |
| 5727 | DRXJ_16TO8(-22), /* re18 */ |
| 5728 | DRXJ_16TO8(45), /* re19 */ |
| 5729 | DRXJ_16TO8(25), /* re20 */ |
| 5730 | DRXJ_16TO8(-70), /* re21 */ |
| 5731 | DRXJ_16TO8(-28), /* re22 */ |
| 5732 | DRXJ_16TO8(111), /* re23 */ |
| 5733 | DRXJ_16TO8(30), /* re24 */ |
| 5734 | DRXJ_16TO8(-201), /* re25 */ |
| 5735 | DRXJ_16TO8(-31), /* re26 */ |
| 5736 | DRXJ_16TO8(629) /* re27 */ |
| 5737 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5738 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5739 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 5740 | common_attr = (struct drx_common_attr *) demod->my_common_attr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 5741 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5742 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5743 | /* stop all comm_exec */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5744 | rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5745 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5746 | pr_err("error %d\n", rc); |
| 5747 | goto rw_error; |
| 5748 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5749 | rc = drxj_dap_write_reg16(dev_addr, VSB_COMM_EXEC__A, VSB_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5750 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5751 | pr_err("error %d\n", rc); |
| 5752 | goto rw_error; |
| 5753 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5754 | rc = drxj_dap_write_reg16(dev_addr, IQM_FS_COMM_EXEC__A, IQM_FS_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5755 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5756 | pr_err("error %d\n", rc); |
| 5757 | goto rw_error; |
| 5758 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5759 | rc = drxj_dap_write_reg16(dev_addr, IQM_FD_COMM_EXEC__A, IQM_FD_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5760 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5761 | pr_err("error %d\n", rc); |
| 5762 | goto rw_error; |
| 5763 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5764 | rc = drxj_dap_write_reg16(dev_addr, IQM_RC_COMM_EXEC__A, IQM_RC_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5765 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5766 | pr_err("error %d\n", rc); |
| 5767 | goto rw_error; |
| 5768 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5769 | rc = drxj_dap_write_reg16(dev_addr, IQM_RT_COMM_EXEC__A, IQM_RT_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5770 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5771 | pr_err("error %d\n", rc); |
| 5772 | goto rw_error; |
| 5773 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5774 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_COMM_EXEC__A, IQM_CF_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5775 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5776 | pr_err("error %d\n", rc); |
| 5777 | goto rw_error; |
| 5778 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5779 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5780 | /* reset demodulator */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5781 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_VSB |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5782 | | SCU_RAM_COMMAND_CMD_DEMOD_RESET; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5783 | cmd_scu.parameter_len = 0; |
| 5784 | cmd_scu.result_len = 1; |
| 5785 | cmd_scu.parameter = NULL; |
| 5786 | cmd_scu.result = &cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5787 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5788 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5789 | pr_err("error %d\n", rc); |
| 5790 | goto rw_error; |
| 5791 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5792 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5793 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_DCF_BYPASS__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5794 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5795 | pr_err("error %d\n", rc); |
| 5796 | goto rw_error; |
| 5797 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5798 | rc = drxj_dap_write_reg16(dev_addr, IQM_FS_ADJ_SEL__A, IQM_FS_ADJ_SEL_B_VSB, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5799 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5800 | pr_err("error %d\n", rc); |
| 5801 | goto rw_error; |
| 5802 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5803 | rc = drxj_dap_write_reg16(dev_addr, IQM_RC_ADJ_SEL__A, IQM_RC_ADJ_SEL_B_VSB, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5804 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5805 | pr_err("error %d\n", rc); |
| 5806 | goto rw_error; |
| 5807 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5808 | ext_attr->iqm_rc_rate_ofs = 0x00AD0D79; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5809 | rc = drxdap_fasi_write_reg32(dev_addr, IQM_RC_RATE_OFS_LO__A, ext_attr->iqm_rc_rate_ofs, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5810 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5811 | pr_err("error %d\n", rc); |
| 5812 | goto rw_error; |
| 5813 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5814 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CFAGC_GAINSHIFT__A, 4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5815 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5816 | pr_err("error %d\n", rc); |
| 5817 | goto rw_error; |
| 5818 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5819 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CYGN1TRK__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5820 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5821 | pr_err("error %d\n", rc); |
| 5822 | goto rw_error; |
| 5823 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5824 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5825 | rc = drxj_dap_write_reg16(dev_addr, IQM_RC_CROUT_ENA__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5826 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5827 | pr_err("error %d\n", rc); |
| 5828 | goto rw_error; |
| 5829 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5830 | rc = drxj_dap_write_reg16(dev_addr, IQM_RC_STRETCH__A, 28, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5831 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5832 | pr_err("error %d\n", rc); |
| 5833 | goto rw_error; |
| 5834 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5835 | rc = drxj_dap_write_reg16(dev_addr, IQM_RT_ACTIVE__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5836 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5837 | pr_err("error %d\n", rc); |
| 5838 | goto rw_error; |
| 5839 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5840 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SYMMETRIC__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5841 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5842 | pr_err("error %d\n", rc); |
| 5843 | goto rw_error; |
| 5844 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5845 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_MIDTAP__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5846 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5847 | pr_err("error %d\n", rc); |
| 5848 | goto rw_error; |
| 5849 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5850 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_OUT_ENA__A, IQM_CF_OUT_ENA_VSB__M, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5851 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5852 | pr_err("error %d\n", rc); |
| 5853 | goto rw_error; |
| 5854 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5855 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SCALE__A, 1393, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5856 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5857 | pr_err("error %d\n", rc); |
| 5858 | goto rw_error; |
| 5859 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5860 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SCALE_SH__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5861 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5862 | pr_err("error %d\n", rc); |
| 5863 | goto rw_error; |
| 5864 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5865 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_POW_MEAS_LEN__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5866 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5867 | pr_err("error %d\n", rc); |
| 5868 | goto rw_error; |
| 5869 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5870 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5871 | rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_RE0__A, sizeof(vsb_taps_re), ((u8 *)vsb_taps_re), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5872 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5873 | pr_err("error %d\n", rc); |
| 5874 | goto rw_error; |
| 5875 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5876 | rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_IM0__A, sizeof(vsb_taps_re), ((u8 *)vsb_taps_re), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5877 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5878 | pr_err("error %d\n", rc); |
| 5879 | goto rw_error; |
| 5880 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5881 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5882 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_BNTHRESH__A, 330, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5883 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5884 | pr_err("error %d\n", rc); |
| 5885 | goto rw_error; |
| 5886 | } /* set higher threshold */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5887 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CLPLASTNUM__A, 90, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5888 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5889 | pr_err("error %d\n", rc); |
| 5890 | goto rw_error; |
| 5891 | } /* burst detection on */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5892 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_SNRTH_RCA1__A, 0x0042, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5893 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5894 | pr_err("error %d\n", rc); |
| 5895 | goto rw_error; |
| 5896 | } /* drop thresholds by 1 dB */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5897 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_SNRTH_RCA2__A, 0x0053, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5898 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5899 | pr_err("error %d\n", rc); |
| 5900 | goto rw_error; |
| 5901 | } /* drop thresholds by 2 dB */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5902 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_EQCTRL__A, 0x1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5903 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5904 | pr_err("error %d\n", rc); |
| 5905 | goto rw_error; |
| 5906 | } /* cma on */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5907 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_GPIO__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5908 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5909 | pr_err("error %d\n", rc); |
| 5910 | goto rw_error; |
| 5911 | } /* GPIO */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5912 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5913 | /* Initialize the FEC Subsystem */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5914 | rc = drxj_dap_write_reg16(dev_addr, FEC_TOP_ANNEX__A, FEC_TOP_ANNEX_D, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5915 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5916 | pr_err("error %d\n", rc); |
| 5917 | goto rw_error; |
| 5918 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5919 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5920 | u16 fec_oc_snc_mode = 0; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5921 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_SNC_MODE__A, &fec_oc_snc_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5922 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5923 | pr_err("error %d\n", rc); |
| 5924 | goto rw_error; |
| 5925 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5926 | /* output data even when not locked */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5927 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_MODE__A, fec_oc_snc_mode | FEC_OC_SNC_MODE_UNLOCK_ENABLE__M, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5928 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5929 | pr_err("error %d\n", rc); |
| 5930 | goto rw_error; |
| 5931 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5932 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5933 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5934 | /* set clip */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5935 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_CLP_LEN__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5936 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5937 | pr_err("error %d\n", rc); |
| 5938 | goto rw_error; |
| 5939 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5940 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_CLP_TH__A, 470, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5941 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5942 | pr_err("error %d\n", rc); |
| 5943 | goto rw_error; |
| 5944 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5945 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_SNS_LEN__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5946 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5947 | pr_err("error %d\n", rc); |
| 5948 | goto rw_error; |
| 5949 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5950 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_SNRTH_PT__A, 0xD4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5951 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5952 | pr_err("error %d\n", rc); |
| 5953 | goto rw_error; |
| 5954 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5955 | /* no transparent, no A&C framing; parity is set in mpegoutput */ |
| 5956 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 5957 | u16 fec_oc_reg_mode = 0; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5958 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_MODE__A, &fec_oc_reg_mode, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5959 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5960 | pr_err("error %d\n", rc); |
| 5961 | goto rw_error; |
| 5962 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5963 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_MODE__A, fec_oc_reg_mode & (~(FEC_OC_MODE_TRANSPARENT__M | FEC_OC_MODE_CLEAR__M | FEC_OC_MODE_RETAIN_FRAMING__M)), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5964 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5965 | pr_err("error %d\n", rc); |
| 5966 | goto rw_error; |
| 5967 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5968 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5969 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5970 | rc = drxj_dap_write_reg16(dev_addr, FEC_DI_TIMEOUT_LO__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5971 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5972 | pr_err("error %d\n", rc); |
| 5973 | goto rw_error; |
| 5974 | } /* timeout counter for restarting */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5975 | rc = drxj_dap_write_reg16(dev_addr, FEC_DI_TIMEOUT_HI__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5976 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5977 | pr_err("error %d\n", rc); |
| 5978 | goto rw_error; |
| 5979 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5980 | rc = drxj_dap_write_reg16(dev_addr, FEC_RS_MODE__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5981 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5982 | pr_err("error %d\n", rc); |
| 5983 | goto rw_error; |
| 5984 | } /* bypass disabled */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5985 | /* initialize RS packet error measurement parameters */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5986 | rc = drxj_dap_write_reg16(dev_addr, FEC_RS_MEASUREMENT_PERIOD__A, FEC_RS_MEASUREMENT_PERIOD, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5987 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5988 | pr_err("error %d\n", rc); |
| 5989 | goto rw_error; |
| 5990 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5991 | rc = drxj_dap_write_reg16(dev_addr, FEC_RS_MEASUREMENT_PRESCALE__A, FEC_RS_MEASUREMENT_PRESCALE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5992 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 5993 | pr_err("error %d\n", rc); |
| 5994 | goto rw_error; |
| 5995 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 5996 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 5997 | /* init measurement period of MER/SER */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 5998 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_MEASUREMENT_PERIOD__A, VSB_TOP_MEASUREMENT_PERIOD, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 5999 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6000 | pr_err("error %d\n", rc); |
| 6001 | goto rw_error; |
| 6002 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6003 | rc = drxdap_fasi_write_reg32(dev_addr, SCU_RAM_FEC_ACCUM_CW_CORRECTED_LO__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6004 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6005 | pr_err("error %d\n", rc); |
| 6006 | goto rw_error; |
| 6007 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6008 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_FEC_MEAS_COUNT__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6009 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6010 | pr_err("error %d\n", rc); |
| 6011 | goto rw_error; |
| 6012 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6013 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6014 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6015 | pr_err("error %d\n", rc); |
| 6016 | goto rw_error; |
| 6017 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6018 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6019 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CKGN1TRK__A, 128, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6020 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6021 | pr_err("error %d\n", rc); |
| 6022 | goto rw_error; |
| 6023 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6024 | /* B-Input to ADC, PGA+filter in standby */ |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 6025 | if (!ext_attr->has_lna) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6026 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_AMUX__A, 0x02, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6027 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6028 | pr_err("error %d\n", rc); |
| 6029 | goto rw_error; |
| 6030 | } |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 6031 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6032 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6033 | /* turn on IQMAF. It has to be in front of setAgc**() */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6034 | rc = set_iqm_af(demod, true); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6035 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6036 | pr_err("error %d\n", rc); |
| 6037 | goto rw_error; |
| 6038 | } |
| 6039 | rc = adc_synchronization(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6040 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6041 | pr_err("error %d\n", rc); |
| 6042 | goto rw_error; |
| 6043 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6044 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6045 | rc = init_agc(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6046 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6047 | pr_err("error %d\n", rc); |
| 6048 | goto rw_error; |
| 6049 | } |
| 6050 | rc = set_agc_if(demod, &(ext_attr->vsb_if_agc_cfg), false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6051 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6052 | pr_err("error %d\n", rc); |
| 6053 | goto rw_error; |
| 6054 | } |
| 6055 | rc = set_agc_rf(demod, &(ext_attr->vsb_rf_agc_cfg), false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6056 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6057 | pr_err("error %d\n", rc); |
| 6058 | goto rw_error; |
| 6059 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6060 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 6061 | /* TODO fix this, store a struct drxj_cfg_afe_gain structure in struct drxj_data instead |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6062 | of only the gain */ |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 6063 | struct drxj_cfg_afe_gain vsb_pga_cfg = { DRX_STANDARD_8VSB, 0 }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6064 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6065 | vsb_pga_cfg.gain = ext_attr->vsb_pga_cfg; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6066 | rc = ctrl_set_cfg_afe_gain(demod, &vsb_pga_cfg); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6067 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6068 | pr_err("error %d\n", rc); |
| 6069 | goto rw_error; |
| 6070 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6071 | } |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6072 | rc = ctrl_set_cfg_pre_saw(demod, &(ext_attr->vsb_pre_saw_cfg)); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6073 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6074 | pr_err("error %d\n", rc); |
| 6075 | goto rw_error; |
| 6076 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6077 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6078 | /* Mpeg output has to be in front of FEC active */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6079 | rc = set_mpegtei_handling(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6080 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6081 | pr_err("error %d\n", rc); |
| 6082 | goto rw_error; |
| 6083 | } |
| 6084 | rc = bit_reverse_mpeg_output(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6085 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6086 | pr_err("error %d\n", rc); |
| 6087 | goto rw_error; |
| 6088 | } |
| 6089 | rc = set_mpeg_start_width(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6090 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6091 | pr_err("error %d\n", rc); |
| 6092 | goto rw_error; |
| 6093 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6094 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6095 | /* TODO: move to set_standard after hardware reset value problem is solved */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6096 | /* Configure initial MPEG output */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 6097 | struct drx_cfg_mpeg_output cfg_mpeg_output; |
Mauro Carvalho Chehab | 41b5cc0 | 2014-03-02 11:01:11 -0300 | [diff] [blame] | 6098 | |
| 6099 | memcpy(&cfg_mpeg_output, &common_attr->mpeg_cfg, sizeof(cfg_mpeg_output)); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6100 | cfg_mpeg_output.enable_mpeg_output = true; |
Mauro Carvalho Chehab | 41b5cc0 | 2014-03-02 11:01:11 -0300 | [diff] [blame] | 6101 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6102 | rc = ctrl_set_cfg_mpeg_output(demod, &cfg_mpeg_output); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6103 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6104 | pr_err("error %d\n", rc); |
| 6105 | goto rw_error; |
| 6106 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6107 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6108 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6109 | /* TBD: what parameters should be set */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6110 | cmd_param = 0x00; /* Default mode AGC on, etc */ |
| 6111 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_VSB |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6112 | | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6113 | cmd_scu.parameter_len = 1; |
| 6114 | cmd_scu.result_len = 1; |
| 6115 | cmd_scu.parameter = &cmd_param; |
| 6116 | cmd_scu.result = &cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6117 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6118 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6119 | pr_err("error %d\n", rc); |
| 6120 | goto rw_error; |
| 6121 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6122 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6123 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_BEAGC_GAINSHIFT__A, 0x0004, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6124 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6125 | pr_err("error %d\n", rc); |
| 6126 | goto rw_error; |
| 6127 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6128 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_SNRTH_PT__A, 0x00D2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6129 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6130 | pr_err("error %d\n", rc); |
| 6131 | goto rw_error; |
| 6132 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6133 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_SYSSMTRNCTRL__A, VSB_TOP_SYSSMTRNCTRL__PRE | VSB_TOP_SYSSMTRNCTRL_NCOTIMEOUTCNTEN__M, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6134 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6135 | pr_err("error %d\n", rc); |
| 6136 | goto rw_error; |
| 6137 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6138 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_BEDETCTRL__A, 0x142, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6139 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6140 | pr_err("error %d\n", rc); |
| 6141 | goto rw_error; |
| 6142 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6143 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_LBAGCREFLVL__A, 640, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6144 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6145 | pr_err("error %d\n", rc); |
| 6146 | goto rw_error; |
| 6147 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6148 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CYGN1ACQ__A, 4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6149 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6150 | pr_err("error %d\n", rc); |
| 6151 | goto rw_error; |
| 6152 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6153 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CYGN1TRK__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6154 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6155 | pr_err("error %d\n", rc); |
| 6156 | goto rw_error; |
| 6157 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6158 | rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CYGN2TRK__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6159 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6160 | pr_err("error %d\n", rc); |
| 6161 | goto rw_error; |
| 6162 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6163 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6164 | /* start demodulator */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6165 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_VSB |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6166 | | SCU_RAM_COMMAND_CMD_DEMOD_START; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6167 | cmd_scu.parameter_len = 0; |
| 6168 | cmd_scu.result_len = 1; |
| 6169 | cmd_scu.parameter = NULL; |
| 6170 | cmd_scu.result = &cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6171 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6172 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6173 | pr_err("error %d\n", rc); |
| 6174 | goto rw_error; |
| 6175 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6176 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6177 | rc = drxj_dap_write_reg16(dev_addr, IQM_COMM_EXEC__A, IQM_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6178 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6179 | pr_err("error %d\n", rc); |
| 6180 | goto rw_error; |
| 6181 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6182 | rc = drxj_dap_write_reg16(dev_addr, VSB_COMM_EXEC__A, VSB_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6183 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6184 | pr_err("error %d\n", rc); |
| 6185 | goto rw_error; |
| 6186 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6187 | rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6188 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6189 | pr_err("error %d\n", rc); |
| 6190 | goto rw_error; |
| 6191 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6192 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6193 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6194 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6195 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6196 | } |
| 6197 | |
| 6198 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6199 | * \fn static short get_vsb_post_rs_pck_err(struct i2c_device_addr *dev_addr, u16 *PckErrs) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6200 | * \brief Get the values of packet error in 8VSB mode |
| 6201 | * \return Error code |
| 6202 | */ |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 6203 | static int get_vsb_post_rs_pck_err(struct i2c_device_addr *dev_addr, |
Mauro Carvalho Chehab | d591590 | 2014-03-10 08:22:34 -0300 | [diff] [blame] | 6204 | u32 *pck_errs, u32 *pck_count) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6205 | { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6206 | int rc; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 6207 | u16 data = 0; |
| 6208 | u16 period = 0; |
| 6209 | u16 prescale = 0; |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 6210 | u16 packet_errors_mant = 0; |
| 6211 | u16 packet_errors_exp = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6212 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6213 | rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_FAILURES__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6214 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6215 | pr_err("error %d\n", rc); |
| 6216 | goto rw_error; |
| 6217 | } |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 6218 | packet_errors_mant = data & FEC_RS_NR_FAILURES_FIXED_MANT__M; |
| 6219 | packet_errors_exp = (data & FEC_RS_NR_FAILURES_EXP__M) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6220 | >> FEC_RS_NR_FAILURES_EXP__B; |
| 6221 | period = FEC_RS_MEASUREMENT_PERIOD; |
| 6222 | prescale = FEC_RS_MEASUREMENT_PRESCALE; |
| 6223 | /* packet error rate = (error packet number) per second */ |
| 6224 | /* 77.3 us is time for per packet */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6225 | if (period * prescale == 0) { |
| 6226 | pr_err("error: period and/or prescale is zero!\n"); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6227 | return -EIO; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6228 | } |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 6229 | *pck_errs = packet_errors_mant * (1 << packet_errors_exp); |
| 6230 | *pck_count = period * prescale * 77; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6231 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6232 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6233 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6234 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6235 | } |
| 6236 | |
| 6237 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6238 | * \fn static short GetVSBBer(struct i2c_device_addr *dev_addr, u32 *ber) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6239 | * \brief Get the values of ber in VSB mode |
| 6240 | * \return Error code |
| 6241 | */ |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 6242 | static int get_vs_bpost_viterbi_ber(struct i2c_device_addr *dev_addr, |
| 6243 | u32 *ber, u32 *cnt) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6244 | { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6245 | int rc; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 6246 | u16 data = 0; |
| 6247 | u16 period = 0; |
| 6248 | u16 prescale = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6249 | u16 bit_errors_mant = 0; |
| 6250 | u16 bit_errors_exp = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6251 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6252 | rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_BIT_ERRORS__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6253 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6254 | pr_err("error %d\n", rc); |
| 6255 | goto rw_error; |
| 6256 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6257 | period = FEC_RS_MEASUREMENT_PERIOD; |
| 6258 | prescale = FEC_RS_MEASUREMENT_PRESCALE; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6259 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6260 | bit_errors_mant = data & FEC_RS_NR_BIT_ERRORS_FIXED_MANT__M; |
| 6261 | bit_errors_exp = (data & FEC_RS_NR_BIT_ERRORS_EXP__M) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6262 | >> FEC_RS_NR_BIT_ERRORS_EXP__B; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6263 | |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 6264 | *cnt = period * prescale * 207 * ((bit_errors_exp > 2) ? 1 : 8); |
| 6265 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6266 | if (((bit_errors_mant << bit_errors_exp) >> 3) > 68700) |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 6267 | *ber = (*cnt) * 26570; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6268 | else { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6269 | if (period * prescale == 0) { |
| 6270 | pr_err("error: period and/or prescale is zero!\n"); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6271 | return -EIO; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6272 | } |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 6273 | *ber = bit_errors_mant << ((bit_errors_exp > 2) ? |
| 6274 | (bit_errors_exp - 3) : bit_errors_exp); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6275 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6276 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6277 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6278 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6279 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6283 | * \fn static short get_vs_bpre_viterbi_ber(struct i2c_device_addr *dev_addr, u32 *ber) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6284 | * \brief Get the values of ber in VSB mode |
| 6285 | * \return Error code |
| 6286 | */ |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 6287 | static int get_vs_bpre_viterbi_ber(struct i2c_device_addr *dev_addr, |
| 6288 | u32 *ber, u32 *cnt) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6289 | { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 6290 | u16 data = 0; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6291 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6292 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6293 | rc = drxj_dap_read_reg16(dev_addr, VSB_TOP_NR_SYM_ERRS__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6294 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6295 | pr_err("error %d\n", rc); |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 6296 | return -EIO; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6297 | } |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 6298 | *ber = data; |
| 6299 | *cnt = VSB_TOP_MEASUREMENT_PERIOD * SYMBOLS_PER_SEGMENT; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6300 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6301 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6302 | } |
| 6303 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6304 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6305 | * \fn static int get_vsbmer(struct i2c_device_addr *dev_addr, u16 *mer) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6306 | * \brief Get the values of MER |
| 6307 | * \return Error code |
| 6308 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6309 | static int get_vsbmer(struct i2c_device_addr *dev_addr, u16 *mer) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6310 | { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6311 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6312 | u16 data_hi = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6313 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6314 | rc = drxj_dap_read_reg16(dev_addr, VSB_TOP_ERR_ENERGY_H__A, &data_hi, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6315 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6316 | pr_err("error %d\n", rc); |
| 6317 | goto rw_error; |
| 6318 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6319 | *mer = |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6320 | (u16) (log1_times100(21504) - log1_times100((data_hi << 6) / 52)); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6321 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6322 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6323 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6324 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6325 | } |
| 6326 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6327 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6328 | /*============================================================================*/ |
| 6329 | /*== END 8VSB DATAPATH FUNCTIONS ==*/ |
| 6330 | /*============================================================================*/ |
| 6331 | |
| 6332 | /*============================================================================*/ |
| 6333 | /*============================================================================*/ |
| 6334 | /*== QAM DATAPATH FUNCTIONS ==*/ |
| 6335 | /*============================================================================*/ |
| 6336 | /*============================================================================*/ |
| 6337 | |
| 6338 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6339 | * \fn int power_down_qam () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6340 | * \brief Powr down QAM related blocks. |
| 6341 | * \param demod instance of demodulator. |
| 6342 | * \param channel pointer to channel data. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 6343 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6344 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 6345 | static int power_down_qam(struct drx_demod_instance *demod, bool primary) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6346 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 6347 | struct drxjscu_cmd cmd_scu = { /* command */ 0, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6348 | /* parameter_len */ 0, |
| 6349 | /* result_len */ 0, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6350 | /* *parameter */ NULL, |
| 6351 | /* *result */ NULL |
| 6352 | }; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6353 | int rc; |
Mauro Carvalho Chehab | 4d7bb0e | 2014-01-16 11:49:13 -0300 | [diff] [blame] | 6354 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 6355 | struct drx_cfg_mpeg_output cfg_mpeg_output; |
Mauro Carvalho Chehab | 41b5cc0 | 2014-03-02 11:01:11 -0300 | [diff] [blame] | 6356 | struct drx_common_attr *common_attr = demod->my_common_attr; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6357 | u16 cmd_result = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6358 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6359 | /* |
| 6360 | STOP demodulator |
| 6361 | resets IQM, QAM and FEC HW blocks |
| 6362 | */ |
| 6363 | /* stop all comm_exec */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6364 | rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6365 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6366 | pr_err("error %d\n", rc); |
| 6367 | goto rw_error; |
| 6368 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6369 | rc = drxj_dap_write_reg16(dev_addr, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6370 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6371 | pr_err("error %d\n", rc); |
| 6372 | goto rw_error; |
| 6373 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6374 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6375 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6376 | SCU_RAM_COMMAND_CMD_DEMOD_STOP; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6377 | cmd_scu.parameter_len = 0; |
| 6378 | cmd_scu.result_len = 1; |
| 6379 | cmd_scu.parameter = NULL; |
| 6380 | cmd_scu.result = &cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6381 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6382 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6383 | pr_err("error %d\n", rc); |
| 6384 | goto rw_error; |
| 6385 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6386 | |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 6387 | if (primary) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6388 | rc = drxj_dap_write_reg16(dev_addr, IQM_COMM_EXEC__A, IQM_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6389 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6390 | pr_err("error %d\n", rc); |
| 6391 | goto rw_error; |
| 6392 | } |
| 6393 | rc = set_iqm_af(demod, false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6394 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6395 | pr_err("error %d\n", rc); |
| 6396 | goto rw_error; |
| 6397 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6398 | } else { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6399 | rc = drxj_dap_write_reg16(dev_addr, IQM_FS_COMM_EXEC__A, IQM_FS_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6400 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6401 | pr_err("error %d\n", rc); |
| 6402 | goto rw_error; |
| 6403 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6404 | rc = drxj_dap_write_reg16(dev_addr, IQM_FD_COMM_EXEC__A, IQM_FD_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6405 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6406 | pr_err("error %d\n", rc); |
| 6407 | goto rw_error; |
| 6408 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6409 | rc = drxj_dap_write_reg16(dev_addr, IQM_RC_COMM_EXEC__A, IQM_RC_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6410 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6411 | pr_err("error %d\n", rc); |
| 6412 | goto rw_error; |
| 6413 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6414 | rc = drxj_dap_write_reg16(dev_addr, IQM_RT_COMM_EXEC__A, IQM_RT_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6415 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6416 | pr_err("error %d\n", rc); |
| 6417 | goto rw_error; |
| 6418 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6419 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_COMM_EXEC__A, IQM_CF_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6420 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6421 | pr_err("error %d\n", rc); |
| 6422 | goto rw_error; |
| 6423 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6424 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6425 | |
Mauro Carvalho Chehab | 41b5cc0 | 2014-03-02 11:01:11 -0300 | [diff] [blame] | 6426 | memcpy(&cfg_mpeg_output, &common_attr->mpeg_cfg, sizeof(cfg_mpeg_output)); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6427 | cfg_mpeg_output.enable_mpeg_output = false; |
Mauro Carvalho Chehab | 41b5cc0 | 2014-03-02 11:01:11 -0300 | [diff] [blame] | 6428 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6429 | rc = ctrl_set_cfg_mpeg_output(demod, &cfg_mpeg_output); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6430 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6431 | pr_err("error %d\n", rc); |
| 6432 | goto rw_error; |
| 6433 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6434 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6435 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6436 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6437 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6438 | } |
| 6439 | |
| 6440 | /*============================================================================*/ |
| 6441 | |
| 6442 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6443 | * \fn int set_qam_measurement () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6444 | * \brief Setup of the QAM Measuremnt intervals for signal quality |
| 6445 | * \param demod instance of demod. |
| 6446 | * \param constellation current constellation. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 6447 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6448 | * |
| 6449 | * NOTE: |
| 6450 | * Take into account that for certain settings the errorcounters can overflow. |
| 6451 | * The implementation does not check this. |
| 6452 | * |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6453 | * TODO: overriding the ext_attr->fec_bits_desired by constellation dependent |
| 6454 | * constants to get a measurement period of approx. 1 sec. Remove fec_bits_desired |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6455 | * field ? |
| 6456 | * |
| 6457 | */ |
| 6458 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 6459 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 6460 | set_qam_measurement(struct drx_demod_instance *demod, |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 6461 | enum drx_modulation constellation, u32 symbol_rate) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6462 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6463 | struct i2c_device_addr *dev_addr = NULL; /* device address for I2C writes */ |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 6464 | struct drxj_data *ext_attr = NULL; /* Global data container for DRXJ specif data */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6465 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6466 | u32 fec_bits_desired = 0; /* BER accounting period */ |
| 6467 | u16 fec_rs_plen = 0; /* defines RS BER measurement period */ |
| 6468 | u16 fec_rs_prescale = 0; /* ReedSolomon Measurement Prescale */ |
| 6469 | u32 fec_rs_period = 0; /* Value for corresponding I2C register */ |
| 6470 | u32 fec_rs_bit_cnt = 0; /* Actual precise amount of bits */ |
| 6471 | u32 fec_oc_snc_fail_period = 0; /* Value for corresponding I2C register */ |
| 6472 | u32 qam_vd_period = 0; /* Value for corresponding I2C register */ |
| 6473 | u32 qam_vd_bit_cnt = 0; /* Actual precise amount of bits */ |
| 6474 | u16 fec_vd_plen = 0; /* no of trellis symbols: VD SER measur period */ |
| 6475 | u16 qam_vd_prescale = 0; /* Viterbi Measurement Prescale */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6476 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6477 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 6478 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6479 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6480 | fec_bits_desired = ext_attr->fec_bits_desired; |
| 6481 | fec_rs_prescale = ext_attr->fec_rs_prescale; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6482 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6483 | switch (constellation) { |
| 6484 | case DRX_CONSTELLATION_QAM16: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6485 | fec_bits_desired = 4 * symbol_rate; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6486 | break; |
| 6487 | case DRX_CONSTELLATION_QAM32: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6488 | fec_bits_desired = 5 * symbol_rate; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6489 | break; |
| 6490 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6491 | fec_bits_desired = 6 * symbol_rate; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6492 | break; |
| 6493 | case DRX_CONSTELLATION_QAM128: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6494 | fec_bits_desired = 7 * symbol_rate; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6495 | break; |
| 6496 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6497 | fec_bits_desired = 8 * symbol_rate; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6498 | break; |
| 6499 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6500 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6501 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6502 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6503 | /* Parameters for Reed-Solomon Decoder */ |
| 6504 | /* fecrs_period = (int)ceil(FEC_BITS_DESIRED/(fecrs_prescale*plen)) */ |
| 6505 | /* rs_bit_cnt = fecrs_period*fecrs_prescale*plen */ |
| 6506 | /* result is within 32 bit arithmetic -> */ |
| 6507 | /* no need for mult or frac functions */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6508 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6509 | /* TODO: use constant instead of calculation and remove the fec_rs_plen in ext_attr */ |
| 6510 | switch (ext_attr->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6511 | case DRX_STANDARD_ITU_A: |
| 6512 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6513 | fec_rs_plen = 204 * 8; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6514 | break; |
| 6515 | case DRX_STANDARD_ITU_B: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6516 | fec_rs_plen = 128 * 7; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6517 | break; |
| 6518 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6519 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6520 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6521 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6522 | ext_attr->fec_rs_plen = fec_rs_plen; /* for getSigQual */ |
| 6523 | fec_rs_bit_cnt = fec_rs_prescale * fec_rs_plen; /* temp storage */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6524 | if (fec_rs_bit_cnt == 0) { |
| 6525 | pr_err("error: fec_rs_bit_cnt is zero!\n"); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6526 | return -EIO; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6527 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6528 | fec_rs_period = fec_bits_desired / fec_rs_bit_cnt + 1; /* ceil */ |
| 6529 | if (ext_attr->standard != DRX_STANDARD_ITU_B) |
| 6530 | fec_oc_snc_fail_period = fec_rs_period; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6531 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6532 | /* limit to max 16 bit value (I2C register width) if needed */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6533 | if (fec_rs_period > 0xFFFF) |
| 6534 | fec_rs_period = 0xFFFF; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6535 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6536 | /* write corresponding registers */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6537 | switch (ext_attr->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6538 | case DRX_STANDARD_ITU_A: |
| 6539 | case DRX_STANDARD_ITU_C: |
| 6540 | break; |
| 6541 | case DRX_STANDARD_ITU_B: |
| 6542 | switch (constellation) { |
| 6543 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6544 | fec_rs_period = 31581; |
| 6545 | fec_oc_snc_fail_period = 17932; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6546 | break; |
| 6547 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6548 | fec_rs_period = 45446; |
| 6549 | fec_oc_snc_fail_period = 25805; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6550 | break; |
| 6551 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6552 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6553 | } |
| 6554 | break; |
| 6555 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6556 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6557 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6558 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6559 | rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_FAIL_PERIOD__A, (u16)fec_oc_snc_fail_period, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6560 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6561 | pr_err("error %d\n", rc); |
| 6562 | goto rw_error; |
| 6563 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6564 | rc = drxj_dap_write_reg16(dev_addr, FEC_RS_MEASUREMENT_PERIOD__A, (u16)fec_rs_period, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6565 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6566 | pr_err("error %d\n", rc); |
| 6567 | goto rw_error; |
| 6568 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6569 | rc = drxj_dap_write_reg16(dev_addr, FEC_RS_MEASUREMENT_PRESCALE__A, fec_rs_prescale, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6570 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6571 | pr_err("error %d\n", rc); |
| 6572 | goto rw_error; |
| 6573 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6574 | ext_attr->fec_rs_period = (u16) fec_rs_period; |
| 6575 | ext_attr->fec_rs_prescale = fec_rs_prescale; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6576 | rc = drxdap_fasi_write_reg32(dev_addr, SCU_RAM_FEC_ACCUM_CW_CORRECTED_LO__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6577 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6578 | pr_err("error %d\n", rc); |
| 6579 | goto rw_error; |
| 6580 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6581 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_FEC_MEAS_COUNT__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6582 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6583 | pr_err("error %d\n", rc); |
| 6584 | goto rw_error; |
| 6585 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6586 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6587 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6588 | pr_err("error %d\n", rc); |
| 6589 | goto rw_error; |
| 6590 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6591 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6592 | if (ext_attr->standard == DRX_STANDARD_ITU_B) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6593 | /* Parameters for Viterbi Decoder */ |
| 6594 | /* qamvd_period = (int)ceil(FEC_BITS_DESIRED/ */ |
| 6595 | /* (qamvd_prescale*plen*(qam_constellation+1))) */ |
| 6596 | /* vd_bit_cnt = qamvd_period*qamvd_prescale*plen */ |
| 6597 | /* result is within 32 bit arithmetic -> */ |
| 6598 | /* no need for mult or frac functions */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6599 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6600 | /* a(8 bit) * b(8 bit) = 16 bit result => mult32 not needed */ |
| 6601 | fec_vd_plen = ext_attr->fec_vd_plen; |
| 6602 | qam_vd_prescale = ext_attr->qam_vd_prescale; |
| 6603 | qam_vd_bit_cnt = qam_vd_prescale * fec_vd_plen; /* temp storage */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6604 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6605 | switch (constellation) { |
| 6606 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6607 | /* a(16 bit) * b(4 bit) = 20 bit result => mult32 not needed */ |
| 6608 | qam_vd_period = |
| 6609 | qam_vd_bit_cnt * (QAM_TOP_CONSTELLATION_QAM64 + 1) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6610 | * (QAM_TOP_CONSTELLATION_QAM64 + 1); |
| 6611 | break; |
| 6612 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6613 | /* a(16 bit) * b(5 bit) = 21 bit result => mult32 not needed */ |
| 6614 | qam_vd_period = |
| 6615 | qam_vd_bit_cnt * (QAM_TOP_CONSTELLATION_QAM256 + 1) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6616 | * (QAM_TOP_CONSTELLATION_QAM256 + 1); |
| 6617 | break; |
| 6618 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6619 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6620 | } |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6621 | if (qam_vd_period == 0) { |
| 6622 | pr_err("error: qam_vd_period is zero!\n"); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6623 | return -EIO; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6624 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6625 | qam_vd_period = fec_bits_desired / qam_vd_period; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6626 | /* limit to max 16 bit value (I2C register width) if needed */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6627 | if (qam_vd_period > 0xFFFF) |
| 6628 | qam_vd_period = 0xFFFF; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6629 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6630 | /* a(16 bit) * b(16 bit) = 32 bit result => mult32 not needed */ |
| 6631 | qam_vd_bit_cnt *= qam_vd_period; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6632 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6633 | rc = drxj_dap_write_reg16(dev_addr, QAM_VD_MEASUREMENT_PERIOD__A, (u16)qam_vd_period, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6634 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6635 | pr_err("error %d\n", rc); |
| 6636 | goto rw_error; |
| 6637 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6638 | rc = drxj_dap_write_reg16(dev_addr, QAM_VD_MEASUREMENT_PRESCALE__A, qam_vd_prescale, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6639 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6640 | pr_err("error %d\n", rc); |
| 6641 | goto rw_error; |
| 6642 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6643 | ext_attr->qam_vd_period = (u16) qam_vd_period; |
| 6644 | ext_attr->qam_vd_prescale = qam_vd_prescale; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6645 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6646 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6647 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6648 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6649 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6650 | } |
| 6651 | |
| 6652 | /*============================================================================*/ |
| 6653 | |
| 6654 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6655 | * \fn int set_qam16 () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6656 | * \brief QAM16 specific setup |
| 6657 | * \param demod instance of demod. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 6658 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6659 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 6660 | static int set_qam16(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6661 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6662 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6663 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6664 | const u8 qam_dq_qual_fun[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6665 | DRXJ_16TO8(2), /* fun0 */ |
| 6666 | DRXJ_16TO8(2), /* fun1 */ |
| 6667 | DRXJ_16TO8(2), /* fun2 */ |
| 6668 | DRXJ_16TO8(2), /* fun3 */ |
| 6669 | DRXJ_16TO8(3), /* fun4 */ |
| 6670 | DRXJ_16TO8(3), /* fun5 */ |
| 6671 | }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6672 | const u8 qam_eq_cma_rad[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6673 | DRXJ_16TO8(13517), /* RAD0 */ |
| 6674 | DRXJ_16TO8(13517), /* RAD1 */ |
| 6675 | DRXJ_16TO8(13517), /* RAD2 */ |
| 6676 | DRXJ_16TO8(13517), /* RAD3 */ |
| 6677 | DRXJ_16TO8(13517), /* RAD4 */ |
| 6678 | DRXJ_16TO8(13517), /* RAD5 */ |
| 6679 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6680 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6681 | rc = drxdap_fasi_write_block(dev_addr, QAM_DQ_QUAL_FUN0__A, sizeof(qam_dq_qual_fun), ((u8 *)qam_dq_qual_fun), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6682 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6683 | pr_err("error %d\n", rc); |
| 6684 | goto rw_error; |
| 6685 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6686 | rc = drxdap_fasi_write_block(dev_addr, SCU_RAM_QAM_EQ_CMA_RAD0__A, sizeof(qam_eq_cma_rad), ((u8 *)qam_eq_cma_rad), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6687 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6688 | pr_err("error %d\n", rc); |
| 6689 | goto rw_error; |
| 6690 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6691 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6692 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RTH__A, 140, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6693 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6694 | pr_err("error %d\n", rc); |
| 6695 | goto rw_error; |
| 6696 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6697 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FTH__A, 50, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6698 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6699 | pr_err("error %d\n", rc); |
| 6700 | goto rw_error; |
| 6701 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6702 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_PTH__A, 120, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6703 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6704 | pr_err("error %d\n", rc); |
| 6705 | goto rw_error; |
| 6706 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6707 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_QTH__A, 230, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6708 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6709 | pr_err("error %d\n", rc); |
| 6710 | goto rw_error; |
| 6711 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6712 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_CTH__A, 95, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6713 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6714 | pr_err("error %d\n", rc); |
| 6715 | goto rw_error; |
| 6716 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6717 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MTH__A, 105, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6718 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6719 | pr_err("error %d\n", rc); |
| 6720 | goto rw_error; |
| 6721 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6722 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6723 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RATE_LIM__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6724 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6725 | pr_err("error %d\n", rc); |
| 6726 | goto rw_error; |
| 6727 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6728 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FREQ_LIM__A, 56, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6729 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6730 | pr_err("error %d\n", rc); |
| 6731 | goto rw_error; |
| 6732 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6733 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_COUNT_LIM__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6734 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6735 | pr_err("error %d\n", rc); |
| 6736 | goto rw_error; |
| 6737 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6738 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6739 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6740 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6741 | pr_err("error %d\n", rc); |
| 6742 | goto rw_error; |
| 6743 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6744 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, 220, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6745 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6746 | pr_err("error %d\n", rc); |
| 6747 | goto rw_error; |
| 6748 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6749 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, 25, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6750 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6751 | pr_err("error %d\n", rc); |
| 6752 | goto rw_error; |
| 6753 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6754 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, 6, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6755 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6756 | pr_err("error %d\n", rc); |
| 6757 | goto rw_error; |
| 6758 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6759 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16)(-24), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6760 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6761 | pr_err("error %d\n", rc); |
| 6762 | goto rw_error; |
| 6763 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6764 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16)(-65), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6765 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6766 | pr_err("error %d\n", rc); |
| 6767 | goto rw_error; |
| 6768 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6769 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16)(-127), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6770 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6771 | pr_err("error %d\n", rc); |
| 6772 | goto rw_error; |
| 6773 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6774 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6775 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_FINE__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6776 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6777 | pr_err("error %d\n", rc); |
| 6778 | goto rw_error; |
| 6779 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6780 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_COARSE__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6781 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6782 | pr_err("error %d\n", rc); |
| 6783 | goto rw_error; |
| 6784 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6785 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_FINE__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6786 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6787 | pr_err("error %d\n", rc); |
| 6788 | goto rw_error; |
| 6789 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6790 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6791 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6792 | pr_err("error %d\n", rc); |
| 6793 | goto rw_error; |
| 6794 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6795 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_COARSE__A, 255, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6796 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6797 | pr_err("error %d\n", rc); |
| 6798 | goto rw_error; |
| 6799 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6800 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_FINE__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6801 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6802 | pr_err("error %d\n", rc); |
| 6803 | goto rw_error; |
| 6804 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6805 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_MEDIUM__A, 10, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6806 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6807 | pr_err("error %d\n", rc); |
| 6808 | goto rw_error; |
| 6809 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6810 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_COARSE__A, 50, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6811 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6812 | pr_err("error %d\n", rc); |
| 6813 | goto rw_error; |
| 6814 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6815 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_FINE__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6816 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6817 | pr_err("error %d\n", rc); |
| 6818 | goto rw_error; |
| 6819 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6820 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6821 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6822 | pr_err("error %d\n", rc); |
| 6823 | goto rw_error; |
| 6824 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6825 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_COARSE__A, 24, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6826 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6827 | pr_err("error %d\n", rc); |
| 6828 | goto rw_error; |
| 6829 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6830 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_FINE__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6831 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6832 | pr_err("error %d\n", rc); |
| 6833 | goto rw_error; |
| 6834 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6835 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6836 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6837 | pr_err("error %d\n", rc); |
| 6838 | goto rw_error; |
| 6839 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6840 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_COARSE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6841 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6842 | pr_err("error %d\n", rc); |
| 6843 | goto rw_error; |
| 6844 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6845 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_FINE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6846 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6847 | pr_err("error %d\n", rc); |
| 6848 | goto rw_error; |
| 6849 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6850 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_MEDIUM__A, 32, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6851 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6852 | pr_err("error %d\n", rc); |
| 6853 | goto rw_error; |
| 6854 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6855 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_COARSE__A, 240, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6856 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6857 | pr_err("error %d\n", rc); |
| 6858 | goto rw_error; |
| 6859 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6860 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_FINE__A, 5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6861 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6862 | pr_err("error %d\n", rc); |
| 6863 | goto rw_error; |
| 6864 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6865 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6866 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6867 | pr_err("error %d\n", rc); |
| 6868 | goto rw_error; |
| 6869 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6870 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_COARSE__A, 32, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6871 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6872 | pr_err("error %d\n", rc); |
| 6873 | goto rw_error; |
| 6874 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6875 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6876 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_SL_SIG_POWER__A, 40960, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6877 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6878 | pr_err("error %d\n", rc); |
| 6879 | goto rw_error; |
| 6880 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6881 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6882 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6883 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6884 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6885 | } |
| 6886 | |
| 6887 | /*============================================================================*/ |
| 6888 | |
| 6889 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6890 | * \fn int set_qam32 () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6891 | * \brief QAM32 specific setup |
| 6892 | * \param demod instance of demod. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 6893 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6894 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 6895 | static int set_qam32(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6896 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6897 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6898 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6899 | const u8 qam_dq_qual_fun[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6900 | DRXJ_16TO8(3), /* fun0 */ |
| 6901 | DRXJ_16TO8(3), /* fun1 */ |
| 6902 | DRXJ_16TO8(3), /* fun2 */ |
| 6903 | DRXJ_16TO8(3), /* fun3 */ |
| 6904 | DRXJ_16TO8(4), /* fun4 */ |
| 6905 | DRXJ_16TO8(4), /* fun5 */ |
| 6906 | }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 6907 | const u8 qam_eq_cma_rad[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 6908 | DRXJ_16TO8(6707), /* RAD0 */ |
| 6909 | DRXJ_16TO8(6707), /* RAD1 */ |
| 6910 | DRXJ_16TO8(6707), /* RAD2 */ |
| 6911 | DRXJ_16TO8(6707), /* RAD3 */ |
| 6912 | DRXJ_16TO8(6707), /* RAD4 */ |
| 6913 | DRXJ_16TO8(6707), /* RAD5 */ |
| 6914 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6915 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6916 | rc = drxdap_fasi_write_block(dev_addr, QAM_DQ_QUAL_FUN0__A, sizeof(qam_dq_qual_fun), ((u8 *)qam_dq_qual_fun), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6917 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6918 | pr_err("error %d\n", rc); |
| 6919 | goto rw_error; |
| 6920 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6921 | rc = drxdap_fasi_write_block(dev_addr, SCU_RAM_QAM_EQ_CMA_RAD0__A, sizeof(qam_eq_cma_rad), ((u8 *)qam_eq_cma_rad), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6922 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6923 | pr_err("error %d\n", rc); |
| 6924 | goto rw_error; |
| 6925 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6926 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6927 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RTH__A, 90, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6928 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6929 | pr_err("error %d\n", rc); |
| 6930 | goto rw_error; |
| 6931 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6932 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FTH__A, 50, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6933 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6934 | pr_err("error %d\n", rc); |
| 6935 | goto rw_error; |
| 6936 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6937 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_PTH__A, 100, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6938 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6939 | pr_err("error %d\n", rc); |
| 6940 | goto rw_error; |
| 6941 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6942 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_QTH__A, 170, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6943 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6944 | pr_err("error %d\n", rc); |
| 6945 | goto rw_error; |
| 6946 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6947 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_CTH__A, 80, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6948 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6949 | pr_err("error %d\n", rc); |
| 6950 | goto rw_error; |
| 6951 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6952 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MTH__A, 100, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6953 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6954 | pr_err("error %d\n", rc); |
| 6955 | goto rw_error; |
| 6956 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6957 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6958 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RATE_LIM__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6959 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6960 | pr_err("error %d\n", rc); |
| 6961 | goto rw_error; |
| 6962 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6963 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FREQ_LIM__A, 56, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6964 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6965 | pr_err("error %d\n", rc); |
| 6966 | goto rw_error; |
| 6967 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6968 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_COUNT_LIM__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6969 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6970 | pr_err("error %d\n", rc); |
| 6971 | goto rw_error; |
| 6972 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 6973 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6974 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6975 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6976 | pr_err("error %d\n", rc); |
| 6977 | goto rw_error; |
| 6978 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6979 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, 140, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6980 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6981 | pr_err("error %d\n", rc); |
| 6982 | goto rw_error; |
| 6983 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6984 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16)(-8), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6985 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6986 | pr_err("error %d\n", rc); |
| 6987 | goto rw_error; |
| 6988 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6989 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16)(-16), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6990 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6991 | pr_err("error %d\n", rc); |
| 6992 | goto rw_error; |
| 6993 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6994 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16)(-26), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 6995 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 6996 | pr_err("error %d\n", rc); |
| 6997 | goto rw_error; |
| 6998 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 6999 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16)(-56), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7000 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7001 | pr_err("error %d\n", rc); |
| 7002 | goto rw_error; |
| 7003 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7004 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16)(-86), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7005 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7006 | pr_err("error %d\n", rc); |
| 7007 | goto rw_error; |
| 7008 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7009 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7010 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_FINE__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7011 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7012 | pr_err("error %d\n", rc); |
| 7013 | goto rw_error; |
| 7014 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7015 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_COARSE__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7016 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7017 | pr_err("error %d\n", rc); |
| 7018 | goto rw_error; |
| 7019 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7020 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_FINE__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7021 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7022 | pr_err("error %d\n", rc); |
| 7023 | goto rw_error; |
| 7024 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7025 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7026 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7027 | pr_err("error %d\n", rc); |
| 7028 | goto rw_error; |
| 7029 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7030 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_COARSE__A, 255, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7031 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7032 | pr_err("error %d\n", rc); |
| 7033 | goto rw_error; |
| 7034 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7035 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_FINE__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7036 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7037 | pr_err("error %d\n", rc); |
| 7038 | goto rw_error; |
| 7039 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7040 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_MEDIUM__A, 10, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7041 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7042 | pr_err("error %d\n", rc); |
| 7043 | goto rw_error; |
| 7044 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7045 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_COARSE__A, 50, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7046 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7047 | pr_err("error %d\n", rc); |
| 7048 | goto rw_error; |
| 7049 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7050 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_FINE__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7051 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7052 | pr_err("error %d\n", rc); |
| 7053 | goto rw_error; |
| 7054 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7055 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7056 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7057 | pr_err("error %d\n", rc); |
| 7058 | goto rw_error; |
| 7059 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7060 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_COARSE__A, 24, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7061 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7062 | pr_err("error %d\n", rc); |
| 7063 | goto rw_error; |
| 7064 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7065 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_FINE__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7066 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7067 | pr_err("error %d\n", rc); |
| 7068 | goto rw_error; |
| 7069 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7070 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7071 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7072 | pr_err("error %d\n", rc); |
| 7073 | goto rw_error; |
| 7074 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7075 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_COARSE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7076 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7077 | pr_err("error %d\n", rc); |
| 7078 | goto rw_error; |
| 7079 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7080 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_FINE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7081 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7082 | pr_err("error %d\n", rc); |
| 7083 | goto rw_error; |
| 7084 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7085 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_MEDIUM__A, 32, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7086 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7087 | pr_err("error %d\n", rc); |
| 7088 | goto rw_error; |
| 7089 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7090 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_COARSE__A, 176, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7091 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7092 | pr_err("error %d\n", rc); |
| 7093 | goto rw_error; |
| 7094 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7095 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_FINE__A, 5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7096 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7097 | pr_err("error %d\n", rc); |
| 7098 | goto rw_error; |
| 7099 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7100 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7101 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7102 | pr_err("error %d\n", rc); |
| 7103 | goto rw_error; |
| 7104 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7105 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_COARSE__A, 8, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7106 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7107 | pr_err("error %d\n", rc); |
| 7108 | goto rw_error; |
| 7109 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7110 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7111 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_SL_SIG_POWER__A, 20480, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7112 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7113 | pr_err("error %d\n", rc); |
| 7114 | goto rw_error; |
| 7115 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7116 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7117 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7118 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7119 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7120 | } |
| 7121 | |
| 7122 | /*============================================================================*/ |
| 7123 | |
| 7124 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7125 | * \fn int set_qam64 () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7126 | * \brief QAM64 specific setup |
| 7127 | * \param demod instance of demod. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 7128 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7129 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 7130 | static int set_qam64(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7131 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7132 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7133 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7134 | const u8 qam_dq_qual_fun[] = { /* this is hw reset value. no necessary to re-write */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7135 | DRXJ_16TO8(4), /* fun0 */ |
| 7136 | DRXJ_16TO8(4), /* fun1 */ |
| 7137 | DRXJ_16TO8(4), /* fun2 */ |
| 7138 | DRXJ_16TO8(4), /* fun3 */ |
| 7139 | DRXJ_16TO8(6), /* fun4 */ |
| 7140 | DRXJ_16TO8(6), /* fun5 */ |
| 7141 | }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7142 | const u8 qam_eq_cma_rad[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7143 | DRXJ_16TO8(13336), /* RAD0 */ |
| 7144 | DRXJ_16TO8(12618), /* RAD1 */ |
| 7145 | DRXJ_16TO8(11988), /* RAD2 */ |
| 7146 | DRXJ_16TO8(13809), /* RAD3 */ |
| 7147 | DRXJ_16TO8(13809), /* RAD4 */ |
| 7148 | DRXJ_16TO8(15609), /* RAD5 */ |
| 7149 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7150 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7151 | rc = drxdap_fasi_write_block(dev_addr, QAM_DQ_QUAL_FUN0__A, sizeof(qam_dq_qual_fun), ((u8 *)qam_dq_qual_fun), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7152 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7153 | pr_err("error %d\n", rc); |
| 7154 | goto rw_error; |
| 7155 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7156 | rc = drxdap_fasi_write_block(dev_addr, SCU_RAM_QAM_EQ_CMA_RAD0__A, sizeof(qam_eq_cma_rad), ((u8 *)qam_eq_cma_rad), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7157 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7158 | pr_err("error %d\n", rc); |
| 7159 | goto rw_error; |
| 7160 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7161 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7162 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RTH__A, 105, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7163 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7164 | pr_err("error %d\n", rc); |
| 7165 | goto rw_error; |
| 7166 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7167 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FTH__A, 60, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7168 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7169 | pr_err("error %d\n", rc); |
| 7170 | goto rw_error; |
| 7171 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7172 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_PTH__A, 100, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7173 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7174 | pr_err("error %d\n", rc); |
| 7175 | goto rw_error; |
| 7176 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7177 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_QTH__A, 195, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7178 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7179 | pr_err("error %d\n", rc); |
| 7180 | goto rw_error; |
| 7181 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7182 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_CTH__A, 80, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7183 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7184 | pr_err("error %d\n", rc); |
| 7185 | goto rw_error; |
| 7186 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7187 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MTH__A, 84, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7188 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7189 | pr_err("error %d\n", rc); |
| 7190 | goto rw_error; |
| 7191 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7192 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7193 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RATE_LIM__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7194 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7195 | pr_err("error %d\n", rc); |
| 7196 | goto rw_error; |
| 7197 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7198 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FREQ_LIM__A, 32, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7199 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7200 | pr_err("error %d\n", rc); |
| 7201 | goto rw_error; |
| 7202 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7203 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_COUNT_LIM__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7204 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7205 | pr_err("error %d\n", rc); |
| 7206 | goto rw_error; |
| 7207 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7208 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7209 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7210 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7211 | pr_err("error %d\n", rc); |
| 7212 | goto rw_error; |
| 7213 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7214 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, 141, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7215 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7216 | pr_err("error %d\n", rc); |
| 7217 | goto rw_error; |
| 7218 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7219 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, 7, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7220 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7221 | pr_err("error %d\n", rc); |
| 7222 | goto rw_error; |
| 7223 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7224 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7225 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7226 | pr_err("error %d\n", rc); |
| 7227 | goto rw_error; |
| 7228 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7229 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16)(-15), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7230 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7231 | pr_err("error %d\n", rc); |
| 7232 | goto rw_error; |
| 7233 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7234 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16)(-45), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7235 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7236 | pr_err("error %d\n", rc); |
| 7237 | goto rw_error; |
| 7238 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7239 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16)(-80), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7240 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7241 | pr_err("error %d\n", rc); |
| 7242 | goto rw_error; |
| 7243 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7244 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7245 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_FINE__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7246 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7247 | pr_err("error %d\n", rc); |
| 7248 | goto rw_error; |
| 7249 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7250 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_COARSE__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7251 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7252 | pr_err("error %d\n", rc); |
| 7253 | goto rw_error; |
| 7254 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7255 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_FINE__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7256 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7257 | pr_err("error %d\n", rc); |
| 7258 | goto rw_error; |
| 7259 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7260 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_MEDIUM__A, 30, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7261 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7262 | pr_err("error %d\n", rc); |
| 7263 | goto rw_error; |
| 7264 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7265 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_COARSE__A, 255, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7266 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7267 | pr_err("error %d\n", rc); |
| 7268 | goto rw_error; |
| 7269 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7270 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_FINE__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7271 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7272 | pr_err("error %d\n", rc); |
| 7273 | goto rw_error; |
| 7274 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7275 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_MEDIUM__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7276 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7277 | pr_err("error %d\n", rc); |
| 7278 | goto rw_error; |
| 7279 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7280 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_COARSE__A, 80, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7281 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7282 | pr_err("error %d\n", rc); |
| 7283 | goto rw_error; |
| 7284 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7285 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_FINE__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7286 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7287 | pr_err("error %d\n", rc); |
| 7288 | goto rw_error; |
| 7289 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7290 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7291 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7292 | pr_err("error %d\n", rc); |
| 7293 | goto rw_error; |
| 7294 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7295 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_COARSE__A, 24, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7296 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7297 | pr_err("error %d\n", rc); |
| 7298 | goto rw_error; |
| 7299 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7300 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_FINE__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7301 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7302 | pr_err("error %d\n", rc); |
| 7303 | goto rw_error; |
| 7304 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7305 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7306 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7307 | pr_err("error %d\n", rc); |
| 7308 | goto rw_error; |
| 7309 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7310 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_COARSE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7311 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7312 | pr_err("error %d\n", rc); |
| 7313 | goto rw_error; |
| 7314 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7315 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_FINE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7316 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7317 | pr_err("error %d\n", rc); |
| 7318 | goto rw_error; |
| 7319 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7320 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_MEDIUM__A, 48, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7321 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7322 | pr_err("error %d\n", rc); |
| 7323 | goto rw_error; |
| 7324 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7325 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_COARSE__A, 160, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7326 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7327 | pr_err("error %d\n", rc); |
| 7328 | goto rw_error; |
| 7329 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7330 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_FINE__A, 5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7331 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7332 | pr_err("error %d\n", rc); |
| 7333 | goto rw_error; |
| 7334 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7335 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7336 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7337 | pr_err("error %d\n", rc); |
| 7338 | goto rw_error; |
| 7339 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7340 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_COARSE__A, 32, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7341 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7342 | pr_err("error %d\n", rc); |
| 7343 | goto rw_error; |
| 7344 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7345 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7346 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_SL_SIG_POWER__A, 43008, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7347 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7348 | pr_err("error %d\n", rc); |
| 7349 | goto rw_error; |
| 7350 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7351 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7352 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7353 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7354 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7355 | } |
| 7356 | |
| 7357 | /*============================================================================*/ |
| 7358 | |
| 7359 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7360 | * \fn int set_qam128 () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7361 | * \brief QAM128 specific setup |
| 7362 | * \param demod: instance of demod. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 7363 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7364 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 7365 | static int set_qam128(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7366 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7367 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7368 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7369 | const u8 qam_dq_qual_fun[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7370 | DRXJ_16TO8(6), /* fun0 */ |
| 7371 | DRXJ_16TO8(6), /* fun1 */ |
| 7372 | DRXJ_16TO8(6), /* fun2 */ |
| 7373 | DRXJ_16TO8(6), /* fun3 */ |
| 7374 | DRXJ_16TO8(9), /* fun4 */ |
| 7375 | DRXJ_16TO8(9), /* fun5 */ |
| 7376 | }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7377 | const u8 qam_eq_cma_rad[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7378 | DRXJ_16TO8(6164), /* RAD0 */ |
| 7379 | DRXJ_16TO8(6598), /* RAD1 */ |
| 7380 | DRXJ_16TO8(6394), /* RAD2 */ |
| 7381 | DRXJ_16TO8(6409), /* RAD3 */ |
| 7382 | DRXJ_16TO8(6656), /* RAD4 */ |
| 7383 | DRXJ_16TO8(7238), /* RAD5 */ |
| 7384 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7385 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7386 | rc = drxdap_fasi_write_block(dev_addr, QAM_DQ_QUAL_FUN0__A, sizeof(qam_dq_qual_fun), ((u8 *)qam_dq_qual_fun), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7387 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7388 | pr_err("error %d\n", rc); |
| 7389 | goto rw_error; |
| 7390 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7391 | rc = drxdap_fasi_write_block(dev_addr, SCU_RAM_QAM_EQ_CMA_RAD0__A, sizeof(qam_eq_cma_rad), ((u8 *)qam_eq_cma_rad), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7392 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7393 | pr_err("error %d\n", rc); |
| 7394 | goto rw_error; |
| 7395 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7396 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7397 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RTH__A, 50, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7398 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7399 | pr_err("error %d\n", rc); |
| 7400 | goto rw_error; |
| 7401 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7402 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FTH__A, 60, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7403 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7404 | pr_err("error %d\n", rc); |
| 7405 | goto rw_error; |
| 7406 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7407 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_PTH__A, 100, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7408 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7409 | pr_err("error %d\n", rc); |
| 7410 | goto rw_error; |
| 7411 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7412 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_QTH__A, 140, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7413 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7414 | pr_err("error %d\n", rc); |
| 7415 | goto rw_error; |
| 7416 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7417 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_CTH__A, 80, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7418 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7419 | pr_err("error %d\n", rc); |
| 7420 | goto rw_error; |
| 7421 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7422 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MTH__A, 100, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7423 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7424 | pr_err("error %d\n", rc); |
| 7425 | goto rw_error; |
| 7426 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7427 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7428 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RATE_LIM__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7429 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7430 | pr_err("error %d\n", rc); |
| 7431 | goto rw_error; |
| 7432 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7433 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FREQ_LIM__A, 32, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7434 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7435 | pr_err("error %d\n", rc); |
| 7436 | goto rw_error; |
| 7437 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7438 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_COUNT_LIM__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7439 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7440 | pr_err("error %d\n", rc); |
| 7441 | goto rw_error; |
| 7442 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7443 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7444 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, 8, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7445 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7446 | pr_err("error %d\n", rc); |
| 7447 | goto rw_error; |
| 7448 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7449 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, 65, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7450 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7451 | pr_err("error %d\n", rc); |
| 7452 | goto rw_error; |
| 7453 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7454 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, 5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7455 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7456 | pr_err("error %d\n", rc); |
| 7457 | goto rw_error; |
| 7458 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7459 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7460 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7461 | pr_err("error %d\n", rc); |
| 7462 | goto rw_error; |
| 7463 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7464 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16)(-1), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7465 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7466 | pr_err("error %d\n", rc); |
| 7467 | goto rw_error; |
| 7468 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7469 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7470 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7471 | pr_err("error %d\n", rc); |
| 7472 | goto rw_error; |
| 7473 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7474 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16)(-23), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7475 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7476 | pr_err("error %d\n", rc); |
| 7477 | goto rw_error; |
| 7478 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7479 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7480 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_FINE__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7481 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7482 | pr_err("error %d\n", rc); |
| 7483 | goto rw_error; |
| 7484 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7485 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_COARSE__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7486 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7487 | pr_err("error %d\n", rc); |
| 7488 | goto rw_error; |
| 7489 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7490 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_FINE__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7491 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7492 | pr_err("error %d\n", rc); |
| 7493 | goto rw_error; |
| 7494 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7495 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_MEDIUM__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7496 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7497 | pr_err("error %d\n", rc); |
| 7498 | goto rw_error; |
| 7499 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7500 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_COARSE__A, 255, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7501 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7502 | pr_err("error %d\n", rc); |
| 7503 | goto rw_error; |
| 7504 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7505 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_FINE__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7506 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7507 | pr_err("error %d\n", rc); |
| 7508 | goto rw_error; |
| 7509 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7510 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_MEDIUM__A, 20, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7511 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7512 | pr_err("error %d\n", rc); |
| 7513 | goto rw_error; |
| 7514 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7515 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_COARSE__A, 80, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7516 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7517 | pr_err("error %d\n", rc); |
| 7518 | goto rw_error; |
| 7519 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7520 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_FINE__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7521 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7522 | pr_err("error %d\n", rc); |
| 7523 | goto rw_error; |
| 7524 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7525 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7526 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7527 | pr_err("error %d\n", rc); |
| 7528 | goto rw_error; |
| 7529 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7530 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_COARSE__A, 24, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7531 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7532 | pr_err("error %d\n", rc); |
| 7533 | goto rw_error; |
| 7534 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7535 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_FINE__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7536 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7537 | pr_err("error %d\n", rc); |
| 7538 | goto rw_error; |
| 7539 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7540 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7541 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7542 | pr_err("error %d\n", rc); |
| 7543 | goto rw_error; |
| 7544 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7545 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_COARSE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7546 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7547 | pr_err("error %d\n", rc); |
| 7548 | goto rw_error; |
| 7549 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7550 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_FINE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7551 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7552 | pr_err("error %d\n", rc); |
| 7553 | goto rw_error; |
| 7554 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7555 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_MEDIUM__A, 32, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7556 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7557 | pr_err("error %d\n", rc); |
| 7558 | goto rw_error; |
| 7559 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7560 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_COARSE__A, 144, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7561 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7562 | pr_err("error %d\n", rc); |
| 7563 | goto rw_error; |
| 7564 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7565 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_FINE__A, 5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7566 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7567 | pr_err("error %d\n", rc); |
| 7568 | goto rw_error; |
| 7569 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7570 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7571 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7572 | pr_err("error %d\n", rc); |
| 7573 | goto rw_error; |
| 7574 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7575 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_COARSE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7576 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7577 | pr_err("error %d\n", rc); |
| 7578 | goto rw_error; |
| 7579 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7580 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7581 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_SL_SIG_POWER__A, 20992, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7582 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7583 | pr_err("error %d\n", rc); |
| 7584 | goto rw_error; |
| 7585 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7586 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7587 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7588 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7589 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7590 | } |
| 7591 | |
| 7592 | /*============================================================================*/ |
| 7593 | |
| 7594 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7595 | * \fn int set_qam256 () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7596 | * \brief QAM256 specific setup |
| 7597 | * \param demod: instance of demod. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 7598 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7599 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 7600 | static int set_qam256(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7601 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7602 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7603 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7604 | const u8 qam_dq_qual_fun[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7605 | DRXJ_16TO8(8), /* fun0 */ |
| 7606 | DRXJ_16TO8(8), /* fun1 */ |
| 7607 | DRXJ_16TO8(8), /* fun2 */ |
| 7608 | DRXJ_16TO8(8), /* fun3 */ |
| 7609 | DRXJ_16TO8(12), /* fun4 */ |
| 7610 | DRXJ_16TO8(12), /* fun5 */ |
| 7611 | }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7612 | const u8 qam_eq_cma_rad[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7613 | DRXJ_16TO8(12345), /* RAD0 */ |
| 7614 | DRXJ_16TO8(12345), /* RAD1 */ |
| 7615 | DRXJ_16TO8(13626), /* RAD2 */ |
| 7616 | DRXJ_16TO8(12931), /* RAD3 */ |
| 7617 | DRXJ_16TO8(14719), /* RAD4 */ |
| 7618 | DRXJ_16TO8(15356), /* RAD5 */ |
| 7619 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7620 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7621 | rc = drxdap_fasi_write_block(dev_addr, QAM_DQ_QUAL_FUN0__A, sizeof(qam_dq_qual_fun), ((u8 *)qam_dq_qual_fun), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7622 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7623 | pr_err("error %d\n", rc); |
| 7624 | goto rw_error; |
| 7625 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7626 | rc = drxdap_fasi_write_block(dev_addr, SCU_RAM_QAM_EQ_CMA_RAD0__A, sizeof(qam_eq_cma_rad), ((u8 *)qam_eq_cma_rad), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7627 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7628 | pr_err("error %d\n", rc); |
| 7629 | goto rw_error; |
| 7630 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7631 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7632 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RTH__A, 50, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7633 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7634 | pr_err("error %d\n", rc); |
| 7635 | goto rw_error; |
| 7636 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7637 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FTH__A, 60, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7638 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7639 | pr_err("error %d\n", rc); |
| 7640 | goto rw_error; |
| 7641 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7642 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_PTH__A, 100, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7643 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7644 | pr_err("error %d\n", rc); |
| 7645 | goto rw_error; |
| 7646 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7647 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_QTH__A, 150, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7648 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7649 | pr_err("error %d\n", rc); |
| 7650 | goto rw_error; |
| 7651 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7652 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_CTH__A, 80, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7653 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7654 | pr_err("error %d\n", rc); |
| 7655 | goto rw_error; |
| 7656 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7657 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MTH__A, 110, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7658 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7659 | pr_err("error %d\n", rc); |
| 7660 | goto rw_error; |
| 7661 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7662 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7663 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RATE_LIM__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7664 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7665 | pr_err("error %d\n", rc); |
| 7666 | goto rw_error; |
| 7667 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7668 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FREQ_LIM__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7669 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7670 | pr_err("error %d\n", rc); |
| 7671 | goto rw_error; |
| 7672 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7673 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_COUNT_LIM__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7674 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7675 | pr_err("error %d\n", rc); |
| 7676 | goto rw_error; |
| 7677 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7678 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7679 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, 8, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7680 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7681 | pr_err("error %d\n", rc); |
| 7682 | goto rw_error; |
| 7683 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7684 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, 74, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7685 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7686 | pr_err("error %d\n", rc); |
| 7687 | goto rw_error; |
| 7688 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7689 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, 18, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7690 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7691 | pr_err("error %d\n", rc); |
| 7692 | goto rw_error; |
| 7693 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7694 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, 13, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7695 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7696 | pr_err("error %d\n", rc); |
| 7697 | goto rw_error; |
| 7698 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7699 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, 7, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7700 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7701 | pr_err("error %d\n", rc); |
| 7702 | goto rw_error; |
| 7703 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7704 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7705 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7706 | pr_err("error %d\n", rc); |
| 7707 | goto rw_error; |
| 7708 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7709 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16)(-8), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7710 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7711 | pr_err("error %d\n", rc); |
| 7712 | goto rw_error; |
| 7713 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7714 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7715 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_FINE__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7716 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7717 | pr_err("error %d\n", rc); |
| 7718 | goto rw_error; |
| 7719 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7720 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_COARSE__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7721 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7722 | pr_err("error %d\n", rc); |
| 7723 | goto rw_error; |
| 7724 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7725 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_FINE__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7726 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7727 | pr_err("error %d\n", rc); |
| 7728 | goto rw_error; |
| 7729 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7730 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_MEDIUM__A, 50, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7731 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7732 | pr_err("error %d\n", rc); |
| 7733 | goto rw_error; |
| 7734 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7735 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_COARSE__A, 255, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7736 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7737 | pr_err("error %d\n", rc); |
| 7738 | goto rw_error; |
| 7739 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7740 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_FINE__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7741 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7742 | pr_err("error %d\n", rc); |
| 7743 | goto rw_error; |
| 7744 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7745 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_MEDIUM__A, 25, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7746 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7747 | pr_err("error %d\n", rc); |
| 7748 | goto rw_error; |
| 7749 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7750 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_COARSE__A, 80, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7751 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7752 | pr_err("error %d\n", rc); |
| 7753 | goto rw_error; |
| 7754 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7755 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_FINE__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7756 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7757 | pr_err("error %d\n", rc); |
| 7758 | goto rw_error; |
| 7759 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7760 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7761 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7762 | pr_err("error %d\n", rc); |
| 7763 | goto rw_error; |
| 7764 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7765 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_COARSE__A, 24, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7766 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7767 | pr_err("error %d\n", rc); |
| 7768 | goto rw_error; |
| 7769 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7770 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_FINE__A, 12, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7771 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7772 | pr_err("error %d\n", rc); |
| 7773 | goto rw_error; |
| 7774 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7775 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7776 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7777 | pr_err("error %d\n", rc); |
| 7778 | goto rw_error; |
| 7779 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7780 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_COARSE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7781 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7782 | pr_err("error %d\n", rc); |
| 7783 | goto rw_error; |
| 7784 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7785 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_FINE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7786 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7787 | pr_err("error %d\n", rc); |
| 7788 | goto rw_error; |
| 7789 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7790 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_MEDIUM__A, 48, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7791 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7792 | pr_err("error %d\n", rc); |
| 7793 | goto rw_error; |
| 7794 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7795 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_COARSE__A, 80, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7796 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7797 | pr_err("error %d\n", rc); |
| 7798 | goto rw_error; |
| 7799 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7800 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_FINE__A, 5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7801 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7802 | pr_err("error %d\n", rc); |
| 7803 | goto rw_error; |
| 7804 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7805 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 15, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7806 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7807 | pr_err("error %d\n", rc); |
| 7808 | goto rw_error; |
| 7809 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7810 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_COARSE__A, 16, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7811 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7812 | pr_err("error %d\n", rc); |
| 7813 | goto rw_error; |
| 7814 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7815 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 7816 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_SL_SIG_POWER__A, 43520, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7817 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7818 | pr_err("error %d\n", rc); |
| 7819 | goto rw_error; |
| 7820 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7821 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7822 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7823 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 7824 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7825 | } |
| 7826 | |
| 7827 | /*============================================================================*/ |
| 7828 | #define QAM_SET_OP_ALL 0x1 |
| 7829 | #define QAM_SET_OP_CONSTELLATION 0x2 |
| 7830 | #define QAM_SET_OP_SPECTRUM 0X4 |
| 7831 | |
| 7832 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7833 | * \fn int set_qam () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7834 | * \brief Set QAM demod. |
| 7835 | * \param demod: instance of demod. |
| 7836 | * \param channel: pointer to channel data. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 7837 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7838 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 7839 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 7840 | set_qam(struct drx_demod_instance *demod, |
| 7841 | struct drx_channel *channel, s32 tuner_freq_offset, u32 op) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7842 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7843 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 7844 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 7845 | struct drx_common_attr *common_attr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7846 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7847 | u32 adc_frequency = 0; |
| 7848 | u32 iqm_rc_rate = 0; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 7849 | u16 cmd_result = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7850 | u16 lc_symbol_freq = 0; |
| 7851 | u16 iqm_rc_stretch = 0; |
| 7852 | u16 set_env_parameters = 0; |
| 7853 | u16 set_param_parameters[2] = { 0 }; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 7854 | struct drxjscu_cmd cmd_scu = { /* command */ 0, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7855 | /* parameter_len */ 0, |
| 7856 | /* result_len */ 0, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7857 | /* parameter */ NULL, |
| 7858 | /* result */ NULL |
| 7859 | }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7860 | const u8 qam_a_taps[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7861 | DRXJ_16TO8(-1), /* re0 */ |
| 7862 | DRXJ_16TO8(1), /* re1 */ |
| 7863 | DRXJ_16TO8(1), /* re2 */ |
| 7864 | DRXJ_16TO8(-1), /* re3 */ |
| 7865 | DRXJ_16TO8(-1), /* re4 */ |
| 7866 | DRXJ_16TO8(2), /* re5 */ |
| 7867 | DRXJ_16TO8(1), /* re6 */ |
| 7868 | DRXJ_16TO8(-2), /* re7 */ |
| 7869 | DRXJ_16TO8(0), /* re8 */ |
| 7870 | DRXJ_16TO8(3), /* re9 */ |
| 7871 | DRXJ_16TO8(-1), /* re10 */ |
| 7872 | DRXJ_16TO8(-3), /* re11 */ |
| 7873 | DRXJ_16TO8(4), /* re12 */ |
| 7874 | DRXJ_16TO8(1), /* re13 */ |
| 7875 | DRXJ_16TO8(-8), /* re14 */ |
| 7876 | DRXJ_16TO8(4), /* re15 */ |
| 7877 | DRXJ_16TO8(13), /* re16 */ |
| 7878 | DRXJ_16TO8(-13), /* re17 */ |
| 7879 | DRXJ_16TO8(-19), /* re18 */ |
| 7880 | DRXJ_16TO8(28), /* re19 */ |
| 7881 | DRXJ_16TO8(25), /* re20 */ |
| 7882 | DRXJ_16TO8(-53), /* re21 */ |
| 7883 | DRXJ_16TO8(-31), /* re22 */ |
| 7884 | DRXJ_16TO8(96), /* re23 */ |
| 7885 | DRXJ_16TO8(37), /* re24 */ |
| 7886 | DRXJ_16TO8(-190), /* re25 */ |
| 7887 | DRXJ_16TO8(-40), /* re26 */ |
| 7888 | DRXJ_16TO8(619) /* re27 */ |
| 7889 | }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7890 | const u8 qam_b64_taps[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7891 | DRXJ_16TO8(0), /* re0 */ |
| 7892 | DRXJ_16TO8(-2), /* re1 */ |
| 7893 | DRXJ_16TO8(1), /* re2 */ |
| 7894 | DRXJ_16TO8(2), /* re3 */ |
| 7895 | DRXJ_16TO8(-2), /* re4 */ |
| 7896 | DRXJ_16TO8(0), /* re5 */ |
| 7897 | DRXJ_16TO8(4), /* re6 */ |
| 7898 | DRXJ_16TO8(-2), /* re7 */ |
| 7899 | DRXJ_16TO8(-4), /* re8 */ |
| 7900 | DRXJ_16TO8(4), /* re9 */ |
| 7901 | DRXJ_16TO8(3), /* re10 */ |
| 7902 | DRXJ_16TO8(-6), /* re11 */ |
| 7903 | DRXJ_16TO8(0), /* re12 */ |
| 7904 | DRXJ_16TO8(6), /* re13 */ |
| 7905 | DRXJ_16TO8(-5), /* re14 */ |
| 7906 | DRXJ_16TO8(-3), /* re15 */ |
| 7907 | DRXJ_16TO8(11), /* re16 */ |
| 7908 | DRXJ_16TO8(-4), /* re17 */ |
| 7909 | DRXJ_16TO8(-19), /* re18 */ |
| 7910 | DRXJ_16TO8(19), /* re19 */ |
| 7911 | DRXJ_16TO8(28), /* re20 */ |
| 7912 | DRXJ_16TO8(-45), /* re21 */ |
| 7913 | DRXJ_16TO8(-36), /* re22 */ |
| 7914 | DRXJ_16TO8(90), /* re23 */ |
| 7915 | DRXJ_16TO8(42), /* re24 */ |
| 7916 | DRXJ_16TO8(-185), /* re25 */ |
| 7917 | DRXJ_16TO8(-46), /* re26 */ |
| 7918 | DRXJ_16TO8(614) /* re27 */ |
| 7919 | }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7920 | const u8 qam_b256_taps[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7921 | DRXJ_16TO8(-2), /* re0 */ |
| 7922 | DRXJ_16TO8(4), /* re1 */ |
| 7923 | DRXJ_16TO8(1), /* re2 */ |
| 7924 | DRXJ_16TO8(-4), /* re3 */ |
| 7925 | DRXJ_16TO8(0), /* re4 */ |
| 7926 | DRXJ_16TO8(4), /* re5 */ |
| 7927 | DRXJ_16TO8(-2), /* re6 */ |
| 7928 | DRXJ_16TO8(-4), /* re7 */ |
| 7929 | DRXJ_16TO8(5), /* re8 */ |
| 7930 | DRXJ_16TO8(2), /* re9 */ |
| 7931 | DRXJ_16TO8(-8), /* re10 */ |
| 7932 | DRXJ_16TO8(2), /* re11 */ |
| 7933 | DRXJ_16TO8(11), /* re12 */ |
| 7934 | DRXJ_16TO8(-8), /* re13 */ |
| 7935 | DRXJ_16TO8(-15), /* re14 */ |
| 7936 | DRXJ_16TO8(16), /* re15 */ |
| 7937 | DRXJ_16TO8(19), /* re16 */ |
| 7938 | DRXJ_16TO8(-27), /* re17 */ |
| 7939 | DRXJ_16TO8(-22), /* re18 */ |
| 7940 | DRXJ_16TO8(44), /* re19 */ |
| 7941 | DRXJ_16TO8(26), /* re20 */ |
| 7942 | DRXJ_16TO8(-69), /* re21 */ |
| 7943 | DRXJ_16TO8(-28), /* re22 */ |
| 7944 | DRXJ_16TO8(110), /* re23 */ |
| 7945 | DRXJ_16TO8(31), /* re24 */ |
| 7946 | DRXJ_16TO8(-201), /* re25 */ |
| 7947 | DRXJ_16TO8(-32), /* re26 */ |
| 7948 | DRXJ_16TO8(628) /* re27 */ |
| 7949 | }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7950 | const u8 qam_c_taps[] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7951 | DRXJ_16TO8(-3), /* re0 */ |
| 7952 | DRXJ_16TO8(3), /* re1 */ |
| 7953 | DRXJ_16TO8(2), /* re2 */ |
| 7954 | DRXJ_16TO8(-4), /* re3 */ |
| 7955 | DRXJ_16TO8(0), /* re4 */ |
| 7956 | DRXJ_16TO8(4), /* re5 */ |
| 7957 | DRXJ_16TO8(-1), /* re6 */ |
| 7958 | DRXJ_16TO8(-4), /* re7 */ |
| 7959 | DRXJ_16TO8(3), /* re8 */ |
| 7960 | DRXJ_16TO8(3), /* re9 */ |
| 7961 | DRXJ_16TO8(-5), /* re10 */ |
| 7962 | DRXJ_16TO8(0), /* re11 */ |
| 7963 | DRXJ_16TO8(9), /* re12 */ |
| 7964 | DRXJ_16TO8(-4), /* re13 */ |
| 7965 | DRXJ_16TO8(-12), /* re14 */ |
| 7966 | DRXJ_16TO8(10), /* re15 */ |
| 7967 | DRXJ_16TO8(16), /* re16 */ |
| 7968 | DRXJ_16TO8(-21), /* re17 */ |
| 7969 | DRXJ_16TO8(-20), /* re18 */ |
| 7970 | DRXJ_16TO8(37), /* re19 */ |
| 7971 | DRXJ_16TO8(25), /* re20 */ |
| 7972 | DRXJ_16TO8(-62), /* re21 */ |
| 7973 | DRXJ_16TO8(-28), /* re22 */ |
| 7974 | DRXJ_16TO8(105), /* re23 */ |
| 7975 | DRXJ_16TO8(31), /* re24 */ |
| 7976 | DRXJ_16TO8(-197), /* re25 */ |
| 7977 | DRXJ_16TO8(-33), /* re26 */ |
| 7978 | DRXJ_16TO8(626) /* re27 */ |
| 7979 | }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7980 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7981 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 7982 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 7983 | common_attr = (struct drx_common_attr *) demod->my_common_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 7984 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7985 | if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_CONSTELLATION)) { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7986 | if (ext_attr->standard == DRX_STANDARD_ITU_B) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7987 | switch (channel->constellation) { |
| 7988 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7989 | iqm_rc_rate = 0x00AE3562; |
| 7990 | lc_symbol_freq = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7991 | QAM_LC_SYMBOL_FREQ_FREQ_QAM_B_256; |
| 7992 | channel->symbolrate = 5360537; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7993 | iqm_rc_stretch = IQM_RC_STRETCH_QAM_B_256; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7994 | break; |
| 7995 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7996 | iqm_rc_rate = 0x00C05A0E; |
| 7997 | lc_symbol_freq = 409; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 7998 | channel->symbolrate = 5056941; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 7999 | iqm_rc_stretch = IQM_RC_STRETCH_QAM_B_64; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8000 | break; |
| 8001 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8002 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8003 | } |
| 8004 | } else { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8005 | adc_frequency = (common_attr->sys_clock_freq * 1000) / 3; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8006 | if (channel->symbolrate == 0) { |
| 8007 | pr_err("error: channel symbolrate is zero!\n"); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8008 | return -EIO; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8009 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8010 | iqm_rc_rate = |
| 8011 | (adc_frequency / channel->symbolrate) * (1 << 21) + |
| 8012 | (frac28 |
| 8013 | ((adc_frequency % channel->symbolrate), |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8014 | channel->symbolrate) >> 7) - (1 << 23); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8015 | lc_symbol_freq = |
| 8016 | (u16) (frac28 |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8017 | (channel->symbolrate + |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8018 | (adc_frequency >> 13), |
| 8019 | adc_frequency) >> 16); |
| 8020 | if (lc_symbol_freq > 511) |
| 8021 | lc_symbol_freq = 511; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8022 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8023 | iqm_rc_stretch = 21; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8024 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8025 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8026 | if (ext_attr->standard == DRX_STANDARD_ITU_A) { |
| 8027 | set_env_parameters = QAM_TOP_ANNEX_A; /* annex */ |
| 8028 | set_param_parameters[0] = channel->constellation; /* constellation */ |
| 8029 | set_param_parameters[1] = DRX_INTERLEAVEMODE_I12_J17; /* interleave mode */ |
| 8030 | } else if (ext_attr->standard == DRX_STANDARD_ITU_B) { |
| 8031 | set_env_parameters = QAM_TOP_ANNEX_B; /* annex */ |
| 8032 | set_param_parameters[0] = channel->constellation; /* constellation */ |
| 8033 | set_param_parameters[1] = channel->interleavemode; /* interleave mode */ |
| 8034 | } else if (ext_attr->standard == DRX_STANDARD_ITU_C) { |
| 8035 | set_env_parameters = QAM_TOP_ANNEX_C; /* annex */ |
| 8036 | set_param_parameters[0] = channel->constellation; /* constellation */ |
| 8037 | set_param_parameters[1] = DRX_INTERLEAVEMODE_I12_J17; /* interleave mode */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8038 | } else { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8039 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8040 | } |
| 8041 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8042 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8043 | if (op & QAM_SET_OP_ALL) { |
| 8044 | /* |
| 8045 | STEP 1: reset demodulator |
| 8046 | resets IQM, QAM and FEC HW blocks |
| 8047 | resets SCU variables |
| 8048 | */ |
| 8049 | /* stop all comm_exec */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8050 | rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8051 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8052 | pr_err("error %d\n", rc); |
| 8053 | goto rw_error; |
| 8054 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8055 | rc = drxj_dap_write_reg16(dev_addr, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8056 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8057 | pr_err("error %d\n", rc); |
| 8058 | goto rw_error; |
| 8059 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8060 | rc = drxj_dap_write_reg16(dev_addr, IQM_FS_COMM_EXEC__A, IQM_FS_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8061 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8062 | pr_err("error %d\n", rc); |
| 8063 | goto rw_error; |
| 8064 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8065 | rc = drxj_dap_write_reg16(dev_addr, IQM_FD_COMM_EXEC__A, IQM_FD_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8066 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8067 | pr_err("error %d\n", rc); |
| 8068 | goto rw_error; |
| 8069 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8070 | rc = drxj_dap_write_reg16(dev_addr, IQM_RC_COMM_EXEC__A, IQM_RC_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8071 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8072 | pr_err("error %d\n", rc); |
| 8073 | goto rw_error; |
| 8074 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8075 | rc = drxj_dap_write_reg16(dev_addr, IQM_RT_COMM_EXEC__A, IQM_RT_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8076 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8077 | pr_err("error %d\n", rc); |
| 8078 | goto rw_error; |
| 8079 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8080 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_COMM_EXEC__A, IQM_CF_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8081 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8082 | pr_err("error %d\n", rc); |
| 8083 | goto rw_error; |
| 8084 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8085 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8086 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8087 | SCU_RAM_COMMAND_CMD_DEMOD_RESET; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8088 | cmd_scu.parameter_len = 0; |
| 8089 | cmd_scu.result_len = 1; |
| 8090 | cmd_scu.parameter = NULL; |
| 8091 | cmd_scu.result = &cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8092 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8093 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8094 | pr_err("error %d\n", rc); |
| 8095 | goto rw_error; |
| 8096 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8097 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8098 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8099 | if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_CONSTELLATION)) { |
| 8100 | /* |
| 8101 | STEP 2: configure demodulator |
| 8102 | -set env |
| 8103 | -set params (resets IQM,QAM,FEC HW; initializes some SCU variables ) |
| 8104 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8105 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8106 | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8107 | cmd_scu.parameter_len = 1; |
| 8108 | cmd_scu.result_len = 1; |
| 8109 | cmd_scu.parameter = &set_env_parameters; |
| 8110 | cmd_scu.result = &cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8111 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8112 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8113 | pr_err("error %d\n", rc); |
| 8114 | goto rw_error; |
| 8115 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8116 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8117 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8118 | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8119 | cmd_scu.parameter_len = 2; |
| 8120 | cmd_scu.result_len = 1; |
| 8121 | cmd_scu.parameter = set_param_parameters; |
| 8122 | cmd_scu.result = &cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8123 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8124 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8125 | pr_err("error %d\n", rc); |
| 8126 | goto rw_error; |
| 8127 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8128 | /* set symbol rate */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8129 | rc = drxdap_fasi_write_reg32(dev_addr, IQM_RC_RATE_OFS_LO__A, iqm_rc_rate, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8130 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8131 | pr_err("error %d\n", rc); |
| 8132 | goto rw_error; |
| 8133 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8134 | ext_attr->iqm_rc_rate_ofs = iqm_rc_rate; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8135 | rc = set_qam_measurement(demod, channel->constellation, channel->symbolrate); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8136 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8137 | pr_err("error %d\n", rc); |
| 8138 | goto rw_error; |
| 8139 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8140 | } |
| 8141 | /* STEP 3: enable the system in a mode where the ADC provides valid signal |
| 8142 | setup constellation independent registers */ |
| 8143 | /* from qam_cmd.py script (qam_driver_b) */ |
| 8144 | /* TODO: remove re-writes of HW reset values */ |
| 8145 | if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_SPECTRUM)) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8146 | rc = set_frequency(demod, channel, tuner_freq_offset); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8147 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8148 | pr_err("error %d\n", rc); |
| 8149 | goto rw_error; |
| 8150 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8151 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8152 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8153 | if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_CONSTELLATION)) { |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8154 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8155 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_SYMBOL_FREQ__A, lc_symbol_freq, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8156 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8157 | pr_err("error %d\n", rc); |
| 8158 | goto rw_error; |
| 8159 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8160 | rc = drxj_dap_write_reg16(dev_addr, IQM_RC_STRETCH__A, iqm_rc_stretch, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8161 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8162 | pr_err("error %d\n", rc); |
| 8163 | goto rw_error; |
| 8164 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8165 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8166 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8167 | if (op & QAM_SET_OP_ALL) { |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 8168 | if (!ext_attr->has_lna) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8169 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_AMUX__A, 0x02, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8170 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8171 | pr_err("error %d\n", rc); |
| 8172 | goto rw_error; |
| 8173 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8174 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8175 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SYMMETRIC__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8176 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8177 | pr_err("error %d\n", rc); |
| 8178 | goto rw_error; |
| 8179 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8180 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_MIDTAP__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8181 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8182 | pr_err("error %d\n", rc); |
| 8183 | goto rw_error; |
| 8184 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8185 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_OUT_ENA__A, IQM_CF_OUT_ENA_QAM__M, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8186 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8187 | pr_err("error %d\n", rc); |
| 8188 | goto rw_error; |
| 8189 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8190 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8191 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_WR_RSV_0__A, 0x5f, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8192 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8193 | pr_err("error %d\n", rc); |
| 8194 | goto rw_error; |
| 8195 | } /* scu temporary shut down agc */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8196 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8197 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_SYNC_SEL__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8198 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8199 | pr_err("error %d\n", rc); |
| 8200 | goto rw_error; |
| 8201 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8202 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_CLP_LEN__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8203 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8204 | pr_err("error %d\n", rc); |
| 8205 | goto rw_error; |
| 8206 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8207 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_CLP_TH__A, 448, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8208 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8209 | pr_err("error %d\n", rc); |
| 8210 | goto rw_error; |
| 8211 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8212 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_SNS_LEN__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8213 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8214 | pr_err("error %d\n", rc); |
| 8215 | goto rw_error; |
| 8216 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8217 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_PDREF__A, 4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8218 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8219 | pr_err("error %d\n", rc); |
| 8220 | goto rw_error; |
| 8221 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8222 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, 0x10, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8223 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8224 | pr_err("error %d\n", rc); |
| 8225 | goto rw_error; |
| 8226 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8227 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_PGA_GAIN__A, 11, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8228 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8229 | pr_err("error %d\n", rc); |
| 8230 | goto rw_error; |
| 8231 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8232 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8233 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_POW_MEAS_LEN__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8234 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8235 | pr_err("error %d\n", rc); |
| 8236 | goto rw_error; |
| 8237 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8238 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SCALE_SH__A, IQM_CF_SCALE_SH__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8239 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8240 | pr_err("error %d\n", rc); |
| 8241 | goto rw_error; |
| 8242 | } /*! reset default val ! */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8243 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8244 | rc = drxj_dap_write_reg16(dev_addr, QAM_SY_TIMEOUT__A, QAM_SY_TIMEOUT__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8245 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8246 | pr_err("error %d\n", rc); |
| 8247 | goto rw_error; |
| 8248 | } /*! reset default val ! */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8249 | if (ext_attr->standard == DRX_STANDARD_ITU_B) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8250 | rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_LWM__A, QAM_SY_SYNC_LWM__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8251 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8252 | pr_err("error %d\n", rc); |
| 8253 | goto rw_error; |
| 8254 | } /*! reset default val ! */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8255 | rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_AWM__A, QAM_SY_SYNC_AWM__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8256 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8257 | pr_err("error %d\n", rc); |
| 8258 | goto rw_error; |
| 8259 | } /*! reset default val ! */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8260 | rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_HWM__A, QAM_SY_SYNC_HWM__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8261 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8262 | pr_err("error %d\n", rc); |
| 8263 | goto rw_error; |
| 8264 | } /*! reset default val ! */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8265 | } else { |
| 8266 | switch (channel->constellation) { |
| 8267 | case DRX_CONSTELLATION_QAM16: |
| 8268 | case DRX_CONSTELLATION_QAM64: |
| 8269 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8270 | rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_LWM__A, 0x03, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8271 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8272 | pr_err("error %d\n", rc); |
| 8273 | goto rw_error; |
| 8274 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8275 | rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_AWM__A, 0x04, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8276 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8277 | pr_err("error %d\n", rc); |
| 8278 | goto rw_error; |
| 8279 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8280 | rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_HWM__A, QAM_SY_SYNC_HWM__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8281 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8282 | pr_err("error %d\n", rc); |
| 8283 | goto rw_error; |
| 8284 | } /*! reset default val ! */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8285 | break; |
| 8286 | case DRX_CONSTELLATION_QAM32: |
| 8287 | case DRX_CONSTELLATION_QAM128: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8288 | rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_LWM__A, 0x03, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8289 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8290 | pr_err("error %d\n", rc); |
| 8291 | goto rw_error; |
| 8292 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8293 | rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_AWM__A, 0x05, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8294 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8295 | pr_err("error %d\n", rc); |
| 8296 | goto rw_error; |
| 8297 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8298 | rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_HWM__A, 0x06, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8299 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8300 | pr_err("error %d\n", rc); |
| 8301 | goto rw_error; |
| 8302 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8303 | break; |
| 8304 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8305 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8306 | } /* switch */ |
| 8307 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8308 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8309 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_MODE__A, QAM_LC_MODE__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8310 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8311 | pr_err("error %d\n", rc); |
| 8312 | goto rw_error; |
| 8313 | } /*! reset default val ! */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8314 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_RATE_LIMIT__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8315 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8316 | pr_err("error %d\n", rc); |
| 8317 | goto rw_error; |
| 8318 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8319 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_LPF_FACTORP__A, 4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8320 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8321 | pr_err("error %d\n", rc); |
| 8322 | goto rw_error; |
| 8323 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8324 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_LPF_FACTORI__A, 4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8325 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8326 | pr_err("error %d\n", rc); |
| 8327 | goto rw_error; |
| 8328 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8329 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_MODE__A, 7, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8330 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8331 | pr_err("error %d\n", rc); |
| 8332 | goto rw_error; |
| 8333 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8334 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB0__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8335 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8336 | pr_err("error %d\n", rc); |
| 8337 | goto rw_error; |
| 8338 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8339 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB1__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8340 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8341 | pr_err("error %d\n", rc); |
| 8342 | goto rw_error; |
| 8343 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8344 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB2__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8345 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8346 | pr_err("error %d\n", rc); |
| 8347 | goto rw_error; |
| 8348 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8349 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB3__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8350 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8351 | pr_err("error %d\n", rc); |
| 8352 | goto rw_error; |
| 8353 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8354 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB4__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8355 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8356 | pr_err("error %d\n", rc); |
| 8357 | goto rw_error; |
| 8358 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8359 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB5__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8360 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8361 | pr_err("error %d\n", rc); |
| 8362 | goto rw_error; |
| 8363 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8364 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB6__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8365 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8366 | pr_err("error %d\n", rc); |
| 8367 | goto rw_error; |
| 8368 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8369 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB8__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8370 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8371 | pr_err("error %d\n", rc); |
| 8372 | goto rw_error; |
| 8373 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8374 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB9__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8375 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8376 | pr_err("error %d\n", rc); |
| 8377 | goto rw_error; |
| 8378 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8379 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB10__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8380 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8381 | pr_err("error %d\n", rc); |
| 8382 | goto rw_error; |
| 8383 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8384 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB12__A, 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8385 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8386 | pr_err("error %d\n", rc); |
| 8387 | goto rw_error; |
| 8388 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8389 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB15__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8390 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8391 | pr_err("error %d\n", rc); |
| 8392 | goto rw_error; |
| 8393 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8394 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB16__A, 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8395 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8396 | pr_err("error %d\n", rc); |
| 8397 | goto rw_error; |
| 8398 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8399 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB20__A, 4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8400 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8401 | pr_err("error %d\n", rc); |
| 8402 | goto rw_error; |
| 8403 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8404 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB25__A, 4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8405 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8406 | pr_err("error %d\n", rc); |
| 8407 | goto rw_error; |
| 8408 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8409 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8410 | rc = drxj_dap_write_reg16(dev_addr, IQM_FS_ADJ_SEL__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8411 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8412 | pr_err("error %d\n", rc); |
| 8413 | goto rw_error; |
| 8414 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8415 | rc = drxj_dap_write_reg16(dev_addr, IQM_RC_ADJ_SEL__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8416 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8417 | pr_err("error %d\n", rc); |
| 8418 | goto rw_error; |
| 8419 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8420 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_ADJ_SEL__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8421 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8422 | pr_err("error %d\n", rc); |
| 8423 | goto rw_error; |
| 8424 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8425 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_POW_MEAS_LEN__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8426 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8427 | pr_err("error %d\n", rc); |
| 8428 | goto rw_error; |
| 8429 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8430 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_GPIO__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8431 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8432 | pr_err("error %d\n", rc); |
| 8433 | goto rw_error; |
| 8434 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8435 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8436 | /* No more resets of the IQM, current standard correctly set => |
| 8437 | now AGCs can be configured. */ |
| 8438 | /* turn on IQMAF. It has to be in front of setAgc**() */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8439 | rc = set_iqm_af(demod, true); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8440 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8441 | pr_err("error %d\n", rc); |
| 8442 | goto rw_error; |
| 8443 | } |
| 8444 | rc = adc_synchronization(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8445 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8446 | pr_err("error %d\n", rc); |
| 8447 | goto rw_error; |
| 8448 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8449 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8450 | rc = init_agc(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8451 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8452 | pr_err("error %d\n", rc); |
| 8453 | goto rw_error; |
| 8454 | } |
| 8455 | rc = set_agc_if(demod, &(ext_attr->qam_if_agc_cfg), false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8456 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8457 | pr_err("error %d\n", rc); |
| 8458 | goto rw_error; |
| 8459 | } |
| 8460 | rc = set_agc_rf(demod, &(ext_attr->qam_rf_agc_cfg), false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8461 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8462 | pr_err("error %d\n", rc); |
| 8463 | goto rw_error; |
| 8464 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8465 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 8466 | /* TODO fix this, store a struct drxj_cfg_afe_gain structure in struct drxj_data instead |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8467 | of only the gain */ |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 8468 | struct drxj_cfg_afe_gain qam_pga_cfg = { DRX_STANDARD_ITU_B, 0 }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8469 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8470 | qam_pga_cfg.gain = ext_attr->qam_pga_cfg; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8471 | rc = ctrl_set_cfg_afe_gain(demod, &qam_pga_cfg); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8472 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8473 | pr_err("error %d\n", rc); |
| 8474 | goto rw_error; |
| 8475 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8476 | } |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8477 | rc = ctrl_set_cfg_pre_saw(demod, &(ext_attr->qam_pre_saw_cfg)); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8478 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8479 | pr_err("error %d\n", rc); |
| 8480 | goto rw_error; |
| 8481 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8482 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8483 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8484 | if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_CONSTELLATION)) { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8485 | if (ext_attr->standard == DRX_STANDARD_ITU_A) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8486 | rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_RE0__A, sizeof(qam_a_taps), ((u8 *)qam_a_taps), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8487 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8488 | pr_err("error %d\n", rc); |
| 8489 | goto rw_error; |
| 8490 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8491 | rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_IM0__A, sizeof(qam_a_taps), ((u8 *)qam_a_taps), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8492 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8493 | pr_err("error %d\n", rc); |
| 8494 | goto rw_error; |
| 8495 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8496 | } else if (ext_attr->standard == DRX_STANDARD_ITU_B) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8497 | switch (channel->constellation) { |
| 8498 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8499 | rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_RE0__A, sizeof(qam_b64_taps), ((u8 *)qam_b64_taps), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8500 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8501 | pr_err("error %d\n", rc); |
| 8502 | goto rw_error; |
| 8503 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8504 | rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_IM0__A, sizeof(qam_b64_taps), ((u8 *)qam_b64_taps), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8505 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8506 | pr_err("error %d\n", rc); |
| 8507 | goto rw_error; |
| 8508 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8509 | break; |
| 8510 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8511 | rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_RE0__A, sizeof(qam_b256_taps), ((u8 *)qam_b256_taps), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8512 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8513 | pr_err("error %d\n", rc); |
| 8514 | goto rw_error; |
| 8515 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8516 | rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_IM0__A, sizeof(qam_b256_taps), ((u8 *)qam_b256_taps), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8517 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8518 | pr_err("error %d\n", rc); |
| 8519 | goto rw_error; |
| 8520 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8521 | break; |
| 8522 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8523 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8524 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8525 | } else if (ext_attr->standard == DRX_STANDARD_ITU_C) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8526 | rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_RE0__A, sizeof(qam_c_taps), ((u8 *)qam_c_taps), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8527 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8528 | pr_err("error %d\n", rc); |
| 8529 | goto rw_error; |
| 8530 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8531 | rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_IM0__A, sizeof(qam_c_taps), ((u8 *)qam_c_taps), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8532 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8533 | pr_err("error %d\n", rc); |
| 8534 | goto rw_error; |
| 8535 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8536 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8537 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8538 | /* SETP 4: constellation specific setup */ |
| 8539 | switch (channel->constellation) { |
| 8540 | case DRX_CONSTELLATION_QAM16: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8541 | rc = set_qam16(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8542 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8543 | pr_err("error %d\n", rc); |
| 8544 | goto rw_error; |
| 8545 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8546 | break; |
| 8547 | case DRX_CONSTELLATION_QAM32: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8548 | rc = set_qam32(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8549 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8550 | pr_err("error %d\n", rc); |
| 8551 | goto rw_error; |
| 8552 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8553 | break; |
| 8554 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8555 | rc = set_qam64(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8556 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8557 | pr_err("error %d\n", rc); |
| 8558 | goto rw_error; |
| 8559 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8560 | break; |
| 8561 | case DRX_CONSTELLATION_QAM128: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8562 | rc = set_qam128(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8563 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8564 | pr_err("error %d\n", rc); |
| 8565 | goto rw_error; |
| 8566 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8567 | break; |
| 8568 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8569 | rc = set_qam256(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8570 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8571 | pr_err("error %d\n", rc); |
| 8572 | goto rw_error; |
| 8573 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8574 | break; |
| 8575 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8576 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8577 | } /* switch */ |
| 8578 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8579 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8580 | if ((op & QAM_SET_OP_ALL)) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8581 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SCALE_SH__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8582 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8583 | pr_err("error %d\n", rc); |
| 8584 | goto rw_error; |
| 8585 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8586 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8587 | /* Mpeg output has to be in front of FEC active */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8588 | rc = set_mpegtei_handling(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8589 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8590 | pr_err("error %d\n", rc); |
| 8591 | goto rw_error; |
| 8592 | } |
| 8593 | rc = bit_reverse_mpeg_output(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8594 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8595 | pr_err("error %d\n", rc); |
| 8596 | goto rw_error; |
| 8597 | } |
| 8598 | rc = set_mpeg_start_width(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8599 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8600 | pr_err("error %d\n", rc); |
| 8601 | goto rw_error; |
| 8602 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8603 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8604 | /* TODO: move to set_standard after hardware reset value problem is solved */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8605 | /* Configure initial MPEG output */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 8606 | struct drx_cfg_mpeg_output cfg_mpeg_output; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8607 | |
Mauro Carvalho Chehab | 41b5cc0 | 2014-03-02 11:01:11 -0300 | [diff] [blame] | 8608 | memcpy(&cfg_mpeg_output, &common_attr->mpeg_cfg, sizeof(cfg_mpeg_output)); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8609 | cfg_mpeg_output.enable_mpeg_output = true; |
Mauro Carvalho Chehab | 41b5cc0 | 2014-03-02 11:01:11 -0300 | [diff] [blame] | 8610 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8611 | rc = ctrl_set_cfg_mpeg_output(demod, &cfg_mpeg_output); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8612 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8613 | pr_err("error %d\n", rc); |
| 8614 | goto rw_error; |
| 8615 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8616 | } |
| 8617 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8618 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8619 | if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_CONSTELLATION)) { |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8620 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8621 | /* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8622 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8623 | SCU_RAM_COMMAND_CMD_DEMOD_START; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8624 | cmd_scu.parameter_len = 0; |
| 8625 | cmd_scu.result_len = 1; |
| 8626 | cmd_scu.parameter = NULL; |
| 8627 | cmd_scu.result = &cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8628 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8629 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8630 | pr_err("error %d\n", rc); |
| 8631 | goto rw_error; |
| 8632 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8633 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8634 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8635 | rc = drxj_dap_write_reg16(dev_addr, IQM_COMM_EXEC__A, IQM_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8636 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8637 | pr_err("error %d\n", rc); |
| 8638 | goto rw_error; |
| 8639 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8640 | rc = drxj_dap_write_reg16(dev_addr, QAM_COMM_EXEC__A, QAM_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8641 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8642 | pr_err("error %d\n", rc); |
| 8643 | goto rw_error; |
| 8644 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8645 | rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8646 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8647 | pr_err("error %d\n", rc); |
| 8648 | goto rw_error; |
| 8649 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8650 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8651 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8652 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8653 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8654 | } |
| 8655 | |
| 8656 | /*============================================================================*/ |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 8657 | static int ctrl_get_qam_sig_quality(struct drx_demod_instance *demod); |
| 8658 | |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 8659 | static int qam_flip_spec(struct drx_demod_instance *demod, struct drx_channel *channel) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8660 | { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 8661 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
| 8662 | struct drxj_data *ext_attr = demod->my_ext_attr; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8663 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8664 | u32 iqm_fs_rate_ofs = 0; |
| 8665 | u32 iqm_fs_rate_lo = 0; |
| 8666 | u16 qam_ctl_ena = 0; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 8667 | u16 data = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8668 | u16 equ_mode = 0; |
| 8669 | u16 fsm_state = 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8670 | int i = 0; |
| 8671 | int ofsofs = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8672 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8673 | /* Silence the controlling of lc, equ, and the acquisition state machine */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8674 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_QAM_CTL_ENA__A, &qam_ctl_ena, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8675 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8676 | pr_err("error %d\n", rc); |
| 8677 | goto rw_error; |
| 8678 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8679 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_CTL_ENA__A, qam_ctl_ena & ~(SCU_RAM_QAM_CTL_ENA_ACQ__M | SCU_RAM_QAM_CTL_ENA_EQU__M | SCU_RAM_QAM_CTL_ENA_LC__M), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8680 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8681 | pr_err("error %d\n", rc); |
| 8682 | goto rw_error; |
| 8683 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8684 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8685 | /* freeze the frequency control loop */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8686 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_CF__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8687 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8688 | pr_err("error %d\n", rc); |
| 8689 | goto rw_error; |
| 8690 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8691 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_CF1__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8692 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8693 | pr_err("error %d\n", rc); |
| 8694 | goto rw_error; |
| 8695 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8696 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8697 | rc = drxj_dap_atomic_read_reg32(dev_addr, IQM_FS_RATE_OFS_LO__A, &iqm_fs_rate_ofs, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8698 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8699 | pr_err("error %d\n", rc); |
| 8700 | goto rw_error; |
| 8701 | } |
| 8702 | rc = drxj_dap_atomic_read_reg32(dev_addr, IQM_FS_RATE_LO__A, &iqm_fs_rate_lo, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8703 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8704 | pr_err("error %d\n", rc); |
| 8705 | goto rw_error; |
| 8706 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8707 | ofsofs = iqm_fs_rate_lo - iqm_fs_rate_ofs; |
| 8708 | iqm_fs_rate_ofs = ~iqm_fs_rate_ofs + 1; |
| 8709 | iqm_fs_rate_ofs -= 2 * ofsofs; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8710 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8711 | /* freeze dq/fq updating */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8712 | rc = drxj_dap_read_reg16(dev_addr, QAM_DQ_MODE__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8713 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8714 | pr_err("error %d\n", rc); |
| 8715 | goto rw_error; |
| 8716 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8717 | data = (data & 0xfff9); |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8718 | rc = drxj_dap_write_reg16(dev_addr, QAM_DQ_MODE__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8719 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8720 | pr_err("error %d\n", rc); |
| 8721 | goto rw_error; |
| 8722 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8723 | rc = drxj_dap_write_reg16(dev_addr, QAM_FQ_MODE__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8724 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8725 | pr_err("error %d\n", rc); |
| 8726 | goto rw_error; |
| 8727 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8728 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8729 | /* lc_cp / _ci / _ca */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8730 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_CI__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8731 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8732 | pr_err("error %d\n", rc); |
| 8733 | goto rw_error; |
| 8734 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8735 | rc = drxj_dap_write_reg16(dev_addr, QAM_LC_EP__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8736 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8737 | pr_err("error %d\n", rc); |
| 8738 | goto rw_error; |
| 8739 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8740 | rc = drxj_dap_write_reg16(dev_addr, QAM_FQ_LA_FACTOR__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8741 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8742 | pr_err("error %d\n", rc); |
| 8743 | goto rw_error; |
| 8744 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8745 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8746 | /* flip the spec */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8747 | rc = drxdap_fasi_write_reg32(dev_addr, IQM_FS_RATE_OFS_LO__A, iqm_fs_rate_ofs, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8748 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8749 | pr_err("error %d\n", rc); |
| 8750 | goto rw_error; |
| 8751 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8752 | ext_attr->iqm_fs_rate_ofs = iqm_fs_rate_ofs; |
| 8753 | ext_attr->pos_image = (ext_attr->pos_image) ? false : true; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8754 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8755 | /* freeze dq/fq updating */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8756 | rc = drxj_dap_read_reg16(dev_addr, QAM_DQ_MODE__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8757 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8758 | pr_err("error %d\n", rc); |
| 8759 | goto rw_error; |
| 8760 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8761 | equ_mode = data; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8762 | data = (data & 0xfff9); |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8763 | rc = drxj_dap_write_reg16(dev_addr, QAM_DQ_MODE__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8764 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8765 | pr_err("error %d\n", rc); |
| 8766 | goto rw_error; |
| 8767 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8768 | rc = drxj_dap_write_reg16(dev_addr, QAM_FQ_MODE__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8769 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8770 | pr_err("error %d\n", rc); |
| 8771 | goto rw_error; |
| 8772 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8773 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8774 | for (i = 0; i < 28; i++) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8775 | rc = drxj_dap_read_reg16(dev_addr, QAM_DQ_TAP_IM_EL0__A + (2 * i), &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8776 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8777 | pr_err("error %d\n", rc); |
| 8778 | goto rw_error; |
| 8779 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8780 | rc = drxj_dap_write_reg16(dev_addr, QAM_DQ_TAP_IM_EL0__A + (2 * i), -data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8781 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8782 | pr_err("error %d\n", rc); |
| 8783 | goto rw_error; |
| 8784 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8785 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8786 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8787 | for (i = 0; i < 24; i++) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8788 | rc = drxj_dap_read_reg16(dev_addr, QAM_FQ_TAP_IM_EL0__A + (2 * i), &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8789 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8790 | pr_err("error %d\n", rc); |
| 8791 | goto rw_error; |
| 8792 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8793 | rc = drxj_dap_write_reg16(dev_addr, QAM_FQ_TAP_IM_EL0__A + (2 * i), -data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8794 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8795 | pr_err("error %d\n", rc); |
| 8796 | goto rw_error; |
| 8797 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8798 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8799 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8800 | data = equ_mode; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8801 | rc = drxj_dap_write_reg16(dev_addr, QAM_DQ_MODE__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8802 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8803 | pr_err("error %d\n", rc); |
| 8804 | goto rw_error; |
| 8805 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8806 | rc = drxj_dap_write_reg16(dev_addr, QAM_FQ_MODE__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8807 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8808 | pr_err("error %d\n", rc); |
| 8809 | goto rw_error; |
| 8810 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8811 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8812 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_STATE_TGT__A, 4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8813 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8814 | pr_err("error %d\n", rc); |
| 8815 | goto rw_error; |
| 8816 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8817 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8818 | i = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8819 | while ((fsm_state != 4) && (i++ < 100)) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8820 | rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_QAM_FSM_STATE__A, &fsm_state, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8821 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8822 | pr_err("error %d\n", rc); |
| 8823 | goto rw_error; |
| 8824 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8825 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8826 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_CTL_ENA__A, (qam_ctl_ena | 0x0016), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8827 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8828 | pr_err("error %d\n", rc); |
| 8829 | goto rw_error; |
| 8830 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8831 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8832 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8833 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8834 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8835 | |
| 8836 | } |
| 8837 | |
| 8838 | #define NO_LOCK 0x0 |
| 8839 | #define DEMOD_LOCKED 0x1 |
| 8840 | #define SYNC_FLIPPED 0x2 |
| 8841 | #define SPEC_MIRRORED 0x4 |
| 8842 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8843 | * \fn int qam64auto () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8844 | * \brief auto do sync pattern switching and mirroring. |
| 8845 | * \param demod: instance of demod. |
| 8846 | * \param channel: pointer to channel data. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8847 | * \param tuner_freq_offset: tuner frequency offset. |
| 8848 | * \param lock_status: pointer to lock status. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 8849 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8850 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 8851 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 8852 | qam64auto(struct drx_demod_instance *demod, |
| 8853 | struct drx_channel *channel, |
| 8854 | s32 tuner_freq_offset, enum drx_lock_status *lock_status) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8855 | { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 8856 | struct drxj_data *ext_attr = demod->my_ext_attr; |
| 8857 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
| 8858 | struct drx39xxj_state *state = dev_addr->user_data; |
| 8859 | struct dtv_frontend_properties *p = &state->frontend.dtv_property_cache; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8860 | int rc; |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 8861 | u32 lck_state = NO_LOCK; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8862 | u32 start_time = 0; |
| 8863 | u32 d_locked_time = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8864 | u32 timeout_ofs = 0; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8865 | u16 data = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8866 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8867 | /* external attributes for storing aquired channel constellation */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8868 | *lock_status = DRX_NOT_LOCKED; |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 8869 | start_time = jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 8870 | lck_state = NO_LOCK; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8871 | do { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8872 | rc = ctrl_lock_status(demod, lock_status); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8873 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8874 | pr_err("error %d\n", rc); |
| 8875 | goto rw_error; |
| 8876 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8877 | |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 8878 | switch (lck_state) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8879 | case NO_LOCK: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8880 | if (*lock_status == DRXJ_DEMOD_LOCK) { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 8881 | rc = ctrl_get_qam_sig_quality(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8882 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8883 | pr_err("error %d\n", rc); |
| 8884 | goto rw_error; |
| 8885 | } |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 8886 | if (p->cnr.stat[0].svalue > 20800) { |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 8887 | lck_state = DEMOD_LOCKED; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8888 | /* some delay to see if fec_lock possible TODO find the right value */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8889 | timeout_ofs += DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME; /* see something, waiting longer */ |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 8890 | d_locked_time = jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8891 | } |
| 8892 | } |
| 8893 | break; |
| 8894 | case DEMOD_LOCKED: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8895 | if ((*lock_status == DRXJ_DEMOD_LOCK) && /* still demod_lock in 150ms */ |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 8896 | ((jiffies_to_msecs(jiffies) - d_locked_time) > |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8897 | DRXJ_QAM_FEC_LOCK_WAITTIME)) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8898 | rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8899 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8900 | pr_err("error %d\n", rc); |
| 8901 | goto rw_error; |
| 8902 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8903 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, data | 0x1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8904 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8905 | pr_err("error %d\n", rc); |
| 8906 | goto rw_error; |
| 8907 | } |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 8908 | lck_state = SYNC_FLIPPED; |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 8909 | msleep(10); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8910 | } |
| 8911 | break; |
| 8912 | case SYNC_FLIPPED: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8913 | if (*lock_status == DRXJ_DEMOD_LOCK) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8914 | if (channel->mirror == DRX_MIRROR_AUTO) { |
| 8915 | /* flip sync pattern back */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8916 | rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8917 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8918 | pr_err("error %d\n", rc); |
| 8919 | goto rw_error; |
| 8920 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8921 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, data & 0xFFFE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8922 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8923 | pr_err("error %d\n", rc); |
| 8924 | goto rw_error; |
| 8925 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8926 | /* flip spectrum */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8927 | ext_attr->mirror = DRX_MIRROR_YES; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8928 | rc = qam_flip_spec(demod, channel); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8929 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8930 | pr_err("error %d\n", rc); |
| 8931 | goto rw_error; |
| 8932 | } |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 8933 | lck_state = SPEC_MIRRORED; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8934 | /* reset timer TODO: still need 500ms? */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8935 | start_time = d_locked_time = |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 8936 | jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8937 | timeout_ofs = 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8938 | } else { /* no need to wait lock */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8939 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8940 | start_time = |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 8941 | jiffies_to_msecs(jiffies) - |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8942 | DRXJ_QAM_MAX_WAITTIME - timeout_ofs; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8943 | } |
| 8944 | } |
| 8945 | break; |
| 8946 | case SPEC_MIRRORED: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8947 | if ((*lock_status == DRXJ_DEMOD_LOCK) && /* still demod_lock in 150ms */ |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 8948 | ((jiffies_to_msecs(jiffies) - d_locked_time) > |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8949 | DRXJ_QAM_FEC_LOCK_WAITTIME)) { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 8950 | rc = ctrl_get_qam_sig_quality(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8951 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8952 | pr_err("error %d\n", rc); |
| 8953 | goto rw_error; |
| 8954 | } |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 8955 | if (p->cnr.stat[0].svalue > 20800) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8956 | rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8957 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8958 | pr_err("error %d\n", rc); |
| 8959 | goto rw_error; |
| 8960 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 8961 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, data | 0x1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8962 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 8963 | pr_err("error %d\n", rc); |
| 8964 | goto rw_error; |
| 8965 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8966 | /* no need to wait lock */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8967 | start_time = |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 8968 | jiffies_to_msecs(jiffies) - |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8969 | DRXJ_QAM_MAX_WAITTIME - timeout_ofs; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8970 | } |
| 8971 | } |
| 8972 | break; |
| 8973 | default: |
| 8974 | break; |
| 8975 | } |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 8976 | msleep(10); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8977 | } while |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8978 | ((*lock_status != DRX_LOCKED) && |
| 8979 | (*lock_status != DRX_NEVER_LOCK) && |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 8980 | ((jiffies_to_msecs(jiffies) - start_time) < |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8981 | (DRXJ_QAM_MAX_WAITTIME + timeout_ofs)) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 8982 | ); |
| 8983 | /* Returning control to apllication ... */ |
| 8984 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8985 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8986 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 8987 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8988 | } |
| 8989 | |
| 8990 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8991 | * \fn int qam256auto () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8992 | * \brief auto do sync pattern switching and mirroring. |
| 8993 | * \param demod: instance of demod. |
| 8994 | * \param channel: pointer to channel data. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 8995 | * \param tuner_freq_offset: tuner frequency offset. |
| 8996 | * \param lock_status: pointer to lock status. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 8997 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 8998 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 8999 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 9000 | qam256auto(struct drx_demod_instance *demod, |
| 9001 | struct drx_channel *channel, |
| 9002 | s32 tuner_freq_offset, enum drx_lock_status *lock_status) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9003 | { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9004 | struct drxj_data *ext_attr = demod->my_ext_attr; |
| 9005 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
| 9006 | struct drx39xxj_state *state = dev_addr->user_data; |
| 9007 | struct dtv_frontend_properties *p = &state->frontend.dtv_property_cache; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9008 | int rc; |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 9009 | u32 lck_state = NO_LOCK; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9010 | u32 start_time = 0; |
| 9011 | u32 d_locked_time = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9012 | u32 timeout_ofs = DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9013 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9014 | /* external attributes for storing aquired channel constellation */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9015 | *lock_status = DRX_NOT_LOCKED; |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 9016 | start_time = jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 9017 | lck_state = NO_LOCK; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9018 | do { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9019 | rc = ctrl_lock_status(demod, lock_status); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9020 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9021 | pr_err("error %d\n", rc); |
| 9022 | goto rw_error; |
| 9023 | } |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 9024 | switch (lck_state) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9025 | case NO_LOCK: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9026 | if (*lock_status == DRXJ_DEMOD_LOCK) { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9027 | rc = ctrl_get_qam_sig_quality(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9028 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9029 | pr_err("error %d\n", rc); |
| 9030 | goto rw_error; |
| 9031 | } |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9032 | if (p->cnr.stat[0].svalue > 26800) { |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 9033 | lck_state = DEMOD_LOCKED; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9034 | timeout_ofs += DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME; /* see something, wait longer */ |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 9035 | d_locked_time = jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9036 | } |
| 9037 | } |
| 9038 | break; |
| 9039 | case DEMOD_LOCKED: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9040 | if (*lock_status == DRXJ_DEMOD_LOCK) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9041 | if ((channel->mirror == DRX_MIRROR_AUTO) && |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 9042 | ((jiffies_to_msecs(jiffies) - d_locked_time) > |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9043 | DRXJ_QAM_FEC_LOCK_WAITTIME)) { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9044 | ext_attr->mirror = DRX_MIRROR_YES; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9045 | rc = qam_flip_spec(demod, channel); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9046 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9047 | pr_err("error %d\n", rc); |
| 9048 | goto rw_error; |
| 9049 | } |
Mauro Carvalho Chehab | 6f64c52 | 2014-03-09 17:30:48 -0300 | [diff] [blame] | 9050 | lck_state = SPEC_MIRRORED; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9051 | /* reset timer TODO: still need 300ms? */ |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 9052 | start_time = jiffies_to_msecs(jiffies); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9053 | timeout_ofs = -DRXJ_QAM_MAX_WAITTIME / 2; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9054 | } |
| 9055 | } |
| 9056 | break; |
| 9057 | case SPEC_MIRRORED: |
| 9058 | break; |
| 9059 | default: |
| 9060 | break; |
| 9061 | } |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 9062 | msleep(10); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9063 | } while |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9064 | ((*lock_status < DRX_LOCKED) && |
| 9065 | (*lock_status != DRX_NEVER_LOCK) && |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 9066 | ((jiffies_to_msecs(jiffies) - start_time) < |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9067 | (DRXJ_QAM_MAX_WAITTIME + timeout_ofs))); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9068 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9069 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9070 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9071 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9072 | } |
| 9073 | |
| 9074 | /** |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 9075 | * \fn int set_qam_channel () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9076 | * \brief Set QAM channel according to the requested constellation. |
| 9077 | * \param demod: instance of demod. |
| 9078 | * \param channel: pointer to channel data. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 9079 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9080 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 9081 | static int |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 9082 | set_qam_channel(struct drx_demod_instance *demod, |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 9083 | struct drx_channel *channel, s32 tuner_freq_offset) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9084 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 9085 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9086 | int rc; |
| 9087 | enum drx_lock_status lock_status = DRX_NOT_LOCKED; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9088 | bool auto_flag = false; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9089 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9090 | /* external attributes for storing aquired channel constellation */ |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 9091 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9092 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9093 | /* set QAM channel constellation */ |
| 9094 | switch (channel->constellation) { |
| 9095 | case DRX_CONSTELLATION_QAM16: |
| 9096 | case DRX_CONSTELLATION_QAM32: |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9097 | case DRX_CONSTELLATION_QAM128: |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9098 | return -EINVAL; |
| 9099 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9100 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9101 | if (ext_attr->standard != DRX_STANDARD_ITU_B) |
| 9102 | return -EINVAL; |
| 9103 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9104 | ext_attr->constellation = channel->constellation; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9105 | if (channel->mirror == DRX_MIRROR_AUTO) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9106 | ext_attr->mirror = DRX_MIRROR_NO; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9107 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9108 | ext_attr->mirror = channel->mirror; |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9109 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9110 | rc = set_qam(demod, channel, tuner_freq_offset, QAM_SET_OP_ALL); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9111 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9112 | pr_err("error %d\n", rc); |
| 9113 | goto rw_error; |
| 9114 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9115 | |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9116 | if (channel->constellation == DRX_CONSTELLATION_QAM64) |
| 9117 | rc = qam64auto(demod, channel, tuner_freq_offset, |
| 9118 | &lock_status); |
| 9119 | else |
| 9120 | rc = qam256auto(demod, channel, tuner_freq_offset, |
| 9121 | &lock_status); |
| 9122 | if (rc != 0) { |
| 9123 | pr_err("error %d\n", rc); |
| 9124 | goto rw_error; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9125 | } |
| 9126 | break; |
| 9127 | case DRX_CONSTELLATION_AUTO: /* for channel scan */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9128 | if (ext_attr->standard == DRX_STANDARD_ITU_B) { |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9129 | u16 qam_ctl_ena = 0; |
| 9130 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9131 | auto_flag = true; |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9132 | |
| 9133 | /* try to lock default QAM constellation: QAM256 */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9134 | channel->constellation = DRX_CONSTELLATION_QAM256; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9135 | ext_attr->constellation = DRX_CONSTELLATION_QAM256; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9136 | if (channel->mirror == DRX_MIRROR_AUTO) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9137 | ext_attr->mirror = DRX_MIRROR_NO; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9138 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9139 | ext_attr->mirror = channel->mirror; |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9140 | rc = set_qam(demod, channel, tuner_freq_offset, |
| 9141 | QAM_SET_OP_ALL); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9142 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9143 | pr_err("error %d\n", rc); |
| 9144 | goto rw_error; |
| 9145 | } |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9146 | rc = qam256auto(demod, channel, tuner_freq_offset, |
| 9147 | &lock_status); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9148 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9149 | pr_err("error %d\n", rc); |
| 9150 | goto rw_error; |
| 9151 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9152 | |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9153 | if (lock_status >= DRX_LOCKED) { |
| 9154 | channel->constellation = DRX_CONSTELLATION_AUTO; |
| 9155 | break; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9156 | } |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9157 | |
| 9158 | /* QAM254 not locked. Try QAM64 constellation */ |
| 9159 | channel->constellation = DRX_CONSTELLATION_QAM64; |
| 9160 | ext_attr->constellation = DRX_CONSTELLATION_QAM64; |
| 9161 | if (channel->mirror == DRX_MIRROR_AUTO) |
| 9162 | ext_attr->mirror = DRX_MIRROR_NO; |
| 9163 | else |
| 9164 | ext_attr->mirror = channel->mirror; |
| 9165 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9166 | rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9167 | SCU_RAM_QAM_CTL_ENA__A, |
| 9168 | &qam_ctl_ena, 0); |
| 9169 | if (rc != 0) { |
| 9170 | pr_err("error %d\n", rc); |
| 9171 | goto rw_error; |
| 9172 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9173 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9174 | SCU_RAM_QAM_CTL_ENA__A, |
| 9175 | qam_ctl_ena & ~SCU_RAM_QAM_CTL_ENA_ACQ__M, 0); |
| 9176 | if (rc != 0) { |
| 9177 | pr_err("error %d\n", rc); |
| 9178 | goto rw_error; |
| 9179 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9180 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9181 | SCU_RAM_QAM_FSM_STATE_TGT__A, |
| 9182 | 0x2, 0); |
| 9183 | if (rc != 0) { |
| 9184 | pr_err("error %d\n", rc); |
| 9185 | goto rw_error; |
| 9186 | } /* force to rate hunting */ |
| 9187 | |
| 9188 | rc = set_qam(demod, channel, tuner_freq_offset, |
| 9189 | QAM_SET_OP_CONSTELLATION); |
| 9190 | if (rc != 0) { |
| 9191 | pr_err("error %d\n", rc); |
| 9192 | goto rw_error; |
| 9193 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9194 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9195 | SCU_RAM_QAM_CTL_ENA__A, |
| 9196 | qam_ctl_ena, 0); |
| 9197 | if (rc != 0) { |
| 9198 | pr_err("error %d\n", rc); |
| 9199 | goto rw_error; |
| 9200 | } |
| 9201 | |
| 9202 | rc = qam64auto(demod, channel, tuner_freq_offset, |
| 9203 | &lock_status); |
| 9204 | if (rc != 0) { |
| 9205 | pr_err("error %d\n", rc); |
| 9206 | goto rw_error; |
| 9207 | } |
| 9208 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9209 | channel->constellation = DRX_CONSTELLATION_AUTO; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9210 | } else if (ext_attr->standard == DRX_STANDARD_ITU_C) { |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9211 | u16 qam_ctl_ena = 0; |
| 9212 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9213 | channel->constellation = DRX_CONSTELLATION_QAM64; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9214 | ext_attr->constellation = DRX_CONSTELLATION_QAM64; |
| 9215 | auto_flag = true; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9216 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9217 | if (channel->mirror == DRX_MIRROR_AUTO) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9218 | ext_attr->mirror = DRX_MIRROR_NO; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9219 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9220 | ext_attr->mirror = channel->mirror; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9221 | rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9222 | SCU_RAM_QAM_CTL_ENA__A, |
| 9223 | &qam_ctl_ena, 0); |
| 9224 | if (rc != 0) { |
| 9225 | pr_err("error %d\n", rc); |
| 9226 | goto rw_error; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9227 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9228 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9229 | SCU_RAM_QAM_CTL_ENA__A, |
| 9230 | qam_ctl_ena & ~SCU_RAM_QAM_CTL_ENA_ACQ__M, 0); |
| 9231 | if (rc != 0) { |
| 9232 | pr_err("error %d\n", rc); |
| 9233 | goto rw_error; |
| 9234 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9235 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9236 | SCU_RAM_QAM_FSM_STATE_TGT__A, |
| 9237 | 0x2, 0); |
| 9238 | if (rc != 0) { |
| 9239 | pr_err("error %d\n", rc); |
| 9240 | goto rw_error; |
| 9241 | } /* force to rate hunting */ |
| 9242 | |
| 9243 | rc = set_qam(demod, channel, tuner_freq_offset, |
| 9244 | QAM_SET_OP_CONSTELLATION); |
| 9245 | if (rc != 0) { |
| 9246 | pr_err("error %d\n", rc); |
| 9247 | goto rw_error; |
| 9248 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9249 | rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, |
Mauro Carvalho Chehab | 938f11f | 2014-01-26 16:41:51 -0300 | [diff] [blame] | 9250 | SCU_RAM_QAM_CTL_ENA__A, |
| 9251 | qam_ctl_ena, 0); |
| 9252 | if (rc != 0) { |
| 9253 | pr_err("error %d\n", rc); |
| 9254 | goto rw_error; |
| 9255 | } |
| 9256 | rc = qam64auto(demod, channel, tuner_freq_offset, |
| 9257 | &lock_status); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9258 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9259 | pr_err("error %d\n", rc); |
| 9260 | goto rw_error; |
| 9261 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9262 | channel->constellation = DRX_CONSTELLATION_AUTO; |
| 9263 | } else { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9264 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9265 | } |
| 9266 | break; |
| 9267 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9268 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9269 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9270 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9271 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9272 | rw_error: |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9273 | /* restore starting value */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9274 | if (auto_flag) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9275 | channel->constellation = DRX_CONSTELLATION_AUTO; |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9276 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9277 | } |
| 9278 | |
| 9279 | /*============================================================================*/ |
| 9280 | |
| 9281 | /** |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 9282 | * \fn static short get_qamrs_err_count(struct i2c_device_addr *dev_addr) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9283 | * \brief Get RS error count in QAM mode (used for post RS BER calculation) |
| 9284 | * \return Error code |
| 9285 | * |
| 9286 | * precondition: measurement period & measurement prescale must be set |
| 9287 | * |
| 9288 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 9289 | static int |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 9290 | get_qamrs_err_count(struct i2c_device_addr *dev_addr, |
| 9291 | struct drxjrs_errors *rs_errors) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9292 | { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9293 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9294 | u16 nr_bit_errors = 0, |
| 9295 | nr_symbol_errors = 0, |
| 9296 | nr_packet_errors = 0, nr_failures = 0, nr_snc_par_fail_count = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9297 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9298 | /* check arguments */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9299 | if (dev_addr == NULL) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9300 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9301 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9302 | /* all reported errors are received in the */ |
| 9303 | /* most recently finished measurment period */ |
| 9304 | /* no of pre RS bit errors */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9305 | rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_BIT_ERRORS__A, &nr_bit_errors, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9306 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9307 | pr_err("error %d\n", rc); |
| 9308 | goto rw_error; |
| 9309 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9310 | /* no of symbol errors */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9311 | rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_SYMBOL_ERRORS__A, &nr_symbol_errors, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9312 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9313 | pr_err("error %d\n", rc); |
| 9314 | goto rw_error; |
| 9315 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9316 | /* no of packet errors */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9317 | rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_PACKET_ERRORS__A, &nr_packet_errors, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9318 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9319 | pr_err("error %d\n", rc); |
| 9320 | goto rw_error; |
| 9321 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9322 | /* no of failures to decode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9323 | rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_FAILURES__A, &nr_failures, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9324 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9325 | pr_err("error %d\n", rc); |
| 9326 | goto rw_error; |
| 9327 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9328 | /* no of post RS bit erros */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9329 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_SNC_FAIL_COUNT__A, &nr_snc_par_fail_count, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9330 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9331 | pr_err("error %d\n", rc); |
| 9332 | goto rw_error; |
| 9333 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9334 | /* TODO: NOTE */ |
| 9335 | /* These register values are fetched in non-atomic fashion */ |
| 9336 | /* It is possible that the read values contain unrelated information */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9337 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9338 | rs_errors->nr_bit_errors = nr_bit_errors & FEC_RS_NR_BIT_ERRORS__M; |
| 9339 | rs_errors->nr_symbol_errors = nr_symbol_errors & FEC_RS_NR_SYMBOL_ERRORS__M; |
| 9340 | rs_errors->nr_packet_errors = nr_packet_errors & FEC_RS_NR_PACKET_ERRORS__M; |
| 9341 | rs_errors->nr_failures = nr_failures & FEC_RS_NR_FAILURES__M; |
| 9342 | rs_errors->nr_snc_par_fail_count = |
| 9343 | nr_snc_par_fail_count & FEC_OC_SNC_FAIL_COUNT__M; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9344 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9345 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9346 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9347 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9348 | } |
| 9349 | |
| 9350 | /*============================================================================*/ |
| 9351 | |
| 9352 | /** |
Mauro Carvalho Chehab | 80e5ed1 | 2014-03-09 17:37:27 -0300 | [diff] [blame] | 9353 | * \fn int get_sig_strength() |
| 9354 | * \brief Retrieve signal strength for VSB and QAM. |
| 9355 | * \param demod Pointer to demod instance |
| 9356 | * \param u16-t Pointer to signal strength data; range 0, .. , 100. |
| 9357 | * \return int. |
| 9358 | * \retval 0 sig_strength contains valid data. |
| 9359 | * \retval -EINVAL sig_strength is NULL. |
| 9360 | * \retval -EIO Erroneous data, sig_strength contains invalid data. |
| 9361 | */ |
| 9362 | #define DRXJ_AGC_TOP 0x2800 |
| 9363 | #define DRXJ_AGC_SNS 0x1600 |
| 9364 | #define DRXJ_RFAGC_MAX 0x3fff |
| 9365 | #define DRXJ_RFAGC_MIN 0x800 |
| 9366 | |
| 9367 | static int get_sig_strength(struct drx_demod_instance *demod, u16 *sig_strength) |
| 9368 | { |
| 9369 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
| 9370 | int rc; |
| 9371 | u16 rf_gain = 0; |
| 9372 | u16 if_gain = 0; |
| 9373 | u16 if_agc_sns = 0; |
| 9374 | u16 if_agc_top = 0; |
| 9375 | u16 rf_agc_max = 0; |
| 9376 | u16 rf_agc_min = 0; |
| 9377 | |
| 9378 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_AGC_IF__A, &if_gain, 0); |
| 9379 | if (rc != 0) { |
| 9380 | pr_err("error %d\n", rc); |
| 9381 | goto rw_error; |
| 9382 | } |
| 9383 | if_gain &= IQM_AF_AGC_IF__M; |
| 9384 | rc = drxj_dap_read_reg16(dev_addr, IQM_AF_AGC_RF__A, &rf_gain, 0); |
| 9385 | if (rc != 0) { |
| 9386 | pr_err("error %d\n", rc); |
| 9387 | goto rw_error; |
| 9388 | } |
| 9389 | rf_gain &= IQM_AF_AGC_RF__M; |
| 9390 | |
| 9391 | if_agc_sns = DRXJ_AGC_SNS; |
| 9392 | if_agc_top = DRXJ_AGC_TOP; |
| 9393 | rf_agc_max = DRXJ_RFAGC_MAX; |
| 9394 | rf_agc_min = DRXJ_RFAGC_MIN; |
| 9395 | |
| 9396 | if (if_gain > if_agc_top) { |
| 9397 | if (rf_gain > rf_agc_max) |
| 9398 | *sig_strength = 100; |
| 9399 | else if (rf_gain > rf_agc_min) { |
| 9400 | if (rf_agc_max == rf_agc_min) { |
| 9401 | pr_err("error: rf_agc_max == rf_agc_min\n"); |
| 9402 | return -EIO; |
| 9403 | } |
| 9404 | *sig_strength = |
| 9405 | 75 + 25 * (rf_gain - rf_agc_min) / (rf_agc_max - |
| 9406 | rf_agc_min); |
| 9407 | } else |
| 9408 | *sig_strength = 75; |
| 9409 | } else if (if_gain > if_agc_sns) { |
| 9410 | if (if_agc_top == if_agc_sns) { |
| 9411 | pr_err("error: if_agc_top == if_agc_sns\n"); |
| 9412 | return -EIO; |
| 9413 | } |
| 9414 | *sig_strength = |
| 9415 | 20 + 55 * (if_gain - if_agc_sns) / (if_agc_top - if_agc_sns); |
| 9416 | } else { |
| 9417 | if (!if_agc_sns) { |
| 9418 | pr_err("error: if_agc_sns is zero!\n"); |
| 9419 | return -EIO; |
| 9420 | } |
| 9421 | *sig_strength = (20 * if_gain / if_agc_sns); |
| 9422 | } |
| 9423 | |
Mauro Carvalho Chehab | 80846a5 | 2014-03-10 08:18:31 -0300 | [diff] [blame] | 9424 | if (*sig_strength <= 7) |
| 9425 | *sig_strength = 0; |
| 9426 | |
Mauro Carvalho Chehab | 80e5ed1 | 2014-03-09 17:37:27 -0300 | [diff] [blame] | 9427 | return 0; |
| 9428 | rw_error: |
| 9429 | return -EIO; |
| 9430 | } |
| 9431 | |
| 9432 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9433 | * \fn int ctrl_get_qam_sig_quality() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9434 | * \brief Retreive QAM signal quality from device. |
| 9435 | * \param devmod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9436 | * \param sig_quality Pointer to signal quality data. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 9437 | * \return int. |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9438 | * \retval 0 sig_quality contains valid data. |
| 9439 | * \retval -EINVAL sig_quality is NULL. |
| 9440 | * \retval -EIO Erroneous data, sig_quality contains invalid data. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9441 | |
| 9442 | * Pre-condition: Device must be started and in lock. |
| 9443 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 9444 | static int |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9445 | ctrl_get_qam_sig_quality(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9446 | { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9447 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
| 9448 | struct drxj_data *ext_attr = demod->my_ext_attr; |
| 9449 | struct drx39xxj_state *state = dev_addr->user_data; |
| 9450 | struct dtv_frontend_properties *p = &state->frontend.dtv_property_cache; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 9451 | struct drxjrs_errors measuredrs_errors = { 0, 0, 0, 0, 0 }; |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9452 | enum drx_modulation constellation = ext_attr->constellation; |
| 9453 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9454 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9455 | u32 pre_bit_err_rs = 0; /* pre RedSolomon Bit Error Rate */ |
| 9456 | u32 post_bit_err_rs = 0; /* post RedSolomon Bit Error Rate */ |
| 9457 | u32 pkt_errs = 0; /* no of packet errors in RS */ |
| 9458 | u16 qam_sl_err_power = 0; /* accumulated error between raw and sliced symbols */ |
| 9459 | u16 qsym_err_vd = 0; /* quadrature symbol errors in QAM_VD */ |
| 9460 | u16 fec_oc_period = 0; /* SNC sync failure measurement period */ |
| 9461 | u16 fec_rs_prescale = 0; /* ReedSolomon Measurement Prescale */ |
| 9462 | u16 fec_rs_period = 0; /* Value for corresponding I2C register */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9463 | /* calculation constants */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9464 | u32 rs_bit_cnt = 0; /* RedSolomon Bit Count */ |
| 9465 | u32 qam_sl_sig_power = 0; /* used for MER, depends of QAM constellation */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9466 | /* intermediate results */ |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 9467 | u32 e = 0; /* exponent value used for QAM BER/SER */ |
| 9468 | u32 m = 0; /* mantisa value used for QAM BER/SER */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9469 | u32 ber_cnt = 0; /* BER count */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9470 | /* signal quality info */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9471 | u32 qam_sl_mer = 0; /* QAM MER */ |
| 9472 | u32 qam_pre_rs_ber = 0; /* Pre RedSolomon BER */ |
| 9473 | u32 qam_post_rs_ber = 0; /* Post RedSolomon BER */ |
| 9474 | u32 qam_vd_ser = 0; /* ViterbiDecoder SER */ |
| 9475 | u16 qam_vd_prescale = 0; /* Viterbi Measurement Prescale */ |
| 9476 | u16 qam_vd_period = 0; /* Viterbi Measurement period */ |
| 9477 | u32 vd_bit_cnt = 0; /* ViterbiDecoder Bit Count */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9478 | |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 9479 | p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 9480 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9481 | /* read the physical registers */ |
| 9482 | /* Get the RS error data */ |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 9483 | rc = get_qamrs_err_count(dev_addr, &measuredrs_errors); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9484 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9485 | pr_err("error %d\n", rc); |
| 9486 | goto rw_error; |
| 9487 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9488 | /* get the register value needed for MER */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9489 | rc = drxj_dap_read_reg16(dev_addr, QAM_SL_ERR_POWER__A, &qam_sl_err_power, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9490 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9491 | pr_err("error %d\n", rc); |
| 9492 | goto rw_error; |
| 9493 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9494 | /* get the register value needed for post RS BER */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9495 | rc = drxj_dap_read_reg16(dev_addr, FEC_OC_SNC_FAIL_PERIOD__A, &fec_oc_period, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9496 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9497 | pr_err("error %d\n", rc); |
| 9498 | goto rw_error; |
| 9499 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9500 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9501 | /* get constants needed for signal quality calculation */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9502 | fec_rs_period = ext_attr->fec_rs_period; |
| 9503 | fec_rs_prescale = ext_attr->fec_rs_prescale; |
| 9504 | rs_bit_cnt = fec_rs_period * fec_rs_prescale * ext_attr->fec_rs_plen; |
| 9505 | qam_vd_period = ext_attr->qam_vd_period; |
| 9506 | qam_vd_prescale = ext_attr->qam_vd_prescale; |
| 9507 | vd_bit_cnt = qam_vd_period * qam_vd_prescale * ext_attr->fec_vd_plen; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9508 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9509 | /* DRXJ_QAM_SL_SIG_POWER_QAMxxx * 4 */ |
| 9510 | switch (constellation) { |
| 9511 | case DRX_CONSTELLATION_QAM16: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9512 | qam_sl_sig_power = DRXJ_QAM_SL_SIG_POWER_QAM16 << 2; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9513 | break; |
| 9514 | case DRX_CONSTELLATION_QAM32: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9515 | qam_sl_sig_power = DRXJ_QAM_SL_SIG_POWER_QAM32 << 2; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9516 | break; |
| 9517 | case DRX_CONSTELLATION_QAM64: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9518 | qam_sl_sig_power = DRXJ_QAM_SL_SIG_POWER_QAM64 << 2; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9519 | break; |
| 9520 | case DRX_CONSTELLATION_QAM128: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9521 | qam_sl_sig_power = DRXJ_QAM_SL_SIG_POWER_QAM128 << 2; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9522 | break; |
| 9523 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9524 | qam_sl_sig_power = DRXJ_QAM_SL_SIG_POWER_QAM256 << 2; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9525 | break; |
| 9526 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9527 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9528 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9529 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9530 | /* ------------------------------ */ |
| 9531 | /* MER Calculation */ |
| 9532 | /* ------------------------------ */ |
| 9533 | /* MER is good if it is above 27.5 for QAM256 or 21.5 for QAM64 */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9534 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9535 | /* 10.0*log10(qam_sl_sig_power * 4.0 / qam_sl_err_power); */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9536 | if (qam_sl_err_power == 0) |
| 9537 | qam_sl_mer = 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9538 | else |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9539 | qam_sl_mer = log1_times100(qam_sl_sig_power) - log1_times100((u32)qam_sl_err_power); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9540 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9541 | /* ----------------------------------------- */ |
| 9542 | /* Pre Viterbi Symbol Error Rate Calculation */ |
| 9543 | /* ----------------------------------------- */ |
| 9544 | /* pre viterbi SER is good if it is bellow 0.025 */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9545 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9546 | /* get the register value */ |
| 9547 | /* no of quadrature symbol errors */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9548 | rc = drxj_dap_read_reg16(dev_addr, QAM_VD_NR_QSYM_ERRORS__A, &qsym_err_vd, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9549 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9550 | pr_err("error %d\n", rc); |
| 9551 | goto rw_error; |
| 9552 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9553 | /* Extract the Exponent and the Mantisa */ |
| 9554 | /* of number of quadrature symbol errors */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9555 | e = (qsym_err_vd & QAM_VD_NR_QSYM_ERRORS_EXP__M) >> |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9556 | QAM_VD_NR_QSYM_ERRORS_EXP__B; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9557 | m = (qsym_err_vd & QAM_VD_NR_SYMBOL_ERRORS_FIXED_MANT__M) >> |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9558 | QAM_VD_NR_SYMBOL_ERRORS_FIXED_MANT__B; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9559 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9560 | if ((m << e) >> 3 > 549752) |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 9561 | qam_vd_ser = 500000 * vd_bit_cnt * ((e > 2) ? 1 : 8) / 8; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9562 | else |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 9563 | qam_vd_ser = m << ((e > 2) ? (e - 3) : e); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9564 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9565 | /* --------------------------------------- */ |
| 9566 | /* pre and post RedSolomon BER Calculation */ |
| 9567 | /* --------------------------------------- */ |
| 9568 | /* pre RS BER is good if it is below 3.5e-4 */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9569 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9570 | /* get the register values */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9571 | pre_bit_err_rs = (u32) measuredrs_errors.nr_bit_errors; |
| 9572 | pkt_errs = post_bit_err_rs = (u32) measuredrs_errors.nr_snc_par_fail_count; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9573 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9574 | /* Extract the Exponent and the Mantisa of the */ |
| 9575 | /* pre Reed-Solomon bit error count */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9576 | e = (pre_bit_err_rs & FEC_RS_NR_BIT_ERRORS_EXP__M) >> |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9577 | FEC_RS_NR_BIT_ERRORS_EXP__B; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9578 | m = (pre_bit_err_rs & FEC_RS_NR_BIT_ERRORS_FIXED_MANT__M) >> |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9579 | FEC_RS_NR_BIT_ERRORS_FIXED_MANT__B; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9580 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9581 | ber_cnt = m << e; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9582 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9583 | /*qam_pre_rs_ber = frac_times1e6( ber_cnt, rs_bit_cnt ); */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9584 | if (m > (rs_bit_cnt >> (e + 1)) || (rs_bit_cnt >> e) == 0) |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 9585 | qam_pre_rs_ber = 500000 * rs_bit_cnt >> e; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9586 | else |
Mauro Carvalho Chehab | ee0f4a1 | 2014-03-11 07:34:44 -0300 | [diff] [blame] | 9587 | qam_pre_rs_ber = ber_cnt; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9588 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9589 | /* post RS BER = 1000000* (11.17 * FEC_OC_SNC_FAIL_COUNT__A) / */ |
| 9590 | /* (1504.0 * FEC_OC_SNC_FAIL_PERIOD__A) */ |
| 9591 | /* |
| 9592 | => c = (1000000*100*11.17)/1504 = |
| 9593 | post RS BER = (( c* FEC_OC_SNC_FAIL_COUNT__A) / |
| 9594 | (100 * FEC_OC_SNC_FAIL_PERIOD__A) |
| 9595 | *100 and /100 is for more precision. |
| 9596 | => (20 bits * 12 bits) /(16 bits * 7 bits) => safe in 32 bits computation |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9597 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9598 | Precision errors still possible. |
| 9599 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9600 | e = post_bit_err_rs * 742686; |
| 9601 | m = fec_oc_period * 100; |
| 9602 | if (fec_oc_period == 0) |
| 9603 | qam_post_rs_ber = 0xFFFFFFFF; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9604 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9605 | qam_post_rs_ber = e / m; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9606 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9607 | /* fill signal quality data structure */ |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9608 | p->pre_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
| 9609 | p->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
| 9610 | p->pre_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 9611 | p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 9612 | p->block_error.stat[0].scale = FE_SCALE_COUNTER; |
| 9613 | p->cnr.stat[0].scale = FE_SCALE_DECIBEL; |
| 9614 | |
| 9615 | p->cnr.stat[0].svalue = ((u16) qam_sl_mer) * 100; |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 9616 | if (ext_attr->standard == DRX_STANDARD_ITU_B) { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9617 | p->pre_bit_error.stat[0].uvalue += qam_vd_ser; |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 9618 | p->pre_bit_count.stat[0].uvalue += vd_bit_cnt * ((e > 2) ? 1 : 8) / 8; |
| 9619 | } else { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9620 | p->pre_bit_error.stat[0].uvalue += qam_pre_rs_ber; |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 9621 | p->pre_bit_count.stat[0].uvalue += rs_bit_cnt >> e; |
| 9622 | } |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9623 | |
Mauro Carvalho Chehab | 0d49e77 | 2014-03-11 07:43:54 -0300 | [diff] [blame] | 9624 | p->post_bit_error.stat[0].uvalue += qam_post_rs_ber; |
| 9625 | p->post_bit_count.stat[0].uvalue += rs_bit_cnt >> e; |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9626 | |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9627 | p->block_error.stat[0].uvalue += pkt_errs; |
| 9628 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9629 | #ifdef DRXJ_SIGNAL_ACCUM_ERR |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9630 | rc = get_acc_pkt_err(demod, &sig_quality->packet_error); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9631 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9632 | pr_err("error %d\n", rc); |
| 9633 | goto rw_error; |
| 9634 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9635 | #endif |
| 9636 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9637 | return 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9638 | rw_error: |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 9639 | p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 9640 | p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 9641 | p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 9642 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 9643 | p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 9644 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 9645 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9646 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9647 | } |
| 9648 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9649 | #endif /* #ifndef DRXJ_VSB_ONLY */ |
| 9650 | |
| 9651 | /*============================================================================*/ |
| 9652 | /*== END QAM DATAPATH FUNCTIONS ==*/ |
| 9653 | /*============================================================================*/ |
| 9654 | |
| 9655 | /*============================================================================*/ |
| 9656 | /*============================================================================*/ |
| 9657 | /*== ATV DATAPATH FUNCTIONS ==*/ |
| 9658 | /*============================================================================*/ |
| 9659 | /*============================================================================*/ |
| 9660 | |
| 9661 | /* |
| 9662 | Implementation notes. |
| 9663 | |
| 9664 | NTSC/FM AGCs |
| 9665 | |
| 9666 | Four AGCs are used for NTSC: |
| 9667 | (1) RF (used to attenuate the input signal in case of to much power) |
| 9668 | (2) IF (used to attenuate the input signal in case of to much power) |
| 9669 | (3) Video AGC (used to amplify the output signal in case input to low) |
| 9670 | (4) SIF AGC (used to amplify the output signal in case input to low) |
| 9671 | |
| 9672 | Video AGC is coupled to RF and IF. SIF AGC is not coupled. It is assumed |
| 9673 | that the coupling between Video AGC and the RF and IF AGCs also works in |
| 9674 | favor of the SIF AGC. |
| 9675 | |
| 9676 | Three AGCs are used for FM: |
| 9677 | (1) RF (used to attenuate the input signal in case of to much power) |
| 9678 | (2) IF (used to attenuate the input signal in case of to much power) |
| 9679 | (3) SIF AGC (used to amplify the output signal in case input to low) |
| 9680 | |
| 9681 | The SIF AGC is now coupled to the RF/IF AGCs. |
| 9682 | The SIF AGC is needed for both SIF ouput and the internal SIF signal to |
| 9683 | the AUD block. |
| 9684 | |
| 9685 | RF and IF AGCs DACs are part of AFE, Video and SIF AGC DACs are part of |
| 9686 | the ATV block. The AGC control algorithms are all implemented in |
| 9687 | microcode. |
| 9688 | |
| 9689 | ATV SETTINGS |
| 9690 | |
| 9691 | (Shadow settings will not be used for now, they will be implemented |
| 9692 | later on because of the schedule) |
| 9693 | |
| 9694 | Several HW/SCU "settings" can be used for ATV. The standard selection |
| 9695 | will reset most of these settings. To avoid that the end user apllication |
| 9696 | has to perform these settings each time the ATV or FM standards is |
| 9697 | selected the driver will shadow these settings. This enables the end user |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9698 | to perform the settings only once after a drx_open(). The driver must |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9699 | write the shadow settings to HW/SCU incase: |
| 9700 | ( setstandard FM/ATV) || |
| 9701 | ( settings have changed && FM/ATV standard is active) |
| 9702 | The shadow settings will be stored in the device specific data container. |
| 9703 | A set of flags will be defined to flag changes in shadow settings. |
| 9704 | A routine will be implemented to write all changed shadow settings to |
| 9705 | HW/SCU. |
| 9706 | |
| 9707 | The "settings" will consist of: AGC settings, filter settings etc. |
| 9708 | |
| 9709 | Disadvantage of use of shadow settings: |
| 9710 | Direct changes in HW/SCU registers will not be reflected in the |
| 9711 | shadow settings and these changes will be overwritten during a next |
| 9712 | update. This can happen during evaluation. This will not be a problem |
| 9713 | for normal customer usage. |
| 9714 | */ |
| 9715 | /* -------------------------------------------------------------------------- */ |
| 9716 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9717 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9718 | * \fn int power_down_atv () |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9719 | * \brief Power down ATV. |
| 9720 | * \param demod instance of demodulator |
| 9721 | * \param standard either NTSC or FM (sub strandard for ATV ) |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 9722 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9723 | * |
| 9724 | * Stops and thus resets ATV and IQM block |
| 9725 | * SIF and CVBS ADC are powered down |
| 9726 | * Calls audio power down |
| 9727 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 9728 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 9729 | power_down_atv(struct drx_demod_instance *demod, enum drx_standard standard, bool primary) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9730 | { |
Mauro Carvalho Chehab | 4d7bb0e | 2014-01-16 11:49:13 -0300 | [diff] [blame] | 9731 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 9732 | struct drxjscu_cmd cmd_scu = { /* command */ 0, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9733 | /* parameter_len */ 0, |
| 9734 | /* result_len */ 0, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9735 | /* *parameter */ NULL, |
| 9736 | /* *result */ NULL |
| 9737 | }; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9738 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9739 | u16 cmd_result = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9740 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9741 | /* ATV NTSC */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9742 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9743 | /* Stop ATV SCU (will reset ATV and IQM hardware */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9744 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_ATV | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9745 | SCU_RAM_COMMAND_CMD_DEMOD_STOP; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9746 | cmd_scu.parameter_len = 0; |
| 9747 | cmd_scu.result_len = 1; |
| 9748 | cmd_scu.parameter = NULL; |
| 9749 | cmd_scu.result = &cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9750 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9751 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9752 | pr_err("error %d\n", rc); |
| 9753 | goto rw_error; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9754 | } |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9755 | /* Disable ATV outputs (ATV reset enables CVBS, undo this) */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9756 | rc = drxj_dap_write_reg16(dev_addr, ATV_TOP_STDBY__A, (ATV_TOP_STDBY_SIF_STDBY_STANDBY & (~ATV_TOP_STDBY_CVBS_STDBY_A2_ACTIVE)), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9757 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9758 | pr_err("error %d\n", rc); |
| 9759 | goto rw_error; |
| 9760 | } |
| 9761 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9762 | rc = drxj_dap_write_reg16(dev_addr, ATV_COMM_EXEC__A, ATV_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9763 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9764 | pr_err("error %d\n", rc); |
| 9765 | goto rw_error; |
| 9766 | } |
Mauro Carvalho Chehab | 259f380 | 2014-01-17 06:40:47 -0300 | [diff] [blame] | 9767 | if (primary) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9768 | rc = drxj_dap_write_reg16(dev_addr, IQM_COMM_EXEC__A, IQM_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9769 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9770 | pr_err("error %d\n", rc); |
| 9771 | goto rw_error; |
| 9772 | } |
| 9773 | rc = set_iqm_af(demod, false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9774 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9775 | pr_err("error %d\n", rc); |
| 9776 | goto rw_error; |
| 9777 | } |
| 9778 | } else { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9779 | rc = drxj_dap_write_reg16(dev_addr, IQM_FS_COMM_EXEC__A, IQM_FS_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9780 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9781 | pr_err("error %d\n", rc); |
| 9782 | goto rw_error; |
| 9783 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9784 | rc = drxj_dap_write_reg16(dev_addr, IQM_FD_COMM_EXEC__A, IQM_FD_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9785 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9786 | pr_err("error %d\n", rc); |
| 9787 | goto rw_error; |
| 9788 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9789 | rc = drxj_dap_write_reg16(dev_addr, IQM_RC_COMM_EXEC__A, IQM_RC_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9790 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9791 | pr_err("error %d\n", rc); |
| 9792 | goto rw_error; |
| 9793 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9794 | rc = drxj_dap_write_reg16(dev_addr, IQM_RT_COMM_EXEC__A, IQM_RT_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9795 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9796 | pr_err("error %d\n", rc); |
| 9797 | goto rw_error; |
| 9798 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9799 | rc = drxj_dap_write_reg16(dev_addr, IQM_CF_COMM_EXEC__A, IQM_CF_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9800 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9801 | pr_err("error %d\n", rc); |
| 9802 | goto rw_error; |
| 9803 | } |
| 9804 | } |
| 9805 | rc = power_down_aud(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9806 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9807 | pr_err("error %d\n", rc); |
| 9808 | goto rw_error; |
| 9809 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9810 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9811 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9812 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9813 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9814 | } |
| 9815 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9816 | /*============================================================================*/ |
| 9817 | |
| 9818 | /** |
| 9819 | * \brief Power up AUD. |
| 9820 | * \param demod instance of demodulator |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 9821 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9822 | * |
| 9823 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 9824 | static int power_down_aud(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9825 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9826 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 9827 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9828 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9829 | |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 9830 | dev_addr = (struct i2c_device_addr *)demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 9831 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9832 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9833 | rc = drxj_dap_write_reg16(dev_addr, AUD_COMM_EXEC__A, AUD_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9834 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9835 | pr_err("error %d\n", rc); |
| 9836 | goto rw_error; |
| 9837 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9838 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9839 | ext_attr->aud_data.audio_is_active = false; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9840 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9841 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9842 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9843 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9844 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9845 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9846 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9847 | * \fn int set_orx_nsu_aox() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9848 | * \brief Configure OrxNsuAox for OOB |
| 9849 | * \param demod instance of demodulator. |
| 9850 | * \param active |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 9851 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9852 | */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 9853 | static int set_orx_nsu_aox(struct drx_demod_instance *demod, bool active) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9854 | { |
Mauro Carvalho Chehab | 4d7bb0e | 2014-01-16 11:49:13 -0300 | [diff] [blame] | 9855 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9856 | int rc; |
| 9857 | u16 data = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9858 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9859 | /* Configure NSU_AOX */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9860 | rc = drxj_dap_read_reg16(dev_addr, ORX_NSU_AOX_STDBY_W__A, &data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9861 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9862 | pr_err("error %d\n", rc); |
| 9863 | goto rw_error; |
| 9864 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9865 | if (!active) |
| 9866 | data &= ((~ORX_NSU_AOX_STDBY_W_STDBYADC_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYAMP_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYBIAS_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYPLL_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYPD_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYTAGC_IF_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYTAGC_RF_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYFLT_A2_ON)); |
| 9867 | else |
| 9868 | data |= (ORX_NSU_AOX_STDBY_W_STDBYADC_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYAMP_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYBIAS_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYPLL_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYPD_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYTAGC_IF_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYTAGC_RF_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYFLT_A2_ON); |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9869 | rc = drxj_dap_write_reg16(dev_addr, ORX_NSU_AOX_STDBY_W__A, data, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9870 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9871 | pr_err("error %d\n", rc); |
| 9872 | goto rw_error; |
| 9873 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9874 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9875 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9876 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9877 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9878 | } |
| 9879 | |
| 9880 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9881 | * \fn int ctrl_set_oob() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9882 | * \brief Set OOB channel to be used. |
| 9883 | * \param demod instance of demodulator |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9884 | * \param oob_param OOB parameters for channel setting. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9885 | * \frequency should be in KHz |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 9886 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9887 | * |
| 9888 | * Accepts only. Returns error otherwise. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9889 | * Demapper value is written after scu_command START |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9890 | * because START command causes COMM_EXEC transition |
| 9891 | * from 0 to 1 which causes all registers to be |
| 9892 | * overwritten with initial value |
| 9893 | * |
| 9894 | */ |
| 9895 | |
| 9896 | /* Nyquist filter impulse response */ |
Mauro Carvalho Chehab | 7ef6675 | 2014-01-16 11:08:15 -0300 | [diff] [blame] | 9897 | #define IMPULSE_COSINE_ALPHA_0_3 {-3, -4, -1, 6, 10, 7, -5, -20, -25, -10, 29, 79, 123, 140} /*sqrt raised-cosine filter with alpha=0.3 */ |
| 9898 | #define IMPULSE_COSINE_ALPHA_0_5 { 2, 0, -2, -2, 2, 5, 2, -10, -20, -14, 20, 74, 125, 145} /*sqrt raised-cosine filter with alpha=0.5 */ |
| 9899 | #define IMPULSE_COSINE_ALPHA_RO_0_5 { 0, 0, 1, 2, 3, 0, -7, -15, -16, 0, 34, 77, 114, 128} /*full raised-cosine filter with alpha=0.5 (receiver only) */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9900 | |
| 9901 | /* Coefficients for the nyquist fitler (total: 27 taps) */ |
| 9902 | #define NYQFILTERLEN 27 |
| 9903 | |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 9904 | static int ctrl_set_oob(struct drx_demod_instance *demod, struct drxoob *oob_param) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9905 | { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9906 | int rc; |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 9907 | s32 freq = 0; /* KHz */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9908 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 9909 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 9910 | u16 i = 0; |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 9911 | bool mirror_freq_spect_oob = false; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9912 | u16 trk_filter_value = 0; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 9913 | struct drxjscu_cmd scu_cmd; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9914 | u16 set_param_parameters[3]; |
| 9915 | u16 cmd_result[2] = { 0, 0 }; |
| 9916 | s16 nyquist_coeffs[4][(NYQFILTERLEN + 1) / 2] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9917 | IMPULSE_COSINE_ALPHA_0_3, /* Target Mode 0 */ |
| 9918 | IMPULSE_COSINE_ALPHA_0_3, /* Target Mode 1 */ |
| 9919 | IMPULSE_COSINE_ALPHA_0_5, /* Target Mode 2 */ |
| 9920 | IMPULSE_COSINE_ALPHA_RO_0_5 /* Target Mode 3 */ |
| 9921 | }; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 9922 | u8 mode_val[4] = { 2, 2, 0, 1 }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9923 | u8 pfi_coeffs[4][6] = { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9924 | {DRXJ_16TO8(-92), DRXJ_16TO8(-108), DRXJ_16TO8(100)}, /* TARGET_MODE = 0: PFI_A = -23/32; PFI_B = -54/32; PFI_C = 25/32; fg = 0.5 MHz (Att=26dB) */ |
| 9925 | {DRXJ_16TO8(-64), DRXJ_16TO8(-80), DRXJ_16TO8(80)}, /* TARGET_MODE = 1: PFI_A = -16/32; PFI_B = -40/32; PFI_C = 20/32; fg = 1.0 MHz (Att=28dB) */ |
| 9926 | {DRXJ_16TO8(-80), DRXJ_16TO8(-98), DRXJ_16TO8(92)}, /* TARGET_MODE = 2, 3: PFI_A = -20/32; PFI_B = -49/32; PFI_C = 23/32; fg = 0.8 MHz (Att=25dB) */ |
| 9927 | {DRXJ_16TO8(-80), DRXJ_16TO8(-98), DRXJ_16TO8(92)} /* TARGET_MODE = 2, 3: PFI_A = -20/32; PFI_B = -49/32; PFI_C = 23/32; fg = 0.8 MHz (Att=25dB) */ |
| 9928 | }; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 9929 | u16 mode_index; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9930 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9931 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 9932 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 9933 | mirror_freq_spect_oob = ext_attr->mirror_freq_spect_oob; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9934 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9935 | /* Check parameters */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9936 | if (oob_param == NULL) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9937 | /* power off oob module */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9938 | scu_cmd.command = SCU_RAM_COMMAND_STANDARD_OOB |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9939 | | SCU_RAM_COMMAND_CMD_DEMOD_STOP; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9940 | scu_cmd.parameter_len = 0; |
| 9941 | scu_cmd.result_len = 1; |
| 9942 | scu_cmd.result = cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9943 | rc = scu_command(dev_addr, &scu_cmd); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9944 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9945 | pr_err("error %d\n", rc); |
| 9946 | goto rw_error; |
| 9947 | } |
| 9948 | rc = set_orx_nsu_aox(demod, false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9949 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9950 | pr_err("error %d\n", rc); |
| 9951 | goto rw_error; |
| 9952 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9953 | rc = drxj_dap_write_reg16(dev_addr, ORX_COMM_EXEC__A, ORX_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9954 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9955 | pr_err("error %d\n", rc); |
| 9956 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9957 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9958 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9959 | ext_attr->oob_power_on = false; |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9960 | return 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9961 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9962 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9963 | freq = oob_param->frequency; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9964 | if ((freq < 70000) || (freq > 130000)) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9965 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9966 | freq = (freq - 50000) / 50; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9967 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9968 | { |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 9969 | u16 index = 0; |
| 9970 | u16 remainder = 0; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9971 | u16 *trk_filtercfg = ext_attr->oob_trk_filter_cfg; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9972 | |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 9973 | index = (u16) ((freq - 400) / 200); |
| 9974 | remainder = (u16) ((freq - 400) % 200); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9975 | trk_filter_value = |
| 9976 | trk_filtercfg[index] - (trk_filtercfg[index] - |
| 9977 | trk_filtercfg[index + |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9978 | 1]) / 10 * remainder / |
| 9979 | 20; |
| 9980 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9981 | |
| 9982 | /*********/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9983 | /* Stop */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 9984 | /*********/ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 9985 | rc = drxj_dap_write_reg16(dev_addr, ORX_COMM_EXEC__A, ORX_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9986 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 9987 | pr_err("error %d\n", rc); |
| 9988 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9989 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9990 | scu_cmd.command = SCU_RAM_COMMAND_STANDARD_OOB |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 9991 | | SCU_RAM_COMMAND_CMD_DEMOD_STOP; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 9992 | scu_cmd.parameter_len = 0; |
| 9993 | scu_cmd.result_len = 1; |
| 9994 | scu_cmd.result = cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9995 | rc = scu_command(dev_addr, &scu_cmd); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 9996 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 9997 | pr_err("error %d\n", rc); |
| 9998 | goto rw_error; |
| 9999 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10000 | /*********/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10001 | /* Reset */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10002 | /*********/ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10003 | scu_cmd.command = SCU_RAM_COMMAND_STANDARD_OOB |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10004 | | SCU_RAM_COMMAND_CMD_DEMOD_RESET; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10005 | scu_cmd.parameter_len = 0; |
| 10006 | scu_cmd.result_len = 1; |
| 10007 | scu_cmd.result = cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10008 | rc = scu_command(dev_addr, &scu_cmd); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10009 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10010 | pr_err("error %d\n", rc); |
| 10011 | goto rw_error; |
| 10012 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10013 | /***********/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10014 | /* SET_ENV */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10015 | /***********/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10016 | /* set frequency, spectrum inversion and data rate */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10017 | scu_cmd.command = SCU_RAM_COMMAND_STANDARD_OOB |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10018 | | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10019 | scu_cmd.parameter_len = 3; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10020 | /* 1-data rate;2-frequency */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10021 | switch (oob_param->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10022 | case DRX_OOB_MODE_A: |
| 10023 | if ( |
| 10024 | /* signal is transmitted inverted */ |
Mauro Carvalho Chehab | 87bf0e5 | 2014-03-09 09:36:59 -0300 | [diff] [blame] | 10025 | ((oob_param->spectrum_inverted == true) && |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10026 | /* and tuner is not mirroring the signal */ |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 10027 | (!mirror_freq_spect_oob)) | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10028 | /* or */ |
| 10029 | /* signal is transmitted noninverted */ |
Mauro Carvalho Chehab | 87bf0e5 | 2014-03-09 09:36:59 -0300 | [diff] [blame] | 10030 | ((oob_param->spectrum_inverted == false) && |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10031 | /* and tuner is mirroring the signal */ |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 10032 | (mirror_freq_spect_oob)) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10033 | ) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10034 | set_param_parameters[0] = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10035 | SCU_RAM_ORX_RF_RX_DATA_RATE_2048KBPS_INVSPEC; |
| 10036 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10037 | set_param_parameters[0] = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10038 | SCU_RAM_ORX_RF_RX_DATA_RATE_2048KBPS_REGSPEC; |
| 10039 | break; |
| 10040 | case DRX_OOB_MODE_B_GRADE_A: |
| 10041 | if ( |
| 10042 | /* signal is transmitted inverted */ |
Mauro Carvalho Chehab | 87bf0e5 | 2014-03-09 09:36:59 -0300 | [diff] [blame] | 10043 | ((oob_param->spectrum_inverted == true) && |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10044 | /* and tuner is not mirroring the signal */ |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 10045 | (!mirror_freq_spect_oob)) | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10046 | /* or */ |
| 10047 | /* signal is transmitted noninverted */ |
Mauro Carvalho Chehab | 87bf0e5 | 2014-03-09 09:36:59 -0300 | [diff] [blame] | 10048 | ((oob_param->spectrum_inverted == false) && |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10049 | /* and tuner is mirroring the signal */ |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 10050 | (mirror_freq_spect_oob)) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10051 | ) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10052 | set_param_parameters[0] = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10053 | SCU_RAM_ORX_RF_RX_DATA_RATE_1544KBPS_INVSPEC; |
| 10054 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10055 | set_param_parameters[0] = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10056 | SCU_RAM_ORX_RF_RX_DATA_RATE_1544KBPS_REGSPEC; |
| 10057 | break; |
| 10058 | case DRX_OOB_MODE_B_GRADE_B: |
| 10059 | default: |
| 10060 | if ( |
| 10061 | /* signal is transmitted inverted */ |
Mauro Carvalho Chehab | 87bf0e5 | 2014-03-09 09:36:59 -0300 | [diff] [blame] | 10062 | ((oob_param->spectrum_inverted == true) && |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10063 | /* and tuner is not mirroring the signal */ |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 10064 | (!mirror_freq_spect_oob)) | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10065 | /* or */ |
| 10066 | /* signal is transmitted noninverted */ |
Mauro Carvalho Chehab | 87bf0e5 | 2014-03-09 09:36:59 -0300 | [diff] [blame] | 10067 | ((oob_param->spectrum_inverted == false) && |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10068 | /* and tuner is mirroring the signal */ |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 10069 | (mirror_freq_spect_oob)) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10070 | ) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10071 | set_param_parameters[0] = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10072 | SCU_RAM_ORX_RF_RX_DATA_RATE_3088KBPS_INVSPEC; |
| 10073 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10074 | set_param_parameters[0] = |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10075 | SCU_RAM_ORX_RF_RX_DATA_RATE_3088KBPS_REGSPEC; |
| 10076 | break; |
| 10077 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10078 | set_param_parameters[1] = (u16) (freq & 0xFFFF); |
| 10079 | set_param_parameters[2] = trk_filter_value; |
| 10080 | scu_cmd.parameter = set_param_parameters; |
| 10081 | scu_cmd.result_len = 1; |
| 10082 | scu_cmd.result = cmd_result; |
| 10083 | mode_index = mode_val[(set_param_parameters[0] & 0xC0) >> 6]; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10084 | rc = scu_command(dev_addr, &scu_cmd); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10085 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10086 | pr_err("error %d\n", rc); |
| 10087 | goto rw_error; |
| 10088 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10089 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10090 | rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0xFABA, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10091 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10092 | pr_err("error %d\n", rc); |
| 10093 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10094 | } /* Write magic word to enable pdr reg write */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10095 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_OOB_CRX_CFG__A, OOB_CRX_DRIVE_STRENGTH << SIO_PDR_OOB_CRX_CFG_DRIVE__B | 0x03 << SIO_PDR_OOB_CRX_CFG_MODE__B, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10096 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10097 | pr_err("error %d\n", rc); |
| 10098 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10099 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10100 | rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_OOB_DRX_CFG__A, OOB_DRX_DRIVE_STRENGTH << SIO_PDR_OOB_DRX_CFG_DRIVE__B | 0x03 << SIO_PDR_OOB_DRX_CFG_MODE__B, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10101 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10102 | pr_err("error %d\n", rc); |
| 10103 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10104 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10105 | rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10106 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10107 | pr_err("error %d\n", rc); |
| 10108 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10109 | } /* Write magic word to disable pdr reg write */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10110 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10111 | rc = drxj_dap_write_reg16(dev_addr, ORX_TOP_COMM_KEY__A, 0, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10112 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10113 | pr_err("error %d\n", rc); |
| 10114 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10115 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10116 | rc = drxj_dap_write_reg16(dev_addr, ORX_FWP_AAG_LEN_W__A, 16000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10117 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10118 | pr_err("error %d\n", rc); |
| 10119 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10120 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10121 | rc = drxj_dap_write_reg16(dev_addr, ORX_FWP_AAG_THR_W__A, 40, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10122 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10123 | pr_err("error %d\n", rc); |
| 10124 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10125 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10126 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10127 | /* ddc */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10128 | rc = drxj_dap_write_reg16(dev_addr, ORX_DDC_OFO_SET_W__A, ORX_DDC_OFO_SET_W__PRE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10129 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10130 | pr_err("error %d\n", rc); |
| 10131 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10132 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10133 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10134 | /* nsu */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10135 | rc = drxj_dap_write_reg16(dev_addr, ORX_NSU_AOX_LOPOW_W__A, ext_attr->oob_lo_pow, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10136 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10137 | pr_err("error %d\n", rc); |
| 10138 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10139 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10140 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10141 | /* initialization for target mode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10142 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TARGET_MODE__A, SCU_RAM_ORX_TARGET_MODE_2048KBPS_SQRT, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10143 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10144 | pr_err("error %d\n", rc); |
| 10145 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10146 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10147 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FREQ_GAIN_CORR__A, SCU_RAM_ORX_FREQ_GAIN_CORR_2048KBPS, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10148 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10149 | pr_err("error %d\n", rc); |
| 10150 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10151 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10152 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10153 | /* Reset bits for timing and freq. recovery */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10154 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_RST_CPH__A, 0x0001, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10155 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10156 | pr_err("error %d\n", rc); |
| 10157 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10158 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10159 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_RST_CTI__A, 0x0002, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10160 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10161 | pr_err("error %d\n", rc); |
| 10162 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10163 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10164 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_RST_KRN__A, 0x0004, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10165 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10166 | pr_err("error %d\n", rc); |
| 10167 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10168 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10169 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_RST_KRP__A, 0x0008, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10170 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10171 | pr_err("error %d\n", rc); |
| 10172 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10173 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10174 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10175 | /* AGN_LOCK = {2048>>3, -2048, 8, -8, 0, 1}; */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10176 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_AGN_LOCK_TH__A, 2048 >> 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10177 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10178 | pr_err("error %d\n", rc); |
| 10179 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10180 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10181 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_AGN_LOCK_TOTH__A, (u16)(-2048), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10182 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10183 | pr_err("error %d\n", rc); |
| 10184 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10185 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10186 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_AGN_ONLOCK_TTH__A, 8, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10187 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10188 | pr_err("error %d\n", rc); |
| 10189 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10190 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10191 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_AGN_UNLOCK_TTH__A, (u16)(-8), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10192 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10193 | pr_err("error %d\n", rc); |
| 10194 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10195 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10196 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_AGN_LOCK_MASK__A, 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10197 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10198 | pr_err("error %d\n", rc); |
| 10199 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10200 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10201 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10202 | /* DGN_LOCK = {10, -2048, 8, -8, 0, 1<<1}; */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10203 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_DGN_LOCK_TH__A, 10, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10204 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10205 | pr_err("error %d\n", rc); |
| 10206 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10207 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10208 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_DGN_LOCK_TOTH__A, (u16)(-2048), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10209 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10210 | pr_err("error %d\n", rc); |
| 10211 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10212 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10213 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_DGN_ONLOCK_TTH__A, 8, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10214 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10215 | pr_err("error %d\n", rc); |
| 10216 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10217 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10218 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_DGN_UNLOCK_TTH__A, (u16)(-8), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10219 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10220 | pr_err("error %d\n", rc); |
| 10221 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10222 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10223 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_DGN_LOCK_MASK__A, 1 << 1, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10224 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10225 | pr_err("error %d\n", rc); |
| 10226 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10227 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10228 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10229 | /* FRQ_LOCK = {15,-2048, 8, -8, 0, 1<<2}; */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10230 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FRQ_LOCK_TH__A, 17, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10231 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10232 | pr_err("error %d\n", rc); |
| 10233 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10234 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10235 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FRQ_LOCK_TOTH__A, (u16)(-2048), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10236 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10237 | pr_err("error %d\n", rc); |
| 10238 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10239 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10240 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FRQ_ONLOCK_TTH__A, 8, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10241 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10242 | pr_err("error %d\n", rc); |
| 10243 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10244 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10245 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FRQ_UNLOCK_TTH__A, (u16)(-8), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10246 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10247 | pr_err("error %d\n", rc); |
| 10248 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10249 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10250 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FRQ_LOCK_MASK__A, 1 << 2, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10251 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10252 | pr_err("error %d\n", rc); |
| 10253 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10254 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10255 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10256 | /* PHA_LOCK = {5000, -2048, 8, -8, 0, 1<<3}; */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10257 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_PHA_LOCK_TH__A, 3000, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10258 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10259 | pr_err("error %d\n", rc); |
| 10260 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10261 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10262 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_PHA_LOCK_TOTH__A, (u16)(-2048), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10263 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10264 | pr_err("error %d\n", rc); |
| 10265 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10266 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10267 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_PHA_ONLOCK_TTH__A, 8, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10268 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10269 | pr_err("error %d\n", rc); |
| 10270 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10271 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10272 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_PHA_UNLOCK_TTH__A, (u16)(-8), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10273 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10274 | pr_err("error %d\n", rc); |
| 10275 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10276 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10277 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_PHA_LOCK_MASK__A, 1 << 3, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10278 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10279 | pr_err("error %d\n", rc); |
| 10280 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10281 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10282 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10283 | /* TIM_LOCK = {300, -2048, 8, -8, 0, 1<<4}; */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10284 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TIM_LOCK_TH__A, 400, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10285 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10286 | pr_err("error %d\n", rc); |
| 10287 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10288 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10289 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TIM_LOCK_TOTH__A, (u16)(-2048), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10290 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10291 | pr_err("error %d\n", rc); |
| 10292 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10293 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10294 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TIM_ONLOCK_TTH__A, 8, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10295 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10296 | pr_err("error %d\n", rc); |
| 10297 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10298 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10299 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TIM_UNLOCK_TTH__A, (u16)(-8), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10300 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10301 | pr_err("error %d\n", rc); |
| 10302 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10303 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10304 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TIM_LOCK_MASK__A, 1 << 4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10305 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10306 | pr_err("error %d\n", rc); |
| 10307 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10308 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10309 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10310 | /* EQU_LOCK = {20, -2048, 8, -8, 0, 1<<5}; */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10311 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_EQU_LOCK_TH__A, 20, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10312 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10313 | pr_err("error %d\n", rc); |
| 10314 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10315 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10316 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_EQU_LOCK_TOTH__A, (u16)(-2048), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10317 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10318 | pr_err("error %d\n", rc); |
| 10319 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10320 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10321 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_EQU_ONLOCK_TTH__A, 4, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10322 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10323 | pr_err("error %d\n", rc); |
| 10324 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10325 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10326 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_EQU_UNLOCK_TTH__A, (u16)(-4), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10327 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10328 | pr_err("error %d\n", rc); |
| 10329 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10330 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10331 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_EQU_LOCK_MASK__A, 1 << 5, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10332 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10333 | pr_err("error %d\n", rc); |
| 10334 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10335 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10336 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10337 | /* PRE-Filter coefficients (PFI) */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10338 | rc = drxdap_fasi_write_block(dev_addr, ORX_FWP_PFI_A_W__A, sizeof(pfi_coeffs[mode_index]), ((u8 *)pfi_coeffs[mode_index]), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10339 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10340 | pr_err("error %d\n", rc); |
| 10341 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10342 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10343 | rc = drxj_dap_write_reg16(dev_addr, ORX_TOP_MDE_W__A, mode_index, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10344 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10345 | pr_err("error %d\n", rc); |
| 10346 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10347 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10348 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10349 | /* NYQUIST-Filter coefficients (NYQ) */ |
| 10350 | for (i = 0; i < (NYQFILTERLEN + 1) / 2; i++) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10351 | rc = drxj_dap_write_reg16(dev_addr, ORX_FWP_NYQ_ADR_W__A, i, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10352 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10353 | pr_err("error %d\n", rc); |
| 10354 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10355 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10356 | rc = drxj_dap_write_reg16(dev_addr, ORX_FWP_NYQ_COF_RW__A, nyquist_coeffs[mode_index][i], 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10357 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10358 | pr_err("error %d\n", rc); |
| 10359 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10360 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10361 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10362 | rc = drxj_dap_write_reg16(dev_addr, ORX_FWP_NYQ_ADR_W__A, 31, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10363 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10364 | pr_err("error %d\n", rc); |
| 10365 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10366 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10367 | rc = drxj_dap_write_reg16(dev_addr, ORX_COMM_EXEC__A, ORX_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10368 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10369 | pr_err("error %d\n", rc); |
| 10370 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10371 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10372 | /*********/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10373 | /* Start */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10374 | /*********/ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10375 | scu_cmd.command = SCU_RAM_COMMAND_STANDARD_OOB |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10376 | | SCU_RAM_COMMAND_CMD_DEMOD_START; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10377 | scu_cmd.parameter_len = 0; |
| 10378 | scu_cmd.result_len = 1; |
| 10379 | scu_cmd.result = cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10380 | rc = scu_command(dev_addr, &scu_cmd); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10381 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10382 | pr_err("error %d\n", rc); |
| 10383 | goto rw_error; |
| 10384 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10385 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10386 | rc = set_orx_nsu_aox(demod, true); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10387 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10388 | pr_err("error %d\n", rc); |
| 10389 | goto rw_error; |
| 10390 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10391 | rc = drxj_dap_write_reg16(dev_addr, ORX_NSU_AOX_STHR_W__A, ext_attr->oob_pre_saw, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10392 | if (rc != 0) { |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10393 | pr_err("error %d\n", rc); |
| 10394 | goto rw_error; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10395 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10396 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10397 | ext_attr->oob_power_on = true; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10398 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10399 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10400 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10401 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10402 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10403 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10404 | /*============================================================================*/ |
| 10405 | /*== END OOB DATAPATH FUNCTIONS ==*/ |
| 10406 | /*============================================================================*/ |
| 10407 | |
| 10408 | /*============================================================================= |
| 10409 | ===== MC command related functions ========================================== |
| 10410 | ===========================================================================*/ |
| 10411 | |
| 10412 | /*============================================================================= |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10413 | ===== ctrl_set_channel() ========================================================== |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10414 | ===========================================================================*/ |
| 10415 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10416 | * \fn int ctrl_set_channel() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10417 | * \brief Select a new transmission channel. |
| 10418 | * \param demod instance of demod. |
| 10419 | * \param channel Pointer to channel data. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 10420 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10421 | * |
| 10422 | * In case the tuner module is not used and in case of NTSC/FM the pogrammer |
| 10423 | * must tune the tuner to the centre frequency of the NTSC/FM channel. |
| 10424 | * |
| 10425 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 10426 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 10427 | ctrl_set_channel(struct drx_demod_instance *demod, struct drx_channel *channel) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10428 | { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10429 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10430 | s32 tuner_freq_offset = 0; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 10431 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10432 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 10433 | enum drx_standard standard = DRX_STANDARD_UNKNOWN; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10434 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10435 | u32 min_symbol_rate = 0; |
| 10436 | u32 max_symbol_rate = 0; |
| 10437 | int bandwidth_temp = 0; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10438 | int bandwidth = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10439 | #endif |
| 10440 | /*== check arguments ======================================================*/ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10441 | if ((demod == NULL) || (channel == NULL)) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10442 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10443 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10444 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 10445 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10446 | standard = ext_attr->standard; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10447 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10448 | /* check valid standards */ |
| 10449 | switch (standard) { |
| 10450 | case DRX_STANDARD_8VSB: |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10451 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10452 | case DRX_STANDARD_ITU_A: |
| 10453 | case DRX_STANDARD_ITU_B: |
| 10454 | case DRX_STANDARD_ITU_C: |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10455 | #endif /* DRXJ_VSB_ONLY */ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10456 | break; |
| 10457 | case DRX_STANDARD_UNKNOWN: |
| 10458 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10459 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10460 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10461 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10462 | /* check bandwidth QAM annex B, NTSC and 8VSB */ |
| 10463 | if ((standard == DRX_STANDARD_ITU_B) || |
| 10464 | (standard == DRX_STANDARD_8VSB) || |
| 10465 | (standard == DRX_STANDARD_NTSC)) { |
| 10466 | switch (channel->bandwidth) { |
| 10467 | case DRX_BANDWIDTH_6MHZ: |
| 10468 | case DRX_BANDWIDTH_UNKNOWN: /* fall through */ |
| 10469 | channel->bandwidth = DRX_BANDWIDTH_6MHZ; |
| 10470 | break; |
| 10471 | case DRX_BANDWIDTH_8MHZ: /* fall through */ |
| 10472 | case DRX_BANDWIDTH_7MHZ: /* fall through */ |
| 10473 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10474 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10475 | } |
| 10476 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10477 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10478 | /* For QAM annex A and annex C: |
| 10479 | -check symbolrate and constellation |
| 10480 | -derive bandwidth from symbolrate (input bandwidth is ignored) |
| 10481 | */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10482 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10483 | if ((standard == DRX_STANDARD_ITU_A) || |
| 10484 | (standard == DRX_STANDARD_ITU_C)) { |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 10485 | struct drxuio_cfg uio_cfg = { DRX_UIO1, DRX_UIO_MODE_FIRMWARE_SAW }; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10486 | int bw_rolloff_factor = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10487 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10488 | bw_rolloff_factor = (standard == DRX_STANDARD_ITU_A) ? 115 : 113; |
| 10489 | min_symbol_rate = DRXJ_QAM_SYMBOLRATE_MIN; |
| 10490 | max_symbol_rate = DRXJ_QAM_SYMBOLRATE_MAX; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10491 | /* config SMA_TX pin to SAW switch mode */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10492 | rc = ctrl_set_uio_cfg(demod, &uio_cfg); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10493 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10494 | pr_err("error %d\n", rc); |
| 10495 | goto rw_error; |
| 10496 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10497 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10498 | if (channel->symbolrate < min_symbol_rate || |
| 10499 | channel->symbolrate > max_symbol_rate) { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10500 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10501 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10502 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10503 | switch (channel->constellation) { |
| 10504 | case DRX_CONSTELLATION_QAM16: /* fall through */ |
| 10505 | case DRX_CONSTELLATION_QAM32: /* fall through */ |
| 10506 | case DRX_CONSTELLATION_QAM64: /* fall through */ |
| 10507 | case DRX_CONSTELLATION_QAM128: /* fall through */ |
| 10508 | case DRX_CONSTELLATION_QAM256: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10509 | bandwidth_temp = channel->symbolrate * bw_rolloff_factor; |
| 10510 | bandwidth = bandwidth_temp / 100; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10511 | |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10512 | if ((bandwidth_temp % 100) >= 50) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10513 | bandwidth++; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10514 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10515 | if (bandwidth <= 6100000) { |
| 10516 | channel->bandwidth = DRX_BANDWIDTH_6MHZ; |
| 10517 | } else if ((bandwidth > 6100000) |
| 10518 | && (bandwidth <= 7100000)) { |
| 10519 | channel->bandwidth = DRX_BANDWIDTH_7MHZ; |
| 10520 | } else if (bandwidth > 7100000) { |
| 10521 | channel->bandwidth = DRX_BANDWIDTH_8MHZ; |
| 10522 | } |
| 10523 | break; |
| 10524 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10525 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10526 | } |
| 10527 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10528 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10529 | /* For QAM annex B: |
| 10530 | -check constellation |
| 10531 | */ |
| 10532 | if (standard == DRX_STANDARD_ITU_B) { |
| 10533 | switch (channel->constellation) { |
| 10534 | case DRX_CONSTELLATION_AUTO: |
| 10535 | case DRX_CONSTELLATION_QAM256: |
| 10536 | case DRX_CONSTELLATION_QAM64: |
| 10537 | break; |
| 10538 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10539 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10540 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10541 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10542 | switch (channel->interleavemode) { |
| 10543 | case DRX_INTERLEAVEMODE_I128_J1: |
| 10544 | case DRX_INTERLEAVEMODE_I128_J1_V2: |
| 10545 | case DRX_INTERLEAVEMODE_I128_J2: |
| 10546 | case DRX_INTERLEAVEMODE_I64_J2: |
| 10547 | case DRX_INTERLEAVEMODE_I128_J3: |
| 10548 | case DRX_INTERLEAVEMODE_I32_J4: |
| 10549 | case DRX_INTERLEAVEMODE_I128_J4: |
| 10550 | case DRX_INTERLEAVEMODE_I16_J8: |
| 10551 | case DRX_INTERLEAVEMODE_I128_J5: |
| 10552 | case DRX_INTERLEAVEMODE_I8_J16: |
| 10553 | case DRX_INTERLEAVEMODE_I128_J6: |
| 10554 | case DRX_INTERLEAVEMODE_I128_J7: |
| 10555 | case DRX_INTERLEAVEMODE_I128_J8: |
| 10556 | case DRX_INTERLEAVEMODE_I12_J17: |
| 10557 | case DRX_INTERLEAVEMODE_I5_J4: |
| 10558 | case DRX_INTERLEAVEMODE_B52_M240: |
| 10559 | case DRX_INTERLEAVEMODE_B52_M720: |
| 10560 | case DRX_INTERLEAVEMODE_UNKNOWN: |
| 10561 | case DRX_INTERLEAVEMODE_AUTO: |
| 10562 | break; |
| 10563 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10564 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10565 | } |
| 10566 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10567 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10568 | if ((ext_attr->uio_sma_tx_mode) == DRX_UIO_MODE_FIRMWARE_SAW) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10569 | /* SAW SW, user UIO is used for switchable SAW */ |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 10570 | struct drxuio_data uio1 = { DRX_UIO1, false }; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10571 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10572 | switch (channel->bandwidth) { |
| 10573 | case DRX_BANDWIDTH_8MHZ: |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 10574 | uio1.value = true; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10575 | break; |
| 10576 | case DRX_BANDWIDTH_7MHZ: |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 10577 | uio1.value = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10578 | break; |
| 10579 | case DRX_BANDWIDTH_6MHZ: |
Mauro Carvalho Chehab | 73f7065 | 2012-03-20 00:59:03 -0300 | [diff] [blame] | 10580 | uio1.value = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10581 | break; |
| 10582 | case DRX_BANDWIDTH_UNKNOWN: |
| 10583 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10584 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10585 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10586 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10587 | rc = ctrl_uio_write(demod, &uio1); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10588 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10589 | pr_err("error %d\n", rc); |
| 10590 | goto rw_error; |
| 10591 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10592 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10593 | #endif /* DRXJ_VSB_ONLY */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10594 | rc = drxj_dap_write_reg16(dev_addr, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10595 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10596 | pr_err("error %d\n", rc); |
| 10597 | goto rw_error; |
| 10598 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10599 | |
Mauro Carvalho Chehab | a6530ce5 | 2014-01-26 14:54:08 -0300 | [diff] [blame] | 10600 | tuner_freq_offset = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10601 | |
| 10602 | /*== Setup demod for specific standard ====================================*/ |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10603 | switch (standard) { |
| 10604 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10605 | if (channel->mirror == DRX_MIRROR_AUTO) |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10606 | ext_attr->mirror = DRX_MIRROR_NO; |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10607 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10608 | ext_attr->mirror = channel->mirror; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10609 | rc = set_vsb(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10610 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10611 | pr_err("error %d\n", rc); |
| 10612 | goto rw_error; |
| 10613 | } |
| 10614 | rc = set_frequency(demod, channel, tuner_freq_offset); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10615 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10616 | pr_err("error %d\n", rc); |
| 10617 | goto rw_error; |
| 10618 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10619 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10620 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10621 | case DRX_STANDARD_ITU_A: /* fallthrough */ |
| 10622 | case DRX_STANDARD_ITU_B: /* fallthrough */ |
| 10623 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | e33f2193 | 2014-01-17 06:47:04 -0300 | [diff] [blame] | 10624 | rc = set_qam_channel(demod, channel, tuner_freq_offset); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10625 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10626 | pr_err("error %d\n", rc); |
| 10627 | goto rw_error; |
| 10628 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10629 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10630 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10631 | case DRX_STANDARD_UNKNOWN: |
| 10632 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10633 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10634 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10635 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10636 | /* flag the packet error counter reset */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10637 | ext_attr->reset_pkt_err_acc = true; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10638 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10639 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10640 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10641 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10642 | } |
| 10643 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10644 | /*============================================================================= |
| 10645 | ===== SigQuality() ========================================================== |
| 10646 | ===========================================================================*/ |
| 10647 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10648 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10649 | * \fn int ctrl_sig_quality() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10650 | * \brief Retreive signal quality form device. |
| 10651 | * \param devmod Pointer to demodulator instance. |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10652 | * \param sig_quality Pointer to signal quality data. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 10653 | * \return int. |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10654 | * \retval 0 sig_quality contains valid data. |
| 10655 | * \retval -EINVAL sig_quality is NULL. |
| 10656 | * \retval -EIO Erroneous data, sig_quality contains invalid data. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10657 | |
| 10658 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 10659 | static int |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10660 | ctrl_sig_quality(struct drx_demod_instance *demod, |
| 10661 | enum drx_lock_status lock_status) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10662 | { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10663 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
| 10664 | struct drxj_data *ext_attr = demod->my_ext_attr; |
| 10665 | struct drx39xxj_state *state = dev_addr->user_data; |
| 10666 | struct dtv_frontend_properties *p = &state->frontend.dtv_property_cache; |
| 10667 | enum drx_standard standard = ext_attr->standard; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10668 | int rc; |
Mauro Carvalho Chehab | d591590 | 2014-03-10 08:22:34 -0300 | [diff] [blame] | 10669 | u32 ber, cnt, err, pkt; |
| 10670 | u16 mer, strength; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10671 | |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10672 | rc = get_sig_strength(demod, &strength); |
| 10673 | if (rc < 0) { |
| 10674 | pr_err("error getting signal strength %d\n", rc); |
| 10675 | p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 10676 | } else { |
| 10677 | p->strength.stat[0].scale = FE_SCALE_RELATIVE; |
| 10678 | p->strength.stat[0].uvalue = 65535UL * strength/ 100; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10679 | } |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10680 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10681 | switch (standard) { |
| 10682 | case DRX_STANDARD_8VSB: |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10683 | #ifdef DRXJ_SIGNAL_ACCUM_ERR |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10684 | rc = get_acc_pkt_err(demod, &pkt); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10685 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10686 | pr_err("error %d\n", rc); |
| 10687 | goto rw_error; |
| 10688 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10689 | #endif |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10690 | if (lock_status != DRXJ_DEMOD_LOCK && lock_status != DRX_LOCKED) { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10691 | p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10692 | p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 10693 | p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10694 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 10695 | p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10696 | p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 10697 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10698 | } else { |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 10699 | rc = get_vsb_post_rs_pck_err(dev_addr, &err, &pkt); |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10700 | if (rc != 0) { |
| 10701 | pr_err("error %d getting UCB\n", rc); |
| 10702 | p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 10703 | } else { |
| 10704 | p->block_error.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 10705 | p->block_error.stat[0].uvalue += err; |
| 10706 | p->block_count.stat[0].scale = FE_SCALE_COUNTER; |
| 10707 | p->block_count.stat[0].uvalue += pkt; |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10708 | } |
| 10709 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10710 | /* PostViterbi is compute in steps of 10^(-6) */ |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 10711 | rc = get_vs_bpre_viterbi_ber(dev_addr, &ber, &cnt); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10712 | if (rc != 0) { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10713 | pr_err("error %d getting pre-ber\n", rc); |
| 10714 | p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 10715 | } else { |
| 10716 | p->pre_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 10717 | p->pre_bit_error.stat[0].uvalue += ber; |
| 10718 | p->pre_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 10719 | p->pre_bit_count.stat[0].uvalue += cnt; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10720 | } |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10721 | |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 10722 | rc = get_vs_bpost_viterbi_ber(dev_addr, &ber, &cnt); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10723 | if (rc != 0) { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10724 | pr_err("error %d getting post-ber\n", rc); |
| 10725 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 10726 | } else { |
| 10727 | p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 10728 | p->post_bit_error.stat[0].uvalue += ber; |
| 10729 | p->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 10730 | p->post_bit_count.stat[0].uvalue += cnt; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10731 | } |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10732 | rc = get_vsbmer(dev_addr, &mer); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10733 | if (rc != 0) { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10734 | pr_err("error %d getting MER\n", rc); |
| 10735 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 10736 | } else { |
| 10737 | p->cnr.stat[0].svalue = mer * 100; |
| 10738 | p->cnr.stat[0].scale = FE_SCALE_DECIBEL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10739 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10740 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10741 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10742 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10743 | case DRX_STANDARD_ITU_A: |
| 10744 | case DRX_STANDARD_ITU_B: |
| 10745 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 10746 | rc = ctrl_get_qam_sig_quality(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10747 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10748 | pr_err("error %d\n", rc); |
| 10749 | goto rw_error; |
| 10750 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10751 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10752 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10753 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10754 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10755 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10756 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10757 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10758 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10759 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10760 | } |
| 10761 | |
| 10762 | /*============================================================================*/ |
| 10763 | |
| 10764 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10765 | * \fn int ctrl_lock_status() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10766 | * \brief Retreive lock status . |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10767 | * \param dev_addr Pointer to demodulator device address. |
| 10768 | * \param lock_stat Pointer to lock status structure. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 10769 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10770 | * |
| 10771 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 10772 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 10773 | ctrl_lock_status(struct drx_demod_instance *demod, enum drx_lock_status *lock_stat) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10774 | { |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 10775 | enum drx_standard standard = DRX_STANDARD_UNKNOWN; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 10776 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10777 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 10778 | struct drxjscu_cmd cmd_scu = { /* command */ 0, |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10779 | /* parameter_len */ 0, |
| 10780 | /* result_len */ 0, |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10781 | /* *parameter */ NULL, |
| 10782 | /* *result */ NULL |
| 10783 | }; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10784 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10785 | u16 cmd_result[2] = { 0, 0 }; |
| 10786 | u16 demod_lock = SCU_RAM_PARAM_1_RES_DEMOD_GET_LOCK_DEMOD_LOCKED; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10787 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10788 | /* check arguments */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10789 | if ((demod == NULL) || (lock_stat == NULL)) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10790 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10791 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10792 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 10793 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10794 | standard = ext_attr->standard; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10795 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10796 | *lock_stat = DRX_NOT_LOCKED; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10797 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10798 | /* define the SCU command code */ |
| 10799 | switch (standard) { |
| 10800 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10801 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_VSB | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10802 | SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10803 | demod_lock |= 0x6; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10804 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10805 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10806 | case DRX_STANDARD_ITU_A: |
| 10807 | case DRX_STANDARD_ITU_B: |
| 10808 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10809 | cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10810 | SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK; |
| 10811 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10812 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10813 | case DRX_STANDARD_UNKNOWN: /* fallthrough */ |
| 10814 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10815 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10816 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10817 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10818 | /* define the SCU command paramters and execute the command */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10819 | cmd_scu.parameter_len = 0; |
| 10820 | cmd_scu.result_len = 2; |
| 10821 | cmd_scu.parameter = NULL; |
| 10822 | cmd_scu.result = cmd_result; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10823 | rc = scu_command(dev_addr, &cmd_scu); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10824 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10825 | pr_err("error %d\n", rc); |
| 10826 | goto rw_error; |
| 10827 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10828 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10829 | /* set the lock status */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10830 | if (cmd_scu.result[1] < demod_lock) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10831 | /* 0x0000 NOT LOCKED */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10832 | *lock_stat = DRX_NOT_LOCKED; |
| 10833 | } else if (cmd_scu.result[1] < SCU_RAM_PARAM_1_RES_DEMOD_GET_LOCK_LOCKED) { |
| 10834 | *lock_stat = DRXJ_DEMOD_LOCK; |
| 10835 | } else if (cmd_scu.result[1] < |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10836 | SCU_RAM_PARAM_1_RES_DEMOD_GET_LOCK_NEVER_LOCK) { |
| 10837 | /* 0x8000 DEMOD + FEC LOCKED (system lock) */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10838 | *lock_stat = DRX_LOCKED; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10839 | } else { |
| 10840 | /* 0xC000 NEVER LOCKED */ |
| 10841 | /* (system will never be able to lock to the signal) */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10842 | *lock_stat = DRX_NEVER_LOCK; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10843 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10844 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10845 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10846 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10847 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10848 | } |
| 10849 | |
| 10850 | /*============================================================================*/ |
| 10851 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10852 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10853 | * \fn int ctrl_set_standard() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10854 | * \brief Set modulation standard to be used. |
| 10855 | * \param standard Modulation standard. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 10856 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10857 | * |
| 10858 | * Setup stuff for the desired demodulation standard. |
| 10859 | * Disable and power down the previous selected demodulation standard |
| 10860 | * |
| 10861 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 10862 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 10863 | ctrl_set_standard(struct drx_demod_instance *demod, enum drx_standard *standard) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10864 | { |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 10865 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10866 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10867 | enum drx_standard prev_standard; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10868 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10869 | /* check arguments */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10870 | if ((standard == NULL) || (demod == NULL)) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10871 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10872 | |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 10873 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10874 | prev_standard = ext_attr->standard; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10875 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10876 | /* |
| 10877 | Stop and power down previous standard |
| 10878 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10879 | switch (prev_standard) { |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10880 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10881 | case DRX_STANDARD_ITU_A: /* fallthrough */ |
| 10882 | case DRX_STANDARD_ITU_B: /* fallthrough */ |
| 10883 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10884 | rc = power_down_qam(demod, false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10885 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10886 | pr_err("error %d\n", rc); |
| 10887 | goto rw_error; |
| 10888 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10889 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10890 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10891 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10892 | rc = power_down_vsb(demod, false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10893 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10894 | pr_err("error %d\n", rc); |
| 10895 | goto rw_error; |
| 10896 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10897 | break; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10898 | case DRX_STANDARD_UNKNOWN: |
| 10899 | /* Do nothing */ |
| 10900 | break; |
| 10901 | case DRX_STANDARD_AUTO: /* fallthrough */ |
| 10902 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10903 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10904 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10905 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10906 | /* |
| 10907 | Initialize channel independent registers |
| 10908 | Power up new standard |
| 10909 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10910 | ext_attr->standard = *standard; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10911 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10912 | switch (*standard) { |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10913 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10914 | case DRX_STANDARD_ITU_A: /* fallthrough */ |
| 10915 | case DRX_STANDARD_ITU_B: /* fallthrough */ |
| 10916 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10917 | do { |
| 10918 | u16 dummy; |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 10919 | rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, SCU_RAM_VERSION_HI__A, &dummy, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10920 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10921 | pr_err("error %d\n", rc); |
| 10922 | goto rw_error; |
| 10923 | } |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 10924 | } while (0); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10925 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10926 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10927 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10928 | rc = set_vsb_leak_n_gain(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10929 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 10930 | pr_err("error %d\n", rc); |
| 10931 | goto rw_error; |
| 10932 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10933 | break; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10934 | default: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10935 | ext_attr->standard = DRX_STANDARD_UNKNOWN; |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10936 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10937 | break; |
| 10938 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10939 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10940 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10941 | rw_error: |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 10942 | /* Don't know what the standard is now ... try again */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 10943 | ext_attr->standard = DRX_STANDARD_UNKNOWN; |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 10944 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10945 | } |
| 10946 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 10947 | /*============================================================================*/ |
| 10948 | |
Mauro Carvalho Chehab | aafdbaa | 2014-01-19 10:31:47 -0300 | [diff] [blame] | 10949 | static void drxj_reset_mode(struct drxj_data *ext_attr) |
| 10950 | { |
| 10951 | /* Initialize default AFE configuartion for QAM */ |
| 10952 | if (ext_attr->has_lna) { |
| 10953 | /* IF AGC off, PGA active */ |
| 10954 | #ifndef DRXJ_VSB_ONLY |
| 10955 | ext_attr->qam_if_agc_cfg.standard = DRX_STANDARD_ITU_B; |
| 10956 | ext_attr->qam_if_agc_cfg.ctrl_mode = DRX_AGC_CTRL_OFF; |
| 10957 | ext_attr->qam_pga_cfg = 140 + (11 * 13); |
| 10958 | #endif |
| 10959 | ext_attr->vsb_if_agc_cfg.standard = DRX_STANDARD_8VSB; |
| 10960 | ext_attr->vsb_if_agc_cfg.ctrl_mode = DRX_AGC_CTRL_OFF; |
| 10961 | ext_attr->vsb_pga_cfg = 140 + (11 * 13); |
| 10962 | } else { |
| 10963 | /* IF AGC on, PGA not active */ |
| 10964 | #ifndef DRXJ_VSB_ONLY |
| 10965 | ext_attr->qam_if_agc_cfg.standard = DRX_STANDARD_ITU_B; |
| 10966 | ext_attr->qam_if_agc_cfg.ctrl_mode = DRX_AGC_CTRL_AUTO; |
| 10967 | ext_attr->qam_if_agc_cfg.min_output_level = 0; |
| 10968 | ext_attr->qam_if_agc_cfg.max_output_level = 0x7FFF; |
| 10969 | ext_attr->qam_if_agc_cfg.speed = 3; |
| 10970 | ext_attr->qam_if_agc_cfg.top = 1297; |
| 10971 | ext_attr->qam_pga_cfg = 140; |
| 10972 | #endif |
| 10973 | ext_attr->vsb_if_agc_cfg.standard = DRX_STANDARD_8VSB; |
| 10974 | ext_attr->vsb_if_agc_cfg.ctrl_mode = DRX_AGC_CTRL_AUTO; |
| 10975 | ext_attr->vsb_if_agc_cfg.min_output_level = 0; |
| 10976 | ext_attr->vsb_if_agc_cfg.max_output_level = 0x7FFF; |
| 10977 | ext_attr->vsb_if_agc_cfg.speed = 3; |
| 10978 | ext_attr->vsb_if_agc_cfg.top = 1024; |
| 10979 | ext_attr->vsb_pga_cfg = 140; |
| 10980 | } |
| 10981 | /* TODO: remove min_output_level and max_output_level for both QAM and VSB after */ |
| 10982 | /* mc has not used them */ |
| 10983 | #ifndef DRXJ_VSB_ONLY |
| 10984 | ext_attr->qam_rf_agc_cfg.standard = DRX_STANDARD_ITU_B; |
| 10985 | ext_attr->qam_rf_agc_cfg.ctrl_mode = DRX_AGC_CTRL_AUTO; |
| 10986 | ext_attr->qam_rf_agc_cfg.min_output_level = 0; |
| 10987 | ext_attr->qam_rf_agc_cfg.max_output_level = 0x7FFF; |
| 10988 | ext_attr->qam_rf_agc_cfg.speed = 3; |
| 10989 | ext_attr->qam_rf_agc_cfg.top = 9500; |
| 10990 | ext_attr->qam_rf_agc_cfg.cut_off_current = 4000; |
| 10991 | ext_attr->qam_pre_saw_cfg.standard = DRX_STANDARD_ITU_B; |
| 10992 | ext_attr->qam_pre_saw_cfg.reference = 0x07; |
| 10993 | ext_attr->qam_pre_saw_cfg.use_pre_saw = true; |
| 10994 | #endif |
| 10995 | /* Initialize default AFE configuartion for VSB */ |
| 10996 | ext_attr->vsb_rf_agc_cfg.standard = DRX_STANDARD_8VSB; |
| 10997 | ext_attr->vsb_rf_agc_cfg.ctrl_mode = DRX_AGC_CTRL_AUTO; |
| 10998 | ext_attr->vsb_rf_agc_cfg.min_output_level = 0; |
| 10999 | ext_attr->vsb_rf_agc_cfg.max_output_level = 0x7FFF; |
| 11000 | ext_attr->vsb_rf_agc_cfg.speed = 3; |
| 11001 | ext_attr->vsb_rf_agc_cfg.top = 9500; |
| 11002 | ext_attr->vsb_rf_agc_cfg.cut_off_current = 4000; |
| 11003 | ext_attr->vsb_pre_saw_cfg.standard = DRX_STANDARD_8VSB; |
| 11004 | ext_attr->vsb_pre_saw_cfg.reference = 0x07; |
| 11005 | ext_attr->vsb_pre_saw_cfg.use_pre_saw = true; |
Mauro Carvalho Chehab | aafdbaa | 2014-01-19 10:31:47 -0300 | [diff] [blame] | 11006 | } |
| 11007 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11008 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11009 | * \fn int ctrl_power_mode() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11010 | * \brief Set the power mode of the device to the specified power mode |
| 11011 | * \param demod Pointer to demodulator instance. |
| 11012 | * \param mode Pointer to new power mode. |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 11013 | * \return int. |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11014 | * \retval 0 Success |
| 11015 | * \retval -EIO I2C error or other failure |
| 11016 | * \retval -EINVAL Invalid mode argument. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11017 | * |
| 11018 | * |
| 11019 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 11020 | static int |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 11021 | ctrl_power_mode(struct drx_demod_instance *demod, enum drx_power_mode *mode) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11022 | { |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 11023 | struct drx_common_attr *common_attr = (struct drx_common_attr *) NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 11024 | struct drxj_data *ext_attr = (struct drxj_data *) NULL; |
Mauro Carvalho Chehab | 2289226 | 2014-01-16 11:28:52 -0300 | [diff] [blame] | 11025 | struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11026 | int rc; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11027 | u16 sio_cc_pwd_mode = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11028 | |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 11029 | common_attr = (struct drx_common_attr *) demod->my_common_attr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 11030 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11031 | dev_addr = demod->my_i2c_dev_addr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11032 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11033 | /* Check arguments */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 11034 | if (mode == NULL) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11035 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11036 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11037 | /* If already in requested power mode, do nothing */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 11038 | if (common_attr->current_power_mode == *mode) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11039 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11040 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11041 | switch (*mode) { |
| 11042 | case DRX_POWER_UP: |
| 11043 | case DRXJ_POWER_DOWN_MAIN_PATH: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11044 | sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_NONE; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11045 | break; |
| 11046 | case DRXJ_POWER_DOWN_CORE: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11047 | sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_CLOCK; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11048 | break; |
| 11049 | case DRXJ_POWER_DOWN_PLL: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11050 | sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_PLL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11051 | break; |
| 11052 | case DRX_POWER_DOWN: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11053 | sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_OSC; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11054 | break; |
| 11055 | default: |
| 11056 | /* Unknow sleep mode */ |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11057 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11058 | break; |
| 11059 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11060 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11061 | /* Check if device needs to be powered up */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11062 | if ((common_attr->current_power_mode != DRX_POWER_UP)) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11063 | rc = power_up_device(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11064 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11065 | pr_err("error %d\n", rc); |
| 11066 | goto rw_error; |
| 11067 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11068 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11069 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11070 | if ((*mode == DRX_POWER_UP)) { |
| 11071 | /* Restore analog & pin configuartion */ |
Mauro Carvalho Chehab | aafdbaa | 2014-01-19 10:31:47 -0300 | [diff] [blame] | 11072 | |
| 11073 | /* Initialize default AFE configuartion for VSB */ |
| 11074 | drxj_reset_mode(ext_attr); |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11075 | } else { |
| 11076 | /* Power down to requested mode */ |
| 11077 | /* Backup some register settings */ |
| 11078 | /* Set pins with possible pull-ups connected to them in input mode */ |
| 11079 | /* Analog power down */ |
| 11080 | /* ADC power down */ |
| 11081 | /* Power down device */ |
| 11082 | /* stop all comm_exec */ |
| 11083 | /* |
| 11084 | Stop and power down previous standard |
| 11085 | */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11086 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11087 | switch (ext_attr->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11088 | case DRX_STANDARD_ITU_A: |
| 11089 | case DRX_STANDARD_ITU_B: |
| 11090 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11091 | rc = power_down_qam(demod, true); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11092 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11093 | pr_err("error %d\n", rc); |
| 11094 | goto rw_error; |
| 11095 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11096 | break; |
| 11097 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11098 | rc = power_down_vsb(demod, true); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11099 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11100 | pr_err("error %d\n", rc); |
| 11101 | goto rw_error; |
| 11102 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11103 | break; |
| 11104 | case DRX_STANDARD_PAL_SECAM_BG: /* fallthrough */ |
| 11105 | case DRX_STANDARD_PAL_SECAM_DK: /* fallthrough */ |
| 11106 | case DRX_STANDARD_PAL_SECAM_I: /* fallthrough */ |
| 11107 | case DRX_STANDARD_PAL_SECAM_L: /* fallthrough */ |
| 11108 | case DRX_STANDARD_PAL_SECAM_LP: /* fallthrough */ |
| 11109 | case DRX_STANDARD_NTSC: /* fallthrough */ |
| 11110 | case DRX_STANDARD_FM: |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11111 | rc = power_down_atv(demod, ext_attr->standard, true); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11112 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11113 | pr_err("error %d\n", rc); |
| 11114 | goto rw_error; |
| 11115 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11116 | break; |
| 11117 | case DRX_STANDARD_UNKNOWN: |
| 11118 | /* Do nothing */ |
| 11119 | break; |
| 11120 | case DRX_STANDARD_AUTO: /* fallthrough */ |
| 11121 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11122 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11123 | } |
Mauro Carvalho Chehab | d7a5478 | 2014-02-27 05:35:13 -0300 | [diff] [blame] | 11124 | ext_attr->standard = DRX_STANDARD_UNKNOWN; |
| 11125 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11126 | |
Mauro Carvalho Chehab | d7a5478 | 2014-02-27 05:35:13 -0300 | [diff] [blame] | 11127 | if (*mode != DRXJ_POWER_DOWN_MAIN_PATH) { |
| 11128 | rc = drxj_dap_write_reg16(dev_addr, SIO_CC_PWD_MODE__A, sio_cc_pwd_mode, 0); |
| 11129 | if (rc != 0) { |
| 11130 | pr_err("error %d\n", rc); |
| 11131 | goto rw_error; |
| 11132 | } |
| 11133 | rc = drxj_dap_write_reg16(dev_addr, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY, 0); |
| 11134 | if (rc != 0) { |
| 11135 | pr_err("error %d\n", rc); |
| 11136 | goto rw_error; |
| 11137 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11138 | |
Mauro Carvalho Chehab | d7a5478 | 2014-02-27 05:35:13 -0300 | [diff] [blame] | 11139 | if ((*mode != DRX_POWER_UP)) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11140 | /* Initialize HI, wakeup key especially before put IC to sleep */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11141 | rc = init_hi(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11142 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11143 | pr_err("error %d\n", rc); |
| 11144 | goto rw_error; |
| 11145 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11146 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11147 | ext_attr->hi_cfg_ctrl |= SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11148 | rc = hi_cfg_command(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11149 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11150 | pr_err("error %d\n", rc); |
| 11151 | goto rw_error; |
| 11152 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11153 | } |
| 11154 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11155 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11156 | common_attr->current_power_mode = *mode; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11157 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11158 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11159 | rw_error: |
Mauro Carvalho Chehab | d7a5478 | 2014-02-27 05:35:13 -0300 | [diff] [blame] | 11160 | return rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11161 | } |
| 11162 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11163 | /*============================================================================*/ |
| 11164 | /*== CTRL Set/Get Config related functions ===================================*/ |
| 11165 | /*============================================================================*/ |
| 11166 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11167 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11168 | * \fn int ctrl_set_cfg_pre_saw() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11169 | * \brief Set Pre-saw reference. |
| 11170 | * \param demod demod instance |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 11171 | * \param u16 * |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 11172 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11173 | * |
| 11174 | * Check arguments |
| 11175 | * Dispatch handling to standard specific function. |
| 11176 | * |
| 11177 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 11178 | static int |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 11179 | ctrl_set_cfg_pre_saw(struct drx_demod_instance *demod, struct drxj_cfg_pre_saw *pre_saw) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11180 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11181 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 11182 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11183 | int rc; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11184 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11185 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 11186 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11187 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11188 | /* check arguments */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11189 | if ((pre_saw == NULL) || (pre_saw->reference > IQM_AF_PDREF__M) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11190 | ) { |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11191 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11192 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11193 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11194 | /* Only if standard is currently active */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11195 | if ((ext_attr->standard == pre_saw->standard) || |
| 11196 | (DRXJ_ISQAMSTD(ext_attr->standard) && |
| 11197 | DRXJ_ISQAMSTD(pre_saw->standard)) || |
| 11198 | (DRXJ_ISATVSTD(ext_attr->standard) && |
| 11199 | DRXJ_ISATVSTD(pre_saw->standard))) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11200 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_PDREF__A, pre_saw->reference, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11201 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11202 | pr_err("error %d\n", rc); |
| 11203 | goto rw_error; |
| 11204 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11205 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11206 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11207 | /* Store pre-saw settings */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11208 | switch (pre_saw->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11209 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11210 | ext_attr->vsb_pre_saw_cfg = *pre_saw; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11211 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11212 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11213 | case DRX_STANDARD_ITU_A: /* fallthrough */ |
| 11214 | case DRX_STANDARD_ITU_B: /* fallthrough */ |
| 11215 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11216 | ext_attr->qam_pre_saw_cfg = *pre_saw; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11217 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11218 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11219 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11220 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11221 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11222 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11223 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11224 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11225 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11226 | } |
| 11227 | |
| 11228 | /*============================================================================*/ |
| 11229 | |
| 11230 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11231 | * \fn int ctrl_set_cfg_afe_gain() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11232 | * \brief Set AFE Gain. |
| 11233 | * \param demod demod instance |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 11234 | * \param u16 * |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 11235 | * \return int. |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11236 | * |
| 11237 | * Check arguments |
| 11238 | * Dispatch handling to standard specific function. |
| 11239 | * |
| 11240 | */ |
Mauro Carvalho Chehab | 61263c7 | 2012-03-20 01:18:02 -0300 | [diff] [blame] | 11241 | static int |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 11242 | ctrl_set_cfg_afe_gain(struct drx_demod_instance *demod, struct drxj_cfg_afe_gain *afe_gain) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11243 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11244 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 11245 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11246 | int rc; |
Mauro Carvalho Chehab | 43a431e | 2012-03-20 00:49:45 -0300 | [diff] [blame] | 11247 | u8 gain = 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11248 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11249 | /* check arguments */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 11250 | if (afe_gain == NULL) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11251 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11252 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11253 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 11254 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11255 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11256 | switch (afe_gain->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11257 | case DRX_STANDARD_8VSB: /* fallthrough */ |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11258 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11259 | case DRX_STANDARD_ITU_A: /* fallthrough */ |
| 11260 | case DRX_STANDARD_ITU_B: /* fallthrough */ |
| 11261 | case DRX_STANDARD_ITU_C: |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11262 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11263 | /* Do nothing */ |
| 11264 | break; |
| 11265 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11266 | return -EINVAL; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11267 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11268 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11269 | /* TODO PGA gain is also written by microcode (at least by QAM and VSB) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11270 | So I (PJ) think interface requires choice between auto, user mode */ |
| 11271 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11272 | if (afe_gain->gain >= 329) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11273 | gain = 15; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11274 | else if (afe_gain->gain <= 147) |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11275 | gain = 0; |
| 11276 | else |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11277 | gain = (afe_gain->gain - 140 + 6) / 13; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11278 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11279 | /* Only if standard is currently active */ |
Mauro Carvalho Chehab | 6371351 | 2014-01-17 07:12:28 -0300 | [diff] [blame] | 11280 | if (ext_attr->standard == afe_gain->standard) { |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11281 | rc = drxj_dap_write_reg16(dev_addr, IQM_AF_PGA_GAIN__A, gain, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11282 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11283 | pr_err("error %d\n", rc); |
| 11284 | goto rw_error; |
| 11285 | } |
| 11286 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11287 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11288 | /* Store AFE Gain settings */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11289 | switch (afe_gain->standard) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11290 | case DRX_STANDARD_8VSB: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11291 | ext_attr->vsb_pga_cfg = gain * 13 + 140; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11292 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11293 | #ifndef DRXJ_VSB_ONLY |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11294 | case DRX_STANDARD_ITU_A: /* fallthrough */ |
| 11295 | case DRX_STANDARD_ITU_B: /* fallthrough */ |
| 11296 | case DRX_STANDARD_ITU_C: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11297 | ext_attr->qam_pga_cfg = gain * 13 + 140; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11298 | break; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11299 | #endif |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11300 | default: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11301 | return -EIO; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11302 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11303 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11304 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11305 | rw_error: |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11306 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11307 | } |
| 11308 | |
| 11309 | /*============================================================================*/ |
| 11310 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11311 | |
| 11312 | /*============================================================================= |
| 11313 | ===== EXPORTED FUNCTIONS ====================================================*/ |
Mauro Carvalho Chehab | aafdbaa | 2014-01-19 10:31:47 -0300 | [diff] [blame] | 11314 | |
Mauro Carvalho Chehab | dc5a91d | 2014-01-24 11:14:17 -0300 | [diff] [blame] | 11315 | static int drx_ctrl_u_code(struct drx_demod_instance *demod, |
| 11316 | struct drxu_code_info *mc_info, |
| 11317 | enum drxu_code_action action); |
| 11318 | |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11319 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11320 | * \fn drxj_open() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11321 | * \brief Open the demod instance, configure device, configure drxdriver |
| 11322 | * \return Status_t Return status. |
| 11323 | * |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11324 | * drxj_open() can be called with a NULL ucode image => no ucode upload. |
| 11325 | * This means that drxj_open() must NOT contain SCU commands or, in general, |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11326 | * rely on SCU or AUD ucode to be present. |
| 11327 | * |
| 11328 | */ |
Mauro Carvalho Chehab | dc5a91d | 2014-01-24 11:14:17 -0300 | [diff] [blame] | 11329 | |
Mauro Carvalho Chehab | 0147314 | 2014-03-09 10:33:19 -0300 | [diff] [blame] | 11330 | static int drxj_open(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11331 | { |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11332 | struct i2c_device_addr *dev_addr = NULL; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 11333 | struct drxj_data *ext_attr = NULL; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 11334 | struct drx_common_attr *common_attr = NULL; |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11335 | u32 driver_version = 0; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 11336 | struct drxu_code_info ucode_info; |
| 11337 | struct drx_cfg_mpeg_output cfg_mpeg_output; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11338 | int rc; |
Mauro Carvalho Chehab | d7a5478 | 2014-02-27 05:35:13 -0300 | [diff] [blame] | 11339 | enum drx_power_mode power_mode = DRX_POWER_UP; |
Mauro Carvalho Chehab | b78359a | 2014-01-24 12:21:17 -0300 | [diff] [blame] | 11340 | |
| 11341 | if ((demod == NULL) || |
| 11342 | (demod->my_common_attr == NULL) || |
| 11343 | (demod->my_ext_attr == NULL) || |
| 11344 | (demod->my_i2c_dev_addr == NULL) || |
| 11345 | (demod->my_common_attr->is_opened)) { |
| 11346 | return -EINVAL; |
| 11347 | } |
| 11348 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11349 | /* Check arguments */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11350 | if (demod->my_ext_attr == NULL) |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11351 | return -EINVAL; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11352 | |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11353 | dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | b3ce3a8 | 2014-01-16 15:33:14 -0300 | [diff] [blame] | 11354 | ext_attr = (struct drxj_data *) demod->my_ext_attr; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 11355 | common_attr = (struct drx_common_attr *) demod->my_common_attr; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11356 | |
Mauro Carvalho Chehab | d7a5478 | 2014-02-27 05:35:13 -0300 | [diff] [blame] | 11357 | rc = ctrl_power_mode(demod, &power_mode); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11358 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11359 | pr_err("error %d\n", rc); |
| 11360 | goto rw_error; |
| 11361 | } |
Mauro Carvalho Chehab | d7a5478 | 2014-02-27 05:35:13 -0300 | [diff] [blame] | 11362 | if (power_mode != DRX_POWER_UP) { |
| 11363 | rc = -EINVAL; |
| 11364 | pr_err("failed to powerup device\n"); |
| 11365 | goto rw_error; |
| 11366 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11367 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11368 | /* has to be in front of setIqmAf and setOrxNsuAox */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11369 | rc = get_device_capabilities(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11370 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11371 | pr_err("error %d\n", rc); |
| 11372 | goto rw_error; |
| 11373 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11374 | |
Mauro Carvalho Chehab | 8afff9a | 2014-02-27 08:48:44 -0300 | [diff] [blame] | 11375 | /* |
| 11376 | * Soft reset of sys- and osc-clockdomain |
| 11377 | * |
| 11378 | * HACK: On windows, it writes a 0x07 here, instead of just 0x03. |
| 11379 | * As we didn't load the firmware here yet, we should do the same. |
| 11380 | * Btw, this is coherent with DRX-K, where we send reset codes |
| 11381 | * for modulation (OFTM, in DRX-k), SYS and OSC clock domains. |
| 11382 | */ |
| 11383 | rc = drxj_dap_write_reg16(dev_addr, SIO_CC_SOFT_RST__A, (0x04 | SIO_CC_SOFT_RST_SYS__M | SIO_CC_SOFT_RST_OSC__M), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11384 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11385 | pr_err("error %d\n", rc); |
| 11386 | goto rw_error; |
| 11387 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11388 | rc = drxj_dap_write_reg16(dev_addr, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11389 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11390 | pr_err("error %d\n", rc); |
| 11391 | goto rw_error; |
| 11392 | } |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 11393 | msleep(1); |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11394 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11395 | /* TODO first make sure that everything keeps working before enabling this */ |
| 11396 | /* PowerDownAnalogBlocks() */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11397 | rc = drxj_dap_write_reg16(dev_addr, ATV_TOP_STDBY__A, (~ATV_TOP_STDBY_CVBS_STDBY_A2_ACTIVE) | ATV_TOP_STDBY_SIF_STDBY_STANDBY, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11398 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11399 | pr_err("error %d\n", rc); |
| 11400 | goto rw_error; |
| 11401 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11402 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11403 | rc = set_iqm_af(demod, false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11404 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11405 | pr_err("error %d\n", rc); |
| 11406 | goto rw_error; |
| 11407 | } |
| 11408 | rc = set_orx_nsu_aox(demod, false); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11409 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11410 | pr_err("error %d\n", rc); |
| 11411 | goto rw_error; |
| 11412 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11413 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11414 | rc = init_hi(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11415 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11416 | pr_err("error %d\n", rc); |
| 11417 | goto rw_error; |
| 11418 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11419 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11420 | /* disable mpegoutput pins */ |
Mauro Carvalho Chehab | 41b5cc0 | 2014-03-02 11:01:11 -0300 | [diff] [blame] | 11421 | memcpy(&cfg_mpeg_output, &common_attr->mpeg_cfg, sizeof(cfg_mpeg_output)); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11422 | cfg_mpeg_output.enable_mpeg_output = false; |
Mauro Carvalho Chehab | 41b5cc0 | 2014-03-02 11:01:11 -0300 | [diff] [blame] | 11423 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11424 | rc = ctrl_set_cfg_mpeg_output(demod, &cfg_mpeg_output); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11425 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11426 | pr_err("error %d\n", rc); |
| 11427 | goto rw_error; |
| 11428 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11429 | /* Stop AUD Inform SetAudio it will need to do all setting */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11430 | rc = power_down_aud(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11431 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11432 | pr_err("error %d\n", rc); |
| 11433 | goto rw_error; |
| 11434 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11435 | /* Stop SCU */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11436 | rc = drxj_dap_write_reg16(dev_addr, SCU_COMM_EXEC__A, SCU_COMM_EXEC_STOP, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11437 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11438 | pr_err("error %d\n", rc); |
| 11439 | goto rw_error; |
| 11440 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11441 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11442 | /* Upload microcode */ |
Mauro Carvalho Chehab | b48293d | 2014-01-18 11:13:02 -0300 | [diff] [blame] | 11443 | if (common_attr->microcode_file != NULL) { |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11444 | /* Dirty trick to use common ucode upload & verify, |
| 11445 | pretend device is already open */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11446 | common_attr->is_opened = true; |
Mauro Carvalho Chehab | b48293d | 2014-01-18 11:13:02 -0300 | [diff] [blame] | 11447 | ucode_info.mc_file = common_attr->microcode_file; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11448 | |
Mauro Carvalho Chehab | dc5a91d | 2014-01-24 11:14:17 -0300 | [diff] [blame] | 11449 | if (DRX_ISPOWERDOWNMODE(demod->my_common_attr->current_power_mode)) { |
| 11450 | pr_err("Should powerup before loading the firmware."); |
| 11451 | return -EINVAL; |
| 11452 | } |
| 11453 | |
| 11454 | rc = drx_ctrl_u_code(demod, &ucode_info, UCODE_UPLOAD); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11455 | if (rc != 0) { |
Mauro Carvalho Chehab | dc5a91d | 2014-01-24 11:14:17 -0300 | [diff] [blame] | 11456 | pr_err("error %d while uploading the firmware\n", rc); |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11457 | goto rw_error; |
| 11458 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11459 | if (common_attr->verify_microcode == true) { |
Mauro Carvalho Chehab | dc5a91d | 2014-01-24 11:14:17 -0300 | [diff] [blame] | 11460 | rc = drx_ctrl_u_code(demod, &ucode_info, UCODE_VERIFY); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11461 | if (rc != 0) { |
Mauro Carvalho Chehab | dc5a91d | 2014-01-24 11:14:17 -0300 | [diff] [blame] | 11462 | pr_err("error %d while verifying the firmware\n", |
| 11463 | rc); |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11464 | goto rw_error; |
| 11465 | } |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11466 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11467 | common_attr->is_opened = false; |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11468 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11469 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11470 | /* Run SCU for a little while to initialize microcode version numbers */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11471 | rc = drxj_dap_write_reg16(dev_addr, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11472 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11473 | pr_err("error %d\n", rc); |
| 11474 | goto rw_error; |
| 11475 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11476 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11477 | /* Initialize scan timeout */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11478 | common_attr->scan_demod_lock_timeout = DRXJ_SCAN_TIMEOUT; |
| 11479 | common_attr->scan_desired_lock = DRX_LOCKED; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11480 | |
Mauro Carvalho Chehab | aafdbaa | 2014-01-19 10:31:47 -0300 | [diff] [blame] | 11481 | drxj_reset_mode(ext_attr); |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11482 | ext_attr->standard = DRX_STANDARD_UNKNOWN; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11483 | |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11484 | rc = smart_ant_init(demod); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11485 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11486 | pr_err("error %d\n", rc); |
| 11487 | goto rw_error; |
| 11488 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11489 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11490 | /* Stamp driver version number in SCU data RAM in BCD code |
| 11491 | Done to enable field application engineers to retreive drxdriver version |
| 11492 | via I2C from SCU RAM |
| 11493 | */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11494 | driver_version = (VERSION_MAJOR / 100) % 10; |
| 11495 | driver_version <<= 4; |
| 11496 | driver_version += (VERSION_MAJOR / 10) % 10; |
| 11497 | driver_version <<= 4; |
| 11498 | driver_version += (VERSION_MAJOR % 10); |
| 11499 | driver_version <<= 4; |
| 11500 | driver_version += (VERSION_MINOR % 10); |
| 11501 | driver_version <<= 4; |
| 11502 | driver_version += (VERSION_PATCH / 1000) % 10; |
| 11503 | driver_version <<= 4; |
| 11504 | driver_version += (VERSION_PATCH / 100) % 10; |
| 11505 | driver_version <<= 4; |
| 11506 | driver_version += (VERSION_PATCH / 10) % 10; |
| 11507 | driver_version <<= 4; |
| 11508 | driver_version += (VERSION_PATCH % 10); |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11509 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_DRIVER_VER_HI__A, (u16)(driver_version >> 16), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11510 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11511 | pr_err("error %d\n", rc); |
| 11512 | goto rw_error; |
| 11513 | } |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11514 | rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_DRIVER_VER_LO__A, (u16)(driver_version & 0xFFFF), 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11515 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11516 | pr_err("error %d\n", rc); |
| 11517 | goto rw_error; |
| 11518 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11519 | |
Mauro Carvalho Chehab | bf9b94a | 2014-03-02 09:52:34 -0300 | [diff] [blame] | 11520 | rc = ctrl_set_oob(demod, NULL); |
| 11521 | if (rc != 0) { |
| 11522 | pr_err("error %d\n", rc); |
| 11523 | goto rw_error; |
| 11524 | } |
| 11525 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11526 | /* refresh the audio data structure with default */ |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11527 | ext_attr->aud_data = drxj_default_aud_data_g; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11528 | |
Mauro Carvalho Chehab | b78359a | 2014-01-24 12:21:17 -0300 | [diff] [blame] | 11529 | demod->my_common_attr->is_opened = true; |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11530 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11531 | rw_error: |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11532 | common_attr->is_opened = false; |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11533 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11534 | } |
| 11535 | |
| 11536 | /*============================================================================*/ |
| 11537 | /** |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11538 | * \fn drxj_close() |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11539 | * \brief Close the demod instance, power down the device |
| 11540 | * \return Status_t Return status. |
| 11541 | * |
| 11542 | */ |
Mauro Carvalho Chehab | 0147314 | 2014-03-09 10:33:19 -0300 | [diff] [blame] | 11543 | static int drxj_close(struct drx_demod_instance *demod) |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11544 | { |
Mauro Carvalho Chehab | 4d7bb0e | 2014-01-16 11:49:13 -0300 | [diff] [blame] | 11545 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11546 | int rc; |
Mauro Carvalho Chehab | 1bfc9e1 | 2014-01-16 12:51:36 -0300 | [diff] [blame] | 11547 | enum drx_power_mode power_mode = DRX_POWER_UP; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11548 | |
Mauro Carvalho Chehab | 1e5ec31 | 2014-03-09 10:33:54 -0300 | [diff] [blame] | 11549 | if ((demod->my_common_attr == NULL) || |
Mauro Carvalho Chehab | b78359a | 2014-01-24 12:21:17 -0300 | [diff] [blame] | 11550 | (demod->my_ext_attr == NULL) || |
| 11551 | (demod->my_i2c_dev_addr == NULL) || |
| 11552 | (!demod->my_common_attr->is_opened)) { |
| 11553 | return -EINVAL; |
| 11554 | } |
| 11555 | |
Mauro Carvalho Chehab | 443f18d | 2012-03-20 00:00:42 -0300 | [diff] [blame] | 11556 | /* power up */ |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11557 | rc = ctrl_power_mode(demod, &power_mode); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11558 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11559 | pr_err("error %d\n", rc); |
| 11560 | goto rw_error; |
| 11561 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11562 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11563 | rc = drxj_dap_write_reg16(dev_addr, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE, 0); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11564 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11565 | pr_err("error %d\n", rc); |
| 11566 | goto rw_error; |
| 11567 | } |
Mauro Carvalho Chehab | 57afe2f | 2014-01-16 11:24:57 -0300 | [diff] [blame] | 11568 | power_mode = DRX_POWER_DOWN; |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11569 | rc = ctrl_power_mode(demod, &power_mode); |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11570 | if (rc != 0) { |
Mauro Carvalho Chehab | 068e94e | 2014-01-16 19:41:13 -0300 | [diff] [blame] | 11571 | pr_err("error %d\n", rc); |
| 11572 | goto rw_error; |
| 11573 | } |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11574 | |
Mauro Carvalho Chehab | b78359a | 2014-01-24 12:21:17 -0300 | [diff] [blame] | 11575 | DRX_ATTR_ISOPENED(demod) = false; |
| 11576 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11577 | return 0; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11578 | rw_error: |
Mauro Carvalho Chehab | b78359a | 2014-01-24 12:21:17 -0300 | [diff] [blame] | 11579 | DRX_ATTR_ISOPENED(demod) = false; |
| 11580 | |
Mauro Carvalho Chehab | 9482354 | 2014-01-17 10:18:16 -0300 | [diff] [blame] | 11581 | return -EIO; |
Devin Heitmueller | 38b2df9 | 2012-08-13 21:18:02 -0300 | [diff] [blame] | 11582 | } |
| 11583 | |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 11584 | /* |
| 11585 | * Microcode related functions |
| 11586 | */ |
| 11587 | |
| 11588 | /** |
| 11589 | * drx_u_code_compute_crc - Compute CRC of block of microcode data. |
| 11590 | * @block_data: Pointer to microcode data. |
| 11591 | * @nr_words: Size of microcode block (number of 16 bits words). |
| 11592 | * |
| 11593 | * returns The computed CRC residue. |
| 11594 | */ |
| 11595 | static u16 drx_u_code_compute_crc(u8 *block_data, u16 nr_words) |
| 11596 | { |
| 11597 | u16 i = 0; |
| 11598 | u16 j = 0; |
| 11599 | u32 crc_word = 0; |
| 11600 | u32 carry = 0; |
| 11601 | |
| 11602 | while (i < nr_words) { |
| 11603 | crc_word |= (u32)be16_to_cpu(*(u32 *)(block_data)); |
| 11604 | for (j = 0; j < 16; j++) { |
| 11605 | crc_word <<= 1; |
| 11606 | if (carry != 0) |
| 11607 | crc_word ^= 0x80050000UL; |
| 11608 | carry = crc_word & 0x80000000UL; |
| 11609 | } |
| 11610 | i++; |
| 11611 | block_data += (sizeof(u16)); |
| 11612 | } |
| 11613 | return (u16)(crc_word >> 16); |
| 11614 | } |
| 11615 | |
| 11616 | /** |
| 11617 | * drx_check_firmware - checks if the loaded firmware is valid |
| 11618 | * |
| 11619 | * @demod: demod structure |
| 11620 | * @mc_data: pointer to the start of the firmware |
| 11621 | * @size: firmware size |
| 11622 | */ |
| 11623 | static int drx_check_firmware(struct drx_demod_instance *demod, u8 *mc_data, |
| 11624 | unsigned size) |
| 11625 | { |
| 11626 | struct drxu_code_block_hdr block_hdr; |
| 11627 | int i; |
| 11628 | unsigned count = 2 * sizeof(u16); |
| 11629 | u32 mc_dev_type, mc_version, mc_base_version; |
| 11630 | u16 mc_nr_of_blks = be16_to_cpu(*(u32 *)(mc_data + sizeof(u16))); |
| 11631 | |
| 11632 | /* |
| 11633 | * Scan microcode blocks first for version info |
| 11634 | * and firmware check |
| 11635 | */ |
| 11636 | |
| 11637 | /* Clear version block */ |
| 11638 | DRX_ATTR_MCRECORD(demod).aux_type = 0; |
| 11639 | DRX_ATTR_MCRECORD(demod).mc_dev_type = 0; |
| 11640 | DRX_ATTR_MCRECORD(demod).mc_version = 0; |
| 11641 | DRX_ATTR_MCRECORD(demod).mc_base_version = 0; |
| 11642 | |
| 11643 | for (i = 0; i < mc_nr_of_blks; i++) { |
| 11644 | if (count + 3 * sizeof(u16) + sizeof(u32) > size) |
| 11645 | goto eof; |
| 11646 | |
| 11647 | /* Process block header */ |
| 11648 | block_hdr.addr = be32_to_cpu(*(u32 *)(mc_data + count)); |
| 11649 | count += sizeof(u32); |
| 11650 | block_hdr.size = be16_to_cpu(*(u32 *)(mc_data + count)); |
| 11651 | count += sizeof(u16); |
| 11652 | block_hdr.flags = be16_to_cpu(*(u32 *)(mc_data + count)); |
| 11653 | count += sizeof(u16); |
| 11654 | block_hdr.CRC = be16_to_cpu(*(u32 *)(mc_data + count)); |
| 11655 | count += sizeof(u16); |
| 11656 | |
| 11657 | pr_debug("%u: addr %u, size %u, flags 0x%04x, CRC 0x%04x\n", |
| 11658 | count, block_hdr.addr, block_hdr.size, block_hdr.flags, |
| 11659 | block_hdr.CRC); |
| 11660 | |
| 11661 | if (block_hdr.flags & 0x8) { |
| 11662 | u8 *auxblk = ((void *)mc_data) + block_hdr.addr; |
| 11663 | u16 auxtype; |
| 11664 | |
| 11665 | if (block_hdr.addr + sizeof(u16) > size) |
| 11666 | goto eof; |
| 11667 | |
| 11668 | auxtype = be16_to_cpu(*(u32 *)(auxblk)); |
| 11669 | |
| 11670 | /* Aux block. Check type */ |
| 11671 | if (DRX_ISMCVERTYPE(auxtype)) { |
| 11672 | if (block_hdr.addr + 2 * sizeof(u16) + 2 * sizeof (u32) > size) |
| 11673 | goto eof; |
| 11674 | |
| 11675 | auxblk += sizeof(u16); |
| 11676 | mc_dev_type = be32_to_cpu(*(u32 *)(auxblk)); |
| 11677 | auxblk += sizeof(u32); |
| 11678 | mc_version = be32_to_cpu(*(u32 *)(auxblk)); |
| 11679 | auxblk += sizeof(u32); |
| 11680 | mc_base_version = be32_to_cpu(*(u32 *)(auxblk)); |
| 11681 | |
| 11682 | DRX_ATTR_MCRECORD(demod).aux_type = auxtype; |
| 11683 | DRX_ATTR_MCRECORD(demod).mc_dev_type = mc_dev_type; |
| 11684 | DRX_ATTR_MCRECORD(demod).mc_version = mc_version; |
| 11685 | DRX_ATTR_MCRECORD(demod).mc_base_version = mc_base_version; |
| 11686 | |
| 11687 | pr_info("Firmware dev %x, ver %x, base ver %x\n", |
| 11688 | mc_dev_type, mc_version, mc_base_version); |
| 11689 | |
| 11690 | } |
| 11691 | } else if (count + block_hdr.size * sizeof(u16) > size) |
| 11692 | goto eof; |
| 11693 | |
| 11694 | count += block_hdr.size * sizeof(u16); |
| 11695 | } |
| 11696 | return 0; |
| 11697 | eof: |
| 11698 | pr_err("Firmware is truncated at pos %u/%u\n", count, size); |
| 11699 | return -EINVAL; |
| 11700 | } |
| 11701 | |
| 11702 | /** |
| 11703 | * drx_ctrl_u_code - Handle microcode upload or verify. |
| 11704 | * @dev_addr: Address of device. |
| 11705 | * @mc_info: Pointer to information about microcode data. |
| 11706 | * @action: Either UCODE_UPLOAD or UCODE_VERIFY |
| 11707 | * |
| 11708 | * This function returns: |
| 11709 | * 0: |
| 11710 | * - In case of UCODE_UPLOAD: code is successfully uploaded. |
| 11711 | * - In case of UCODE_VERIFY: image on device is equal to |
| 11712 | * image provided to this control function. |
| 11713 | * -EIO: |
| 11714 | * - In case of UCODE_UPLOAD: I2C error. |
| 11715 | * - In case of UCODE_VERIFY: I2C error or image on device |
| 11716 | * is not equal to image provided to this control function. |
| 11717 | * -EINVAL: |
| 11718 | * - Invalid arguments. |
| 11719 | * - Provided image is corrupt |
| 11720 | */ |
| 11721 | static int drx_ctrl_u_code(struct drx_demod_instance *demod, |
| 11722 | struct drxu_code_info *mc_info, |
| 11723 | enum drxu_code_action action) |
| 11724 | { |
| 11725 | struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr; |
| 11726 | int rc; |
| 11727 | u16 i = 0; |
| 11728 | u16 mc_nr_of_blks = 0; |
| 11729 | u16 mc_magic_word = 0; |
| 11730 | const u8 *mc_data_init = NULL; |
| 11731 | u8 *mc_data = NULL; |
| 11732 | unsigned size; |
Mauro Carvalho Chehab | 1d001c3 | 2014-03-09 10:10:19 -0300 | [diff] [blame] | 11733 | char *mc_file; |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 11734 | |
| 11735 | /* Check arguments */ |
Mauro Carvalho Chehab | 1d001c3 | 2014-03-09 10:10:19 -0300 | [diff] [blame] | 11736 | if (!mc_info || !mc_info->mc_file) |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 11737 | return -EINVAL; |
| 11738 | |
Mauro Carvalho Chehab | 1d001c3 | 2014-03-09 10:10:19 -0300 | [diff] [blame] | 11739 | mc_file = mc_info->mc_file; |
| 11740 | |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 11741 | if (!demod->firmware) { |
| 11742 | const struct firmware *fw = NULL; |
| 11743 | |
| 11744 | rc = request_firmware(&fw, mc_file, demod->i2c->dev.parent); |
| 11745 | if (rc < 0) { |
| 11746 | pr_err("Couldn't read firmware %s\n", mc_file); |
Mauro Carvalho Chehab | 691cbbe | 2014-03-09 10:36:24 -0300 | [diff] [blame] | 11747 | return rc; |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 11748 | } |
| 11749 | demod->firmware = fw; |
| 11750 | |
| 11751 | if (demod->firmware->size < 2 * sizeof(u16)) { |
| 11752 | rc = -EINVAL; |
| 11753 | pr_err("Firmware is too short!\n"); |
| 11754 | goto release; |
| 11755 | } |
| 11756 | |
| 11757 | pr_info("Firmware %s, size %zu\n", |
| 11758 | mc_file, demod->firmware->size); |
| 11759 | } |
| 11760 | |
| 11761 | mc_data_init = demod->firmware->data; |
| 11762 | size = demod->firmware->size; |
| 11763 | |
| 11764 | mc_data = (void *)mc_data_init; |
| 11765 | /* Check data */ |
| 11766 | mc_magic_word = be16_to_cpu(*(u32 *)(mc_data)); |
| 11767 | mc_data += sizeof(u16); |
| 11768 | mc_nr_of_blks = be16_to_cpu(*(u32 *)(mc_data)); |
| 11769 | mc_data += sizeof(u16); |
| 11770 | |
| 11771 | if ((mc_magic_word != DRX_UCODE_MAGIC_WORD) || (mc_nr_of_blks == 0)) { |
| 11772 | rc = -EINVAL; |
| 11773 | pr_err("Firmware magic word doesn't match\n"); |
| 11774 | goto release; |
| 11775 | } |
| 11776 | |
| 11777 | if (action == UCODE_UPLOAD) { |
| 11778 | rc = drx_check_firmware(demod, (u8 *)mc_data_init, size); |
| 11779 | if (rc) |
| 11780 | goto release; |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 11781 | pr_info("Uploading firmware %s\n", mc_file); |
Mauro Carvalho Chehab | dc5a91d | 2014-01-24 11:14:17 -0300 | [diff] [blame] | 11782 | } else { |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 11783 | pr_info("Verifying if firmware upload was ok.\n"); |
| 11784 | } |
| 11785 | |
| 11786 | /* Process microcode blocks */ |
| 11787 | for (i = 0; i < mc_nr_of_blks; i++) { |
| 11788 | struct drxu_code_block_hdr block_hdr; |
| 11789 | u16 mc_block_nr_bytes = 0; |
| 11790 | |
| 11791 | /* Process block header */ |
| 11792 | block_hdr.addr = be32_to_cpu(*(u32 *)(mc_data)); |
| 11793 | mc_data += sizeof(u32); |
| 11794 | block_hdr.size = be16_to_cpu(*(u32 *)(mc_data)); |
| 11795 | mc_data += sizeof(u16); |
| 11796 | block_hdr.flags = be16_to_cpu(*(u32 *)(mc_data)); |
| 11797 | mc_data += sizeof(u16); |
| 11798 | block_hdr.CRC = be16_to_cpu(*(u32 *)(mc_data)); |
| 11799 | mc_data += sizeof(u16); |
| 11800 | |
| 11801 | pr_debug("%u: addr %u, size %u, flags 0x%04x, CRC 0x%04x\n", |
| 11802 | (unsigned)(mc_data - mc_data_init), block_hdr.addr, |
| 11803 | block_hdr.size, block_hdr.flags, block_hdr.CRC); |
| 11804 | |
| 11805 | /* Check block header on: |
| 11806 | - data larger than 64Kb |
| 11807 | - if CRC enabled check CRC |
| 11808 | */ |
| 11809 | if ((block_hdr.size > 0x7FFF) || |
| 11810 | (((block_hdr.flags & DRX_UCODE_CRC_FLAG) != 0) && |
| 11811 | (block_hdr.CRC != drx_u_code_compute_crc(mc_data, block_hdr.size))) |
| 11812 | ) { |
| 11813 | /* Wrong data ! */ |
| 11814 | rc = -EINVAL; |
| 11815 | pr_err("firmware CRC is wrong\n"); |
| 11816 | goto release; |
| 11817 | } |
| 11818 | |
| 11819 | if (!block_hdr.size) |
| 11820 | continue; |
| 11821 | |
| 11822 | mc_block_nr_bytes = block_hdr.size * ((u16) sizeof(u16)); |
| 11823 | |
| 11824 | /* Perform the desired action */ |
| 11825 | switch (action) { |
| 11826 | case UCODE_UPLOAD: /* Upload microcode */ |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11827 | if (drxdap_fasi_write_block(dev_addr, |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 11828 | block_hdr.addr, |
| 11829 | mc_block_nr_bytes, |
| 11830 | mc_data, 0x0000)) { |
| 11831 | rc = -EIO; |
| 11832 | pr_err("error writing firmware at pos %u\n", |
| 11833 | (unsigned)(mc_data - mc_data_init)); |
| 11834 | goto release; |
| 11835 | } |
| 11836 | break; |
| 11837 | case UCODE_VERIFY: { /* Verify uploaded microcode */ |
| 11838 | int result = 0; |
| 11839 | u8 mc_data_buffer[DRX_UCODE_MAX_BUF_SIZE]; |
| 11840 | u32 bytes_to_comp = 0; |
| 11841 | u32 bytes_left = mc_block_nr_bytes; |
| 11842 | u32 curr_addr = block_hdr.addr; |
| 11843 | u8 *curr_ptr = mc_data; |
| 11844 | |
| 11845 | while (bytes_left != 0) { |
| 11846 | if (bytes_left > DRX_UCODE_MAX_BUF_SIZE) |
| 11847 | bytes_to_comp = DRX_UCODE_MAX_BUF_SIZE; |
| 11848 | else |
| 11849 | bytes_to_comp = bytes_left; |
| 11850 | |
Mauro Carvalho Chehab | 244c0e0 | 2014-01-27 02:33:18 -0300 | [diff] [blame] | 11851 | if (drxdap_fasi_read_block(dev_addr, |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 11852 | curr_addr, |
| 11853 | (u16)bytes_to_comp, |
| 11854 | (u8 *)mc_data_buffer, |
| 11855 | 0x0000)) { |
| 11856 | pr_err("error reading firmware at pos %u\n", |
| 11857 | (unsigned)(mc_data - mc_data_init)); |
| 11858 | return -EIO; |
| 11859 | } |
| 11860 | |
Mauro Carvalho Chehab | d7b0631 | 2014-01-26 14:23:24 -0300 | [diff] [blame] | 11861 | result = memcmp(curr_ptr, mc_data_buffer, |
| 11862 | bytes_to_comp); |
Mauro Carvalho Chehab | b240eac | 2014-01-24 06:25:07 -0300 | [diff] [blame] | 11863 | |
| 11864 | if (result) { |
| 11865 | pr_err("error verifying firmware at pos %u\n", |
| 11866 | (unsigned)(mc_data - mc_data_init)); |
| 11867 | return -EIO; |
| 11868 | } |
| 11869 | |
| 11870 | curr_addr += ((dr_xaddr_t)(bytes_to_comp / 2)); |
| 11871 | curr_ptr =&(curr_ptr[bytes_to_comp]); |
| 11872 | bytes_left -=((u32) bytes_to_comp); |
| 11873 | } |
| 11874 | break; |
| 11875 | } |
| 11876 | default: |
| 11877 | return -EINVAL; |
| 11878 | break; |
| 11879 | |
| 11880 | } |
| 11881 | mc_data += mc_block_nr_bytes; |
| 11882 | } |
| 11883 | |
| 11884 | return 0; |
| 11885 | |
| 11886 | release: |
| 11887 | release_firmware(demod->firmware); |
| 11888 | demod->firmware = NULL; |
| 11889 | |
| 11890 | return rc; |
| 11891 | } |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 11892 | |
| 11893 | /* |
| 11894 | * The Linux DVB Driver for Micronas DRX39xx family (drx3933j) |
| 11895 | * |
| 11896 | * Written by Devin Heitmueller <devin.heitmueller@kernellabs.com> |
| 11897 | */ |
| 11898 | |
| 11899 | static int drx39xxj_set_powerstate(struct dvb_frontend *fe, int enable) |
| 11900 | { |
| 11901 | struct drx39xxj_state *state = fe->demodulator_priv; |
| 11902 | struct drx_demod_instance *demod = state->demod; |
| 11903 | int result; |
| 11904 | enum drx_power_mode power_mode; |
| 11905 | |
| 11906 | if (enable) |
| 11907 | power_mode = DRX_POWER_UP; |
| 11908 | else |
| 11909 | power_mode = DRX_POWER_DOWN; |
| 11910 | |
Mauro Carvalho Chehab | b0baeb4 | 2014-01-24 13:00:08 -0300 | [diff] [blame] | 11911 | result = ctrl_power_mode(demod, &power_mode); |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 11912 | if (result != 0) { |
| 11913 | pr_err("Power state change failed\n"); |
| 11914 | return 0; |
| 11915 | } |
| 11916 | |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 11917 | return 0; |
| 11918 | } |
| 11919 | |
| 11920 | static int drx39xxj_read_status(struct dvb_frontend *fe, fe_status_t *status) |
| 11921 | { |
| 11922 | struct drx39xxj_state *state = fe->demodulator_priv; |
| 11923 | struct drx_demod_instance *demod = state->demod; |
| 11924 | int result; |
| 11925 | enum drx_lock_status lock_status; |
| 11926 | |
| 11927 | *status = 0; |
| 11928 | |
Mauro Carvalho Chehab | b0baeb4 | 2014-01-24 13:00:08 -0300 | [diff] [blame] | 11929 | result = ctrl_lock_status(demod, &lock_status); |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 11930 | if (result != 0) { |
| 11931 | pr_err("drx39xxj: could not get lock status!\n"); |
| 11932 | *status = 0; |
| 11933 | } |
| 11934 | |
| 11935 | switch (lock_status) { |
| 11936 | case DRX_NEVER_LOCK: |
| 11937 | *status = 0; |
| 11938 | pr_err("drx says NEVER_LOCK\n"); |
| 11939 | break; |
| 11940 | case DRX_NOT_LOCKED: |
| 11941 | *status = 0; |
| 11942 | break; |
| 11943 | case DRX_LOCK_STATE_1: |
| 11944 | case DRX_LOCK_STATE_2: |
| 11945 | case DRX_LOCK_STATE_3: |
| 11946 | case DRX_LOCK_STATE_4: |
| 11947 | case DRX_LOCK_STATE_5: |
| 11948 | case DRX_LOCK_STATE_6: |
| 11949 | case DRX_LOCK_STATE_7: |
| 11950 | case DRX_LOCK_STATE_8: |
| 11951 | case DRX_LOCK_STATE_9: |
| 11952 | *status = FE_HAS_SIGNAL |
| 11953 | | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC; |
| 11954 | break; |
| 11955 | case DRX_LOCKED: |
| 11956 | *status = FE_HAS_SIGNAL |
| 11957 | | FE_HAS_CARRIER |
| 11958 | | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; |
| 11959 | break; |
| 11960 | default: |
| 11961 | pr_err("Lock state unknown %d\n", lock_status); |
| 11962 | } |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 11963 | ctrl_sig_quality(demod, lock_status); |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 11964 | |
| 11965 | return 0; |
| 11966 | } |
| 11967 | |
| 11968 | static int drx39xxj_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 11969 | { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 11970 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 11971 | |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 11972 | if (p->pre_bit_error.stat[0].scale == FE_SCALE_NOT_AVAILABLE) { |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 11973 | *ber = 0; |
| 11974 | return 0; |
| 11975 | } |
| 11976 | |
Mauro Carvalho Chehab | 6983257 | 2014-03-10 08:08:53 -0300 | [diff] [blame] | 11977 | if (!p->pre_bit_count.stat[0].uvalue) { |
| 11978 | if (!p->pre_bit_error.stat[0].uvalue) |
| 11979 | *ber = 0; |
| 11980 | else |
| 11981 | *ber = 1000000; |
| 11982 | } else { |
| 11983 | *ber = frac_times1e6(p->pre_bit_error.stat[0].uvalue, |
| 11984 | p->pre_bit_count.stat[0].uvalue); |
| 11985 | } |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 11986 | return 0; |
| 11987 | } |
| 11988 | |
| 11989 | static int drx39xxj_read_signal_strength(struct dvb_frontend *fe, |
| 11990 | u16 *strength) |
| 11991 | { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 11992 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 11993 | |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 11994 | if (p->strength.stat[0].scale == FE_SCALE_NOT_AVAILABLE) { |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 11995 | *strength = 0; |
| 11996 | return 0; |
| 11997 | } |
| 11998 | |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 11999 | *strength = p->strength.stat[0].uvalue; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12000 | return 0; |
| 12001 | } |
| 12002 | |
| 12003 | static int drx39xxj_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 12004 | { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 12005 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Gianluca Gennari | 90d9c3e | 2014-03-11 10:41:47 -0300 | [diff] [blame] | 12006 | u64 tmp64; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12007 | |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 12008 | if (p->cnr.stat[0].scale == FE_SCALE_NOT_AVAILABLE) { |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12009 | *snr = 0; |
| 12010 | return 0; |
| 12011 | } |
| 12012 | |
Gianluca Gennari | 90d9c3e | 2014-03-11 10:41:47 -0300 | [diff] [blame] | 12013 | tmp64 = p->cnr.stat[0].svalue; |
| 12014 | do_div(tmp64, 10); |
| 12015 | *snr = tmp64; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12016 | return 0; |
| 12017 | } |
| 12018 | |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 12019 | static int drx39xxj_read_ucblocks(struct dvb_frontend *fe, u32 *ucb) |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12020 | { |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 12021 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12022 | |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 12023 | if (p->block_error.stat[0].scale == FE_SCALE_NOT_AVAILABLE) { |
| 12024 | *ucb = 0; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12025 | return 0; |
| 12026 | } |
| 12027 | |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 12028 | *ucb = p->block_error.stat[0].uvalue; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12029 | return 0; |
| 12030 | } |
| 12031 | |
| 12032 | static int drx39xxj_set_frontend(struct dvb_frontend *fe) |
| 12033 | { |
| 12034 | #ifdef DJH_DEBUG |
| 12035 | int i; |
| 12036 | #endif |
| 12037 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 12038 | struct drx39xxj_state *state = fe->demodulator_priv; |
| 12039 | struct drx_demod_instance *demod = state->demod; |
| 12040 | enum drx_standard standard = DRX_STANDARD_8VSB; |
| 12041 | struct drx_channel channel; |
| 12042 | int result; |
| 12043 | struct drxuio_data uio_data; |
| 12044 | static const struct drx_channel def_channel = { |
| 12045 | /* frequency */ 0, |
| 12046 | /* bandwidth */ DRX_BANDWIDTH_6MHZ, |
| 12047 | /* mirror */ DRX_MIRROR_NO, |
| 12048 | /* constellation */ DRX_CONSTELLATION_AUTO, |
| 12049 | /* hierarchy */ DRX_HIERARCHY_UNKNOWN, |
| 12050 | /* priority */ DRX_PRIORITY_UNKNOWN, |
| 12051 | /* coderate */ DRX_CODERATE_UNKNOWN, |
| 12052 | /* guard */ DRX_GUARD_UNKNOWN, |
| 12053 | /* fftmode */ DRX_FFTMODE_UNKNOWN, |
| 12054 | /* classification */ DRX_CLASSIFICATION_AUTO, |
| 12055 | /* symbolrate */ 5057000, |
| 12056 | /* interleavemode */ DRX_INTERLEAVEMODE_UNKNOWN, |
| 12057 | /* ldpc */ DRX_LDPC_UNKNOWN, |
| 12058 | /* carrier */ DRX_CARRIER_UNKNOWN, |
| 12059 | /* frame mode */ DRX_FRAMEMODE_UNKNOWN |
| 12060 | }; |
| 12061 | u32 constellation = DRX_CONSTELLATION_AUTO; |
| 12062 | |
| 12063 | /* Bring the demod out of sleep */ |
| 12064 | drx39xxj_set_powerstate(fe, 1); |
| 12065 | |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12066 | if (fe->ops.tuner_ops.set_params) { |
Mauro Carvalho Chehab | 7abc7a5 | 2014-01-26 15:02:25 -0300 | [diff] [blame] | 12067 | u32 int_freq; |
| 12068 | |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12069 | if (fe->ops.i2c_gate_ctrl) |
| 12070 | fe->ops.i2c_gate_ctrl(fe, 1); |
Mauro Carvalho Chehab | 7abc7a5 | 2014-01-26 15:02:25 -0300 | [diff] [blame] | 12071 | |
| 12072 | /* Set tuner to desired frequency and standard */ |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12073 | fe->ops.tuner_ops.set_params(fe); |
Mauro Carvalho Chehab | 7abc7a5 | 2014-01-26 15:02:25 -0300 | [diff] [blame] | 12074 | |
| 12075 | /* Use the tuner's IF */ |
| 12076 | if (fe->ops.tuner_ops.get_if_frequency) { |
| 12077 | fe->ops.tuner_ops.get_if_frequency(fe, &int_freq); |
| 12078 | demod->my_common_attr->intermediate_freq = int_freq / 1000; |
| 12079 | } |
| 12080 | |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12081 | if (fe->ops.i2c_gate_ctrl) |
| 12082 | fe->ops.i2c_gate_ctrl(fe, 0); |
| 12083 | } |
| 12084 | |
| 12085 | switch (p->delivery_system) { |
| 12086 | case SYS_ATSC: |
| 12087 | standard = DRX_STANDARD_8VSB; |
| 12088 | break; |
| 12089 | case SYS_DVBC_ANNEX_B: |
| 12090 | standard = DRX_STANDARD_ITU_B; |
| 12091 | |
| 12092 | switch (p->modulation) { |
| 12093 | case QAM_64: |
| 12094 | constellation = DRX_CONSTELLATION_QAM64; |
| 12095 | break; |
| 12096 | case QAM_256: |
| 12097 | constellation = DRX_CONSTELLATION_QAM256; |
| 12098 | break; |
| 12099 | default: |
| 12100 | constellation = DRX_CONSTELLATION_AUTO; |
| 12101 | break; |
| 12102 | } |
| 12103 | break; |
| 12104 | default: |
| 12105 | return -EINVAL; |
| 12106 | } |
Mauro Carvalho Chehab | c4dc6f9 | 2014-01-26 15:39:06 -0300 | [diff] [blame] | 12107 | /* Set the standard (will be powered up if necessary */ |
| 12108 | result = ctrl_set_standard(demod, &standard); |
| 12109 | if (result != 0) { |
| 12110 | pr_err("Failed to set standard! result=%02x\n", |
| 12111 | result); |
| 12112 | return -EINVAL; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12113 | } |
| 12114 | |
| 12115 | /* set channel parameters */ |
| 12116 | channel = def_channel; |
| 12117 | channel.frequency = p->frequency / 1000; |
| 12118 | channel.bandwidth = DRX_BANDWIDTH_6MHZ; |
| 12119 | channel.constellation = constellation; |
| 12120 | |
| 12121 | /* program channel */ |
Mauro Carvalho Chehab | b0baeb4 | 2014-01-24 13:00:08 -0300 | [diff] [blame] | 12122 | result = ctrl_set_channel(demod, &channel); |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12123 | if (result != 0) { |
| 12124 | pr_err("Failed to set channel!\n"); |
| 12125 | return -EINVAL; |
| 12126 | } |
| 12127 | /* Just for giggles, let's shut off the LNA again.... */ |
| 12128 | uio_data.uio = DRX_UIO1; |
| 12129 | uio_data.value = false; |
Mauro Carvalho Chehab | b0baeb4 | 2014-01-24 13:00:08 -0300 | [diff] [blame] | 12130 | result = ctrl_uio_write(demod, &uio_data); |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12131 | if (result != 0) { |
| 12132 | pr_err("Failed to disable LNA!\n"); |
| 12133 | return 0; |
| 12134 | } |
Mauro Carvalho Chehab | 03fdfbf | 2014-03-09 17:46:01 -0300 | [diff] [blame] | 12135 | |
| 12136 | /* After set_frontend, except for strength, stats aren't available */ |
| 12137 | p->strength.stat[0].scale = FE_SCALE_RELATIVE; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12138 | |
| 12139 | return 0; |
| 12140 | } |
| 12141 | |
| 12142 | static int drx39xxj_sleep(struct dvb_frontend *fe) |
| 12143 | { |
| 12144 | /* power-down the demodulator */ |
| 12145 | return drx39xxj_set_powerstate(fe, 0); |
| 12146 | } |
| 12147 | |
| 12148 | static int drx39xxj_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 12149 | { |
| 12150 | struct drx39xxj_state *state = fe->demodulator_priv; |
| 12151 | struct drx_demod_instance *demod = state->demod; |
| 12152 | bool i2c_gate_state; |
| 12153 | int result; |
| 12154 | |
| 12155 | #ifdef DJH_DEBUG |
Shuah Khan | 6c955b8 | 2014-02-28 18:23:00 -0300 | [diff] [blame] | 12156 | pr_debug("i2c gate call: enable=%d state=%d\n", enable, |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12157 | state->i2c_gate_open); |
| 12158 | #endif |
| 12159 | |
| 12160 | if (enable) |
| 12161 | i2c_gate_state = true; |
| 12162 | else |
| 12163 | i2c_gate_state = false; |
| 12164 | |
| 12165 | if (state->i2c_gate_open == enable) { |
| 12166 | /* We're already in the desired state */ |
| 12167 | return 0; |
| 12168 | } |
| 12169 | |
Mauro Carvalho Chehab | b0baeb4 | 2014-01-24 13:00:08 -0300 | [diff] [blame] | 12170 | result = ctrl_i2c_bridge(demod, &i2c_gate_state); |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12171 | if (result != 0) { |
| 12172 | pr_err("drx39xxj: could not open i2c gate [%d]\n", |
| 12173 | result); |
| 12174 | dump_stack(); |
| 12175 | } else { |
| 12176 | state->i2c_gate_open = enable; |
| 12177 | } |
| 12178 | return 0; |
| 12179 | } |
| 12180 | |
| 12181 | static int drx39xxj_init(struct dvb_frontend *fe) |
| 12182 | { |
| 12183 | /* Bring the demod out of sleep */ |
| 12184 | drx39xxj_set_powerstate(fe, 1); |
| 12185 | |
| 12186 | return 0; |
| 12187 | } |
| 12188 | |
Mauro Carvalho Chehab | ea8f3c2 | 2014-02-16 00:38:44 -0300 | [diff] [blame] | 12189 | static int drx39xxj_set_lna(struct dvb_frontend *fe) |
| 12190 | { |
| 12191 | int result; |
| 12192 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 12193 | struct drx39xxj_state *state = fe->demodulator_priv; |
| 12194 | struct drx_demod_instance *demod = state->demod; |
| 12195 | struct drxj_data *ext_attr = demod->my_ext_attr; |
| 12196 | struct drxuio_cfg uio_cfg; |
| 12197 | struct drxuio_data uio_data; |
| 12198 | |
| 12199 | if (c->lna) { |
| 12200 | if (!ext_attr->has_lna) { |
| 12201 | pr_err("LNA is not supported on this device!\n"); |
| 12202 | return -EINVAL; |
| 12203 | |
| 12204 | } |
| 12205 | } |
| 12206 | |
| 12207 | /* Turn off the LNA */ |
| 12208 | uio_cfg.uio = DRX_UIO1; |
| 12209 | uio_cfg.mode = DRX_UIO_MODE_READWRITE; |
| 12210 | /* Configure user-I/O #3: enable read/write */ |
| 12211 | result = ctrl_set_uio_cfg(demod, &uio_cfg); |
| 12212 | if (result) { |
| 12213 | pr_err("Failed to setup LNA GPIO!\n"); |
| 12214 | return result; |
| 12215 | } |
| 12216 | |
| 12217 | uio_data.uio = DRX_UIO1; |
| 12218 | uio_data.value = c->lna; |
| 12219 | result = ctrl_uio_write(demod, &uio_data); |
| 12220 | if (result != 0) { |
| 12221 | pr_err("Failed to %sable LNA!\n", |
| 12222 | c->lna ? "en" : "dis"); |
| 12223 | return result; |
| 12224 | } |
| 12225 | |
| 12226 | return 0; |
| 12227 | } |
| 12228 | |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12229 | static int drx39xxj_get_tune_settings(struct dvb_frontend *fe, |
| 12230 | struct dvb_frontend_tune_settings *tune) |
| 12231 | { |
| 12232 | tune->min_delay_ms = 1000; |
| 12233 | return 0; |
| 12234 | } |
| 12235 | |
| 12236 | static void drx39xxj_release(struct dvb_frontend *fe) |
| 12237 | { |
| 12238 | struct drx39xxj_state *state = fe->demodulator_priv; |
| 12239 | struct drx_demod_instance *demod = state->demod; |
| 12240 | |
Mauro Carvalho Chehab | 1e5ec31 | 2014-03-09 10:33:54 -0300 | [diff] [blame] | 12241 | drxj_close(demod); |
| 12242 | |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12243 | kfree(demod->my_ext_attr); |
| 12244 | kfree(demod->my_common_attr); |
| 12245 | kfree(demod->my_i2c_dev_addr); |
| 12246 | if (demod->firmware) |
| 12247 | release_firmware(demod->firmware); |
| 12248 | kfree(demod); |
| 12249 | kfree(state); |
| 12250 | } |
| 12251 | |
| 12252 | static struct dvb_frontend_ops drx39xxj_ops; |
| 12253 | |
| 12254 | struct dvb_frontend *drx39xxj_attach(struct i2c_adapter *i2c) |
| 12255 | { |
| 12256 | struct drx39xxj_state *state = NULL; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12257 | struct i2c_device_addr *demod_addr = NULL; |
| 12258 | struct drx_common_attr *demod_comm_attr = NULL; |
| 12259 | struct drxj_data *demod_ext_attr = NULL; |
| 12260 | struct drx_demod_instance *demod = NULL; |
Mauro Carvalho Chehab | d591590 | 2014-03-10 08:22:34 -0300 | [diff] [blame] | 12261 | struct dtv_frontend_properties *p; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12262 | struct drxuio_cfg uio_cfg; |
| 12263 | struct drxuio_data uio_data; |
| 12264 | int result; |
| 12265 | |
| 12266 | /* allocate memory for the internal state */ |
| 12267 | state = kzalloc(sizeof(struct drx39xxj_state), GFP_KERNEL); |
| 12268 | if (state == NULL) |
| 12269 | goto error; |
| 12270 | |
| 12271 | demod = kmalloc(sizeof(struct drx_demod_instance), GFP_KERNEL); |
| 12272 | if (demod == NULL) |
| 12273 | goto error; |
| 12274 | |
| 12275 | demod_addr = kmalloc(sizeof(struct i2c_device_addr), GFP_KERNEL); |
| 12276 | if (demod_addr == NULL) |
| 12277 | goto error; |
| 12278 | memcpy(demod_addr, &drxj_default_addr_g, |
| 12279 | sizeof(struct i2c_device_addr)); |
| 12280 | |
| 12281 | demod_comm_attr = kmalloc(sizeof(struct drx_common_attr), GFP_KERNEL); |
| 12282 | if (demod_comm_attr == NULL) |
| 12283 | goto error; |
| 12284 | memcpy(demod_comm_attr, &drxj_default_comm_attr_g, |
| 12285 | sizeof(struct drx_common_attr)); |
| 12286 | |
| 12287 | demod_ext_attr = kmalloc(sizeof(struct drxj_data), GFP_KERNEL); |
| 12288 | if (demod_ext_attr == NULL) |
| 12289 | goto error; |
| 12290 | memcpy(demod_ext_attr, &drxj_data_g, sizeof(struct drxj_data)); |
| 12291 | |
| 12292 | /* setup the state */ |
| 12293 | state->i2c = i2c; |
| 12294 | state->demod = demod; |
| 12295 | |
| 12296 | /* setup the demod data */ |
| 12297 | memcpy(demod, &drxj_default_demod_g, sizeof(struct drx_demod_instance)); |
| 12298 | |
| 12299 | demod->my_i2c_dev_addr = demod_addr; |
| 12300 | demod->my_common_attr = demod_comm_attr; |
| 12301 | demod->my_i2c_dev_addr->user_data = state; |
| 12302 | demod->my_common_attr->microcode_file = DRX39XX_MAIN_FIRMWARE; |
| 12303 | demod->my_common_attr->verify_microcode = true; |
| 12304 | demod->my_common_attr->intermediate_freq = 5000; |
Mauro Carvalho Chehab | d7a5478 | 2014-02-27 05:35:13 -0300 | [diff] [blame] | 12305 | demod->my_common_attr->current_power_mode = DRX_POWER_DOWN; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12306 | demod->my_ext_attr = demod_ext_attr; |
| 12307 | ((struct drxj_data *)demod_ext_attr)->uio_sma_tx_mode = DRX_UIO_MODE_READWRITE; |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12308 | demod->i2c = i2c; |
| 12309 | |
| 12310 | result = drxj_open(demod); |
| 12311 | if (result != 0) { |
| 12312 | pr_err("DRX open failed! Aborting\n"); |
| 12313 | goto error; |
| 12314 | } |
| 12315 | |
| 12316 | /* Turn off the LNA */ |
| 12317 | uio_cfg.uio = DRX_UIO1; |
| 12318 | uio_cfg.mode = DRX_UIO_MODE_READWRITE; |
| 12319 | /* Configure user-I/O #3: enable read/write */ |
Mauro Carvalho Chehab | b0baeb4 | 2014-01-24 13:00:08 -0300 | [diff] [blame] | 12320 | result = ctrl_set_uio_cfg(demod, &uio_cfg); |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12321 | if (result) { |
| 12322 | pr_err("Failed to setup LNA GPIO!\n"); |
| 12323 | goto error; |
| 12324 | } |
| 12325 | |
| 12326 | uio_data.uio = DRX_UIO1; |
| 12327 | uio_data.value = false; |
Mauro Carvalho Chehab | b0baeb4 | 2014-01-24 13:00:08 -0300 | [diff] [blame] | 12328 | result = ctrl_uio_write(demod, &uio_data); |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12329 | if (result != 0) { |
| 12330 | pr_err("Failed to disable LNA!\n"); |
| 12331 | goto error; |
| 12332 | } |
| 12333 | |
| 12334 | /* create dvb_frontend */ |
| 12335 | memcpy(&state->frontend.ops, &drx39xxj_ops, |
| 12336 | sizeof(struct dvb_frontend_ops)); |
| 12337 | |
| 12338 | state->frontend.demodulator_priv = state; |
Mauro Carvalho Chehab | d591590 | 2014-03-10 08:22:34 -0300 | [diff] [blame] | 12339 | |
| 12340 | /* Initialize stats - needed for DVBv5 stats to work */ |
| 12341 | p = &state->frontend.dtv_property_cache; |
| 12342 | p->strength.len = 1; |
| 12343 | p->pre_bit_count.len = 1; |
| 12344 | p->pre_bit_error.len = 1; |
| 12345 | p->post_bit_count.len = 1; |
| 12346 | p->post_bit_error.len = 1; |
| 12347 | p->block_count.len = 1; |
| 12348 | p->block_error.len = 1; |
| 12349 | p->cnr.len = 1; |
| 12350 | |
| 12351 | p->strength.stat[0].scale = FE_SCALE_RELATIVE; |
| 12352 | p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 12353 | p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 12354 | p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 12355 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 12356 | p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 12357 | p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 12358 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 12359 | |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12360 | return &state->frontend; |
| 12361 | |
| 12362 | error: |
| 12363 | kfree(demod_ext_attr); |
| 12364 | kfree(demod_comm_attr); |
| 12365 | kfree(demod_addr); |
| 12366 | kfree(demod); |
| 12367 | kfree(state); |
| 12368 | |
| 12369 | return NULL; |
| 12370 | } |
| 12371 | EXPORT_SYMBOL(drx39xxj_attach); |
| 12372 | |
| 12373 | static struct dvb_frontend_ops drx39xxj_ops = { |
| 12374 | .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B }, |
| 12375 | .info = { |
| 12376 | .name = "Micronas DRX39xxj family Frontend", |
| 12377 | .frequency_stepsize = 62500, |
| 12378 | .frequency_min = 51000000, |
| 12379 | .frequency_max = 858000000, |
| 12380 | .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB |
| 12381 | }, |
| 12382 | |
| 12383 | .init = drx39xxj_init, |
| 12384 | .i2c_gate_ctrl = drx39xxj_i2c_gate_ctrl, |
| 12385 | .sleep = drx39xxj_sleep, |
| 12386 | .set_frontend = drx39xxj_set_frontend, |
| 12387 | .get_tune_settings = drx39xxj_get_tune_settings, |
| 12388 | .read_status = drx39xxj_read_status, |
| 12389 | .read_ber = drx39xxj_read_ber, |
| 12390 | .read_signal_strength = drx39xxj_read_signal_strength, |
| 12391 | .read_snr = drx39xxj_read_snr, |
| 12392 | .read_ucblocks = drx39xxj_read_ucblocks, |
| 12393 | .release = drx39xxj_release, |
Mauro Carvalho Chehab | ea8f3c2 | 2014-02-16 00:38:44 -0300 | [diff] [blame] | 12394 | .set_lna = drx39xxj_set_lna, |
Mauro Carvalho Chehab | 1901374 | 2014-01-24 12:25:04 -0300 | [diff] [blame] | 12395 | }; |
| 12396 | |
| 12397 | MODULE_DESCRIPTION("Micronas DRX39xxj Frontend"); |
| 12398 | MODULE_AUTHOR("Devin Heitmueller"); |
| 12399 | MODULE_LICENSE("GPL"); |
| 12400 | MODULE_FIRMWARE(DRX39XX_MAIN_FIRMWARE); |