Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 1 | #include <linux/init.h> |
| 2 | #include <linux/kernel.h> |
| 3 | #include <linux/module.h> |
| 4 | #include <linux/string.h> |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 5 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 6 | #include "mt2063.h" |
| 7 | |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 8 | static unsigned int verbose; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 9 | module_param(verbose, int, 0644); |
| 10 | |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 11 | /* Internal structures and types */ |
| 12 | |
Mauro Carvalho Chehab | 29a0a4fe | 2011-07-20 23:44:10 -0300 | [diff] [blame] | 13 | /* FIXME: Those two error codes need conversion*/ |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 14 | /* Error: Upconverter PLL is not locked */ |
| 15 | #define MT2063_UPC_UNLOCK (0x80000002) |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 16 | /* Error: Downconverter PLL is not locked */ |
| 17 | #define MT2063_DNC_UNLOCK (0x80000004) |
Mauro Carvalho Chehab | 29a0a4fe | 2011-07-20 23:44:10 -0300 | [diff] [blame] | 18 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 19 | /* Info: Unavoidable LO-related spur may be present in the output */ |
Mauro Carvalho Chehab | 29a0a4fe | 2011-07-20 23:44:10 -0300 | [diff] [blame] | 20 | #define MT2063_SPUR_PRESENT_ERR (0x00800000) |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 21 | |
| 22 | /* Info: Mask of bits used for # of LO-related spurs that were avoided during tuning */ |
| 23 | #define MT2063_SPUR_CNT_MASK (0x001f0000) |
| 24 | #define MT2063_SPUR_SHIFT (16) |
| 25 | |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 26 | /* Info: Upconverter frequency is out of range (may be reason for MT_UPC_UNLOCK) */ |
| 27 | #define MT2063_UPC_RANGE (0x04000000) |
| 28 | |
| 29 | /* Info: Downconverter frequency is out of range (may be reason for MT_DPC_UNLOCK) */ |
| 30 | #define MT2063_DNC_RANGE (0x08000000) |
| 31 | |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 32 | /* |
Mauro Carvalho Chehab | 29a0a4fe | 2011-07-20 23:44:10 -0300 | [diff] [blame] | 33 | * Data Types |
| 34 | */ |
| 35 | |
| 36 | /* |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 37 | * Constant defining the version of the following structure |
| 38 | * and therefore the API for this code. |
| 39 | * |
| 40 | * When compiling the tuner driver, the preprocessor will |
| 41 | * check against this version number to make sure that |
| 42 | * it matches the version that the tuner driver knows about. |
| 43 | */ |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 44 | |
| 45 | /* DECT Frequency Avoidance */ |
| 46 | #define MT2063_DECT_AVOID_US_FREQS 0x00000001 |
| 47 | |
| 48 | #define MT2063_DECT_AVOID_EURO_FREQS 0x00000002 |
| 49 | |
| 50 | #define MT2063_EXCLUDE_US_DECT_FREQUENCIES(s) (((s) & MT2063_DECT_AVOID_US_FREQS) != 0) |
| 51 | |
| 52 | #define MT2063_EXCLUDE_EURO_DECT_FREQUENCIES(s) (((s) & MT2063_DECT_AVOID_EURO_FREQS) != 0) |
| 53 | |
| 54 | enum MT2063_DECT_Avoid_Type { |
| 55 | MT2063_NO_DECT_AVOIDANCE = 0, /* Do not create DECT exclusion zones. */ |
| 56 | MT2063_AVOID_US_DECT = MT2063_DECT_AVOID_US_FREQS, /* Avoid US DECT frequencies. */ |
| 57 | MT2063_AVOID_EURO_DECT = MT2063_DECT_AVOID_EURO_FREQS, /* Avoid European DECT frequencies. */ |
| 58 | MT2063_AVOID_BOTH /* Avoid both regions. Not typically used. */ |
| 59 | }; |
| 60 | |
| 61 | #define MT2063_MAX_ZONES 48 |
| 62 | |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 63 | struct MT2063_ExclZone_t { |
| 64 | u32 min_; |
| 65 | u32 max_; |
| 66 | struct MT2063_ExclZone_t *next_; |
| 67 | }; |
| 68 | |
| 69 | /* |
| 70 | * Structure of data needed for Spur Avoidance |
| 71 | */ |
| 72 | struct MT2063_AvoidSpursData_t { |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 73 | u32 f_ref; |
| 74 | u32 f_in; |
| 75 | u32 f_LO1; |
| 76 | u32 f_if1_Center; |
| 77 | u32 f_if1_Request; |
| 78 | u32 f_if1_bw; |
| 79 | u32 f_LO2; |
| 80 | u32 f_out; |
| 81 | u32 f_out_bw; |
| 82 | u32 f_LO1_Step; |
| 83 | u32 f_LO2_Step; |
| 84 | u32 f_LO1_FracN_Avoid; |
| 85 | u32 f_LO2_FracN_Avoid; |
| 86 | u32 f_zif_bw; |
| 87 | u32 f_min_LO_Separation; |
| 88 | u32 maxH1; |
| 89 | u32 maxH2; |
| 90 | enum MT2063_DECT_Avoid_Type avoidDECT; |
| 91 | u32 bSpurPresent; |
| 92 | u32 bSpurAvoided; |
| 93 | u32 nSpursFound; |
| 94 | u32 nZones; |
| 95 | struct MT2063_ExclZone_t *freeZones; |
| 96 | struct MT2063_ExclZone_t *usedZones; |
| 97 | struct MT2063_ExclZone_t MT2063_ExclZones[MT2063_MAX_ZONES]; |
| 98 | }; |
| 99 | |
| 100 | /* |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 101 | * Parameter for function MT2063_SetPowerMask that specifies the power down |
| 102 | * of various sections of the MT2063. |
| 103 | */ |
| 104 | enum MT2063_Mask_Bits { |
| 105 | MT2063_REG_SD = 0x0040, /* Shutdown regulator */ |
| 106 | MT2063_SRO_SD = 0x0020, /* Shutdown SRO */ |
| 107 | MT2063_AFC_SD = 0x0010, /* Shutdown AFC A/D */ |
| 108 | MT2063_PD_SD = 0x0002, /* Enable power detector shutdown */ |
| 109 | MT2063_PDADC_SD = 0x0001, /* Enable power detector A/D shutdown */ |
| 110 | MT2063_VCO_SD = 0x8000, /* Enable VCO shutdown */ |
| 111 | MT2063_LTX_SD = 0x4000, /* Enable LTX shutdown */ |
| 112 | MT2063_LT1_SD = 0x2000, /* Enable LT1 shutdown */ |
| 113 | MT2063_LNA_SD = 0x1000, /* Enable LNA shutdown */ |
| 114 | MT2063_UPC_SD = 0x0800, /* Enable upconverter shutdown */ |
| 115 | MT2063_DNC_SD = 0x0400, /* Enable downconverter shutdown */ |
| 116 | MT2063_VGA_SD = 0x0200, /* Enable VGA shutdown */ |
| 117 | MT2063_AMP_SD = 0x0100, /* Enable AMP shutdown */ |
| 118 | MT2063_ALL_SD = 0xFF73, /* All shutdown bits for this tuner */ |
| 119 | MT2063_NONE_SD = 0x0000 /* No shutdown bits */ |
| 120 | }; |
| 121 | |
| 122 | /* |
| 123 | * Parameter for function MT2063_GetParam & MT2063_SetParam that |
| 124 | * specifies the tuning algorithm parameter to be read/written. |
| 125 | */ |
| 126 | enum MT2063_Param { |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 127 | /* min tuning step size (default: 50000 Hz) */ |
| 128 | MT2063_STEPSIZE, |
| 129 | |
| 130 | /* input center frequency set by MT2063_Tune() */ |
| 131 | MT2063_INPUT_FREQ, |
| 132 | |
| 133 | /* LO1 Frequency set by MT2063_Tune() */ |
| 134 | MT2063_LO1_FREQ, |
| 135 | |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 136 | /* LO2 Frequency set by MT2063_Tune() */ |
| 137 | MT2063_LO2_FREQ, |
| 138 | |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 139 | /* output center frequency set by MT2063_Tune() */ |
| 140 | MT2063_OUTPUT_FREQ, |
| 141 | |
| 142 | /* output bandwidth set by MT2063_Tune() */ |
| 143 | MT2063_OUTPUT_BW, |
| 144 | |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 145 | /* Receiver Mode for some parameters. 1 is DVB-T */ |
| 146 | MT2063_RCVR_MODE, |
| 147 | |
| 148 | /* directly set LNA attenuation, parameter is value to set */ |
| 149 | MT2063_ACLNA, |
| 150 | |
| 151 | /* maximum LNA attenuation, parameter is value to set */ |
| 152 | MT2063_ACLNA_MAX, |
| 153 | |
| 154 | /* directly set ATN attenuation. Paremeter is value to set. */ |
| 155 | MT2063_ACRF, |
| 156 | |
| 157 | /* maxium ATN attenuation. Paremeter is value to set. */ |
| 158 | MT2063_ACRF_MAX, |
| 159 | |
| 160 | /* directly set FIF attenuation. Paremeter is value to set. */ |
| 161 | MT2063_ACFIF, |
| 162 | |
| 163 | /* maxium FIF attenuation. Paremeter is value to set. */ |
| 164 | MT2063_ACFIF_MAX, |
| 165 | |
| 166 | /* LNA Rin */ |
| 167 | MT2063_LNA_RIN, |
| 168 | |
| 169 | /* Power Detector LNA level target */ |
| 170 | MT2063_LNA_TGT, |
| 171 | |
| 172 | /* Power Detector 1 level */ |
| 173 | MT2063_PD1, |
| 174 | |
| 175 | /* Power Detector 1 level target */ |
| 176 | MT2063_PD1_TGT, |
| 177 | |
| 178 | /* Power Detector 2 level */ |
| 179 | MT2063_PD2, |
| 180 | |
| 181 | /* Power Detector 2 level target */ |
| 182 | MT2063_PD2_TGT, |
| 183 | |
| 184 | /* Selects, which DNC is activ */ |
| 185 | MT2063_DNC_OUTPUT_ENABLE, |
| 186 | |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 187 | MT2063_EOP /* last entry in enumerated list */ |
| 188 | }; |
| 189 | |
| 190 | /* |
| 191 | * Parameter for selecting tuner mode |
| 192 | */ |
| 193 | enum MT2063_RCVR_MODES { |
| 194 | MT2063_CABLE_QAM = 0, /* Digital cable */ |
| 195 | MT2063_CABLE_ANALOG, /* Analog cable */ |
| 196 | MT2063_OFFAIR_COFDM, /* Digital offair */ |
| 197 | MT2063_OFFAIR_COFDM_SAWLESS, /* Digital offair without SAW */ |
| 198 | MT2063_OFFAIR_ANALOG, /* Analog offair */ |
| 199 | MT2063_OFFAIR_8VSB, /* Analog offair */ |
| 200 | MT2063_NUM_RCVR_MODES |
| 201 | }; |
| 202 | |
| 203 | /* |
| 204 | * Possible values for MT2063_DNC_OUTPUT |
| 205 | */ |
| 206 | enum MT2063_DNC_Output_Enable { |
| 207 | MT2063_DNC_NONE = 0, |
| 208 | MT2063_DNC_1, |
| 209 | MT2063_DNC_2, |
| 210 | MT2063_DNC_BOTH |
| 211 | }; |
| 212 | |
| 213 | /* |
| 214 | ** Two-wire serial bus subaddresses of the tuner registers. |
| 215 | ** Also known as the tuner's register addresses. |
| 216 | */ |
| 217 | enum MT2063_Register_Offsets { |
| 218 | MT2063_REG_PART_REV = 0, /* 0x00: Part/Rev Code */ |
| 219 | MT2063_REG_LO1CQ_1, /* 0x01: LO1C Queued Byte 1 */ |
| 220 | MT2063_REG_LO1CQ_2, /* 0x02: LO1C Queued Byte 2 */ |
| 221 | MT2063_REG_LO2CQ_1, /* 0x03: LO2C Queued Byte 1 */ |
| 222 | MT2063_REG_LO2CQ_2, /* 0x04: LO2C Queued Byte 2 */ |
| 223 | MT2063_REG_LO2CQ_3, /* 0x05: LO2C Queued Byte 3 */ |
| 224 | MT2063_REG_RSVD_06, /* 0x06: Reserved */ |
| 225 | MT2063_REG_LO_STATUS, /* 0x07: LO Status */ |
| 226 | MT2063_REG_FIFFC, /* 0x08: FIFF Center */ |
| 227 | MT2063_REG_CLEARTUNE, /* 0x09: ClearTune Filter */ |
| 228 | MT2063_REG_ADC_OUT, /* 0x0A: ADC_OUT */ |
| 229 | MT2063_REG_LO1C_1, /* 0x0B: LO1C Byte 1 */ |
| 230 | MT2063_REG_LO1C_2, /* 0x0C: LO1C Byte 2 */ |
| 231 | MT2063_REG_LO2C_1, /* 0x0D: LO2C Byte 1 */ |
| 232 | MT2063_REG_LO2C_2, /* 0x0E: LO2C Byte 2 */ |
| 233 | MT2063_REG_LO2C_3, /* 0x0F: LO2C Byte 3 */ |
| 234 | MT2063_REG_RSVD_10, /* 0x10: Reserved */ |
| 235 | MT2063_REG_PWR_1, /* 0x11: PWR Byte 1 */ |
| 236 | MT2063_REG_PWR_2, /* 0x12: PWR Byte 2 */ |
| 237 | MT2063_REG_TEMP_STATUS, /* 0x13: Temp Status */ |
| 238 | MT2063_REG_XO_STATUS, /* 0x14: Crystal Status */ |
| 239 | MT2063_REG_RF_STATUS, /* 0x15: RF Attn Status */ |
| 240 | MT2063_REG_FIF_STATUS, /* 0x16: FIF Attn Status */ |
| 241 | MT2063_REG_LNA_OV, /* 0x17: LNA Attn Override */ |
| 242 | MT2063_REG_RF_OV, /* 0x18: RF Attn Override */ |
| 243 | MT2063_REG_FIF_OV, /* 0x19: FIF Attn Override */ |
| 244 | MT2063_REG_LNA_TGT, /* 0x1A: Reserved */ |
| 245 | MT2063_REG_PD1_TGT, /* 0x1B: Pwr Det 1 Target */ |
| 246 | MT2063_REG_PD2_TGT, /* 0x1C: Pwr Det 2 Target */ |
| 247 | MT2063_REG_RSVD_1D, /* 0x1D: Reserved */ |
| 248 | MT2063_REG_RSVD_1E, /* 0x1E: Reserved */ |
| 249 | MT2063_REG_RSVD_1F, /* 0x1F: Reserved */ |
| 250 | MT2063_REG_RSVD_20, /* 0x20: Reserved */ |
| 251 | MT2063_REG_BYP_CTRL, /* 0x21: Bypass Control */ |
| 252 | MT2063_REG_RSVD_22, /* 0x22: Reserved */ |
| 253 | MT2063_REG_RSVD_23, /* 0x23: Reserved */ |
| 254 | MT2063_REG_RSVD_24, /* 0x24: Reserved */ |
| 255 | MT2063_REG_RSVD_25, /* 0x25: Reserved */ |
| 256 | MT2063_REG_RSVD_26, /* 0x26: Reserved */ |
| 257 | MT2063_REG_RSVD_27, /* 0x27: Reserved */ |
| 258 | MT2063_REG_FIFF_CTRL, /* 0x28: FIFF Control */ |
| 259 | MT2063_REG_FIFF_OFFSET, /* 0x29: FIFF Offset */ |
| 260 | MT2063_REG_CTUNE_CTRL, /* 0x2A: Reserved */ |
| 261 | MT2063_REG_CTUNE_OV, /* 0x2B: Reserved */ |
| 262 | MT2063_REG_CTRL_2C, /* 0x2C: Reserved */ |
| 263 | MT2063_REG_FIFF_CTRL2, /* 0x2D: Fiff Control */ |
| 264 | MT2063_REG_RSVD_2E, /* 0x2E: Reserved */ |
| 265 | MT2063_REG_DNC_GAIN, /* 0x2F: DNC Control */ |
| 266 | MT2063_REG_VGA_GAIN, /* 0x30: VGA Gain Ctrl */ |
| 267 | MT2063_REG_RSVD_31, /* 0x31: Reserved */ |
| 268 | MT2063_REG_TEMP_SEL, /* 0x32: Temperature Selection */ |
| 269 | MT2063_REG_RSVD_33, /* 0x33: Reserved */ |
| 270 | MT2063_REG_RSVD_34, /* 0x34: Reserved */ |
| 271 | MT2063_REG_RSVD_35, /* 0x35: Reserved */ |
| 272 | MT2063_REG_RSVD_36, /* 0x36: Reserved */ |
| 273 | MT2063_REG_RSVD_37, /* 0x37: Reserved */ |
| 274 | MT2063_REG_RSVD_38, /* 0x38: Reserved */ |
| 275 | MT2063_REG_RSVD_39, /* 0x39: Reserved */ |
| 276 | MT2063_REG_RSVD_3A, /* 0x3A: Reserved */ |
| 277 | MT2063_REG_RSVD_3B, /* 0x3B: Reserved */ |
| 278 | MT2063_REG_RSVD_3C, /* 0x3C: Reserved */ |
| 279 | MT2063_REG_END_REGS |
| 280 | }; |
| 281 | |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 282 | enum MTTune_atv_standard { |
| 283 | MTTUNEA_UNKNOWN = 0, |
| 284 | MTTUNEA_PAL_B, |
| 285 | MTTUNEA_PAL_G, |
| 286 | MTTUNEA_PAL_I, |
| 287 | MTTUNEA_PAL_L, |
| 288 | MTTUNEA_PAL_MN, |
| 289 | MTTUNEA_PAL_DK, |
| 290 | MTTUNEA_DIGITAL, |
| 291 | MTTUNEA_FMRADIO, |
| 292 | MTTUNEA_DVBC, |
| 293 | MTTUNEA_DVBT |
| 294 | }; |
| 295 | |
| 296 | |
| 297 | struct mt2063_state { |
| 298 | struct i2c_adapter *i2c; |
| 299 | |
| 300 | const struct mt2063_config *config; |
| 301 | struct dvb_tuner_ops ops; |
| 302 | struct dvb_frontend *frontend; |
| 303 | struct tuner_state status; |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 304 | |
| 305 | enum MTTune_atv_standard tv_type; |
| 306 | u32 frequency; |
| 307 | u32 srate; |
| 308 | u32 bandwidth; |
| 309 | u32 reference; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 310 | |
| 311 | u32 tuner_id; |
| 312 | struct MT2063_AvoidSpursData_t AS_Data; |
| 313 | u32 f_IF1_actual; |
| 314 | u32 rcvr_mode; |
| 315 | u32 ctfilt_sw; |
| 316 | u32 CTFiltMax[31]; |
| 317 | u32 num_regs; |
| 318 | u8 reg[MT2063_REG_END_REGS]; |
Mauro Carvalho Chehab | 6d3d748 | 2011-07-20 22:21:26 -0300 | [diff] [blame] | 319 | }; |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 320 | |
Mauro Carvalho Chehab | bf97555 | 2011-07-20 21:43:30 -0300 | [diff] [blame] | 321 | /* Prototypes */ |
| 322 | static void MT2063_AddExclZone(struct MT2063_AvoidSpursData_t *pAS_Info, |
| 323 | u32 f_min, u32 f_max); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 324 | static u32 MT2063_GetReg(struct mt2063_state *state, u8 reg, u8 * val); |
| 325 | static u32 MT2063_GetParam(struct mt2063_state *state, enum MT2063_Param param, u32 * pValue); |
| 326 | static u32 MT2063_SetReg(struct mt2063_state *state, u8 reg, u8 val); |
| 327 | static u32 MT2063_SetParam(struct mt2063_state *state, enum MT2063_Param param, |
Mauro Carvalho Chehab | 29a0a4fe | 2011-07-20 23:44:10 -0300 | [diff] [blame] | 328 | enum MT2063_DNC_Output_Enable nValue); |
Mauro Carvalho Chehab | 8c64f932 | 2011-07-21 03:29:06 -0300 | [diff] [blame] | 329 | static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown); |
| 330 | static u32 MT2063_ClearPowerMaskBits(struct mt2063_state *state, enum MT2063_Mask_Bits Bits); |
| 331 | |
Mauro Carvalho Chehab | bf97555 | 2011-07-20 21:43:30 -0300 | [diff] [blame] | 332 | |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 333 | /*****************/ |
| 334 | /* From drivers/media/common/tuners/mt2063_cfg.h */ |
| 335 | |
Mauro Carvalho Chehab | f867695 | 2011-07-20 22:00:30 -0300 | [diff] [blame] | 336 | unsigned int mt2063_setTune(struct dvb_frontend *fe, u32 f_in, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 337 | u32 bw_in, |
| 338 | enum MTTune_atv_standard tv_type) |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 339 | { |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 340 | struct dvb_frontend_ops *frontend_ops = NULL; |
| 341 | struct dvb_tuner_ops *tuner_ops = NULL; |
| 342 | struct tuner_state t_state; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 343 | struct mt2063_state *state = fe->tuner_priv; |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 344 | int err = 0; |
| 345 | |
| 346 | t_state.frequency = f_in; |
| 347 | t_state.bandwidth = bw_in; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 348 | state->tv_type = tv_type; |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 349 | if (&fe->ops) |
| 350 | frontend_ops = &fe->ops; |
| 351 | if (&frontend_ops->tuner_ops) |
| 352 | tuner_ops = &frontend_ops->tuner_ops; |
| 353 | if (tuner_ops->set_state) { |
| 354 | if ((err = |
| 355 | tuner_ops->set_state(fe, DVBFE_TUNER_FREQUENCY, |
| 356 | &t_state)) < 0) { |
| 357 | printk("%s: Invalid parameter\n", __func__); |
| 358 | return err; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | return err; |
| 363 | } |
| 364 | |
Mauro Carvalho Chehab | f867695 | 2011-07-20 22:00:30 -0300 | [diff] [blame] | 365 | unsigned int mt2063_lockStatus(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 366 | { |
| 367 | struct dvb_frontend_ops *frontend_ops = &fe->ops; |
| 368 | struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; |
| 369 | struct tuner_state t_state; |
| 370 | int err = 0; |
| 371 | |
| 372 | if (&fe->ops) |
| 373 | frontend_ops = &fe->ops; |
| 374 | if (&frontend_ops->tuner_ops) |
| 375 | tuner_ops = &frontend_ops->tuner_ops; |
| 376 | if (tuner_ops->get_state) { |
| 377 | if ((err = |
| 378 | tuner_ops->get_state(fe, DVBFE_TUNER_REFCLOCK, |
| 379 | &t_state)) < 0) { |
| 380 | printk("%s: Invalid parameter\n", __func__); |
| 381 | return err; |
| 382 | } |
| 383 | } |
| 384 | return err; |
| 385 | } |
| 386 | |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 387 | |
Mauro Carvalho Chehab | f867695 | 2011-07-20 22:00:30 -0300 | [diff] [blame] | 388 | unsigned int tuner_MT2063_SoftwareShutdown(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 389 | { |
Mauro Carvalho Chehab | 8c64f932 | 2011-07-21 03:29:06 -0300 | [diff] [blame] | 390 | struct mt2063_state *state = fe->tuner_priv; |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 391 | struct dvb_frontend_ops *frontend_ops = &fe->ops; |
| 392 | struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 393 | int err = 0; |
| 394 | |
| 395 | if (&fe->ops) |
| 396 | frontend_ops = &fe->ops; |
| 397 | if (&frontend_ops->tuner_ops) |
| 398 | tuner_ops = &frontend_ops->tuner_ops; |
| 399 | if (tuner_ops->set_state) { |
Mauro Carvalho Chehab | 8c64f932 | 2011-07-21 03:29:06 -0300 | [diff] [blame] | 400 | err = MT2063_SoftwareShutdown(state, 1); |
| 401 | if (err < 0) { |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 402 | printk("%s: Invalid parameter\n", __func__); |
| 403 | return err; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | return err; |
| 408 | } |
| 409 | |
Mauro Carvalho Chehab | f867695 | 2011-07-20 22:00:30 -0300 | [diff] [blame] | 410 | unsigned int tuner_MT2063_ClearPowerMaskBits(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 411 | { |
Mauro Carvalho Chehab | 8c64f932 | 2011-07-21 03:29:06 -0300 | [diff] [blame] | 412 | struct mt2063_state *state = fe->tuner_priv; |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 413 | struct dvb_frontend_ops *frontend_ops = &fe->ops; |
| 414 | struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 415 | int err = 0; |
| 416 | |
| 417 | if (&fe->ops) |
| 418 | frontend_ops = &fe->ops; |
| 419 | if (&frontend_ops->tuner_ops) |
| 420 | tuner_ops = &frontend_ops->tuner_ops; |
| 421 | if (tuner_ops->set_state) { |
Mauro Carvalho Chehab | 8c64f932 | 2011-07-21 03:29:06 -0300 | [diff] [blame] | 422 | err = MT2063_ClearPowerMaskBits(state, MT2063_ALL_SD); |
| 423 | if (err < 0) { |
Mauro Carvalho Chehab | 0ff4843 | 2011-07-20 20:21:42 -0300 | [diff] [blame] | 424 | printk("%s: Invalid parameter\n", __func__); |
| 425 | return err; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | return err; |
| 430 | } |
| 431 | |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 432 | /* |
| 433 | * mt2063_write - Write data into the I2C bus |
| 434 | */ |
| 435 | static u32 mt2063_write(struct mt2063_state *state, |
| 436 | u8 reg, u8 *data, u32 len) |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 437 | { |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 438 | struct dvb_frontend *fe = state->frontend; |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 439 | int ret; |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 440 | u8 buf[60]; |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 441 | struct i2c_msg msg = { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 442 | .addr = state->config->tuner_address, |
| 443 | .flags = 0, |
| 444 | .buf = buf, |
| 445 | .len = len + 1 |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 446 | }; |
| 447 | |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 448 | msg.buf[0] = reg; |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 449 | memcpy(msg.buf + 1, data, len); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 450 | |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 451 | fe->ops.i2c_gate_ctrl(fe, 1); |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 452 | ret = i2c_transfer(state->i2c, &msg, 1); |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 453 | fe->ops.i2c_gate_ctrl(fe, 0); |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 454 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 455 | if (ret < 0) |
| 456 | printk("mt2063_writeregs error ret=%d\n", ret); |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 457 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 458 | return ret; |
| 459 | } |
| 460 | |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 461 | /* |
| 462 | * mt2063_read - Read data from the I2C bus |
| 463 | */ |
| 464 | static u32 mt2063_read(struct mt2063_state *state, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 465 | u8 subAddress, u8 *pData, u32 cnt) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 466 | { |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 467 | u32 status = 0; /* Status to be returned */ |
| 468 | struct dvb_frontend *fe = state->frontend; |
| 469 | u32 i = 0; |
| 470 | |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 471 | fe->ops.i2c_gate_ctrl(fe, 1); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 472 | |
| 473 | for (i = 0; i < cnt; i++) { |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 474 | int ret; |
| 475 | u8 b0[] = { subAddress + i }; |
| 476 | struct i2c_msg msg[] = { |
| 477 | { |
| 478 | .addr = state->config->tuner_address, |
| 479 | .flags = I2C_M_RD, |
| 480 | .buf = b0, |
| 481 | .len = 1 |
| 482 | }, { |
| 483 | .addr = state->config->tuner_address, |
| 484 | .flags = I2C_M_RD, |
| 485 | .buf = pData + 1, |
| 486 | .len = 1 |
| 487 | } |
| 488 | }; |
| 489 | |
| 490 | ret = i2c_transfer(state->i2c, msg, 2); |
| 491 | if (ret < 0) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 492 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 493 | } |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 494 | fe->ops.i2c_gate_ctrl(fe, 0); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 495 | return (status); |
| 496 | } |
| 497 | |
Mauro Carvalho Chehab | e930b3a | 2011-07-21 03:02:16 -0300 | [diff] [blame] | 498 | /* |
| 499 | * FIXME: Is this really needed? |
| 500 | */ |
Mauro Carvalho Chehab | f867695 | 2011-07-20 22:00:30 -0300 | [diff] [blame] | 501 | static int MT2063_Sleep(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 502 | { |
| 503 | /* |
| 504 | ** ToDo: Add code here to implement a OS blocking |
| 505 | ** for a period of "nMinDelayTime" milliseconds. |
| 506 | */ |
Mauro Carvalho Chehab | f867695 | 2011-07-20 22:00:30 -0300 | [diff] [blame] | 507 | msleep(10); |
| 508 | |
| 509 | return 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 510 | } |
| 511 | |
Mauro Carvalho Chehab | e930b3a | 2011-07-21 03:02:16 -0300 | [diff] [blame] | 512 | /* |
| 513 | * Microtune spur avoidance |
| 514 | */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 515 | |
| 516 | /* Implement ceiling, floor functions. */ |
| 517 | #define ceil(n, d) (((n) < 0) ? (-((-(n))/(d))) : (n)/(d) + ((n)%(d) != 0)) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 518 | #define floor(n, d) (((n) < 0) ? (-((-(n))/(d))) - ((n)%(d) != 0) : (n)/(d)) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 519 | |
| 520 | struct MT2063_FIFZone_t { |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 521 | s32 min_; |
| 522 | s32 max_; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 523 | }; |
| 524 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 525 | /* |
| 526 | ** Reset all exclusion zones. |
| 527 | ** Add zones to protect the PLL FracN regions near zero |
| 528 | ** |
| 529 | ** N/A I 06-17-2008 RSK Ver 1.19: Refactoring avoidance of DECT |
| 530 | ** frequencies into MT_ResetExclZones(). |
| 531 | */ |
Mauro Carvalho Chehab | bf97555 | 2011-07-20 21:43:30 -0300 | [diff] [blame] | 532 | static void MT2063_ResetExclZones(struct MT2063_AvoidSpursData_t *pAS_Info) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 533 | { |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 534 | u32 center; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 535 | |
| 536 | pAS_Info->nZones = 0; /* this clears the used list */ |
| 537 | pAS_Info->usedZones = NULL; /* reset ptr */ |
| 538 | pAS_Info->freeZones = NULL; /* reset ptr */ |
| 539 | |
| 540 | center = |
| 541 | pAS_Info->f_ref * |
| 542 | ((pAS_Info->f_if1_Center - pAS_Info->f_if1_bw / 2 + |
| 543 | pAS_Info->f_in) / pAS_Info->f_ref) - pAS_Info->f_in; |
| 544 | while (center < |
| 545 | pAS_Info->f_if1_Center + pAS_Info->f_if1_bw / 2 + |
| 546 | pAS_Info->f_LO1_FracN_Avoid) { |
| 547 | /* Exclude LO1 FracN */ |
| 548 | MT2063_AddExclZone(pAS_Info, |
| 549 | center - pAS_Info->f_LO1_FracN_Avoid, |
| 550 | center - 1); |
| 551 | MT2063_AddExclZone(pAS_Info, center + 1, |
| 552 | center + pAS_Info->f_LO1_FracN_Avoid); |
| 553 | center += pAS_Info->f_ref; |
| 554 | } |
| 555 | |
| 556 | center = |
| 557 | pAS_Info->f_ref * |
| 558 | ((pAS_Info->f_if1_Center - pAS_Info->f_if1_bw / 2 - |
| 559 | pAS_Info->f_out) / pAS_Info->f_ref) + pAS_Info->f_out; |
| 560 | while (center < |
| 561 | pAS_Info->f_if1_Center + pAS_Info->f_if1_bw / 2 + |
| 562 | pAS_Info->f_LO2_FracN_Avoid) { |
| 563 | /* Exclude LO2 FracN */ |
| 564 | MT2063_AddExclZone(pAS_Info, |
| 565 | center - pAS_Info->f_LO2_FracN_Avoid, |
| 566 | center - 1); |
| 567 | MT2063_AddExclZone(pAS_Info, center + 1, |
| 568 | center + pAS_Info->f_LO2_FracN_Avoid); |
| 569 | center += pAS_Info->f_ref; |
| 570 | } |
| 571 | |
| 572 | if (MT2063_EXCLUDE_US_DECT_FREQUENCIES(pAS_Info->avoidDECT)) { |
| 573 | /* Exclude LO1 values that conflict with DECT channels */ |
| 574 | MT2063_AddExclZone(pAS_Info, 1920836000 - pAS_Info->f_in, 1922236000 - pAS_Info->f_in); /* Ctr = 1921.536 */ |
| 575 | MT2063_AddExclZone(pAS_Info, 1922564000 - pAS_Info->f_in, 1923964000 - pAS_Info->f_in); /* Ctr = 1923.264 */ |
| 576 | MT2063_AddExclZone(pAS_Info, 1924292000 - pAS_Info->f_in, 1925692000 - pAS_Info->f_in); /* Ctr = 1924.992 */ |
| 577 | MT2063_AddExclZone(pAS_Info, 1926020000 - pAS_Info->f_in, 1927420000 - pAS_Info->f_in); /* Ctr = 1926.720 */ |
| 578 | MT2063_AddExclZone(pAS_Info, 1927748000 - pAS_Info->f_in, 1929148000 - pAS_Info->f_in); /* Ctr = 1928.448 */ |
| 579 | } |
| 580 | |
| 581 | if (MT2063_EXCLUDE_EURO_DECT_FREQUENCIES(pAS_Info->avoidDECT)) { |
| 582 | MT2063_AddExclZone(pAS_Info, 1896644000 - pAS_Info->f_in, 1898044000 - pAS_Info->f_in); /* Ctr = 1897.344 */ |
| 583 | MT2063_AddExclZone(pAS_Info, 1894916000 - pAS_Info->f_in, 1896316000 - pAS_Info->f_in); /* Ctr = 1895.616 */ |
| 584 | MT2063_AddExclZone(pAS_Info, 1893188000 - pAS_Info->f_in, 1894588000 - pAS_Info->f_in); /* Ctr = 1893.888 */ |
| 585 | MT2063_AddExclZone(pAS_Info, 1891460000 - pAS_Info->f_in, 1892860000 - pAS_Info->f_in); /* Ctr = 1892.16 */ |
| 586 | MT2063_AddExclZone(pAS_Info, 1889732000 - pAS_Info->f_in, 1891132000 - pAS_Info->f_in); /* Ctr = 1890.432 */ |
| 587 | MT2063_AddExclZone(pAS_Info, 1888004000 - pAS_Info->f_in, 1889404000 - pAS_Info->f_in); /* Ctr = 1888.704 */ |
| 588 | MT2063_AddExclZone(pAS_Info, 1886276000 - pAS_Info->f_in, 1887676000 - pAS_Info->f_in); /* Ctr = 1886.976 */ |
| 589 | MT2063_AddExclZone(pAS_Info, 1884548000 - pAS_Info->f_in, 1885948000 - pAS_Info->f_in); /* Ctr = 1885.248 */ |
| 590 | MT2063_AddExclZone(pAS_Info, 1882820000 - pAS_Info->f_in, 1884220000 - pAS_Info->f_in); /* Ctr = 1883.52 */ |
| 591 | MT2063_AddExclZone(pAS_Info, 1881092000 - pAS_Info->f_in, 1882492000 - pAS_Info->f_in); /* Ctr = 1881.792 */ |
| 592 | } |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | static struct MT2063_ExclZone_t *InsertNode(struct MT2063_AvoidSpursData_t |
| 596 | *pAS_Info, |
| 597 | struct MT2063_ExclZone_t *pPrevNode) |
| 598 | { |
| 599 | struct MT2063_ExclZone_t *pNode; |
| 600 | /* Check for a node in the free list */ |
| 601 | if (pAS_Info->freeZones != NULL) { |
| 602 | /* Use one from the free list */ |
| 603 | pNode = pAS_Info->freeZones; |
| 604 | pAS_Info->freeZones = pNode->next_; |
| 605 | } else { |
| 606 | /* Grab a node from the array */ |
| 607 | pNode = &pAS_Info->MT2063_ExclZones[pAS_Info->nZones]; |
| 608 | } |
| 609 | |
| 610 | if (pPrevNode != NULL) { |
| 611 | pNode->next_ = pPrevNode->next_; |
| 612 | pPrevNode->next_ = pNode; |
| 613 | } else { /* insert at the beginning of the list */ |
| 614 | |
| 615 | pNode->next_ = pAS_Info->usedZones; |
| 616 | pAS_Info->usedZones = pNode; |
| 617 | } |
| 618 | |
| 619 | pAS_Info->nZones++; |
| 620 | return pNode; |
| 621 | } |
| 622 | |
| 623 | static struct MT2063_ExclZone_t *RemoveNode(struct MT2063_AvoidSpursData_t |
| 624 | *pAS_Info, |
| 625 | struct MT2063_ExclZone_t *pPrevNode, |
| 626 | struct MT2063_ExclZone_t |
| 627 | *pNodeToRemove) |
| 628 | { |
| 629 | struct MT2063_ExclZone_t *pNext = pNodeToRemove->next_; |
| 630 | |
| 631 | /* Make previous node point to the subsequent node */ |
| 632 | if (pPrevNode != NULL) |
| 633 | pPrevNode->next_ = pNext; |
| 634 | |
| 635 | /* Add pNodeToRemove to the beginning of the freeZones */ |
| 636 | pNodeToRemove->next_ = pAS_Info->freeZones; |
| 637 | pAS_Info->freeZones = pNodeToRemove; |
| 638 | |
| 639 | /* Decrement node count */ |
| 640 | pAS_Info->nZones--; |
| 641 | |
| 642 | return pNext; |
| 643 | } |
| 644 | |
| 645 | /***************************************************************************** |
| 646 | ** |
| 647 | ** Name: MT_AddExclZone |
| 648 | ** |
| 649 | ** Description: Add (and merge) an exclusion zone into the list. |
| 650 | ** If the range (f_min, f_max) is totally outside the |
| 651 | ** 1st IF BW, ignore the entry. |
| 652 | ** If the range (f_min, f_max) is negative, ignore the entry. |
| 653 | ** |
| 654 | ** Revision History: |
| 655 | ** |
| 656 | ** SCR Date Author Description |
| 657 | ** ------------------------------------------------------------------------- |
| 658 | ** 103 01-31-2005 DAD Ver 1.14: In MT_AddExclZone(), if the range |
| 659 | ** (f_min, f_max) < 0, ignore the entry. |
| 660 | ** |
| 661 | *****************************************************************************/ |
Mauro Carvalho Chehab | bf97555 | 2011-07-20 21:43:30 -0300 | [diff] [blame] | 662 | static void MT2063_AddExclZone(struct MT2063_AvoidSpursData_t *pAS_Info, |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 663 | u32 f_min, u32 f_max) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 664 | { |
| 665 | struct MT2063_ExclZone_t *pNode = pAS_Info->usedZones; |
| 666 | struct MT2063_ExclZone_t *pPrev = NULL; |
| 667 | struct MT2063_ExclZone_t *pNext = NULL; |
| 668 | |
| 669 | /* Check to see if this overlaps the 1st IF filter */ |
| 670 | if ((f_max > (pAS_Info->f_if1_Center - (pAS_Info->f_if1_bw / 2))) |
| 671 | && (f_min < (pAS_Info->f_if1_Center + (pAS_Info->f_if1_bw / 2))) |
| 672 | && (f_min < f_max)) { |
| 673 | /* |
| 674 | ** 1 2 3 4 5 6 |
| 675 | ** |
| 676 | ** New entry: |---| |--| |--| |-| |---| |--| |
| 677 | ** or or or or or |
| 678 | ** Existing: |--| |--| |--| |---| |-| |--| |
| 679 | */ |
| 680 | |
| 681 | /* Check for our place in the list */ |
| 682 | while ((pNode != NULL) && (pNode->max_ < f_min)) { |
| 683 | pPrev = pNode; |
| 684 | pNode = pNode->next_; |
| 685 | } |
| 686 | |
| 687 | if ((pNode != NULL) && (pNode->min_ < f_max)) { |
| 688 | /* Combine me with pNode */ |
| 689 | if (f_min < pNode->min_) |
| 690 | pNode->min_ = f_min; |
| 691 | if (f_max > pNode->max_) |
| 692 | pNode->max_ = f_max; |
| 693 | } else { |
| 694 | pNode = InsertNode(pAS_Info, pPrev); |
| 695 | pNode->min_ = f_min; |
| 696 | pNode->max_ = f_max; |
| 697 | } |
| 698 | |
| 699 | /* Look for merging possibilities */ |
| 700 | pNext = pNode->next_; |
| 701 | while ((pNext != NULL) && (pNext->min_ < pNode->max_)) { |
| 702 | if (pNext->max_ > pNode->max_) |
| 703 | pNode->max_ = pNext->max_; |
| 704 | pNext = RemoveNode(pAS_Info, pNode, pNext); /* Remove pNext, return ptr to pNext->next */ |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | /***************************************************************************** |
| 710 | ** |
| 711 | ** Name: MT_ChooseFirstIF |
| 712 | ** |
| 713 | ** Description: Choose the best available 1st IF |
| 714 | ** If f_Desired is not excluded, choose that first. |
| 715 | ** Otherwise, return the value closest to f_Center that is |
| 716 | ** not excluded |
| 717 | ** |
| 718 | ** Revision History: |
| 719 | ** |
| 720 | ** SCR Date Author Description |
| 721 | ** ------------------------------------------------------------------------- |
| 722 | ** 117 03-29-2007 RSK Ver 1.15: Re-wrote to match search order from |
| 723 | ** tuner DLL. |
| 724 | ** 147 07-27-2007 RSK Ver 1.17: Corrected calculation (-) to (+) |
| 725 | ** Added logic to force f_Center within 1/2 f_Step. |
| 726 | ** |
| 727 | *****************************************************************************/ |
Mauro Carvalho Chehab | bf97555 | 2011-07-20 21:43:30 -0300 | [diff] [blame] | 728 | static u32 MT2063_ChooseFirstIF(struct MT2063_AvoidSpursData_t *pAS_Info) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 729 | { |
| 730 | /* |
| 731 | ** Update "f_Desired" to be the nearest "combinational-multiple" of "f_LO1_Step". |
| 732 | ** The resulting number, F_LO1 must be a multiple of f_LO1_Step. And F_LO1 is the arithmetic sum |
| 733 | ** of f_in + f_Center. Neither f_in, nor f_Center must be a multiple of f_LO1_Step. |
| 734 | ** However, the sum must be. |
| 735 | */ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 736 | const u32 f_Desired = |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 737 | pAS_Info->f_LO1_Step * |
| 738 | ((pAS_Info->f_if1_Request + pAS_Info->f_in + |
| 739 | pAS_Info->f_LO1_Step / 2) / pAS_Info->f_LO1_Step) - |
| 740 | pAS_Info->f_in; |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 741 | const u32 f_Step = |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 742 | (pAS_Info->f_LO1_Step > |
| 743 | pAS_Info->f_LO2_Step) ? pAS_Info->f_LO1_Step : pAS_Info-> |
| 744 | f_LO2_Step; |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 745 | u32 f_Center; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 746 | |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 747 | s32 i; |
| 748 | s32 j = 0; |
| 749 | u32 bDesiredExcluded = 0; |
| 750 | u32 bZeroExcluded = 0; |
| 751 | s32 tmpMin, tmpMax; |
| 752 | s32 bestDiff; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 753 | struct MT2063_ExclZone_t *pNode = pAS_Info->usedZones; |
| 754 | struct MT2063_FIFZone_t zones[MT2063_MAX_ZONES]; |
| 755 | |
| 756 | if (pAS_Info->nZones == 0) |
| 757 | return f_Desired; |
| 758 | |
| 759 | /* f_Center needs to be an integer multiple of f_Step away from f_Desired */ |
| 760 | if (pAS_Info->f_if1_Center > f_Desired) |
| 761 | f_Center = |
| 762 | f_Desired + |
| 763 | f_Step * |
| 764 | ((pAS_Info->f_if1_Center - f_Desired + |
| 765 | f_Step / 2) / f_Step); |
| 766 | else |
| 767 | f_Center = |
| 768 | f_Desired - |
| 769 | f_Step * |
| 770 | ((f_Desired - pAS_Info->f_if1_Center + |
| 771 | f_Step / 2) / f_Step); |
| 772 | |
| 773 | //assert; |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 774 | //if (!abs((s32) f_Center - (s32) pAS_Info->f_if1_Center) <= (s32) (f_Step/2)) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 775 | // return 0; |
| 776 | |
| 777 | /* Take MT_ExclZones, center around f_Center and change the resolution to f_Step */ |
| 778 | while (pNode != NULL) { |
| 779 | /* floor function */ |
| 780 | tmpMin = |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 781 | floor((s32) (pNode->min_ - f_Center), (s32) f_Step); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 782 | |
| 783 | /* ceil function */ |
| 784 | tmpMax = |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 785 | ceil((s32) (pNode->max_ - f_Center), (s32) f_Step); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 786 | |
| 787 | if ((pNode->min_ < f_Desired) && (pNode->max_ > f_Desired)) |
| 788 | bDesiredExcluded = 1; |
| 789 | |
| 790 | if ((tmpMin < 0) && (tmpMax > 0)) |
| 791 | bZeroExcluded = 1; |
| 792 | |
| 793 | /* See if this zone overlaps the previous */ |
| 794 | if ((j > 0) && (tmpMin < zones[j - 1].max_)) |
| 795 | zones[j - 1].max_ = tmpMax; |
| 796 | else { |
| 797 | /* Add new zone */ |
| 798 | //assert(j<MT2063_MAX_ZONES); |
| 799 | //if (j>=MT2063_MAX_ZONES) |
| 800 | //break; |
| 801 | |
| 802 | zones[j].min_ = tmpMin; |
| 803 | zones[j].max_ = tmpMax; |
| 804 | j++; |
| 805 | } |
| 806 | pNode = pNode->next_; |
| 807 | } |
| 808 | |
| 809 | /* |
| 810 | ** If the desired is okay, return with it |
| 811 | */ |
| 812 | if (bDesiredExcluded == 0) |
| 813 | return f_Desired; |
| 814 | |
| 815 | /* |
| 816 | ** If the desired is excluded and the center is okay, return with it |
| 817 | */ |
| 818 | if (bZeroExcluded == 0) |
| 819 | return f_Center; |
| 820 | |
| 821 | /* Find the value closest to 0 (f_Center) */ |
| 822 | bestDiff = zones[0].min_; |
| 823 | for (i = 0; i < j; i++) { |
| 824 | if (abs(zones[i].min_) < abs(bestDiff)) |
| 825 | bestDiff = zones[i].min_; |
| 826 | if (abs(zones[i].max_) < abs(bestDiff)) |
| 827 | bestDiff = zones[i].max_; |
| 828 | } |
| 829 | |
| 830 | if (bestDiff < 0) |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 831 | return f_Center - ((u32) (-bestDiff) * f_Step); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 832 | |
| 833 | return f_Center + (bestDiff * f_Step); |
| 834 | } |
| 835 | |
| 836 | /**************************************************************************** |
| 837 | ** |
| 838 | ** Name: gcd |
| 839 | ** |
| 840 | ** Description: Uses Euclid's algorithm |
| 841 | ** |
| 842 | ** Parameters: u, v - unsigned values whose GCD is desired. |
| 843 | ** |
| 844 | ** Global: None |
| 845 | ** |
| 846 | ** Returns: greatest common divisor of u and v, if either value |
| 847 | ** is 0, the other value is returned as the result. |
| 848 | ** |
| 849 | ** Dependencies: None. |
| 850 | ** |
| 851 | ** Revision History: |
| 852 | ** |
| 853 | ** SCR Date Author Description |
| 854 | ** ------------------------------------------------------------------------- |
| 855 | ** N/A 06-01-2004 JWS Original |
| 856 | ** N/A 08-03-2004 DAD Changed to Euclid's since it can handle |
| 857 | ** unsigned numbers. |
| 858 | ** |
| 859 | ****************************************************************************/ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 860 | static u32 MT2063_gcd(u32 u, u32 v) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 861 | { |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 862 | u32 r; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 863 | |
| 864 | while (v != 0) { |
| 865 | r = u % v; |
| 866 | u = v; |
| 867 | v = r; |
| 868 | } |
| 869 | |
| 870 | return u; |
| 871 | } |
| 872 | |
| 873 | /**************************************************************************** |
| 874 | ** |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 875 | ** Name: IsSpurInBand |
| 876 | ** |
| 877 | ** Description: Checks to see if a spur will be present within the IF's |
| 878 | ** bandwidth. (fIFOut +/- fIFBW, -fIFOut +/- fIFBW) |
| 879 | ** |
| 880 | ** ma mb mc md |
| 881 | ** <--+-+-+-------------------+-------------------+-+-+--> |
| 882 | ** | ^ 0 ^ | |
| 883 | ** ^ b=-fIFOut+fIFBW/2 -b=+fIFOut-fIFBW/2 ^ |
| 884 | ** a=-fIFOut-fIFBW/2 -a=+fIFOut+fIFBW/2 |
| 885 | ** |
| 886 | ** Note that some equations are doubled to prevent round-off |
| 887 | ** problems when calculating fIFBW/2 |
| 888 | ** |
| 889 | ** Parameters: pAS_Info - Avoid Spurs information block |
| 890 | ** fm - If spur, amount f_IF1 has to move negative |
| 891 | ** fp - If spur, amount f_IF1 has to move positive |
| 892 | ** |
| 893 | ** Global: None |
| 894 | ** |
| 895 | ** Returns: 1 if an LO spur would be present, otherwise 0. |
| 896 | ** |
| 897 | ** Dependencies: None. |
| 898 | ** |
| 899 | ** Revision History: |
| 900 | ** |
| 901 | ** SCR Date Author Description |
| 902 | ** ------------------------------------------------------------------------- |
| 903 | ** N/A 11-28-2002 DAD Implemented algorithm from applied patent |
| 904 | ** |
| 905 | ****************************************************************************/ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 906 | static u32 IsSpurInBand(struct MT2063_AvoidSpursData_t *pAS_Info, |
| 907 | u32 * fm, u32 * fp) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 908 | { |
| 909 | /* |
| 910 | ** Calculate LO frequency settings. |
| 911 | */ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 912 | u32 n, n0; |
| 913 | const u32 f_LO1 = pAS_Info->f_LO1; |
| 914 | const u32 f_LO2 = pAS_Info->f_LO2; |
| 915 | const u32 d = pAS_Info->f_out + pAS_Info->f_out_bw / 2; |
| 916 | const u32 c = d - pAS_Info->f_out_bw; |
| 917 | const u32 f = pAS_Info->f_zif_bw / 2; |
Mauro Carvalho Chehab | d0dcc2d | 2011-07-21 02:30:19 -0300 | [diff] [blame] | 918 | const u32 f_Scale = (f_LO1 / (UINT_MAX / 2 / pAS_Info->maxH1)) + 1; |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 919 | s32 f_nsLO1, f_nsLO2; |
| 920 | s32 f_Spur; |
| 921 | u32 ma, mb, mc, md, me, mf; |
| 922 | u32 lo_gcd, gd_Scale, gc_Scale, gf_Scale, hgds, hgfs, hgcs; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 923 | *fm = 0; |
| 924 | |
| 925 | /* |
| 926 | ** For each edge (d, c & f), calculate a scale, based on the gcd |
| 927 | ** of f_LO1, f_LO2 and the edge value. Use the larger of this |
| 928 | ** gcd-based scale factor or f_Scale. |
| 929 | */ |
| 930 | lo_gcd = MT2063_gcd(f_LO1, f_LO2); |
Mauro Carvalho Chehab | fd1126c | 2011-07-21 03:30:57 -0300 | [diff] [blame] | 931 | gd_Scale = max((u32) MT2063_gcd(lo_gcd, d), f_Scale); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 932 | hgds = gd_Scale / 2; |
Mauro Carvalho Chehab | fd1126c | 2011-07-21 03:30:57 -0300 | [diff] [blame] | 933 | gc_Scale = max((u32) MT2063_gcd(lo_gcd, c), f_Scale); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 934 | hgcs = gc_Scale / 2; |
Mauro Carvalho Chehab | fd1126c | 2011-07-21 03:30:57 -0300 | [diff] [blame] | 935 | gf_Scale = max((u32) MT2063_gcd(lo_gcd, f), f_Scale); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 936 | hgfs = gf_Scale / 2; |
| 937 | |
Mauro Carvalho Chehab | e930b3a | 2011-07-21 03:02:16 -0300 | [diff] [blame] | 938 | n0 = DIV_ROUND_UP(f_LO2 - d, f_LO1 - f_LO2); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 939 | |
| 940 | /* Check out all multiples of LO1 from n0 to m_maxLOSpurHarmonic */ |
| 941 | for (n = n0; n <= pAS_Info->maxH1; ++n) { |
| 942 | md = (n * ((f_LO1 + hgds) / gd_Scale) - |
| 943 | ((d + hgds) / gd_Scale)) / ((f_LO2 + hgds) / gd_Scale); |
| 944 | |
| 945 | /* If # fLO2 harmonics > m_maxLOSpurHarmonic, then no spurs present */ |
| 946 | if (md >= pAS_Info->maxH1) |
| 947 | break; |
| 948 | |
| 949 | ma = (n * ((f_LO1 + hgds) / gd_Scale) + |
| 950 | ((d + hgds) / gd_Scale)) / ((f_LO2 + hgds) / gd_Scale); |
| 951 | |
| 952 | /* If no spurs between +/- (f_out + f_IFBW/2), then try next harmonic */ |
| 953 | if (md == ma) |
| 954 | continue; |
| 955 | |
| 956 | mc = (n * ((f_LO1 + hgcs) / gc_Scale) - |
| 957 | ((c + hgcs) / gc_Scale)) / ((f_LO2 + hgcs) / gc_Scale); |
| 958 | if (mc != md) { |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 959 | f_nsLO1 = (s32) (n * (f_LO1 / gc_Scale)); |
| 960 | f_nsLO2 = (s32) (mc * (f_LO2 / gc_Scale)); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 961 | f_Spur = |
| 962 | (gc_Scale * (f_nsLO1 - f_nsLO2)) + |
| 963 | n * (f_LO1 % gc_Scale) - mc * (f_LO2 % gc_Scale); |
| 964 | |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 965 | *fp = ((f_Spur - (s32) c) / (mc - n)) + 1; |
| 966 | *fm = (((s32) d - f_Spur) / (mc - n)) + 1; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 967 | return 1; |
| 968 | } |
| 969 | |
| 970 | /* Location of Zero-IF-spur to be checked */ |
| 971 | me = (n * ((f_LO1 + hgfs) / gf_Scale) + |
| 972 | ((f + hgfs) / gf_Scale)) / ((f_LO2 + hgfs) / gf_Scale); |
| 973 | mf = (n * ((f_LO1 + hgfs) / gf_Scale) - |
| 974 | ((f + hgfs) / gf_Scale)) / ((f_LO2 + hgfs) / gf_Scale); |
| 975 | if (me != mf) { |
| 976 | f_nsLO1 = n * (f_LO1 / gf_Scale); |
| 977 | f_nsLO2 = me * (f_LO2 / gf_Scale); |
| 978 | f_Spur = |
| 979 | (gf_Scale * (f_nsLO1 - f_nsLO2)) + |
| 980 | n * (f_LO1 % gf_Scale) - me * (f_LO2 % gf_Scale); |
| 981 | |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 982 | *fp = ((f_Spur + (s32) f) / (me - n)) + 1; |
| 983 | *fm = (((s32) f - f_Spur) / (me - n)) + 1; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 984 | return 1; |
| 985 | } |
| 986 | |
| 987 | mb = (n * ((f_LO1 + hgcs) / gc_Scale) + |
| 988 | ((c + hgcs) / gc_Scale)) / ((f_LO2 + hgcs) / gc_Scale); |
| 989 | if (ma != mb) { |
| 990 | f_nsLO1 = n * (f_LO1 / gc_Scale); |
| 991 | f_nsLO2 = ma * (f_LO2 / gc_Scale); |
| 992 | f_Spur = |
| 993 | (gc_Scale * (f_nsLO1 - f_nsLO2)) + |
| 994 | n * (f_LO1 % gc_Scale) - ma * (f_LO2 % gc_Scale); |
| 995 | |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 996 | *fp = (((s32) d + f_Spur) / (ma - n)) + 1; |
| 997 | *fm = (-(f_Spur + (s32) c) / (ma - n)) + 1; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 998 | return 1; |
| 999 | } |
| 1000 | } |
| 1001 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1002 | /* No spurs found */ |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 1003 | return 0; |
| 1004 | } |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1005 | |
| 1006 | /***************************************************************************** |
| 1007 | ** |
| 1008 | ** Name: MT_AvoidSpurs |
| 1009 | ** |
| 1010 | ** Description: Main entry point to avoid spurs. |
| 1011 | ** Checks for existing spurs in present LO1, LO2 freqs |
| 1012 | ** and if present, chooses spur-free LO1, LO2 combination |
| 1013 | ** that tunes the same input/output frequencies. |
| 1014 | ** |
| 1015 | ** Revision History: |
| 1016 | ** |
| 1017 | ** SCR Date Author Description |
| 1018 | ** ------------------------------------------------------------------------- |
| 1019 | ** 096 04-06-2005 DAD Ver 1.11: Fix divide by 0 error if maxH==0. |
| 1020 | ** |
| 1021 | *****************************************************************************/ |
Mauro Carvalho Chehab | bf97555 | 2011-07-20 21:43:30 -0300 | [diff] [blame] | 1022 | static u32 MT2063_AvoidSpurs(void *h, struct MT2063_AvoidSpursData_t * pAS_Info) |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 1023 | { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1024 | u32 status = 0; |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1025 | u32 fm, fp; /* restricted range on LO's */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1026 | pAS_Info->bSpurAvoided = 0; |
| 1027 | pAS_Info->nSpursFound = 0; |
| 1028 | |
| 1029 | if (pAS_Info->maxH1 == 0) |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1030 | return 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1031 | |
| 1032 | /* |
| 1033 | ** Avoid LO Generated Spurs |
| 1034 | ** |
| 1035 | ** Make sure that have no LO-related spurs within the IF output |
| 1036 | ** bandwidth. |
| 1037 | ** |
| 1038 | ** If there is an LO spur in this band, start at the current IF1 frequency |
| 1039 | ** and work out until we find a spur-free frequency or run up against the |
| 1040 | ** 1st IF SAW band edge. Use temporary copies of fLO1 and fLO2 so that they |
| 1041 | ** will be unchanged if a spur-free setting is not found. |
| 1042 | */ |
| 1043 | pAS_Info->bSpurPresent = IsSpurInBand(pAS_Info, &fm, &fp); |
| 1044 | if (pAS_Info->bSpurPresent) { |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1045 | u32 zfIF1 = pAS_Info->f_LO1 - pAS_Info->f_in; /* current attempt at a 1st IF */ |
| 1046 | u32 zfLO1 = pAS_Info->f_LO1; /* current attempt at an LO1 freq */ |
| 1047 | u32 zfLO2 = pAS_Info->f_LO2; /* current attempt at an LO2 freq */ |
| 1048 | u32 delta_IF1; |
| 1049 | u32 new_IF1; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1050 | |
| 1051 | /* |
| 1052 | ** Spur was found, attempt to find a spur-free 1st IF |
| 1053 | */ |
| 1054 | do { |
| 1055 | pAS_Info->nSpursFound++; |
| 1056 | |
| 1057 | /* Raise f_IF1_upper, if needed */ |
| 1058 | MT2063_AddExclZone(pAS_Info, zfIF1 - fm, zfIF1 + fp); |
| 1059 | |
| 1060 | /* Choose next IF1 that is closest to f_IF1_CENTER */ |
| 1061 | new_IF1 = MT2063_ChooseFirstIF(pAS_Info); |
| 1062 | |
| 1063 | if (new_IF1 > zfIF1) { |
| 1064 | pAS_Info->f_LO1 += (new_IF1 - zfIF1); |
| 1065 | pAS_Info->f_LO2 += (new_IF1 - zfIF1); |
| 1066 | } else { |
| 1067 | pAS_Info->f_LO1 -= (zfIF1 - new_IF1); |
| 1068 | pAS_Info->f_LO2 -= (zfIF1 - new_IF1); |
| 1069 | } |
| 1070 | zfIF1 = new_IF1; |
| 1071 | |
| 1072 | if (zfIF1 > pAS_Info->f_if1_Center) |
| 1073 | delta_IF1 = zfIF1 - pAS_Info->f_if1_Center; |
| 1074 | else |
| 1075 | delta_IF1 = pAS_Info->f_if1_Center - zfIF1; |
| 1076 | } |
| 1077 | /* |
| 1078 | ** Continue while the new 1st IF is still within the 1st IF bandwidth |
| 1079 | ** and there is a spur in the band (again) |
| 1080 | */ |
| 1081 | while ((2 * delta_IF1 + pAS_Info->f_out_bw <= |
| 1082 | pAS_Info->f_if1_bw) |
| 1083 | && (pAS_Info->bSpurPresent = |
| 1084 | IsSpurInBand(pAS_Info, &fm, &fp))); |
| 1085 | |
| 1086 | /* |
| 1087 | ** Use the LO-spur free values found. If the search went all the way to |
| 1088 | ** the 1st IF band edge and always found spurs, just leave the original |
| 1089 | ** choice. It's as "good" as any other. |
| 1090 | */ |
| 1091 | if (pAS_Info->bSpurPresent == 1) { |
| 1092 | status |= MT2063_SPUR_PRESENT_ERR; |
| 1093 | pAS_Info->f_LO1 = zfLO1; |
| 1094 | pAS_Info->f_LO2 = zfLO2; |
| 1095 | } else |
| 1096 | pAS_Info->bSpurAvoided = 1; |
| 1097 | } |
| 1098 | |
| 1099 | status |= |
| 1100 | ((pAS_Info-> |
| 1101 | nSpursFound << MT2063_SPUR_SHIFT) & MT2063_SPUR_CNT_MASK); |
| 1102 | |
| 1103 | return (status); |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 1104 | } |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1105 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1106 | /* |
| 1107 | ** The expected version of MT_AvoidSpursData_t |
| 1108 | ** If the version is different, an updated file is needed from Microtune |
| 1109 | */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1110 | |
| 1111 | typedef enum { |
| 1112 | MT2063_SET_ATTEN, |
| 1113 | MT2063_INCR_ATTEN, |
| 1114 | MT2063_DECR_ATTEN |
| 1115 | } MT2063_ATTEN_CNTL_MODE; |
| 1116 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1117 | /* |
Mauro Carvalho Chehab | 66aea30 | 2011-07-21 03:57:10 -0300 | [diff] [blame^] | 1118 | * Constants used by the tuning algorithm |
| 1119 | */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1120 | #define MT2063_REF_FREQ (16000000UL) /* Reference oscillator Frequency (in Hz) */ |
| 1121 | #define MT2063_IF1_BW (22000000UL) /* The IF1 filter bandwidth (in Hz) */ |
| 1122 | #define MT2063_TUNE_STEP_SIZE (50000UL) /* Tune in steps of 50 kHz */ |
| 1123 | #define MT2063_SPUR_STEP_HZ (250000UL) /* Step size (in Hz) to move IF1 when avoiding spurs */ |
| 1124 | #define MT2063_ZIF_BW (2000000UL) /* Zero-IF spur-free bandwidth (in Hz) */ |
| 1125 | #define MT2063_MAX_HARMONICS_1 (15UL) /* Highest intra-tuner LO Spur Harmonic to be avoided */ |
| 1126 | #define MT2063_MAX_HARMONICS_2 (5UL) /* Highest inter-tuner LO Spur Harmonic to be avoided */ |
| 1127 | #define MT2063_MIN_LO_SEP (1000000UL) /* Minimum inter-tuner LO frequency separation */ |
| 1128 | #define MT2063_LO1_FRACN_AVOID (0UL) /* LO1 FracN numerator avoid region (in Hz) */ |
| 1129 | #define MT2063_LO2_FRACN_AVOID (199999UL) /* LO2 FracN numerator avoid region (in Hz) */ |
| 1130 | #define MT2063_MIN_FIN_FREQ (44000000UL) /* Minimum input frequency (in Hz) */ |
| 1131 | #define MT2063_MAX_FIN_FREQ (1100000000UL) /* Maximum input frequency (in Hz) */ |
| 1132 | #define MT2063_MIN_FOUT_FREQ (36000000UL) /* Minimum output frequency (in Hz) */ |
| 1133 | #define MT2063_MAX_FOUT_FREQ (57000000UL) /* Maximum output frequency (in Hz) */ |
| 1134 | #define MT2063_MIN_DNC_FREQ (1293000000UL) /* Minimum LO2 frequency (in Hz) */ |
| 1135 | #define MT2063_MAX_DNC_FREQ (1614000000UL) /* Maximum LO2 frequency (in Hz) */ |
| 1136 | #define MT2063_MIN_UPC_FREQ (1396000000UL) /* Minimum LO1 frequency (in Hz) */ |
| 1137 | #define MT2063_MAX_UPC_FREQ (2750000000UL) /* Maximum LO1 frequency (in Hz) */ |
| 1138 | |
| 1139 | /* |
| 1140 | ** Define the supported Part/Rev codes for the MT2063 |
| 1141 | */ |
| 1142 | #define MT2063_B0 (0x9B) |
| 1143 | #define MT2063_B1 (0x9C) |
| 1144 | #define MT2063_B2 (0x9D) |
| 1145 | #define MT2063_B3 (0x9E) |
| 1146 | |
| 1147 | /* |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1148 | ** Constants for setting receiver modes. |
| 1149 | ** (6 modes defined at this time, enumerated by MT2063_RCVR_MODES) |
| 1150 | ** (DNC1GC & DNC2GC are the values, which are used, when the specific |
| 1151 | ** DNC Output is selected, the other is always off) |
| 1152 | ** |
| 1153 | ** If PAL-L or L' is received, set: |
| 1154 | ** MT2063_SetParam(hMT2063,MT2063_TAGC,1); |
| 1155 | ** |
| 1156 | ** --------------+---------------------------------------------- |
| 1157 | ** Mode 0 : | MT2063_CABLE_QAM |
| 1158 | ** Mode 1 : | MT2063_CABLE_ANALOG |
| 1159 | ** Mode 2 : | MT2063_OFFAIR_COFDM |
| 1160 | ** Mode 3 : | MT2063_OFFAIR_COFDM_SAWLESS |
| 1161 | ** Mode 4 : | MT2063_OFFAIR_ANALOG |
| 1162 | ** Mode 5 : | MT2063_OFFAIR_8VSB |
| 1163 | ** --------------+----+----+----+----+-----+-----+-------------- |
| 1164 | ** Mode | 0 | 1 | 2 | 3 | 4 | 5 | |
| 1165 | ** --------------+----+----+----+----+-----+-----+ |
| 1166 | ** |
| 1167 | ** |
| 1168 | */ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1169 | static const u8 RFAGCEN[] = { 0, 0, 0, 0, 0, 0 }; |
| 1170 | static const u8 LNARIN[] = { 0, 0, 3, 3, 3, 3 }; |
| 1171 | static const u8 FIFFQEN[] = { 1, 1, 1, 1, 1, 1 }; |
| 1172 | static const u8 FIFFQ[] = { 0, 0, 0, 0, 0, 0 }; |
| 1173 | static const u8 DNC1GC[] = { 0, 0, 0, 0, 0, 0 }; |
| 1174 | static const u8 DNC2GC[] = { 0, 0, 0, 0, 0, 0 }; |
| 1175 | static const u8 ACLNAMAX[] = { 31, 31, 31, 31, 31, 31 }; |
| 1176 | static const u8 LNATGT[] = { 44, 43, 43, 43, 43, 43 }; |
| 1177 | static const u8 RFOVDIS[] = { 0, 0, 0, 0, 0, 0 }; |
| 1178 | static const u8 ACRFMAX[] = { 31, 31, 31, 31, 31, 31 }; |
| 1179 | static const u8 PD1TGT[] = { 36, 36, 38, 38, 36, 38 }; |
| 1180 | static const u8 FIFOVDIS[] = { 0, 0, 0, 0, 0, 0 }; |
| 1181 | static const u8 ACFIFMAX[] = { 29, 29, 29, 29, 29, 29 }; |
| 1182 | static const u8 PD2TGT[] = { 40, 33, 38, 42, 30, 38 }; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1183 | |
| 1184 | /* |
| 1185 | ** Local Function Prototypes - not available for external access. |
| 1186 | */ |
| 1187 | |
| 1188 | /* Forward declaration(s): */ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1189 | static u32 MT2063_CalcLO1Mult(u32 * Div, u32 * FracN, u32 f_LO, |
| 1190 | u32 f_LO_Step, u32 f_Ref); |
| 1191 | static u32 MT2063_CalcLO2Mult(u32 * Div, u32 * FracN, u32 f_LO, |
| 1192 | u32 f_LO_Step, u32 f_Ref); |
| 1193 | static u32 MT2063_fLO_FractionalTerm(u32 f_ref, u32 num, |
| 1194 | u32 denom); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1195 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1196 | /**************************************************************************** |
| 1197 | ** |
| 1198 | ** Name: MT2063_GetLocked |
| 1199 | ** |
| 1200 | ** Description: Checks to see if LO1 and LO2 are locked. |
| 1201 | ** |
| 1202 | ** Parameters: h - Open handle to the tuner (from MT2063_Open). |
| 1203 | ** |
| 1204 | ** Returns: status: |
| 1205 | ** MT_OK - No errors |
| 1206 | ** MT_UPC_UNLOCK - Upconverter PLL unlocked |
| 1207 | ** MT_DNC_UNLOCK - Downconverter PLL unlocked |
| 1208 | ** MT_COMM_ERR - Serial bus communications error |
| 1209 | ** MT_INV_HANDLE - Invalid tuner handle |
| 1210 | ** |
| 1211 | ** Dependencies: MT_ReadSub - Read byte(s) of data from the serial bus |
| 1212 | ** MT_Sleep - Delay execution for x milliseconds |
| 1213 | ** |
| 1214 | ** Revision History: |
| 1215 | ** |
| 1216 | ** SCR Date Author Description |
| 1217 | ** ------------------------------------------------------------------------- |
| 1218 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 1219 | ** |
| 1220 | ****************************************************************************/ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1221 | static u32 MT2063_GetLocked(struct mt2063_state *state) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1222 | { |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1223 | const u32 nMaxWait = 100; /* wait a maximum of 100 msec */ |
| 1224 | const u32 nPollRate = 2; /* poll status bits every 2 ms */ |
| 1225 | const u32 nMaxLoops = nMaxWait / nPollRate; |
| 1226 | const u8 LO1LK = 0x80; |
| 1227 | u8 LO2LK = 0x08; |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1228 | u32 status = 0; /* Status to be returned */ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1229 | u32 nDelays = 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1230 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1231 | /* LO2 Lock bit was in a different place for B0 version */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1232 | if (state->tuner_id == MT2063_B0) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1233 | LO2LK = 0x40; |
| 1234 | |
| 1235 | do { |
| 1236 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1237 | mt2063_read(state, |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1238 | MT2063_REG_LO_STATUS, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1239 | &state->reg[MT2063_REG_LO_STATUS], 1); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1240 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1241 | if (status < 0) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1242 | return (status); |
| 1243 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1244 | if ((state->reg[MT2063_REG_LO_STATUS] & (LO1LK | LO2LK)) == |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1245 | (LO1LK | LO2LK)) { |
| 1246 | return (status); |
| 1247 | } |
Mauro Carvalho Chehab | bf97555 | 2011-07-20 21:43:30 -0300 | [diff] [blame] | 1248 | msleep(nPollRate); /* Wait between retries */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1249 | } |
| 1250 | while (++nDelays < nMaxLoops); |
| 1251 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1252 | if ((state->reg[MT2063_REG_LO_STATUS] & LO1LK) == 0x00) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1253 | status |= MT2063_UPC_UNLOCK; |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1254 | if ((state->reg[MT2063_REG_LO_STATUS] & LO2LK) == 0x00) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1255 | status |= MT2063_DNC_UNLOCK; |
| 1256 | |
| 1257 | return (status); |
| 1258 | } |
| 1259 | |
| 1260 | /**************************************************************************** |
| 1261 | ** |
| 1262 | ** Name: MT2063_GetParam |
| 1263 | ** |
| 1264 | ** Description: Gets a tuning algorithm parameter. |
| 1265 | ** |
| 1266 | ** This function provides access to the internals of the |
| 1267 | ** tuning algorithm - mostly for testing purposes. |
| 1268 | ** |
| 1269 | ** Parameters: h - Tuner handle (returned by MT2063_Open) |
| 1270 | ** param - Tuning algorithm parameter |
| 1271 | ** (see enum MT2063_Param) |
| 1272 | ** pValue - ptr to returned value |
| 1273 | ** |
| 1274 | ** param Description |
| 1275 | ** ---------------------- -------------------------------- |
| 1276 | ** MT2063_IC_ADDR Serial Bus address of this tuner |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1277 | ** MT2063_SRO_FREQ crystal frequency |
| 1278 | ** MT2063_STEPSIZE minimum tuning step size |
| 1279 | ** MT2063_INPUT_FREQ input center frequency |
| 1280 | ** MT2063_LO1_FREQ LO1 Frequency |
| 1281 | ** MT2063_LO1_STEPSIZE LO1 minimum step size |
| 1282 | ** MT2063_LO1_FRACN_AVOID LO1 FracN keep-out region |
| 1283 | ** MT2063_IF1_ACTUAL Current 1st IF in use |
| 1284 | ** MT2063_IF1_REQUEST Requested 1st IF |
| 1285 | ** MT2063_IF1_CENTER Center of 1st IF SAW filter |
| 1286 | ** MT2063_IF1_BW Bandwidth of 1st IF SAW filter |
| 1287 | ** MT2063_ZIF_BW zero-IF bandwidth |
| 1288 | ** MT2063_LO2_FREQ LO2 Frequency |
| 1289 | ** MT2063_LO2_STEPSIZE LO2 minimum step size |
| 1290 | ** MT2063_LO2_FRACN_AVOID LO2 FracN keep-out region |
| 1291 | ** MT2063_OUTPUT_FREQ output center frequency |
| 1292 | ** MT2063_OUTPUT_BW output bandwidth |
| 1293 | ** MT2063_LO_SEPARATION min inter-tuner LO separation |
| 1294 | ** MT2063_AS_ALG ID of avoid-spurs algorithm in use |
| 1295 | ** MT2063_MAX_HARM1 max # of intra-tuner harmonics |
| 1296 | ** MT2063_MAX_HARM2 max # of inter-tuner harmonics |
| 1297 | ** MT2063_EXCL_ZONES # of 1st IF exclusion zones |
| 1298 | ** MT2063_NUM_SPURS # of spurs found/avoided |
| 1299 | ** MT2063_SPUR_AVOIDED >0 spurs avoided |
| 1300 | ** MT2063_SPUR_PRESENT >0 spurs in output (mathematically) |
| 1301 | ** MT2063_RCVR_MODE Predefined modes. |
| 1302 | ** MT2063_ACLNA LNA attenuator gain code |
| 1303 | ** MT2063_ACRF RF attenuator gain code |
| 1304 | ** MT2063_ACFIF FIF attenuator gain code |
| 1305 | ** MT2063_ACLNA_MAX LNA attenuator limit |
| 1306 | ** MT2063_ACRF_MAX RF attenuator limit |
| 1307 | ** MT2063_ACFIF_MAX FIF attenuator limit |
| 1308 | ** MT2063_PD1 Actual value of PD1 |
| 1309 | ** MT2063_PD2 Actual value of PD2 |
| 1310 | ** MT2063_DNC_OUTPUT_ENABLE DNC output selection |
| 1311 | ** MT2063_VGAGC VGA gain code |
| 1312 | ** MT2063_VGAOI VGA output current |
| 1313 | ** MT2063_TAGC TAGC setting |
| 1314 | ** MT2063_AMPGC AMP gain code |
| 1315 | ** MT2063_AVOID_DECT Avoid DECT Frequencies |
| 1316 | ** MT2063_CTFILT_SW Cleartune filter selection |
| 1317 | ** |
| 1318 | ** Usage: status |= MT2063_GetParam(hMT2063, |
| 1319 | ** MT2063_IF1_ACTUAL, |
| 1320 | ** &f_IF1_Actual); |
| 1321 | ** |
| 1322 | ** Returns: status: |
| 1323 | ** MT_OK - No errors |
| 1324 | ** MT_INV_HANDLE - Invalid tuner handle |
| 1325 | ** MT_ARG_NULL - Null pointer argument passed |
| 1326 | ** MT_ARG_RANGE - Invalid parameter requested |
| 1327 | ** |
| 1328 | ** Dependencies: USERS MUST CALL MT2063_Open() FIRST! |
| 1329 | ** |
| 1330 | ** See Also: MT2063_SetParam, MT2063_Open |
| 1331 | ** |
| 1332 | ** Revision History: |
| 1333 | ** |
| 1334 | ** SCR Date Author Description |
| 1335 | ** ------------------------------------------------------------------------- |
| 1336 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 1337 | ** 154 09-13-2007 RSK Ver 1.05: Get/SetParam changes for LOx_FREQ |
| 1338 | ** 10-31-2007 PINZ Ver 1.08: Get/SetParam add VGAGC, VGAOI, AMPGC, TAGC |
| 1339 | ** 173 M 01-23-2008 RSK Ver 1.12: Read LO1C and LO2C registers from HW |
| 1340 | ** in GetParam. |
| 1341 | ** 04-18-2008 PINZ Ver 1.15: Add SetParam LNARIN & PDxTGT |
| 1342 | ** Split SetParam up to ACLNA / ACLNA_MAX |
| 1343 | ** removed ACLNA_INRC/DECR (+RF & FIF) |
| 1344 | ** removed GCUAUTO / BYPATNDN/UP |
| 1345 | ** 175 I 16-06-2008 PINZ Ver 1.16: Add control to avoid US DECT freqs. |
| 1346 | ** 175 I 06-19-2008 RSK Ver 1.17: Refactor DECT control to SpurAvoid. |
| 1347 | ** 06-24-2008 PINZ Ver 1.18: Add Get/SetParam CTFILT_SW |
| 1348 | ** |
| 1349 | ****************************************************************************/ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1350 | static u32 MT2063_GetParam(struct mt2063_state *state, enum MT2063_Param param, u32 *pValue) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1351 | { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1352 | u32 status = 0; /* Status to be returned */ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1353 | u32 Div; |
| 1354 | u32 Num; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1355 | |
| 1356 | if (pValue == NULL) |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1357 | return -EINVAL; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1358 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1359 | switch (param) { |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1360 | /* input center frequency */ |
| 1361 | case MT2063_INPUT_FREQ: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1362 | *pValue = state->AS_Data.f_in; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1363 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1364 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1365 | /* LO1 Frequency */ |
| 1366 | case MT2063_LO1_FREQ: |
| 1367 | { |
| 1368 | /* read the actual tuner register values for LO1C_1 and LO1C_2 */ |
| 1369 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1370 | mt2063_read(state, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1371 | MT2063_REG_LO1C_1, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1372 | &state-> |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1373 | reg[MT2063_REG_LO1C_1], 2); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1374 | Div = state->reg[MT2063_REG_LO1C_1]; |
| 1375 | Num = state->reg[MT2063_REG_LO1C_2] & 0x3F; |
| 1376 | state->AS_Data.f_LO1 = |
| 1377 | (state->AS_Data.f_ref * Div) + |
| 1378 | MT2063_fLO_FractionalTerm(state->AS_Data. |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1379 | f_ref, Num, 64); |
| 1380 | } |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1381 | *pValue = state->AS_Data.f_LO1; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1382 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1383 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1384 | /* Bandwidth of 1st IF SAW filter */ |
| 1385 | case MT2063_IF1_BW: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1386 | *pValue = state->AS_Data.f_if1_bw; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1387 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1388 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1389 | /* zero-IF bandwidth */ |
| 1390 | case MT2063_ZIF_BW: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1391 | *pValue = state->AS_Data.f_zif_bw; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1392 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1393 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1394 | /* LO2 Frequency */ |
| 1395 | case MT2063_LO2_FREQ: |
| 1396 | { |
| 1397 | /* Read the actual tuner register values for LO2C_1, LO2C_2 and LO2C_3 */ |
| 1398 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1399 | mt2063_read(state, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1400 | MT2063_REG_LO2C_1, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1401 | &state-> |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1402 | reg[MT2063_REG_LO2C_1], 3); |
| 1403 | Div = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1404 | (state->reg[MT2063_REG_LO2C_1] & 0xFE) >> 1; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1405 | Num = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1406 | ((state-> |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1407 | reg[MT2063_REG_LO2C_1] & 0x01) << 12) | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1408 | (state-> |
| 1409 | reg[MT2063_REG_LO2C_2] << 4) | (state-> |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1410 | reg |
| 1411 | [MT2063_REG_LO2C_3] |
| 1412 | & 0x00F); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1413 | state->AS_Data.f_LO2 = |
| 1414 | (state->AS_Data.f_ref * Div) + |
| 1415 | MT2063_fLO_FractionalTerm(state->AS_Data. |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1416 | f_ref, Num, 8191); |
| 1417 | } |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1418 | *pValue = state->AS_Data.f_LO2; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1419 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1420 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1421 | /* LO2 FracN keep-out region */ |
| 1422 | case MT2063_LO2_FRACN_AVOID: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1423 | *pValue = state->AS_Data.f_LO2_FracN_Avoid; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1424 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1425 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1426 | /* output center frequency */ |
| 1427 | case MT2063_OUTPUT_FREQ: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1428 | *pValue = state->AS_Data.f_out; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1429 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1430 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1431 | /* output bandwidth */ |
| 1432 | case MT2063_OUTPUT_BW: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1433 | *pValue = state->AS_Data.f_out_bw - 750000; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1434 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1435 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1436 | /* Predefined receiver setup combination */ |
| 1437 | case MT2063_RCVR_MODE: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1438 | *pValue = state->rcvr_mode; |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1439 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1440 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1441 | case MT2063_PD1: |
| 1442 | case MT2063_PD2: { |
| 1443 | u8 mask = (param == MT2063_PD1 ? 0x01 : 0x03); /* PD1 vs PD2 */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1444 | u8 orig = (state->reg[MT2063_REG_BYP_CTRL]); |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1445 | u8 reg = (orig & 0xF1) | mask; /* Only set 3 bits (not 5) */ |
| 1446 | int i; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1447 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1448 | *pValue = 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1449 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1450 | /* Initiate ADC output to reg 0x0A */ |
| 1451 | if (reg != orig) |
| 1452 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1453 | mt2063_write(state, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1454 | MT2063_REG_BYP_CTRL, |
| 1455 | ®, 1); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1456 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1457 | if (status < 0) |
| 1458 | return (status); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1459 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1460 | for (i = 0; i < 8; i++) { |
| 1461 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1462 | mt2063_read(state, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1463 | MT2063_REG_ADC_OUT, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1464 | &state-> |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1465 | reg |
| 1466 | [MT2063_REG_ADC_OUT], |
| 1467 | 1); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1468 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1469 | if (status >= 0) |
| 1470 | *pValue += |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1471 | state-> |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1472 | reg[MT2063_REG_ADC_OUT]; |
| 1473 | else { |
| 1474 | if (i) |
| 1475 | *pValue /= i; |
| 1476 | return (status); |
| 1477 | } |
| 1478 | } |
| 1479 | *pValue /= 8; /* divide by number of reads */ |
| 1480 | *pValue >>= 2; /* only want 6 MSB's out of 8 */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1481 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1482 | /* Restore value of Register BYP_CTRL */ |
| 1483 | if (reg != orig) |
| 1484 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1485 | mt2063_write(state, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1486 | MT2063_REG_BYP_CTRL, |
| 1487 | &orig, 1); |
| 1488 | } |
| 1489 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1490 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1491 | /* Get LNA attenuator code */ |
| 1492 | case MT2063_ACLNA: |
| 1493 | { |
| 1494 | u8 val; |
| 1495 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1496 | MT2063_GetReg(state, MT2063_REG_XO_STATUS, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1497 | &val); |
| 1498 | *pValue = val & 0x1f; |
| 1499 | } |
| 1500 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1501 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1502 | /* Get RF attenuator code */ |
| 1503 | case MT2063_ACRF: |
| 1504 | { |
| 1505 | u8 val; |
| 1506 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1507 | MT2063_GetReg(state, MT2063_REG_RF_STATUS, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1508 | &val); |
| 1509 | *pValue = val & 0x1f; |
| 1510 | } |
| 1511 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1512 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1513 | /* Get FIF attenuator code */ |
| 1514 | case MT2063_ACFIF: |
| 1515 | { |
| 1516 | u8 val; |
| 1517 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1518 | MT2063_GetReg(state, MT2063_REG_FIF_STATUS, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1519 | &val); |
| 1520 | *pValue = val & 0x1f; |
| 1521 | } |
| 1522 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1523 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1524 | /* Get LNA attenuator limit */ |
| 1525 | case MT2063_ACLNA_MAX: |
| 1526 | { |
| 1527 | u8 val; |
| 1528 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1529 | MT2063_GetReg(state, MT2063_REG_LNA_OV, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1530 | &val); |
| 1531 | *pValue = val & 0x1f; |
| 1532 | } |
| 1533 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1534 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1535 | /* Get RF attenuator limit */ |
| 1536 | case MT2063_ACRF_MAX: |
| 1537 | { |
| 1538 | u8 val; |
| 1539 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1540 | MT2063_GetReg(state, MT2063_REG_RF_OV, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1541 | &val); |
| 1542 | *pValue = val & 0x1f; |
| 1543 | } |
| 1544 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1545 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1546 | /* Get FIF attenuator limit */ |
| 1547 | case MT2063_ACFIF_MAX: |
| 1548 | { |
| 1549 | u8 val; |
| 1550 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1551 | MT2063_GetReg(state, MT2063_REG_FIF_OV, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1552 | &val); |
| 1553 | *pValue = val & 0x1f; |
| 1554 | } |
| 1555 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1556 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1557 | /* Get current used DNC output */ |
| 1558 | case MT2063_DNC_OUTPUT_ENABLE: |
| 1559 | { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1560 | if ((state->reg[MT2063_REG_DNC_GAIN] & 0x03) == 0x03) { /* if DNC1 is off */ |
| 1561 | if ((state->reg[MT2063_REG_VGA_GAIN] & 0x03) == 0x03) /* if DNC2 is off */ |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1562 | *pValue = |
| 1563 | (u32) MT2063_DNC_NONE; |
| 1564 | else |
| 1565 | *pValue = |
| 1566 | (u32) MT2063_DNC_2; |
| 1567 | } else { /* DNC1 is on */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1568 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1569 | if ((state->reg[MT2063_REG_VGA_GAIN] & 0x03) == 0x03) /* if DNC2 is off */ |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1570 | *pValue = |
| 1571 | (u32) MT2063_DNC_1; |
| 1572 | else |
| 1573 | *pValue = |
| 1574 | (u32) MT2063_DNC_BOTH; |
| 1575 | } |
| 1576 | } |
| 1577 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1578 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 1579 | default: |
| 1580 | status |= -ERANGE; |
| 1581 | } |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1582 | return (status); |
| 1583 | } |
| 1584 | |
| 1585 | /**************************************************************************** |
| 1586 | ** |
| 1587 | ** Name: MT2063_GetReg |
| 1588 | ** |
| 1589 | ** Description: Gets an MT2063 register. |
| 1590 | ** |
| 1591 | ** Parameters: h - Tuner handle (returned by MT2063_Open) |
| 1592 | ** reg - MT2063 register/subaddress location |
| 1593 | ** *val - MT2063 register/subaddress value |
| 1594 | ** |
| 1595 | ** Returns: status: |
| 1596 | ** MT_OK - No errors |
| 1597 | ** MT_COMM_ERR - Serial bus communications error |
| 1598 | ** MT_INV_HANDLE - Invalid tuner handle |
| 1599 | ** MT_ARG_NULL - Null pointer argument passed |
| 1600 | ** MT_ARG_RANGE - Argument out of range |
| 1601 | ** |
| 1602 | ** Dependencies: USERS MUST CALL MT2063_Open() FIRST! |
| 1603 | ** |
| 1604 | ** Use this function if you need to read a register from |
| 1605 | ** the MT2063. |
| 1606 | ** |
| 1607 | ** Revision History: |
| 1608 | ** |
| 1609 | ** SCR Date Author Description |
| 1610 | ** ------------------------------------------------------------------------- |
| 1611 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 1612 | ** |
| 1613 | ****************************************************************************/ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1614 | static u32 MT2063_GetReg(struct mt2063_state *state, u8 reg, u8 * val) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1615 | { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1616 | u32 status = 0; /* Status to be returned */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1617 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1618 | if (val == NULL) |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1619 | return -EINVAL; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1620 | |
| 1621 | if (reg >= MT2063_REG_END_REGS) |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1622 | return -ERANGE; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1623 | |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1624 | status = mt2063_read(state, reg, &state->reg[reg], 1); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1625 | |
| 1626 | return (status); |
| 1627 | } |
| 1628 | |
| 1629 | /****************************************************************************** |
| 1630 | ** |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1631 | ** Name: MT2063_SetReceiverMode |
| 1632 | ** |
| 1633 | ** Description: Set the MT2063 receiver mode |
| 1634 | ** |
| 1635 | ** --------------+---------------------------------------------- |
| 1636 | ** Mode 0 : | MT2063_CABLE_QAM |
| 1637 | ** Mode 1 : | MT2063_CABLE_ANALOG |
| 1638 | ** Mode 2 : | MT2063_OFFAIR_COFDM |
| 1639 | ** Mode 3 : | MT2063_OFFAIR_COFDM_SAWLESS |
| 1640 | ** Mode 4 : | MT2063_OFFAIR_ANALOG |
| 1641 | ** Mode 5 : | MT2063_OFFAIR_8VSB |
| 1642 | ** --------------+----+----+----+----+-----+-------------------- |
| 1643 | ** (DNC1GC & DNC2GC are the values, which are used, when the specific |
| 1644 | ** DNC Output is selected, the other is always off) |
| 1645 | ** |
| 1646 | ** |<---------- Mode -------------->| |
| 1647 | ** Reg Field | 0 | 1 | 2 | 3 | 4 | 5 | |
| 1648 | ** ------------+-----+-----+-----+-----+-----+-----+ |
| 1649 | ** RFAGCen | OFF | OFF | OFF | OFF | OFF | OFF |
| 1650 | ** LNARin | 0 | 0 | 3 | 3 | 3 | 3 |
| 1651 | ** FIFFQen | 1 | 1 | 1 | 1 | 1 | 1 |
| 1652 | ** FIFFq | 0 | 0 | 0 | 0 | 0 | 0 |
| 1653 | ** DNC1gc | 0 | 0 | 0 | 0 | 0 | 0 |
| 1654 | ** DNC2gc | 0 | 0 | 0 | 0 | 0 | 0 |
| 1655 | ** GCU Auto | 1 | 1 | 1 | 1 | 1 | 1 |
| 1656 | ** LNA max Atn | 31 | 31 | 31 | 31 | 31 | 31 |
| 1657 | ** LNA Target | 44 | 43 | 43 | 43 | 43 | 43 |
| 1658 | ** ign RF Ovl | 0 | 0 | 0 | 0 | 0 | 0 |
| 1659 | ** RF max Atn | 31 | 31 | 31 | 31 | 31 | 31 |
| 1660 | ** PD1 Target | 36 | 36 | 38 | 38 | 36 | 38 |
| 1661 | ** ign FIF Ovl | 0 | 0 | 0 | 0 | 0 | 0 |
| 1662 | ** FIF max Atn | 5 | 5 | 5 | 5 | 5 | 5 |
| 1663 | ** PD2 Target | 40 | 33 | 42 | 42 | 33 | 42 |
| 1664 | ** |
| 1665 | ** |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1666 | ** Parameters: state - ptr to mt2063_state structure |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1667 | ** Mode - desired reciever mode |
| 1668 | ** |
| 1669 | ** Usage: status = MT2063_SetReceiverMode(hMT2063, Mode); |
| 1670 | ** |
| 1671 | ** Returns: status: |
| 1672 | ** MT_OK - No errors |
| 1673 | ** MT_COMM_ERR - Serial bus communications error |
| 1674 | ** |
| 1675 | ** Dependencies: MT2063_SetReg - Write a byte of data to a HW register. |
| 1676 | ** Assumes that the tuner cache is valid. |
| 1677 | ** |
| 1678 | ** Revision History: |
| 1679 | ** |
| 1680 | ** SCR Date Author Description |
| 1681 | ** ------------------------------------------------------------------------- |
| 1682 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 1683 | ** N/A 01-10-2007 PINZ Added additional GCU Settings, FIFF Calib will be triggered |
| 1684 | ** 155 10-01-2007 DAD Ver 1.06: Add receiver mode for SECAM positive |
| 1685 | ** modulation |
| 1686 | ** (MT2063_ANALOG_TV_POS_NO_RFAGC_MODE) |
| 1687 | ** N/A 10-22-2007 PINZ Ver 1.07: Changed some Registers at init to have |
| 1688 | ** the same settings as with MT Launcher |
| 1689 | ** N/A 10-30-2007 PINZ Add SetParam VGAGC & VGAOI |
| 1690 | ** Add SetParam DNC_OUTPUT_ENABLE |
| 1691 | ** Removed VGAGC from receiver mode, |
| 1692 | ** default now 1 |
| 1693 | ** N/A 10-31-2007 PINZ Ver 1.08: Add SetParam TAGC, removed from rcvr-mode |
| 1694 | ** Add SetParam AMPGC, removed from rcvr-mode |
| 1695 | ** Corrected names of GCU values |
| 1696 | ** reorganized receiver modes, removed, |
| 1697 | ** (MT2063_ANALOG_TV_POS_NO_RFAGC_MODE) |
| 1698 | ** Actualized Receiver-Mode values |
| 1699 | ** N/A 11-12-2007 PINZ Ver 1.09: Actualized Receiver-Mode values |
| 1700 | ** N/A 11-27-2007 PINZ Improved buffered writing |
| 1701 | ** 01-03-2008 PINZ Ver 1.10: Added a trigger of BYPATNUP for |
| 1702 | ** correct wakeup of the LNA after shutdown |
| 1703 | ** Set AFCsd = 1 as default |
| 1704 | ** Changed CAP1sel default |
| 1705 | ** 01-14-2008 PINZ Ver 1.11: Updated gain settings |
| 1706 | ** 04-18-2008 PINZ Ver 1.15: Add SetParam LNARIN & PDxTGT |
| 1707 | ** Split SetParam up to ACLNA / ACLNA_MAX |
| 1708 | ** removed ACLNA_INRC/DECR (+RF & FIF) |
| 1709 | ** removed GCUAUTO / BYPATNDN/UP |
| 1710 | ** |
| 1711 | ******************************************************************************/ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1712 | static u32 MT2063_SetReceiverMode(struct mt2063_state *state, |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1713 | enum MT2063_RCVR_MODES Mode) |
| 1714 | { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1715 | u32 status = 0; /* Status to be returned */ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1716 | u8 val; |
| 1717 | u32 longval; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1718 | |
| 1719 | if (Mode >= MT2063_NUM_RCVR_MODES) |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1720 | status = -ERANGE; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1721 | |
| 1722 | /* RFAGCen */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1723 | if (status >= 0) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1724 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1725 | (state-> |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1726 | reg[MT2063_REG_PD1_TGT] & (u8) ~ 0x40) | (RFAGCEN[Mode] |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1727 | ? 0x40 : |
| 1728 | 0x00); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1729 | if (state->reg[MT2063_REG_PD1_TGT] != val) { |
| 1730 | status |= MT2063_SetReg(state, MT2063_REG_PD1_TGT, val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | /* LNARin */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1735 | if (status >= 0) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1736 | status |= MT2063_SetParam(state, MT2063_LNA_RIN, LNARIN[Mode]); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | /* FIFFQEN and FIFFQ */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1740 | if (status >= 0) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1741 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1742 | (state-> |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1743 | reg[MT2063_REG_FIFF_CTRL2] & (u8) ~ 0xF0) | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1744 | (FIFFQEN[Mode] << 7) | (FIFFQ[Mode] << 4); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1745 | if (state->reg[MT2063_REG_FIFF_CTRL2] != val) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1746 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1747 | MT2063_SetReg(state, MT2063_REG_FIFF_CTRL2, val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1748 | /* trigger FIFF calibration, needed after changing FIFFQ */ |
| 1749 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1750 | (state->reg[MT2063_REG_FIFF_CTRL] | (u8) 0x01); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1751 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1752 | MT2063_SetReg(state, MT2063_REG_FIFF_CTRL, val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1753 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1754 | (state-> |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1755 | reg[MT2063_REG_FIFF_CTRL] & (u8) ~ 0x01); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1756 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1757 | MT2063_SetReg(state, MT2063_REG_FIFF_CTRL, val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | /* DNC1GC & DNC2GC */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1762 | status |= MT2063_GetParam(state, MT2063_DNC_OUTPUT_ENABLE, &longval); |
| 1763 | status |= MT2063_SetParam(state, MT2063_DNC_OUTPUT_ENABLE, longval); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1764 | |
| 1765 | /* acLNAmax */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1766 | if (status >= 0) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1767 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1768 | MT2063_SetParam(state, MT2063_ACLNA_MAX, ACLNAMAX[Mode]); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | /* LNATGT */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1772 | if (status >= 0) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1773 | status |= MT2063_SetParam(state, MT2063_LNA_TGT, LNATGT[Mode]); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | /* ACRF */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1777 | if (status >= 0) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1778 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1779 | MT2063_SetParam(state, MT2063_ACRF_MAX, ACRFMAX[Mode]); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | /* PD1TGT */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1783 | if (status >= 0) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1784 | status |= MT2063_SetParam(state, MT2063_PD1_TGT, PD1TGT[Mode]); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | /* FIFATN */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1788 | if (status >= 0) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1789 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1790 | MT2063_SetParam(state, MT2063_ACFIF_MAX, ACFIFMAX[Mode]); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | /* PD2TGT */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1794 | if (status >= 0) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1795 | status |= MT2063_SetParam(state, MT2063_PD2_TGT, PD2TGT[Mode]); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | /* Ignore ATN Overload */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1799 | if (status >= 0) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1800 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1801 | (state-> |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1802 | reg[MT2063_REG_LNA_TGT] & (u8) ~ 0x80) | (RFOVDIS[Mode] |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1803 | ? 0x80 : |
| 1804 | 0x00); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1805 | if (state->reg[MT2063_REG_LNA_TGT] != val) { |
| 1806 | status |= MT2063_SetReg(state, MT2063_REG_LNA_TGT, val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | /* Ignore FIF Overload */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1811 | if (status >= 0) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1812 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1813 | (state-> |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1814 | reg[MT2063_REG_PD1_TGT] & (u8) ~ 0x80) | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1815 | (FIFOVDIS[Mode] ? 0x80 : 0x00); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1816 | if (state->reg[MT2063_REG_PD1_TGT] != val) { |
| 1817 | status |= MT2063_SetReg(state, MT2063_REG_PD1_TGT, val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1818 | } |
| 1819 | } |
| 1820 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1821 | if (status >= 0) |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1822 | state->rcvr_mode = Mode; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1823 | |
| 1824 | return (status); |
| 1825 | } |
| 1826 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1827 | /**************************************************************************** |
| 1828 | ** |
| 1829 | ** Name: MT2063_SetParam |
| 1830 | ** |
| 1831 | ** Description: Sets a tuning algorithm parameter. |
| 1832 | ** |
| 1833 | ** This function provides access to the internals of the |
| 1834 | ** tuning algorithm. You can override many of the tuning |
| 1835 | ** algorithm defaults using this function. |
| 1836 | ** |
| 1837 | ** Parameters: h - Tuner handle (returned by MT2063_Open) |
| 1838 | ** param - Tuning algorithm parameter |
| 1839 | ** (see enum MT2063_Param) |
| 1840 | ** nValue - value to be set |
| 1841 | ** |
| 1842 | ** param Description |
| 1843 | ** ---------------------- -------------------------------- |
| 1844 | ** MT2063_SRO_FREQ crystal frequency |
| 1845 | ** MT2063_STEPSIZE minimum tuning step size |
| 1846 | ** MT2063_LO1_FREQ LO1 frequency |
| 1847 | ** MT2063_LO1_STEPSIZE LO1 minimum step size |
| 1848 | ** MT2063_LO1_FRACN_AVOID LO1 FracN keep-out region |
| 1849 | ** MT2063_IF1_REQUEST Requested 1st IF |
| 1850 | ** MT2063_ZIF_BW zero-IF bandwidth |
| 1851 | ** MT2063_LO2_FREQ LO2 frequency |
| 1852 | ** MT2063_LO2_STEPSIZE LO2 minimum step size |
| 1853 | ** MT2063_LO2_FRACN_AVOID LO2 FracN keep-out region |
| 1854 | ** MT2063_OUTPUT_FREQ output center frequency |
| 1855 | ** MT2063_OUTPUT_BW output bandwidth |
| 1856 | ** MT2063_LO_SEPARATION min inter-tuner LO separation |
| 1857 | ** MT2063_MAX_HARM1 max # of intra-tuner harmonics |
| 1858 | ** MT2063_MAX_HARM2 max # of inter-tuner harmonics |
| 1859 | ** MT2063_RCVR_MODE Predefined modes |
| 1860 | ** MT2063_LNA_RIN Set LNA Rin (*) |
| 1861 | ** MT2063_LNA_TGT Set target power level at LNA (*) |
| 1862 | ** MT2063_PD1_TGT Set target power level at PD1 (*) |
| 1863 | ** MT2063_PD2_TGT Set target power level at PD2 (*) |
| 1864 | ** MT2063_ACLNA_MAX LNA attenuator limit (*) |
| 1865 | ** MT2063_ACRF_MAX RF attenuator limit (*) |
| 1866 | ** MT2063_ACFIF_MAX FIF attenuator limit (*) |
| 1867 | ** MT2063_DNC_OUTPUT_ENABLE DNC output selection |
| 1868 | ** MT2063_VGAGC VGA gain code |
| 1869 | ** MT2063_VGAOI VGA output current |
| 1870 | ** MT2063_TAGC TAGC setting |
| 1871 | ** MT2063_AMPGC AMP gain code |
| 1872 | ** MT2063_AVOID_DECT Avoid DECT Frequencies |
| 1873 | ** MT2063_CTFILT_SW Cleartune filter selection |
| 1874 | ** |
| 1875 | ** (*) This parameter is set by MT2063_RCVR_MODE, do not call |
| 1876 | ** additionally. |
| 1877 | ** |
| 1878 | ** Usage: status |= MT2063_SetParam(hMT2063, |
| 1879 | ** MT2063_STEPSIZE, |
| 1880 | ** 50000); |
| 1881 | ** |
| 1882 | ** Returns: status: |
| 1883 | ** MT_OK - No errors |
| 1884 | ** MT_INV_HANDLE - Invalid tuner handle |
| 1885 | ** MT_ARG_NULL - Null pointer argument passed |
| 1886 | ** MT_ARG_RANGE - Invalid parameter requested |
| 1887 | ** or set value out of range |
| 1888 | ** or non-writable parameter |
| 1889 | ** |
| 1890 | ** Dependencies: USERS MUST CALL MT2063_Open() FIRST! |
| 1891 | ** |
| 1892 | ** See Also: MT2063_GetParam, MT2063_Open |
| 1893 | ** |
| 1894 | ** Revision History: |
| 1895 | ** |
| 1896 | ** SCR Date Author Description |
| 1897 | ** ------------------------------------------------------------------------- |
| 1898 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 1899 | ** 154 09-13-2007 RSK Ver 1.05: Get/SetParam changes for LOx_FREQ |
| 1900 | ** 10-31-2007 PINZ Ver 1.08: Get/SetParam add VGAGC, VGAOI, AMPGC, TAGC |
| 1901 | ** 04-18-2008 PINZ Ver 1.15: Add SetParam LNARIN & PDxTGT |
| 1902 | ** Split SetParam up to ACLNA / ACLNA_MAX |
| 1903 | ** removed ACLNA_INRC/DECR (+RF & FIF) |
| 1904 | ** removed GCUAUTO / BYPATNDN/UP |
| 1905 | ** 175 I 06-06-2008 PINZ Ver 1.16: Add control to avoid US DECT freqs. |
| 1906 | ** 175 I 06-19-2008 RSK Ver 1.17: Refactor DECT control to SpurAvoid. |
| 1907 | ** 06-24-2008 PINZ Ver 1.18: Add Get/SetParam CTFILT_SW |
| 1908 | ** |
| 1909 | ****************************************************************************/ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1910 | static u32 MT2063_SetParam(struct mt2063_state *state, |
Mauro Carvalho Chehab | 29a0a4fe | 2011-07-20 23:44:10 -0300 | [diff] [blame] | 1911 | enum MT2063_Param param, |
| 1912 | enum MT2063_DNC_Output_Enable nValue) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1913 | { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1914 | u32 status = 0; /* Status to be returned */ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 1915 | u8 val = 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1916 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1917 | switch (param) { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1918 | /* LO1 frequency */ |
| 1919 | case MT2063_LO1_FREQ: |
| 1920 | { |
| 1921 | /* Note: LO1 and LO2 are BOTH written at toggle of LDLOos */ |
| 1922 | /* Capture the Divider and Numerator portions of other LO */ |
| 1923 | u8 tempLO2CQ[3]; |
| 1924 | u8 tempLO2C[3]; |
| 1925 | u8 tmpOneShot; |
| 1926 | u32 Div, FracN; |
| 1927 | u8 restore = 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1928 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1929 | /* Buffer the queue for restoration later and get actual LO2 values. */ |
| 1930 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1931 | mt2063_read(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1932 | MT2063_REG_LO2CQ_1, |
| 1933 | &(tempLO2CQ[0]), 3); |
| 1934 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1935 | mt2063_read(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1936 | MT2063_REG_LO2C_1, |
| 1937 | &(tempLO2C[0]), 3); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1938 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1939 | /* clear the one-shot bits */ |
| 1940 | tempLO2CQ[2] = tempLO2CQ[2] & 0x0F; |
| 1941 | tempLO2C[2] = tempLO2C[2] & 0x0F; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1942 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1943 | /* only write the queue values if they are different from the actual. */ |
| 1944 | if ((tempLO2CQ[0] != tempLO2C[0]) || |
| 1945 | (tempLO2CQ[1] != tempLO2C[1]) || |
| 1946 | (tempLO2CQ[2] != tempLO2C[2])) { |
| 1947 | /* put actual LO2 value into queue (with 0 in one-shot bits) */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1948 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1949 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1950 | MT2063_REG_LO2CQ_1, |
| 1951 | &(tempLO2C[0]), 3); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1952 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1953 | if (status == 0) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1954 | /* cache the bytes just written. */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1955 | state->reg[MT2063_REG_LO2CQ_1] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1956 | tempLO2C[0]; |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1957 | state->reg[MT2063_REG_LO2CQ_2] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1958 | tempLO2C[1]; |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1959 | state->reg[MT2063_REG_LO2CQ_3] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1960 | tempLO2C[2]; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1961 | } |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1962 | restore = 1; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1963 | } |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1964 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1965 | /* Calculate the Divider and Numberator components of LO1 */ |
| 1966 | status = |
| 1967 | MT2063_CalcLO1Mult(&Div, &FracN, nValue, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1968 | state->AS_Data.f_ref / |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1969 | 64, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1970 | state->AS_Data.f_ref); |
| 1971 | state->reg[MT2063_REG_LO1CQ_1] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1972 | (u8) (Div & 0x00FF); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1973 | state->reg[MT2063_REG_LO1CQ_2] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1974 | (u8) (FracN); |
| 1975 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1976 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1977 | MT2063_REG_LO1CQ_1, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1978 | &state-> |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1979 | reg[MT2063_REG_LO1CQ_1], 2); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1980 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1981 | /* set the one-shot bit to load the pair of LO values */ |
| 1982 | tmpOneShot = tempLO2CQ[2] | 0xE0; |
| 1983 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1984 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1985 | MT2063_REG_LO2CQ_3, |
| 1986 | &tmpOneShot, 1); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1987 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1988 | /* only restore the queue values if they were different from the actual. */ |
| 1989 | if (restore) { |
| 1990 | /* put actual LO2 value into queue (0 in one-shot bits) */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1991 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 1992 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1993 | MT2063_REG_LO2CQ_1, |
| 1994 | &(tempLO2CQ[0]), 3); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 1995 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1996 | /* cache the bytes just written. */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1997 | state->reg[MT2063_REG_LO2CQ_1] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 1998 | tempLO2CQ[0]; |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 1999 | state->reg[MT2063_REG_LO2CQ_2] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2000 | tempLO2CQ[1]; |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2001 | state->reg[MT2063_REG_LO2CQ_3] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2002 | tempLO2CQ[2]; |
| 2003 | } |
| 2004 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2005 | MT2063_GetParam(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2006 | MT2063_LO1_FREQ, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2007 | &state->AS_Data.f_LO1); |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2008 | } |
| 2009 | break; |
| 2010 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2011 | /* zero-IF bandwidth */ |
| 2012 | case MT2063_ZIF_BW: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2013 | state->AS_Data.f_zif_bw = nValue; |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2014 | break; |
| 2015 | |
| 2016 | /* LO2 frequency */ |
| 2017 | case MT2063_LO2_FREQ: |
| 2018 | { |
| 2019 | /* Note: LO1 and LO2 are BOTH written at toggle of LDLOos */ |
| 2020 | /* Capture the Divider and Numerator portions of other LO */ |
| 2021 | u8 tempLO1CQ[2]; |
| 2022 | u8 tempLO1C[2]; |
| 2023 | u32 Div2; |
| 2024 | u32 FracN2; |
| 2025 | u8 tmpOneShot; |
| 2026 | u8 restore = 0; |
| 2027 | |
| 2028 | /* Buffer the queue for restoration later and get actual LO2 values. */ |
| 2029 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2030 | mt2063_read(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2031 | MT2063_REG_LO1CQ_1, |
| 2032 | &(tempLO1CQ[0]), 2); |
| 2033 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2034 | mt2063_read(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2035 | MT2063_REG_LO1C_1, |
| 2036 | &(tempLO1C[0]), 2); |
| 2037 | |
| 2038 | /* only write the queue values if they are different from the actual. */ |
| 2039 | if ((tempLO1CQ[0] != tempLO1C[0]) |
| 2040 | || (tempLO1CQ[1] != tempLO1C[1])) { |
| 2041 | /* put actual LO1 value into queue */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2042 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2043 | mt2063_write(state, |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2044 | MT2063_REG_LO1CQ_1, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2045 | &(tempLO1C[0]), 2); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2046 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2047 | /* cache the bytes just written. */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2048 | state->reg[MT2063_REG_LO1CQ_1] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2049 | tempLO1C[0]; |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2050 | state->reg[MT2063_REG_LO1CQ_2] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2051 | tempLO1C[1]; |
| 2052 | restore = 1; |
| 2053 | } |
| 2054 | |
| 2055 | /* Calculate the Divider and Numberator components of LO2 */ |
| 2056 | status = |
| 2057 | MT2063_CalcLO2Mult(&Div2, &FracN2, nValue, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2058 | state->AS_Data.f_ref / |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2059 | 8191, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2060 | state->AS_Data.f_ref); |
| 2061 | state->reg[MT2063_REG_LO2CQ_1] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2062 | (u8) ((Div2 << 1) | |
| 2063 | ((FracN2 >> 12) & 0x01)) & 0xFF; |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2064 | state->reg[MT2063_REG_LO2CQ_2] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2065 | (u8) ((FracN2 >> 4) & 0xFF); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2066 | state->reg[MT2063_REG_LO2CQ_3] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2067 | (u8) ((FracN2 & 0x0F)); |
| 2068 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2069 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2070 | MT2063_REG_LO1CQ_1, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2071 | &state-> |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2072 | reg[MT2063_REG_LO1CQ_1], 3); |
| 2073 | |
| 2074 | /* set the one-shot bit to load the LO values */ |
| 2075 | tmpOneShot = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2076 | state->reg[MT2063_REG_LO2CQ_3] | 0xE0; |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2077 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2078 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2079 | MT2063_REG_LO2CQ_3, |
| 2080 | &tmpOneShot, 1); |
| 2081 | |
| 2082 | /* only restore LO1 queue value if they were different from the actual. */ |
| 2083 | if (restore) { |
| 2084 | /* put previous LO1 queue value back into queue */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2085 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2086 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2087 | MT2063_REG_LO1CQ_1, |
| 2088 | &(tempLO1CQ[0]), 2); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2089 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2090 | /* cache the bytes just written. */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2091 | state->reg[MT2063_REG_LO1CQ_1] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2092 | tempLO1CQ[0]; |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2093 | state->reg[MT2063_REG_LO1CQ_2] = |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2094 | tempLO1CQ[1]; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2095 | } |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2096 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2097 | MT2063_GetParam(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2098 | MT2063_LO2_FREQ, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2099 | &state->AS_Data.f_LO2); |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2100 | } |
| 2101 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2102 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2103 | /* LO2 FracN keep-out region */ |
| 2104 | case MT2063_LO2_FRACN_AVOID: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2105 | state->AS_Data.f_LO2_FracN_Avoid = nValue; |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2106 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2107 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2108 | /* output center frequency */ |
| 2109 | case MT2063_OUTPUT_FREQ: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2110 | state->AS_Data.f_out = nValue; |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2111 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2112 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2113 | /* output bandwidth */ |
| 2114 | case MT2063_OUTPUT_BW: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2115 | state->AS_Data.f_out_bw = nValue + 750000; |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2116 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2117 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2118 | case MT2063_RCVR_MODE: |
| 2119 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2120 | MT2063_SetReceiverMode(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2121 | (enum MT2063_RCVR_MODES) |
| 2122 | nValue); |
| 2123 | break; |
| 2124 | |
| 2125 | /* Set LNA Rin -- nValue is desired value */ |
| 2126 | case MT2063_LNA_RIN: |
| 2127 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2128 | (state-> |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2129 | reg[MT2063_REG_CTRL_2C] & (u8) ~ 0x03) | |
| 2130 | (nValue & 0x03); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2131 | if (state->reg[MT2063_REG_CTRL_2C] != val) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2132 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2133 | MT2063_SetReg(state, MT2063_REG_CTRL_2C, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2134 | val); |
| 2135 | } |
| 2136 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2137 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2138 | /* Set target power level at LNA -- nValue is desired value */ |
| 2139 | case MT2063_LNA_TGT: |
| 2140 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2141 | (state-> |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2142 | reg[MT2063_REG_LNA_TGT] & (u8) ~ 0x3F) | |
| 2143 | (nValue & 0x3F); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2144 | if (state->reg[MT2063_REG_LNA_TGT] != val) { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2145 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2146 | MT2063_SetReg(state, MT2063_REG_LNA_TGT, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2147 | val); |
| 2148 | } |
| 2149 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2150 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2151 | /* Set target power level at PD1 -- nValue is desired value */ |
| 2152 | case MT2063_PD1_TGT: |
| 2153 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2154 | (state-> |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2155 | reg[MT2063_REG_PD1_TGT] & (u8) ~ 0x3F) | |
| 2156 | (nValue & 0x3F); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2157 | if (state->reg[MT2063_REG_PD1_TGT] != val) { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2158 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2159 | MT2063_SetReg(state, MT2063_REG_PD1_TGT, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2160 | val); |
| 2161 | } |
| 2162 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2163 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2164 | /* Set target power level at PD2 -- nValue is desired value */ |
| 2165 | case MT2063_PD2_TGT: |
| 2166 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2167 | (state-> |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2168 | reg[MT2063_REG_PD2_TGT] & (u8) ~ 0x3F) | |
| 2169 | (nValue & 0x3F); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2170 | if (state->reg[MT2063_REG_PD2_TGT] != val) { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2171 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2172 | MT2063_SetReg(state, MT2063_REG_PD2_TGT, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2173 | val); |
| 2174 | } |
| 2175 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2176 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2177 | /* Set LNA atten limit -- nValue is desired value */ |
| 2178 | case MT2063_ACLNA_MAX: |
| 2179 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2180 | (state-> |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2181 | reg[MT2063_REG_LNA_OV] & (u8) ~ 0x1F) | (nValue |
| 2182 | & |
| 2183 | 0x1F); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2184 | if (state->reg[MT2063_REG_LNA_OV] != val) { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2185 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2186 | MT2063_SetReg(state, MT2063_REG_LNA_OV, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2187 | val); |
| 2188 | } |
| 2189 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2190 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2191 | /* Set RF atten limit -- nValue is desired value */ |
| 2192 | case MT2063_ACRF_MAX: |
| 2193 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2194 | (state-> |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2195 | reg[MT2063_REG_RF_OV] & (u8) ~ 0x1F) | (nValue |
| 2196 | & |
| 2197 | 0x1F); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2198 | if (state->reg[MT2063_REG_RF_OV] != val) { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2199 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2200 | MT2063_SetReg(state, MT2063_REG_RF_OV, val); |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2201 | } |
| 2202 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2203 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2204 | /* Set FIF atten limit -- nValue is desired value, max. 5 if no B3 */ |
| 2205 | case MT2063_ACFIF_MAX: |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2206 | if (state->reg[MT2063_REG_PART_REV] != MT2063_B3 |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2207 | && nValue > 5) |
| 2208 | nValue = 5; |
| 2209 | val = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2210 | (state-> |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2211 | reg[MT2063_REG_FIF_OV] & (u8) ~ 0x1F) | (nValue |
| 2212 | & |
| 2213 | 0x1F); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2214 | if (state->reg[MT2063_REG_FIF_OV] != val) { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2215 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2216 | MT2063_SetReg(state, MT2063_REG_FIF_OV, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2217 | val); |
| 2218 | } |
| 2219 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2220 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2221 | case MT2063_DNC_OUTPUT_ENABLE: |
| 2222 | /* selects, which DNC output is used */ |
Mauro Carvalho Chehab | 29a0a4fe | 2011-07-20 23:44:10 -0300 | [diff] [blame] | 2223 | switch (nValue) { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2224 | case MT2063_DNC_NONE: |
| 2225 | { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2226 | val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | 0x03; /* Set DNC1GC=3 */ |
| 2227 | if (state->reg[MT2063_REG_DNC_GAIN] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2228 | val) |
| 2229 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2230 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2231 | MT2063_REG_DNC_GAIN, |
| 2232 | val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2233 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2234 | val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | 0x03; /* Set DNC2GC=3 */ |
| 2235 | if (state->reg[MT2063_REG_VGA_GAIN] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2236 | val) |
| 2237 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2238 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2239 | MT2063_REG_VGA_GAIN, |
| 2240 | val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2241 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2242 | val = (state->reg[MT2063_REG_RSVD_20] & ~0x40); /* Set PD2MUX=0 */ |
| 2243 | if (state->reg[MT2063_REG_RSVD_20] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2244 | val) |
| 2245 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2246 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2247 | MT2063_REG_RSVD_20, |
| 2248 | val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2249 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2250 | break; |
| 2251 | } |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2252 | case MT2063_DNC_1: |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2253 | { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2254 | val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | (DNC1GC[state->rcvr_mode] & 0x03); /* Set DNC1GC=x */ |
| 2255 | if (state->reg[MT2063_REG_DNC_GAIN] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2256 | val) |
| 2257 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2258 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2259 | MT2063_REG_DNC_GAIN, |
| 2260 | val); |
| 2261 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2262 | val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | 0x03; /* Set DNC2GC=3 */ |
| 2263 | if (state->reg[MT2063_REG_VGA_GAIN] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2264 | val) |
| 2265 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2266 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2267 | MT2063_REG_VGA_GAIN, |
| 2268 | val); |
| 2269 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2270 | val = (state->reg[MT2063_REG_RSVD_20] & ~0x40); /* Set PD2MUX=0 */ |
| 2271 | if (state->reg[MT2063_REG_RSVD_20] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2272 | val) |
| 2273 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2274 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2275 | MT2063_REG_RSVD_20, |
| 2276 | val); |
| 2277 | |
| 2278 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2279 | } |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2280 | case MT2063_DNC_2: |
| 2281 | { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2282 | val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | 0x03; /* Set DNC1GC=3 */ |
| 2283 | if (state->reg[MT2063_REG_DNC_GAIN] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2284 | val) |
| 2285 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2286 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2287 | MT2063_REG_DNC_GAIN, |
| 2288 | val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2289 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2290 | val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | (DNC2GC[state->rcvr_mode] & 0x03); /* Set DNC2GC=x */ |
| 2291 | if (state->reg[MT2063_REG_VGA_GAIN] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2292 | val) |
| 2293 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2294 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2295 | MT2063_REG_VGA_GAIN, |
| 2296 | val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2297 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2298 | val = (state->reg[MT2063_REG_RSVD_20] | 0x40); /* Set PD2MUX=1 */ |
| 2299 | if (state->reg[MT2063_REG_RSVD_20] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2300 | val) |
| 2301 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2302 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2303 | MT2063_REG_RSVD_20, |
| 2304 | val); |
| 2305 | |
| 2306 | break; |
| 2307 | } |
| 2308 | case MT2063_DNC_BOTH: |
| 2309 | { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2310 | val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | (DNC1GC[state->rcvr_mode] & 0x03); /* Set DNC1GC=x */ |
| 2311 | if (state->reg[MT2063_REG_DNC_GAIN] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2312 | val) |
| 2313 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2314 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2315 | MT2063_REG_DNC_GAIN, |
| 2316 | val); |
| 2317 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2318 | val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | (DNC2GC[state->rcvr_mode] & 0x03); /* Set DNC2GC=x */ |
| 2319 | if (state->reg[MT2063_REG_VGA_GAIN] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2320 | val) |
| 2321 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2322 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2323 | MT2063_REG_VGA_GAIN, |
| 2324 | val); |
| 2325 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2326 | val = (state->reg[MT2063_REG_RSVD_20] | 0x40); /* Set PD2MUX=1 */ |
| 2327 | if (state->reg[MT2063_REG_RSVD_20] != |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2328 | val) |
| 2329 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2330 | MT2063_SetReg(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2331 | MT2063_REG_RSVD_20, |
| 2332 | val); |
| 2333 | |
| 2334 | break; |
| 2335 | } |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2336 | default: |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2337 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2338 | } |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2339 | break; |
| 2340 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2341 | default: |
| 2342 | status |= -ERANGE; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2343 | } |
| 2344 | return (status); |
| 2345 | } |
| 2346 | |
| 2347 | /**************************************************************************** |
| 2348 | ** |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2349 | ** Name: MT2063_ClearPowerMaskBits |
| 2350 | ** |
| 2351 | ** Description: Clears the power-down mask bits for various sections of |
| 2352 | ** the MT2063 |
| 2353 | ** |
| 2354 | ** Parameters: h - Tuner handle (returned by MT2063_Open) |
| 2355 | ** Bits - Mask bits to be cleared. |
| 2356 | ** |
| 2357 | ** See definition of MT2063_Mask_Bits type for description |
| 2358 | ** of each of the power bits. |
| 2359 | ** |
| 2360 | ** Returns: status: |
| 2361 | ** MT_OK - No errors |
| 2362 | ** MT_INV_HANDLE - Invalid tuner handle |
| 2363 | ** MT_COMM_ERR - Serial bus communications error |
| 2364 | ** |
| 2365 | ** Dependencies: USERS MUST CALL MT2063_Open() FIRST! |
| 2366 | ** |
| 2367 | ** Revision History: |
| 2368 | ** |
| 2369 | ** SCR Date Author Description |
| 2370 | ** ------------------------------------------------------------------------- |
| 2371 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 2372 | ** |
| 2373 | ****************************************************************************/ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2374 | static u32 MT2063_ClearPowerMaskBits(struct mt2063_state *state, enum MT2063_Mask_Bits Bits) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2375 | { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2376 | u32 status = 0; /* Status to be returned */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2377 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2378 | Bits = (enum MT2063_Mask_Bits)(Bits & MT2063_ALL_SD); /* Only valid bits for this tuner */ |
| 2379 | if ((Bits & 0xFF00) != 0) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2380 | state->reg[MT2063_REG_PWR_2] &= ~(u8) (Bits >> 8); |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2381 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2382 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2383 | MT2063_REG_PWR_2, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2384 | &state->reg[MT2063_REG_PWR_2], 1); |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2385 | } |
| 2386 | if ((Bits & 0xFF) != 0) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2387 | state->reg[MT2063_REG_PWR_1] &= ~(u8) (Bits & 0xFF); |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2388 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2389 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2390 | MT2063_REG_PWR_1, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2391 | &state->reg[MT2063_REG_PWR_1], 1); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | return (status); |
| 2395 | } |
| 2396 | |
| 2397 | /**************************************************************************** |
| 2398 | ** |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2399 | ** Name: MT2063_SoftwareShutdown |
| 2400 | ** |
| 2401 | ** Description: Enables or disables software shutdown function. When |
| 2402 | ** Shutdown==1, any section whose power mask is set will be |
| 2403 | ** shutdown. |
| 2404 | ** |
| 2405 | ** Parameters: h - Tuner handle (returned by MT2063_Open) |
| 2406 | ** Shutdown - 1 = shutdown the masked sections, otherwise |
| 2407 | ** power all sections on |
| 2408 | ** |
| 2409 | ** Returns: status: |
| 2410 | ** MT_OK - No errors |
| 2411 | ** MT_INV_HANDLE - Invalid tuner handle |
| 2412 | ** MT_COMM_ERR - Serial bus communications error |
| 2413 | ** |
| 2414 | ** Dependencies: USERS MUST CALL MT2063_Open() FIRST! |
| 2415 | ** |
| 2416 | ** Revision History: |
| 2417 | ** |
| 2418 | ** SCR Date Author Description |
| 2419 | ** ------------------------------------------------------------------------- |
| 2420 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 2421 | ** 01-03-2008 PINZ Ver 1.xx: Added a trigger of BYPATNUP for |
| 2422 | ** correct wakeup of the LNA |
| 2423 | ** |
| 2424 | ****************************************************************************/ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2425 | static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2426 | { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2427 | u32 status = 0; /* Status to be returned */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2428 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2429 | if (Shutdown == 1) |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2430 | state->reg[MT2063_REG_PWR_1] |= 0x04; /* Turn the bit on */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2431 | else |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2432 | state->reg[MT2063_REG_PWR_1] &= ~0x04; /* Turn off the bit */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2433 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2434 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2435 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2436 | MT2063_REG_PWR_1, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2437 | &state->reg[MT2063_REG_PWR_1], 1); |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2438 | |
| 2439 | if (Shutdown != 1) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2440 | state->reg[MT2063_REG_BYP_CTRL] = |
| 2441 | (state->reg[MT2063_REG_BYP_CTRL] & 0x9F) | 0x40; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2442 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2443 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2444 | MT2063_REG_BYP_CTRL, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2445 | &state->reg[MT2063_REG_BYP_CTRL], |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2446 | 1); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2447 | state->reg[MT2063_REG_BYP_CTRL] = |
| 2448 | (state->reg[MT2063_REG_BYP_CTRL] & 0x9F); |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2449 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2450 | mt2063_write(state, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2451 | MT2063_REG_BYP_CTRL, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2452 | &state->reg[MT2063_REG_BYP_CTRL], |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2453 | 1); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | return (status); |
| 2457 | } |
| 2458 | |
| 2459 | /**************************************************************************** |
| 2460 | ** |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2461 | ** Name: MT2063_SetReg |
| 2462 | ** |
| 2463 | ** Description: Sets an MT2063 register. |
| 2464 | ** |
| 2465 | ** Parameters: h - Tuner handle (returned by MT2063_Open) |
| 2466 | ** reg - MT2063 register/subaddress location |
| 2467 | ** val - MT2063 register/subaddress value |
| 2468 | ** |
| 2469 | ** Returns: status: |
| 2470 | ** MT_OK - No errors |
| 2471 | ** MT_COMM_ERR - Serial bus communications error |
| 2472 | ** MT_INV_HANDLE - Invalid tuner handle |
| 2473 | ** MT_ARG_RANGE - Argument out of range |
| 2474 | ** |
| 2475 | ** Dependencies: USERS MUST CALL MT2063_Open() FIRST! |
| 2476 | ** |
| 2477 | ** Use this function if you need to override a default |
| 2478 | ** register value |
| 2479 | ** |
| 2480 | ** Revision History: |
| 2481 | ** |
| 2482 | ** SCR Date Author Description |
| 2483 | ** ------------------------------------------------------------------------- |
| 2484 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 2485 | ** |
| 2486 | ****************************************************************************/ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2487 | static u32 MT2063_SetReg(struct mt2063_state *state, u8 reg, u8 val) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2488 | { |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2489 | u32 status = 0; /* Status to be returned */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2490 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2491 | if (reg >= MT2063_REG_END_REGS) |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2492 | status |= -ERANGE; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2493 | |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2494 | status = mt2063_write(state, reg, &val, |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2495 | 1); |
| 2496 | if (status >= 0) |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2497 | state->reg[reg] = val; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2498 | |
| 2499 | return (status); |
| 2500 | } |
| 2501 | |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2502 | static u32 MT2063_Round_fLO(u32 f_LO, u32 f_LO_Step, u32 f_ref) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2503 | { |
| 2504 | return f_ref * (f_LO / f_ref) |
| 2505 | + f_LO_Step * (((f_LO % f_ref) + (f_LO_Step / 2)) / f_LO_Step); |
| 2506 | } |
| 2507 | |
| 2508 | /**************************************************************************** |
| 2509 | ** |
| 2510 | ** Name: fLO_FractionalTerm |
| 2511 | ** |
| 2512 | ** Description: Calculates the portion contributed by FracN / denom. |
| 2513 | ** |
| 2514 | ** This function preserves maximum precision without |
| 2515 | ** risk of overflow. It accurately calculates |
| 2516 | ** f_ref * num / denom to within 1 HZ with fixed math. |
| 2517 | ** |
| 2518 | ** Parameters: num - Fractional portion of the multiplier |
| 2519 | ** denom - denominator portion of the ratio |
| 2520 | ** This routine successfully handles denom values |
| 2521 | ** up to and including 2^18. |
| 2522 | ** f_Ref - SRO frequency. This calculation handles |
| 2523 | ** f_ref as two separate 14-bit fields. |
| 2524 | ** Therefore, a maximum value of 2^28-1 |
| 2525 | ** may safely be used for f_ref. This is |
| 2526 | ** the genesis of the magic number "14" and the |
| 2527 | ** magic mask value of 0x03FFF. |
| 2528 | ** |
| 2529 | ** Returns: f_ref * num / denom |
| 2530 | ** |
| 2531 | ** Revision History: |
| 2532 | ** |
| 2533 | ** SCR Date Author Description |
| 2534 | ** ------------------------------------------------------------------------- |
| 2535 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 2536 | ** |
| 2537 | ****************************************************************************/ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2538 | static u32 MT2063_fLO_FractionalTerm(u32 f_ref, |
| 2539 | u32 num, u32 denom) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2540 | { |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2541 | u32 t1 = (f_ref >> 14) * num; |
| 2542 | u32 term1 = t1 / denom; |
| 2543 | u32 loss = t1 % denom; |
| 2544 | u32 term2 = |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2545 | (((f_ref & 0x00003FFF) * num + (loss << 14)) + (denom / 2)) / denom; |
| 2546 | return ((term1 << 14) + term2); |
| 2547 | } |
| 2548 | |
| 2549 | /**************************************************************************** |
| 2550 | ** |
| 2551 | ** Name: CalcLO1Mult |
| 2552 | ** |
| 2553 | ** Description: Calculates Integer divider value and the numerator |
| 2554 | ** value for a FracN PLL. |
| 2555 | ** |
| 2556 | ** This function assumes that the f_LO and f_Ref are |
| 2557 | ** evenly divisible by f_LO_Step. |
| 2558 | ** |
| 2559 | ** Parameters: Div - OUTPUT: Whole number portion of the multiplier |
| 2560 | ** FracN - OUTPUT: Fractional portion of the multiplier |
| 2561 | ** f_LO - desired LO frequency. |
| 2562 | ** f_LO_Step - Minimum step size for the LO (in Hz). |
| 2563 | ** f_Ref - SRO frequency. |
| 2564 | ** f_Avoid - Range of PLL frequencies to avoid near |
| 2565 | ** integer multiples of f_Ref (in Hz). |
| 2566 | ** |
| 2567 | ** Returns: Recalculated LO frequency. |
| 2568 | ** |
| 2569 | ** Revision History: |
| 2570 | ** |
| 2571 | ** SCR Date Author Description |
| 2572 | ** ------------------------------------------------------------------------- |
| 2573 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 2574 | ** |
| 2575 | ****************************************************************************/ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2576 | static u32 MT2063_CalcLO1Mult(u32 * Div, |
| 2577 | u32 * FracN, |
| 2578 | u32 f_LO, |
| 2579 | u32 f_LO_Step, u32 f_Ref) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2580 | { |
| 2581 | /* Calculate the whole number portion of the divider */ |
| 2582 | *Div = f_LO / f_Ref; |
| 2583 | |
| 2584 | /* Calculate the numerator value (round to nearest f_LO_Step) */ |
| 2585 | *FracN = |
| 2586 | (64 * (((f_LO % f_Ref) + (f_LO_Step / 2)) / f_LO_Step) + |
| 2587 | (f_Ref / f_LO_Step / 2)) / (f_Ref / f_LO_Step); |
| 2588 | |
| 2589 | return (f_Ref * (*Div)) + MT2063_fLO_FractionalTerm(f_Ref, *FracN, 64); |
| 2590 | } |
| 2591 | |
| 2592 | /**************************************************************************** |
| 2593 | ** |
| 2594 | ** Name: CalcLO2Mult |
| 2595 | ** |
| 2596 | ** Description: Calculates Integer divider value and the numerator |
| 2597 | ** value for a FracN PLL. |
| 2598 | ** |
| 2599 | ** This function assumes that the f_LO and f_Ref are |
| 2600 | ** evenly divisible by f_LO_Step. |
| 2601 | ** |
| 2602 | ** Parameters: Div - OUTPUT: Whole number portion of the multiplier |
| 2603 | ** FracN - OUTPUT: Fractional portion of the multiplier |
| 2604 | ** f_LO - desired LO frequency. |
| 2605 | ** f_LO_Step - Minimum step size for the LO (in Hz). |
| 2606 | ** f_Ref - SRO frequency. |
| 2607 | ** f_Avoid - Range of PLL frequencies to avoid near |
| 2608 | ** integer multiples of f_Ref (in Hz). |
| 2609 | ** |
| 2610 | ** Returns: Recalculated LO frequency. |
| 2611 | ** |
| 2612 | ** Revision History: |
| 2613 | ** |
| 2614 | ** SCR Date Author Description |
| 2615 | ** ------------------------------------------------------------------------- |
| 2616 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 2617 | ** |
| 2618 | ****************************************************************************/ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2619 | static u32 MT2063_CalcLO2Mult(u32 * Div, |
| 2620 | u32 * FracN, |
| 2621 | u32 f_LO, |
| 2622 | u32 f_LO_Step, u32 f_Ref) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2623 | { |
| 2624 | /* Calculate the whole number portion of the divider */ |
| 2625 | *Div = f_LO / f_Ref; |
| 2626 | |
| 2627 | /* Calculate the numerator value (round to nearest f_LO_Step) */ |
| 2628 | *FracN = |
| 2629 | (8191 * (((f_LO % f_Ref) + (f_LO_Step / 2)) / f_LO_Step) + |
| 2630 | (f_Ref / f_LO_Step / 2)) / (f_Ref / f_LO_Step); |
| 2631 | |
| 2632 | return (f_Ref * (*Div)) + MT2063_fLO_FractionalTerm(f_Ref, *FracN, |
| 2633 | 8191); |
| 2634 | } |
| 2635 | |
| 2636 | /**************************************************************************** |
| 2637 | ** |
| 2638 | ** Name: FindClearTuneFilter |
| 2639 | ** |
| 2640 | ** Description: Calculate the corrrect ClearTune filter to be used for |
| 2641 | ** a given input frequency. |
| 2642 | ** |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2643 | ** Parameters: state - ptr to tuner data structure |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2644 | ** f_in - RF input center frequency (in Hz). |
| 2645 | ** |
| 2646 | ** Returns: ClearTune filter number (0-31) |
| 2647 | ** |
| 2648 | ** Dependencies: MUST CALL MT2064_Open BEFORE FindClearTuneFilter! |
| 2649 | ** |
| 2650 | ** Revision History: |
| 2651 | ** |
| 2652 | ** SCR Date Author Description |
| 2653 | ** ------------------------------------------------------------------------- |
| 2654 | ** 04-10-2008 PINZ Ver 1.14: Use software-controlled ClearTune |
| 2655 | ** cross-over frequency values. |
| 2656 | ** |
| 2657 | ****************************************************************************/ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2658 | static u32 FindClearTuneFilter(struct mt2063_state *state, u32 f_in) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2659 | { |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2660 | u32 RFBand; |
| 2661 | u32 idx; /* index loop */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2662 | |
| 2663 | /* |
| 2664 | ** Find RF Band setting |
| 2665 | */ |
| 2666 | RFBand = 31; /* def when f_in > all */ |
| 2667 | for (idx = 0; idx < 31; ++idx) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2668 | if (state->CTFiltMax[idx] >= f_in) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2669 | RFBand = idx; |
| 2670 | break; |
| 2671 | } |
| 2672 | } |
| 2673 | return (RFBand); |
| 2674 | } |
| 2675 | |
| 2676 | /**************************************************************************** |
| 2677 | ** |
| 2678 | ** Name: MT2063_Tune |
| 2679 | ** |
| 2680 | ** Description: Change the tuner's tuned frequency to RFin. |
| 2681 | ** |
| 2682 | ** Parameters: h - Open handle to the tuner (from MT2063_Open). |
| 2683 | ** f_in - RF input center frequency (in Hz). |
| 2684 | ** |
| 2685 | ** Returns: status: |
| 2686 | ** MT_OK - No errors |
| 2687 | ** MT_INV_HANDLE - Invalid tuner handle |
| 2688 | ** MT_UPC_UNLOCK - Upconverter PLL unlocked |
| 2689 | ** MT_DNC_UNLOCK - Downconverter PLL unlocked |
| 2690 | ** MT_COMM_ERR - Serial bus communications error |
| 2691 | ** MT_SPUR_CNT_MASK - Count of avoided LO spurs |
| 2692 | ** MT_SPUR_PRESENT - LO spur possible in output |
| 2693 | ** MT_FIN_RANGE - Input freq out of range |
| 2694 | ** MT_FOUT_RANGE - Output freq out of range |
| 2695 | ** MT_UPC_RANGE - Upconverter freq out of range |
| 2696 | ** MT_DNC_RANGE - Downconverter freq out of range |
| 2697 | ** |
| 2698 | ** Dependencies: MUST CALL MT2063_Open BEFORE MT2063_Tune! |
| 2699 | ** |
| 2700 | ** MT_ReadSub - Read data from the two-wire serial bus |
| 2701 | ** MT_WriteSub - Write data to the two-wire serial bus |
| 2702 | ** MT_Sleep - Delay execution for x milliseconds |
| 2703 | ** MT2063_GetLocked - Checks to see if LO1 and LO2 are locked |
| 2704 | ** |
| 2705 | ** Revision History: |
| 2706 | ** |
| 2707 | ** SCR Date Author Description |
| 2708 | ** ------------------------------------------------------------------------- |
| 2709 | ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b. |
| 2710 | ** 04-10-2008 PINZ Ver 1.05: Use software-controlled ClearTune |
| 2711 | ** cross-over frequency values. |
| 2712 | ** 175 I 16-06-2008 PINZ Ver 1.16: Add control to avoid US DECT freqs. |
| 2713 | ** 175 I 06-19-2008 RSK Ver 1.17: Refactor DECT control to SpurAvoid. |
| 2714 | ** 06-24-2008 PINZ Ver 1.18: Add Get/SetParam CTFILT_SW |
| 2715 | ** |
| 2716 | ****************************************************************************/ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2717 | static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2718 | { /* RF input center frequency */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2719 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2720 | u32 status = 0; /* status of operation */ |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2721 | u32 LO1; /* 1st LO register value */ |
| 2722 | u32 Num1; /* Numerator for LO1 reg. value */ |
| 2723 | u32 f_IF1; /* 1st IF requested */ |
| 2724 | u32 LO2; /* 2nd LO register value */ |
| 2725 | u32 Num2; /* Numerator for LO2 reg. value */ |
| 2726 | u32 ofLO1, ofLO2; /* last time's LO frequencies */ |
| 2727 | u32 ofin, ofout; /* last time's I/O frequencies */ |
| 2728 | u8 fiffc = 0x80; /* FIFF center freq from tuner */ |
| 2729 | u32 fiffof; /* Offset from FIFF center freq */ |
| 2730 | const u8 LO1LK = 0x80; /* Mask for LO1 Lock bit */ |
| 2731 | u8 LO2LK = 0x08; /* Mask for LO2 Lock bit */ |
| 2732 | u8 val; |
| 2733 | u32 RFBand; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2734 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2735 | /* Check the input and output frequency ranges */ |
| 2736 | if ((f_in < MT2063_MIN_FIN_FREQ) || (f_in > MT2063_MAX_FIN_FREQ)) |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2737 | return -EINVAL; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2738 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2739 | if ((state->AS_Data.f_out < MT2063_MIN_FOUT_FREQ) |
| 2740 | || (state->AS_Data.f_out > MT2063_MAX_FOUT_FREQ)) |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2741 | return -EINVAL; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2742 | |
| 2743 | /* |
| 2744 | ** Save original LO1 and LO2 register values |
| 2745 | */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2746 | ofLO1 = state->AS_Data.f_LO1; |
| 2747 | ofLO2 = state->AS_Data.f_LO2; |
| 2748 | ofin = state->AS_Data.f_in; |
| 2749 | ofout = state->AS_Data.f_out; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2750 | |
| 2751 | /* |
| 2752 | ** Find and set RF Band setting |
| 2753 | */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2754 | if (state->ctfilt_sw == 1) { |
| 2755 | val = (state->reg[MT2063_REG_CTUNE_CTRL] | 0x08); |
| 2756 | if (state->reg[MT2063_REG_CTUNE_CTRL] != val) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2757 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2758 | MT2063_SetReg(state, MT2063_REG_CTUNE_CTRL, val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2759 | } |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2760 | val = state->reg[MT2063_REG_CTUNE_OV]; |
| 2761 | RFBand = FindClearTuneFilter(state, f_in); |
| 2762 | state->reg[MT2063_REG_CTUNE_OV] = |
| 2763 | (u8) ((state->reg[MT2063_REG_CTUNE_OV] & ~0x1F) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2764 | | RFBand); |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2765 | if (state->reg[MT2063_REG_CTUNE_OV] != val) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2766 | status |= |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2767 | MT2063_SetReg(state, MT2063_REG_CTUNE_OV, val); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2768 | } |
| 2769 | } |
| 2770 | |
| 2771 | /* |
| 2772 | ** Read the FIFF Center Frequency from the tuner |
| 2773 | */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2774 | if (status >= 0) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2775 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2776 | mt2063_read(state, |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2777 | MT2063_REG_FIFFC, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2778 | &state->reg[MT2063_REG_FIFFC], 1); |
| 2779 | fiffc = state->reg[MT2063_REG_FIFFC]; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2780 | } |
| 2781 | /* |
| 2782 | ** Assign in the requested values |
| 2783 | */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2784 | state->AS_Data.f_in = f_in; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2785 | /* Request a 1st IF such that LO1 is on a step size */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2786 | state->AS_Data.f_if1_Request = |
| 2787 | MT2063_Round_fLO(state->AS_Data.f_if1_Request + f_in, |
| 2788 | state->AS_Data.f_LO1_Step, |
| 2789 | state->AS_Data.f_ref) - f_in; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2790 | |
| 2791 | /* |
| 2792 | ** Calculate frequency settings. f_IF1_FREQ + f_in is the |
| 2793 | ** desired LO1 frequency |
| 2794 | */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2795 | MT2063_ResetExclZones(&state->AS_Data); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2796 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2797 | f_IF1 = MT2063_ChooseFirstIF(&state->AS_Data); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2798 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2799 | state->AS_Data.f_LO1 = |
| 2800 | MT2063_Round_fLO(f_IF1 + f_in, state->AS_Data.f_LO1_Step, |
| 2801 | state->AS_Data.f_ref); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2802 | |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2803 | state->AS_Data.f_LO2 = |
| 2804 | MT2063_Round_fLO(state->AS_Data.f_LO1 - state->AS_Data.f_out - f_in, |
| 2805 | state->AS_Data.f_LO2_Step, state->AS_Data.f_ref); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2806 | |
| 2807 | /* |
| 2808 | ** Check for any LO spurs in the output bandwidth and adjust |
| 2809 | ** the LO settings to avoid them if needed |
| 2810 | */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2811 | status |= MT2063_AvoidSpurs(state, &state->AS_Data); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2812 | /* |
| 2813 | ** MT_AvoidSpurs spurs may have changed the LO1 & LO2 values. |
| 2814 | ** Recalculate the LO frequencies and the values to be placed |
| 2815 | ** in the tuning registers. |
| 2816 | */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2817 | state->AS_Data.f_LO1 = |
| 2818 | MT2063_CalcLO1Mult(&LO1, &Num1, state->AS_Data.f_LO1, |
| 2819 | state->AS_Data.f_LO1_Step, state->AS_Data.f_ref); |
| 2820 | state->AS_Data.f_LO2 = |
| 2821 | MT2063_Round_fLO(state->AS_Data.f_LO1 - state->AS_Data.f_out - f_in, |
| 2822 | state->AS_Data.f_LO2_Step, state->AS_Data.f_ref); |
| 2823 | state->AS_Data.f_LO2 = |
| 2824 | MT2063_CalcLO2Mult(&LO2, &Num2, state->AS_Data.f_LO2, |
| 2825 | state->AS_Data.f_LO2_Step, state->AS_Data.f_ref); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2826 | |
| 2827 | /* |
| 2828 | ** Check the upconverter and downconverter frequency ranges |
| 2829 | */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2830 | if ((state->AS_Data.f_LO1 < MT2063_MIN_UPC_FREQ) |
| 2831 | || (state->AS_Data.f_LO1 > MT2063_MAX_UPC_FREQ)) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2832 | status |= MT2063_UPC_RANGE; |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2833 | if ((state->AS_Data.f_LO2 < MT2063_MIN_DNC_FREQ) |
| 2834 | || (state->AS_Data.f_LO2 > MT2063_MAX_DNC_FREQ)) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2835 | status |= MT2063_DNC_RANGE; |
| 2836 | /* LO2 Lock bit was in a different place for B0 version */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2837 | if (state->tuner_id == MT2063_B0) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2838 | LO2LK = 0x40; |
| 2839 | |
| 2840 | /* |
| 2841 | ** If we have the same LO frequencies and we're already locked, |
| 2842 | ** then skip re-programming the LO registers. |
| 2843 | */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2844 | if ((ofLO1 != state->AS_Data.f_LO1) |
| 2845 | || (ofLO2 != state->AS_Data.f_LO2) |
| 2846 | || ((state->reg[MT2063_REG_LO_STATUS] & (LO1LK | LO2LK)) != |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2847 | (LO1LK | LO2LK))) { |
| 2848 | /* |
| 2849 | ** Calculate the FIFFOF register value |
| 2850 | ** |
| 2851 | ** IF1_Actual |
| 2852 | ** FIFFOF = ------------ - 8 * FIFFC - 4992 |
| 2853 | ** f_ref/64 |
| 2854 | */ |
| 2855 | fiffof = |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2856 | (state->AS_Data.f_LO1 - |
| 2857 | f_in) / (state->AS_Data.f_ref / 64) - 8 * (u32) fiffc - |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2858 | 4992; |
| 2859 | if (fiffof > 0xFF) |
| 2860 | fiffof = 0xFF; |
| 2861 | |
| 2862 | /* |
| 2863 | ** Place all of the calculated values into the local tuner |
| 2864 | ** register fields. |
| 2865 | */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2866 | if (status >= 0) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2867 | state->reg[MT2063_REG_LO1CQ_1] = (u8) (LO1 & 0xFF); /* DIV1q */ |
| 2868 | state->reg[MT2063_REG_LO1CQ_2] = (u8) (Num1 & 0x3F); /* NUM1q */ |
| 2869 | state->reg[MT2063_REG_LO2CQ_1] = (u8) (((LO2 & 0x7F) << 1) /* DIV2q */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2870 | |(Num2 >> 12)); /* NUM2q (hi) */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2871 | state->reg[MT2063_REG_LO2CQ_2] = (u8) ((Num2 & 0x0FF0) >> 4); /* NUM2q (mid) */ |
| 2872 | state->reg[MT2063_REG_LO2CQ_3] = (u8) (0xE0 | (Num2 & 0x000F)); /* NUM2q (lo) */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2873 | |
| 2874 | /* |
| 2875 | ** Now write out the computed register values |
| 2876 | ** IMPORTANT: There is a required order for writing |
| 2877 | ** (0x05 must follow all the others). |
| 2878 | */ |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2879 | status |= mt2063_write(state, MT2063_REG_LO1CQ_1, &state->reg[MT2063_REG_LO1CQ_1], 5); /* 0x01 - 0x05 */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2880 | if (state->tuner_id == MT2063_B0) { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2881 | /* Re-write the one-shot bits to trigger the tune operation */ |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2882 | status |= mt2063_write(state, MT2063_REG_LO2CQ_3, &state->reg[MT2063_REG_LO2CQ_3], 1); /* 0x05 */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2883 | } |
| 2884 | /* Write out the FIFF offset only if it's changing */ |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2885 | if (state->reg[MT2063_REG_FIFF_OFFSET] != |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2886 | (u8) fiffof) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2887 | state->reg[MT2063_REG_FIFF_OFFSET] = |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2888 | (u8) fiffof; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2889 | status |= |
Mauro Carvalho Chehab | e1de3d1 | 2011-07-21 02:46:49 -0300 | [diff] [blame] | 2890 | mt2063_write(state, |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2891 | MT2063_REG_FIFF_OFFSET, |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2892 | &state-> |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2893 | reg[MT2063_REG_FIFF_OFFSET], |
| 2894 | 1); |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | /* |
| 2899 | ** Check for LO's locking |
| 2900 | */ |
| 2901 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2902 | if (status >= 0) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2903 | status |= MT2063_GetLocked(state); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2904 | } |
| 2905 | /* |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 2906 | ** If we locked OK, assign calculated data to mt2063_state structure |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2907 | */ |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2908 | if (status >= 0) { |
Mauro Carvalho Chehab | dcd52d2 | 2011-07-21 02:25:39 -0300 | [diff] [blame] | 2909 | state->f_IF1_actual = state->AS_Data.f_LO1 - f_in; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2910 | } |
| 2911 | } |
| 2912 | |
| 2913 | return (status); |
| 2914 | } |
| 2915 | |
Mauro Carvalho Chehab | bf97555 | 2011-07-20 21:43:30 -0300 | [diff] [blame] | 2916 | static u32 MT_Tune_atv(void *h, u32 f_in, u32 bw_in, |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2917 | enum MTTune_atv_standard tv_type) |
| 2918 | { |
| 2919 | |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 2920 | u32 status = 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2921 | |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2922 | s32 pict_car = 0; |
| 2923 | s32 pict2chanb_vsb = 0; |
| 2924 | s32 pict2chanb_snd = 0; |
| 2925 | s32 pict2snd1 = 0; |
| 2926 | s32 pict2snd2 = 0; |
| 2927 | s32 ch_bw = 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2928 | |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 2929 | s32 if_mid = 0; |
| 2930 | s32 rcvr_mode = 0; |
| 2931 | u32 mode_get = 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 2932 | |
| 2933 | switch (tv_type) { |
| 2934 | case MTTUNEA_PAL_B:{ |
| 2935 | pict_car = 38900000; |
| 2936 | ch_bw = 8000000; |
| 2937 | pict2chanb_vsb = -1250000; |
| 2938 | pict2snd1 = 5500000; |
| 2939 | pict2snd2 = 5742000; |
| 2940 | rcvr_mode = 1; |
| 2941 | break; |
| 2942 | } |
| 2943 | case MTTUNEA_PAL_G:{ |
| 2944 | pict_car = 38900000; |
| 2945 | ch_bw = 7000000; |
| 2946 | pict2chanb_vsb = -1250000; |
| 2947 | pict2snd1 = 5500000; |
| 2948 | pict2snd2 = 0; |
| 2949 | rcvr_mode = 1; |
| 2950 | break; |
| 2951 | } |
| 2952 | case MTTUNEA_PAL_I:{ |
| 2953 | pict_car = 38900000; |
| 2954 | ch_bw = 8000000; |
| 2955 | pict2chanb_vsb = -1250000; |
| 2956 | pict2snd1 = 6000000; |
| 2957 | pict2snd2 = 0; |
| 2958 | rcvr_mode = 1; |
| 2959 | break; |
| 2960 | } |
| 2961 | case MTTUNEA_PAL_L:{ |
| 2962 | pict_car = 38900000; |
| 2963 | ch_bw = 8000000; |
| 2964 | pict2chanb_vsb = -1250000; |
| 2965 | pict2snd1 = 6500000; |
| 2966 | pict2snd2 = 0; |
| 2967 | rcvr_mode = 1; |
| 2968 | break; |
| 2969 | } |
| 2970 | case MTTUNEA_PAL_MN:{ |
| 2971 | pict_car = 38900000; |
| 2972 | ch_bw = 6000000; |
| 2973 | pict2chanb_vsb = -1250000; |
| 2974 | pict2snd1 = 4500000; |
| 2975 | pict2snd2 = 0; |
| 2976 | rcvr_mode = 1; |
| 2977 | break; |
| 2978 | } |
| 2979 | case MTTUNEA_PAL_DK:{ |
| 2980 | pict_car = 38900000; |
| 2981 | ch_bw = 8000000; |
| 2982 | pict2chanb_vsb = -1250000; |
| 2983 | pict2snd1 = 6500000; |
| 2984 | pict2snd2 = 0; |
| 2985 | rcvr_mode = 1; |
| 2986 | break; |
| 2987 | } |
| 2988 | case MTTUNEA_DIGITAL:{ |
| 2989 | pict_car = 36125000; |
| 2990 | ch_bw = 8000000; |
| 2991 | pict2chanb_vsb = -(ch_bw / 2); |
| 2992 | pict2snd1 = 0; |
| 2993 | pict2snd2 = 0; |
| 2994 | rcvr_mode = 2; |
| 2995 | break; |
| 2996 | } |
| 2997 | case MTTUNEA_FMRADIO:{ |
| 2998 | pict_car = 38900000; |
| 2999 | ch_bw = 8000000; |
| 3000 | pict2chanb_vsb = -(ch_bw / 2); |
| 3001 | pict2snd1 = 0; |
| 3002 | pict2snd2 = 0; |
| 3003 | rcvr_mode = 4; |
| 3004 | //f_in -= 2900000; |
| 3005 | break; |
| 3006 | } |
| 3007 | case MTTUNEA_DVBC:{ |
| 3008 | pict_car = 36125000; |
| 3009 | ch_bw = 8000000; |
| 3010 | pict2chanb_vsb = -(ch_bw / 2); |
| 3011 | pict2snd1 = 0; |
| 3012 | pict2snd2 = 0; |
| 3013 | rcvr_mode = MT2063_CABLE_QAM; |
| 3014 | break; |
| 3015 | } |
| 3016 | case MTTUNEA_DVBT:{ |
| 3017 | pict_car = 36125000; |
| 3018 | ch_bw = bw_in; //8000000 |
| 3019 | pict2chanb_vsb = -(ch_bw / 2); |
| 3020 | pict2snd1 = 0; |
| 3021 | pict2snd2 = 0; |
| 3022 | rcvr_mode = MT2063_OFFAIR_COFDM; |
| 3023 | break; |
| 3024 | } |
| 3025 | case MTTUNEA_UNKNOWN: |
| 3026 | break; |
| 3027 | default: |
| 3028 | break; |
| 3029 | } |
| 3030 | |
| 3031 | pict2chanb_snd = pict2chanb_vsb - ch_bw; |
| 3032 | if_mid = pict_car - (pict2chanb_vsb + (ch_bw / 2)); |
| 3033 | |
| 3034 | status |= MT2063_SetParam(h, MT2063_STEPSIZE, 125000); |
| 3035 | status |= MT2063_SetParam(h, MT2063_OUTPUT_FREQ, if_mid); |
| 3036 | status |= MT2063_SetParam(h, MT2063_OUTPUT_BW, ch_bw); |
| 3037 | status |= MT2063_GetParam(h, MT2063_RCVR_MODE, &mode_get); |
| 3038 | |
| 3039 | status |= MT2063_SetParam(h, MT2063_RCVR_MODE, rcvr_mode); |
| 3040 | status |= MT2063_Tune(h, (f_in + (pict2chanb_vsb + (ch_bw / 2)))); |
| 3041 | status |= MT2063_GetParam(h, MT2063_RCVR_MODE, &mode_get); |
| 3042 | |
Mauro Carvalho Chehab | cfde892 | 2011-07-20 21:01:48 -0300 | [diff] [blame] | 3043 | return (u32) status; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3044 | } |
| 3045 | |
Mauro Carvalho Chehab | 01e0daf | 2011-07-21 03:20:43 -0300 | [diff] [blame] | 3046 | static const u8 MT2063B0_defaults[] = { |
| 3047 | /* Reg, Value */ |
| 3048 | 0x19, 0x05, |
| 3049 | 0x1B, 0x1D, |
| 3050 | 0x1C, 0x1F, |
| 3051 | 0x1D, 0x0F, |
| 3052 | 0x1E, 0x3F, |
| 3053 | 0x1F, 0x0F, |
| 3054 | 0x20, 0x3F, |
| 3055 | 0x22, 0x21, |
| 3056 | 0x23, 0x3F, |
| 3057 | 0x24, 0x20, |
| 3058 | 0x25, 0x3F, |
| 3059 | 0x27, 0xEE, |
| 3060 | 0x2C, 0x27, /* bit at 0x20 is cleared below */ |
| 3061 | 0x30, 0x03, |
| 3062 | 0x2C, 0x07, /* bit at 0x20 is cleared here */ |
| 3063 | 0x2D, 0x87, |
| 3064 | 0x2E, 0xAA, |
| 3065 | 0x28, 0xE1, /* Set the FIFCrst bit here */ |
| 3066 | 0x28, 0xE0, /* Clear the FIFCrst bit here */ |
| 3067 | 0x00 |
| 3068 | }; |
| 3069 | |
| 3070 | /* writing 0x05 0xf0 sw-resets all registers, so we write only needed changes */ |
| 3071 | static const u8 MT2063B1_defaults[] = { |
| 3072 | /* Reg, Value */ |
| 3073 | 0x05, 0xF0, |
| 3074 | 0x11, 0x10, /* New Enable AFCsd */ |
| 3075 | 0x19, 0x05, |
| 3076 | 0x1A, 0x6C, |
| 3077 | 0x1B, 0x24, |
| 3078 | 0x1C, 0x28, |
| 3079 | 0x1D, 0x8F, |
| 3080 | 0x1E, 0x14, |
| 3081 | 0x1F, 0x8F, |
| 3082 | 0x20, 0x57, |
| 3083 | 0x22, 0x21, /* New - ver 1.03 */ |
| 3084 | 0x23, 0x3C, /* New - ver 1.10 */ |
| 3085 | 0x24, 0x20, /* New - ver 1.03 */ |
| 3086 | 0x2C, 0x24, /* bit at 0x20 is cleared below */ |
| 3087 | 0x2D, 0x87, /* FIFFQ=0 */ |
| 3088 | 0x2F, 0xF3, |
| 3089 | 0x30, 0x0C, /* New - ver 1.11 */ |
| 3090 | 0x31, 0x1B, /* New - ver 1.11 */ |
| 3091 | 0x2C, 0x04, /* bit at 0x20 is cleared here */ |
| 3092 | 0x28, 0xE1, /* Set the FIFCrst bit here */ |
| 3093 | 0x28, 0xE0, /* Clear the FIFCrst bit here */ |
| 3094 | 0x00 |
| 3095 | }; |
| 3096 | |
| 3097 | /* writing 0x05 0xf0 sw-resets all registers, so we write only needed changes */ |
| 3098 | static const u8 MT2063B3_defaults[] = { |
| 3099 | /* Reg, Value */ |
| 3100 | 0x05, 0xF0, |
| 3101 | 0x19, 0x3D, |
| 3102 | 0x2C, 0x24, /* bit at 0x20 is cleared below */ |
| 3103 | 0x2C, 0x04, /* bit at 0x20 is cleared here */ |
| 3104 | 0x28, 0xE1, /* Set the FIFCrst bit here */ |
| 3105 | 0x28, 0xE0, /* Clear the FIFCrst bit here */ |
| 3106 | 0x00 |
| 3107 | }; |
| 3108 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3109 | static int mt2063_init(struct dvb_frontend *fe) |
| 3110 | { |
Mauro Carvalho Chehab | 01e0daf | 2011-07-21 03:20:43 -0300 | [diff] [blame] | 3111 | u32 status; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3112 | struct mt2063_state *state = fe->tuner_priv; |
Mauro Carvalho Chehab | 01e0daf | 2011-07-21 03:20:43 -0300 | [diff] [blame] | 3113 | u8 all_resets = 0xF0; /* reset/load bits */ |
| 3114 | const u8 *def = NULL; |
| 3115 | u32 FCRUN; |
| 3116 | s32 maxReads; |
| 3117 | u32 fcu_osc; |
| 3118 | u32 i; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3119 | |
Mauro Carvalho Chehab | 01e0daf | 2011-07-21 03:20:43 -0300 | [diff] [blame] | 3120 | state->rcvr_mode = MT2063_CABLE_QAM; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3121 | |
Mauro Carvalho Chehab | 01e0daf | 2011-07-21 03:20:43 -0300 | [diff] [blame] | 3122 | /* Read the Part/Rev code from the tuner */ |
| 3123 | status = mt2063_read(state, MT2063_REG_PART_REV, state->reg, 1); |
| 3124 | if (status < 0) |
| 3125 | return status; |
| 3126 | |
| 3127 | /* Check the part/rev code */ |
| 3128 | if (((state->reg[MT2063_REG_PART_REV] != MT2063_B0) /* MT2063 B0 */ |
| 3129 | &&(state->reg[MT2063_REG_PART_REV] != MT2063_B1) /* MT2063 B1 */ |
| 3130 | &&(state->reg[MT2063_REG_PART_REV] != MT2063_B3))) /* MT2063 B3 */ |
| 3131 | return -ENODEV; /* Wrong tuner Part/Rev code */ |
| 3132 | |
| 3133 | /* Check the 2nd byte of the Part/Rev code from the tuner */ |
| 3134 | status = mt2063_read(state, MT2063_REG_RSVD_3B, |
| 3135 | &state->reg[MT2063_REG_RSVD_3B], 1); |
| 3136 | |
| 3137 | /* b7 != 0 ==> NOT MT2063 */ |
| 3138 | if (status < 0 ||((state->reg[MT2063_REG_RSVD_3B] & 0x80) != 0x00)) |
| 3139 | return -ENODEV; /* Wrong tuner Part/Rev code */ |
| 3140 | |
| 3141 | /* Reset the tuner */ |
| 3142 | status = mt2063_write(state, MT2063_REG_LO2CQ_3, &all_resets, 1); |
| 3143 | if (status < 0) |
| 3144 | return status; |
| 3145 | |
| 3146 | /* change all of the default values that vary from the HW reset values */ |
| 3147 | /* def = (state->reg[PART_REV] == MT2063_B0) ? MT2063B0_defaults : MT2063B1_defaults; */ |
| 3148 | switch (state->reg[MT2063_REG_PART_REV]) { |
| 3149 | case MT2063_B3: |
| 3150 | def = MT2063B3_defaults; |
| 3151 | break; |
| 3152 | |
| 3153 | case MT2063_B1: |
| 3154 | def = MT2063B1_defaults; |
| 3155 | break; |
| 3156 | |
| 3157 | case MT2063_B0: |
| 3158 | def = MT2063B0_defaults; |
| 3159 | break; |
| 3160 | |
| 3161 | default: |
| 3162 | return -ENODEV; |
| 3163 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3164 | } |
| 3165 | |
Mauro Carvalho Chehab | 01e0daf | 2011-07-21 03:20:43 -0300 | [diff] [blame] | 3166 | while (status >= 0 && *def) { |
| 3167 | u8 reg = *def++; |
| 3168 | u8 val = *def++; |
| 3169 | status = mt2063_write(state, reg, &val, 1); |
| 3170 | } |
| 3171 | if (status < 0) |
| 3172 | return status; |
| 3173 | |
| 3174 | /* Wait for FIFF location to complete. */ |
| 3175 | FCRUN = 1; |
| 3176 | maxReads = 10; |
| 3177 | while (status >= 0 && (FCRUN != 0) && (maxReads-- > 0)) { |
| 3178 | msleep(2); |
| 3179 | status = mt2063_read(state, |
| 3180 | MT2063_REG_XO_STATUS, |
| 3181 | &state-> |
| 3182 | reg[MT2063_REG_XO_STATUS], 1); |
| 3183 | FCRUN = (state->reg[MT2063_REG_XO_STATUS] & 0x40) >> 6; |
| 3184 | } |
| 3185 | |
| 3186 | if (FCRUN != 0 || status < 0) |
| 3187 | return -ENODEV; |
| 3188 | |
| 3189 | status = mt2063_read(state, |
| 3190 | MT2063_REG_FIFFC, |
| 3191 | &state->reg[MT2063_REG_FIFFC], 1); |
| 3192 | if (status < 0) |
| 3193 | return status; |
| 3194 | |
| 3195 | /* Read back all the registers from the tuner */ |
| 3196 | status = mt2063_read(state, |
| 3197 | MT2063_REG_PART_REV, |
| 3198 | state->reg, MT2063_REG_END_REGS); |
| 3199 | if (status < 0) |
| 3200 | return status; |
| 3201 | |
| 3202 | /* Initialize the tuner state. */ |
| 3203 | state->tuner_id = state->reg[MT2063_REG_PART_REV]; |
| 3204 | state->AS_Data.f_ref = MT2063_REF_FREQ; |
| 3205 | state->AS_Data.f_if1_Center = (state->AS_Data.f_ref / 8) * |
| 3206 | ((u32) state->reg[MT2063_REG_FIFFC] + 640); |
| 3207 | state->AS_Data.f_if1_bw = MT2063_IF1_BW; |
| 3208 | state->AS_Data.f_out = 43750000UL; |
| 3209 | state->AS_Data.f_out_bw = 6750000UL; |
| 3210 | state->AS_Data.f_zif_bw = MT2063_ZIF_BW; |
| 3211 | state->AS_Data.f_LO1_Step = state->AS_Data.f_ref / 64; |
| 3212 | state->AS_Data.f_LO2_Step = MT2063_TUNE_STEP_SIZE; |
| 3213 | state->AS_Data.maxH1 = MT2063_MAX_HARMONICS_1; |
| 3214 | state->AS_Data.maxH2 = MT2063_MAX_HARMONICS_2; |
| 3215 | state->AS_Data.f_min_LO_Separation = MT2063_MIN_LO_SEP; |
| 3216 | state->AS_Data.f_if1_Request = state->AS_Data.f_if1_Center; |
| 3217 | state->AS_Data.f_LO1 = 2181000000UL; |
| 3218 | state->AS_Data.f_LO2 = 1486249786UL; |
| 3219 | state->f_IF1_actual = state->AS_Data.f_if1_Center; |
| 3220 | state->AS_Data.f_in = state->AS_Data.f_LO1 - state->f_IF1_actual; |
| 3221 | state->AS_Data.f_LO1_FracN_Avoid = MT2063_LO1_FRACN_AVOID; |
| 3222 | state->AS_Data.f_LO2_FracN_Avoid = MT2063_LO2_FRACN_AVOID; |
| 3223 | state->num_regs = MT2063_REG_END_REGS; |
| 3224 | state->AS_Data.avoidDECT = MT2063_AVOID_BOTH; |
| 3225 | state->ctfilt_sw = 0; |
| 3226 | |
| 3227 | state->CTFiltMax[0] = 69230000; |
| 3228 | state->CTFiltMax[1] = 105770000; |
| 3229 | state->CTFiltMax[2] = 140350000; |
| 3230 | state->CTFiltMax[3] = 177110000; |
| 3231 | state->CTFiltMax[4] = 212860000; |
| 3232 | state->CTFiltMax[5] = 241130000; |
| 3233 | state->CTFiltMax[6] = 274370000; |
| 3234 | state->CTFiltMax[7] = 309820000; |
| 3235 | state->CTFiltMax[8] = 342450000; |
| 3236 | state->CTFiltMax[9] = 378870000; |
| 3237 | state->CTFiltMax[10] = 416210000; |
| 3238 | state->CTFiltMax[11] = 456500000; |
| 3239 | state->CTFiltMax[12] = 495790000; |
| 3240 | state->CTFiltMax[13] = 534530000; |
| 3241 | state->CTFiltMax[14] = 572610000; |
| 3242 | state->CTFiltMax[15] = 598970000; |
| 3243 | state->CTFiltMax[16] = 635910000; |
| 3244 | state->CTFiltMax[17] = 672130000; |
| 3245 | state->CTFiltMax[18] = 714840000; |
| 3246 | state->CTFiltMax[19] = 739660000; |
| 3247 | state->CTFiltMax[20] = 770410000; |
| 3248 | state->CTFiltMax[21] = 814660000; |
| 3249 | state->CTFiltMax[22] = 846950000; |
| 3250 | state->CTFiltMax[23] = 867820000; |
| 3251 | state->CTFiltMax[24] = 915980000; |
| 3252 | state->CTFiltMax[25] = 947450000; |
| 3253 | state->CTFiltMax[26] = 983110000; |
| 3254 | state->CTFiltMax[27] = 1021630000; |
| 3255 | state->CTFiltMax[28] = 1061870000; |
| 3256 | state->CTFiltMax[29] = 1098330000; |
| 3257 | state->CTFiltMax[30] = 1138990000; |
| 3258 | |
| 3259 | /* |
| 3260 | ** Fetch the FCU osc value and use it and the fRef value to |
| 3261 | ** scale all of the Band Max values |
| 3262 | */ |
| 3263 | |
| 3264 | state->reg[MT2063_REG_CTUNE_CTRL] = 0x0A; |
| 3265 | status = mt2063_write(state, MT2063_REG_CTUNE_CTRL, |
| 3266 | &state->reg[MT2063_REG_CTUNE_CTRL], 1); |
| 3267 | if (status < 0) |
| 3268 | return status; |
| 3269 | |
| 3270 | /* Read the ClearTune filter calibration value */ |
| 3271 | status = mt2063_read(state, MT2063_REG_FIFFC, |
| 3272 | &state->reg[MT2063_REG_FIFFC], 1); |
| 3273 | if (status < 0) |
| 3274 | return status; |
| 3275 | |
| 3276 | fcu_osc = state->reg[MT2063_REG_FIFFC]; |
| 3277 | |
| 3278 | state->reg[MT2063_REG_CTUNE_CTRL] = 0x00; |
| 3279 | status = mt2063_write(state, MT2063_REG_CTUNE_CTRL, |
| 3280 | &state->reg[MT2063_REG_CTUNE_CTRL], 1); |
| 3281 | if (status < 0) |
| 3282 | return status; |
| 3283 | |
| 3284 | /* Adjust each of the values in the ClearTune filter cross-over table */ |
| 3285 | for (i = 0; i < 31; i++) |
| 3286 | state->CTFiltMax[i] =(state->CTFiltMax[i] / 768) * (fcu_osc + 640); |
| 3287 | |
| 3288 | status = MT2063_SoftwareShutdown(state, 1); |
| 3289 | if (status < 0) |
| 3290 | return status; |
| 3291 | status = MT2063_ClearPowerMaskBits(state, MT2063_ALL_SD); |
| 3292 | if (status < 0) |
| 3293 | return status; |
| 3294 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3295 | return 0; |
| 3296 | } |
| 3297 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3298 | static int mt2063_get_status(struct dvb_frontend *fe, u32 * status) |
| 3299 | { |
| 3300 | int rc = 0; |
| 3301 | |
| 3302 | //get tuner lock status |
| 3303 | |
| 3304 | return rc; |
| 3305 | } |
| 3306 | |
| 3307 | static int mt2063_get_state(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 3308 | enum tuner_param param, struct tuner_state *tunstate) |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3309 | { |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 3310 | struct mt2063_state *state = fe->tuner_priv; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3311 | |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3312 | switch (param) { |
| 3313 | case DVBFE_TUNER_FREQUENCY: |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3314 | //get frequency |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3315 | break; |
| 3316 | case DVBFE_TUNER_TUNERSTEP: |
| 3317 | break; |
| 3318 | case DVBFE_TUNER_IFFREQ: |
| 3319 | break; |
| 3320 | case DVBFE_TUNER_BANDWIDTH: |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3321 | //get bandwidth |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3322 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3323 | case DVBFE_TUNER_REFCLOCK: |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 3324 | tunstate->refclock = (u32) MT2063_GetLocked(state); |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3325 | break; |
| 3326 | default: |
| 3327 | break; |
| 3328 | } |
| 3329 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 3330 | return (int)tunstate->refclock; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3331 | } |
| 3332 | |
| 3333 | static int mt2063_set_state(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 3334 | enum tuner_param param, struct tuner_state *tunstate) |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3335 | { |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 3336 | struct mt2063_state *state = fe->tuner_priv; |
Mauro Carvalho Chehab | fdf77a4 | 2011-07-20 22:55:25 -0300 | [diff] [blame] | 3337 | u32 status = 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3338 | |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3339 | switch (param) { |
| 3340 | case DVBFE_TUNER_FREQUENCY: |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3341 | //set frequency |
| 3342 | |
| 3343 | status = |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 3344 | MT_Tune_atv(state, |
| 3345 | tunstate->frequency, tunstate->bandwidth, |
| 3346 | state->tv_type); |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3347 | |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 3348 | state->frequency = tunstate->frequency; |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3349 | break; |
| 3350 | case DVBFE_TUNER_TUNERSTEP: |
| 3351 | break; |
| 3352 | case DVBFE_TUNER_IFFREQ: |
| 3353 | break; |
| 3354 | case DVBFE_TUNER_BANDWIDTH: |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3355 | //set bandwidth |
Mauro Carvalho Chehab | 51f0f7b | 2011-07-21 02:24:18 -0300 | [diff] [blame] | 3356 | state->bandwidth = tunstate->bandwidth; |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3357 | break; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3358 | case DVBFE_TUNER_REFCLOCK: |
| 3359 | |
| 3360 | break; |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3361 | default: |
| 3362 | break; |
| 3363 | } |
| 3364 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3365 | return (int)status; |
| 3366 | } |
| 3367 | |
| 3368 | static int mt2063_release(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3369 | { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3370 | struct mt2063_state *state = fe->tuner_priv; |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3371 | |
| 3372 | fe->tuner_priv = NULL; |
| 3373 | kfree(state); |
| 3374 | |
| 3375 | return 0; |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3376 | } |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3377 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3378 | static struct dvb_tuner_ops mt2063_ops = { |
| 3379 | .info = { |
| 3380 | .name = "MT2063 Silicon Tuner", |
| 3381 | .frequency_min = 45000000, |
| 3382 | .frequency_max = 850000000, |
| 3383 | .frequency_step = 0, |
| 3384 | }, |
| 3385 | |
| 3386 | .init = mt2063_init, |
Mauro Carvalho Chehab | bf97555 | 2011-07-20 21:43:30 -0300 | [diff] [blame] | 3387 | .sleep = MT2063_Sleep, |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3388 | .get_status = mt2063_get_status, |
| 3389 | .get_state = mt2063_get_state, |
| 3390 | .set_state = mt2063_set_state, |
| 3391 | .release = mt2063_release |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3392 | }; |
| 3393 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3394 | struct dvb_frontend *mt2063_attach(struct dvb_frontend *fe, |
| 3395 | struct mt2063_config *config, |
| 3396 | struct i2c_adapter *i2c) |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3397 | { |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3398 | struct mt2063_state *state = NULL; |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3399 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3400 | state = kzalloc(sizeof(struct mt2063_state), GFP_KERNEL); |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3401 | if (state == NULL) |
| 3402 | goto error; |
| 3403 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3404 | state->config = config; |
| 3405 | state->i2c = i2c; |
| 3406 | state->frontend = fe; |
| 3407 | state->reference = config->refclock / 1000; /* kHz */ |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3408 | fe->tuner_priv = state; |
| 3409 | fe->ops.tuner_ops = mt2063_ops; |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3410 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3411 | printk("%s: Attaching MT2063 \n", __func__); |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3412 | return fe; |
| 3413 | |
| 3414 | error: |
| 3415 | kfree(state); |
| 3416 | return NULL; |
| 3417 | } |
| 3418 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3419 | EXPORT_SYMBOL(mt2063_attach); |
Mauro Carvalho Chehab | 223c7b0 | 2011-07-20 19:48:59 -0300 | [diff] [blame] | 3420 | MODULE_PARM_DESC(verbose, "Set Verbosity level"); |
| 3421 | |
Mauro Carvalho Chehab | 0e30144 | 2011-07-20 19:52:49 -0300 | [diff] [blame] | 3422 | MODULE_AUTHOR("Henry"); |
| 3423 | MODULE_DESCRIPTION("MT2063 Silicon tuner"); |
| 3424 | MODULE_LICENSE("GPL"); |