|
1 # HG changeset patch |
|
2 # Parent abd3aac6644e1a31020f4cdfdee84bde7ca1e1b4 |
|
3 Import of 090730_RTL2832U_LINUX_Ver1.1.rar into ./linux/drivers/media/dvb/dvb-usb/ |
|
4 |
|
5 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/demod_rtl2832.c |
|
6 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
7 +++ b/linux/drivers/media/dvb/dvb-usb/demod_rtl2832.c Wed Oct 27 09:16:44 2010 +0200 |
|
8 @@ -0,0 +1,2828 @@ |
|
9 +/** |
|
10 + |
|
11 +@file |
|
12 + |
|
13 +@brief RTL2832 demod module definition |
|
14 + |
|
15 +One can manipulate RTL2832 demod through RTL2832 module. |
|
16 +RTL2832 module is derived from DVB-T demod module. |
|
17 + |
|
18 +*/ |
|
19 + |
|
20 + |
|
21 +#include "demod_rtl2832.h" |
|
22 + |
|
23 + |
|
24 + |
|
25 + |
|
26 + |
|
27 +/** |
|
28 + |
|
29 +@brief RTL2832 demod module builder |
|
30 + |
|
31 +Use BuildRtl2832Module() to build RTL2832 module, set all module function pointers with the corresponding |
|
32 +functions, and initialize module private variables. |
|
33 + |
|
34 + |
|
35 +@param [in] ppDemod Pointer to RTL2832 demod module pointer |
|
36 +@param [in] pDvbtDemodModuleMemory Pointer to an allocated DVB-T demod module memory |
|
37 +@param [in] pRtl2832ExtraModuleMemory Pointer to an allocated RTL2832 extra module memory |
|
38 +@param [in] pBaseInterfaceModuleMemory Pointer to an allocated base interface module memory |
|
39 +@param [in] pI2cBridgeModuleMemory Pointer to an allocated I2C bridge module memory |
|
40 +@param [in] DeviceAddr RTL2832 I2C device address |
|
41 +@param [in] CrystalFreqHz RTL2832 crystal frequency in Hz |
|
42 +@param [in] AppMode RTL2832 application mode for setting |
|
43 +@param [in] UpdateFuncRefPeriodMs RTL2832 update function reference period in millisecond for setting |
|
44 +@param [in] IsFunc1Enabled RTL2832 Function 1 enabling status for setting |
|
45 + |
|
46 + |
|
47 +@note |
|
48 + -# One should call BuildRtl2832Module() to build RTL2832 module before using it. |
|
49 + |
|
50 +*/ |
|
51 +void |
|
52 +BuildRtl2832Module( |
|
53 + DVBT_DEMOD_MODULE **ppDemod, |
|
54 + DVBT_DEMOD_MODULE *pDvbtDemodModuleMemory, |
|
55 + RTL2832_EXTRA_MODULE *pRtl2832ExtraModuleMemory, |
|
56 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
57 + I2C_BRIDGE_MODULE *pI2cBridgeModuleMemory, |
|
58 + unsigned char DeviceAddr, |
|
59 + unsigned long CrystalFreqHz, |
|
60 + int AppMode, |
|
61 + unsigned long UpdateFuncRefPeriodMs, |
|
62 + int IsFunc1Enabled |
|
63 + ) |
|
64 +{ |
|
65 + DVBT_DEMOD_MODULE *pDemod; |
|
66 + RTL2832_EXTRA_MODULE *pExtra; |
|
67 + |
|
68 + |
|
69 + |
|
70 + // Set demod module pointer, |
|
71 + *ppDemod = pDvbtDemodModuleMemory; |
|
72 + |
|
73 + // Get demod module. |
|
74 + pDemod = *ppDemod; |
|
75 + |
|
76 + // Set demod extra module pointer, base interface module pointer, and I2C bridge module pointer. |
|
77 + pDemod->pExtra = pRtl2832ExtraModuleMemory; |
|
78 + pDemod->pBaseInterface = pBaseInterfaceModuleMemory; |
|
79 + pDemod->pI2cBridge = pI2cBridgeModuleMemory; |
|
80 + |
|
81 + // Get demod extra module. |
|
82 + pExtra = (RTL2832_EXTRA_MODULE *)pDemod->pExtra; |
|
83 + |
|
84 + |
|
85 + // Set demod type. |
|
86 + pDemod->DemodType = DVBT_DEMOD_TYPE_RTL2832; |
|
87 + |
|
88 + // Set demod I2C device address. |
|
89 + pDemod->DeviceAddr = DeviceAddr; |
|
90 + |
|
91 + // Set demod crystal frequency in Hz. |
|
92 + pDemod->CrystalFreqHz = CrystalFreqHz; |
|
93 + |
|
94 + |
|
95 + // Initialize demod parameter setting status |
|
96 + pDemod->IsBandwidthModeSet = NO; |
|
97 + pDemod->IsIfFreqHzSet = NO; |
|
98 + pDemod->IsSpectrumModeSet = NO; |
|
99 + |
|
100 + |
|
101 + // Initialize demod register table. |
|
102 + rtl2832_InitRegTable(pDemod); |
|
103 + |
|
104 + |
|
105 + // Set I2C bridge demod arguments. |
|
106 + rtl2832_SetI2cBridgeModuleDemodArg(pDemod); |
|
107 + |
|
108 + |
|
109 + // Set demod module I2C function pointers with default functions. |
|
110 + pDemod->SetRegPage = dvbt_demod_default_SetRegPage; |
|
111 + pDemod->SetRegBytes = dvbt_demod_default_SetRegBytes; |
|
112 + pDemod->GetRegBytes = dvbt_demod_default_GetRegBytes; |
|
113 + pDemod->SetRegMaskBits = dvbt_demod_default_SetRegMaskBits; |
|
114 + pDemod->GetRegMaskBits = dvbt_demod_default_GetRegMaskBits; |
|
115 + pDemod->SetRegBits = dvbt_demod_default_SetRegBits; |
|
116 + pDemod->GetRegBits = dvbt_demod_default_GetRegBits; |
|
117 + pDemod->SetRegBitsWithPage = dvbt_demod_default_SetRegBitsWithPage; |
|
118 + pDemod->GetRegBitsWithPage = dvbt_demod_default_GetRegBitsWithPage; |
|
119 + |
|
120 + |
|
121 + // Set demod module manipulating function pointers with default functions. |
|
122 + pDemod->GetDemodType = dvbt_demod_default_GetDemodType; |
|
123 + pDemod->GetDeviceAddr = dvbt_demod_default_GetDeviceAddr; |
|
124 + pDemod->GetCrystalFreqHz = dvbt_demod_default_GetCrystalFreqHz; |
|
125 + |
|
126 + pDemod->GetBandwidthMode = dvbt_demod_default_GetBandwidthMode; |
|
127 + pDemod->GetIfFreqHz = dvbt_demod_default_GetIfFreqHz; |
|
128 + pDemod->GetSpectrumMode = dvbt_demod_default_GetSpectrumMode; |
|
129 + |
|
130 + |
|
131 + // Set demod module manipulating function pointers with particular functions. |
|
132 + pDemod->IsConnectedToI2c = rtl2832_IsConnectedToI2c; |
|
133 + pDemod->SoftwareReset = rtl2832_SoftwareReset; |
|
134 + pDemod->Initialize = rtl2832_Initialize; |
|
135 + pDemod->SetBandwidthMode = rtl2832_SetBandwidthMode; |
|
136 + pDemod->SetIfFreqHz = rtl2832_SetIfFreqHz; |
|
137 + pDemod->SetSpectrumMode = rtl2832_SetSpectrumMode; |
|
138 + |
|
139 + pDemod->IsTpsLocked = rtl2832_IsTpsLocked; |
|
140 + pDemod->IsSignalLocked = rtl2832_IsSignalLocked; |
|
141 + |
|
142 + pDemod->GetSignalStrength = rtl2832_GetSignalStrength; |
|
143 + pDemod->GetSignalQuality = rtl2832_GetSignalQuality; |
|
144 + |
|
145 + pDemod->GetBer = rtl2832_GetBer; |
|
146 + pDemod->GetSnrDb = rtl2832_GetSnrDb; |
|
147 + |
|
148 + pDemod->GetRfAgc = rtl2832_GetRfAgc; |
|
149 + pDemod->GetIfAgc = rtl2832_GetIfAgc; |
|
150 + pDemod->GetDiAgc = rtl2832_GetDiAgc; |
|
151 + |
|
152 + pDemod->GetTrOffsetPpm = rtl2832_GetTrOffsetPpm; |
|
153 + pDemod->GetCrOffsetHz = rtl2832_GetCrOffsetHz; |
|
154 + |
|
155 + pDemod->GetConstellation = rtl2832_GetConstellation; |
|
156 + pDemod->GetHierarchy = rtl2832_GetHierarchy; |
|
157 + pDemod->GetCodeRateLp = rtl2832_GetCodeRateLp; |
|
158 + pDemod->GetCodeRateHp = rtl2832_GetCodeRateHp; |
|
159 + pDemod->GetGuardInterval = rtl2832_GetGuardInterval; |
|
160 + pDemod->GetFftMode = rtl2832_GetFftMode; |
|
161 + |
|
162 + pDemod->UpdateFunction = rtl2832_UpdateFunction; |
|
163 + pDemod->ResetFunction = rtl2832_ResetFunction; |
|
164 + |
|
165 + |
|
166 + // Initialize demod extra module variables. |
|
167 + pExtra->AppMode = AppMode; |
|
168 + |
|
169 + |
|
170 + // Initialize demod Function 1 variables. |
|
171 + pExtra->Func1State = RTL2832_FUNC1_STATE_NORMAL; |
|
172 + |
|
173 + pExtra->IsFunc1Enabled = IsFunc1Enabled; |
|
174 + |
|
175 + pExtra->Func1WaitTimeMax = DivideWithCeiling(RTL2832_FUNC1_WAIT_TIME_MS, UpdateFuncRefPeriodMs); |
|
176 + pExtra->Func1GettingTimeMax = DivideWithCeiling(RTL2832_FUNC1_GETTING_TIME_MS, UpdateFuncRefPeriodMs); |
|
177 + pExtra->Func1GettingNumEachTime = DivideWithCeiling(RTL2832_FUNC1_GETTING_NUM_MIN, pExtra->Func1GettingTimeMax + 1); |
|
178 + |
|
179 + pExtra->Func1QamBak = 0xff; |
|
180 + pExtra->Func1HierBak = 0xff; |
|
181 + pExtra->Func1LpCrBak = 0xff; |
|
182 + pExtra->Func1HpCrBak = 0xff; |
|
183 + pExtra->Func1GiBak = 0xff; |
|
184 + pExtra->Func1FftBak = 0xff; |
|
185 + |
|
186 + |
|
187 + // Set demod extra module function pointers. |
|
188 + pExtra->GetAppMode = rtl2832_GetAppMode; |
|
189 + |
|
190 + |
|
191 + return; |
|
192 +} |
|
193 + |
|
194 + |
|
195 + |
|
196 + |
|
197 + |
|
198 +/** |
|
199 + |
|
200 +@see DVBT_DEMOD_FP_IS_CONNECTED_TO_I2C |
|
201 + |
|
202 +*/ |
|
203 +void |
|
204 +rtl2832_IsConnectedToI2c( |
|
205 + DVBT_DEMOD_MODULE *pDemod, |
|
206 + int *pAnswer |
|
207 + ) |
|
208 +{ |
|
209 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
210 + |
|
211 + unsigned char Nothing; |
|
212 + |
|
213 + |
|
214 + |
|
215 + // Get base interface. |
|
216 + pBaseInterface = pDemod->pBaseInterface; |
|
217 + |
|
218 + |
|
219 + // Send read command. |
|
220 + // Note: The number of reading bytes must be greater than 0. |
|
221 + if(pBaseInterface->I2cRead(pBaseInterface, pDemod->DeviceAddr, &Nothing, LEN_1_BYTE) == FUNCTION_ERROR) |
|
222 + goto error_status_i2c_read; |
|
223 + |
|
224 + |
|
225 + // Set I2cConnectionStatus with YES. |
|
226 + *pAnswer = YES; |
|
227 + |
|
228 + |
|
229 + return; |
|
230 + |
|
231 + |
|
232 +error_status_i2c_read: |
|
233 + |
|
234 + // Set I2cConnectionStatus with NO. |
|
235 + *pAnswer = NO; |
|
236 + |
|
237 + |
|
238 + return; |
|
239 +} |
|
240 + |
|
241 + |
|
242 + |
|
243 + |
|
244 + |
|
245 +/** |
|
246 + |
|
247 +@see DVBT_DEMOD_FP_SOFTWARE_RESET |
|
248 + |
|
249 +*/ |
|
250 +int |
|
251 +rtl2832_SoftwareReset( |
|
252 + DVBT_DEMOD_MODULE *pDemod |
|
253 + ) |
|
254 +{ |
|
255 + // Set SOFT_RST with 1. Then, set SOFT_RST with 0. |
|
256 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SOFT_RST, 0x1) != FUNCTION_SUCCESS) |
|
257 + goto error_status_set_registers; |
|
258 + |
|
259 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SOFT_RST, 0x0) != FUNCTION_SUCCESS) |
|
260 + goto error_status_set_registers; |
|
261 + |
|
262 + |
|
263 + return FUNCTION_SUCCESS; |
|
264 + |
|
265 + |
|
266 +error_status_set_registers: |
|
267 + return FUNCTION_ERROR; |
|
268 +} |
|
269 + |
|
270 + |
|
271 + |
|
272 + |
|
273 + |
|
274 +/** |
|
275 + |
|
276 +@see DVBT_DEMOD_FP_INITIALIZE |
|
277 + |
|
278 +*/ |
|
279 +int |
|
280 +rtl2832_Initialize( |
|
281 + DVBT_DEMOD_MODULE *pDemod |
|
282 + ) |
|
283 +{ |
|
284 + // Initializing table entry only used in Initialize() |
|
285 + typedef struct |
|
286 + { |
|
287 + int RegBitName; |
|
288 + unsigned long WritingValue; |
|
289 + } |
|
290 + INIT_TABLE_ENTRY; |
|
291 + |
|
292 + // Initializing table entry with mode only used in Initialize() |
|
293 + typedef struct |
|
294 + { |
|
295 + int RegBitName; |
|
296 + unsigned long WritingValue[RTL2832_APPLICATION_MODE_NUM]; |
|
297 + } |
|
298 + INIT_TABLE_ENTRY_WITH_MODE; |
|
299 + |
|
300 + |
|
301 + |
|
302 + static const INIT_TABLE_ENTRY InitTable[RTL2832_INIT_TABLE_LEN] = |
|
303 + { |
|
304 + // RegBitName, WritingValue |
|
305 + {DVBT_AD_EN_REG, 0x1 }, |
|
306 + {DVBT_AD_EN_REG1, 0x1 }, |
|
307 + {DVBT_RSD_BER_FAIL_VAL, 0x2800 }, |
|
308 + {DVBT_MGD_THD0, 0x10 }, |
|
309 + {DVBT_MGD_THD1, 0x20 }, |
|
310 + {DVBT_MGD_THD2, 0x20 }, |
|
311 + {DVBT_MGD_THD3, 0x40 }, |
|
312 + {DVBT_MGD_THD4, 0x22 }, |
|
313 + {DVBT_MGD_THD5, 0x32 }, |
|
314 + {DVBT_MGD_THD6, 0x37 }, |
|
315 + {DVBT_MGD_THD7, 0x39 }, |
|
316 + {DVBT_EN_BK_TRK, 0x0 }, |
|
317 + {DVBT_EN_CACQ_NOTCH, 0x0 }, |
|
318 + {DVBT_AD_AV_REF, 0x2a }, |
|
319 + {DVBT_REG_PI, 0x3 }, |
|
320 + {DVBT_PIP_ON, 0x0 }, |
|
321 + {DVBT_CDIV_PH0, 0x8 }, |
|
322 + {DVBT_CDIV_PH1, 0x8 }, |
|
323 + {DVBT_SCALE1_B92, 0x4 }, |
|
324 + {DVBT_SCALE1_B93, 0xb0 }, |
|
325 + {DVBT_SCALE1_BA7, 0x78 }, |
|
326 + {DVBT_SCALE1_BA9, 0x28 }, |
|
327 + {DVBT_SCALE1_BAA, 0x59 }, |
|
328 + {DVBT_SCALE1_BAB, 0x83 }, |
|
329 + {DVBT_SCALE1_BAC, 0xd4 }, |
|
330 + {DVBT_SCALE1_BB0, 0x65 }, |
|
331 + {DVBT_SCALE1_BB1, 0x43 }, |
|
332 + {DVBT_KB_P1, 0x1 }, |
|
333 + {DVBT_KB_P2, 0x4 }, |
|
334 + {DVBT_KB_P3, 0x7 }, |
|
335 + {DVBT_K1_CR_STEP12, 0xa }, |
|
336 + }; |
|
337 + |
|
338 + static const INIT_TABLE_ENTRY_WITH_MODE InitTableWithAppMode[RTL2832_INIT_TABLE_LEN_WITH_APP_MODE] = |
|
339 + { |
|
340 + // RegBitName, WritingValue for {Dongle, STB} |
|
341 + {DVBT_TRK_KS_P2, {0x4, 0x4}}, |
|
342 + {DVBT_TRK_KS_I2, {0x7, 0x7}}, |
|
343 + {DVBT_TR_THD_SET2, {0x6, 0x6}}, |
|
344 + {DVBT_TRK_KC_I2, {0x5, 0x6}}, |
|
345 + {DVBT_CR_THD_SET2, {0x1, 0x1}}, |
|
346 + }; |
|
347 + |
|
348 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
349 + RTL2832_EXTRA_MODULE *pExtra; |
|
350 + |
|
351 + int i; |
|
352 + |
|
353 + int AppMode; |
|
354 + |
|
355 + |
|
356 + |
|
357 + // Get base interface and demod extra module. |
|
358 + pBaseInterface = pDemod->pBaseInterface; |
|
359 + pExtra = (RTL2832_EXTRA_MODULE *)pDemod->pExtra; |
|
360 + |
|
361 + // Get application mode. |
|
362 + pExtra->GetAppMode(pDemod, &AppMode); |
|
363 + |
|
364 + |
|
365 + // Initialize demod registers according to the initializing table. |
|
366 + for(i = 0; i < RTL2832_INIT_TABLE_LEN; i++) |
|
367 + { |
|
368 + if(pDemod->SetRegBitsWithPage(pDemod, InitTable[i].RegBitName, InitTable[i].WritingValue) |
|
369 + != FUNCTION_SUCCESS) |
|
370 + goto error_status_set_registers; |
|
371 + } |
|
372 + |
|
373 + |
|
374 + // Initialize demod registers according to the initializing table with application mode. |
|
375 + for(i = 0; i < RTL2832_INIT_TABLE_LEN_WITH_APP_MODE; i++) |
|
376 + { |
|
377 + if(pDemod->SetRegBitsWithPage(pDemod, InitTableWithAppMode[i].RegBitName, |
|
378 + InitTableWithAppMode[i].WritingValue[AppMode]) != FUNCTION_SUCCESS) |
|
379 + goto error_status_set_registers; |
|
380 + } |
|
381 + |
|
382 + |
|
383 + return FUNCTION_SUCCESS; |
|
384 + |
|
385 + |
|
386 +error_status_set_registers: |
|
387 + return FUNCTION_ERROR; |
|
388 +} |
|
389 + |
|
390 + |
|
391 + |
|
392 + |
|
393 + |
|
394 +/** |
|
395 + |
|
396 +@see DVBT_DEMOD_FP_SET_BANDWIDTH_MODE |
|
397 + |
|
398 +*/ |
|
399 +int |
|
400 +rtl2832_SetBandwidthMode( |
|
401 + DVBT_DEMOD_MODULE *pDemod, |
|
402 + int BandwidthMode |
|
403 + ) |
|
404 +{ |
|
405 + static const unsigned char HlpfxTable[DVBT_BANDWIDTH_MODE_NUM][RTL2832_H_LPF_X_LEN] = |
|
406 + { |
|
407 + // H_LPF_X writing value for 6 MHz bandwidth |
|
408 + { |
|
409 + 0xf5, 0xff, 0x15, 0x38, 0x5d, 0x6d, 0x52, 0x07, 0xfa, 0x2f, |
|
410 + 0x53, 0xf5, 0x3f, 0xca, 0x0b, 0x91, 0xea, 0x30, 0x63, 0xb2, |
|
411 + 0x13, 0xda, 0x0b, 0xc4, 0x18, 0x7e, 0x16, 0x66, 0x08, 0x67, |
|
412 + 0x19, 0xe0, |
|
413 + }, |
|
414 + |
|
415 + // H_LPF_X writing value for 7 MHz bandwidth |
|
416 + { |
|
417 + 0xe7, 0xcc, 0xb5, 0xba, 0xe8, 0x2f, 0x67, 0x61, 0x00, 0xaf, |
|
418 + 0x86, 0xf2, 0xbf, 0x59, 0x04, 0x11, 0xb6, 0x33, 0xa4, 0x30, |
|
419 + 0x15, 0x10, 0x0a, 0x42, 0x18, 0xf8, 0x17, 0xd9, 0x07, 0x22, |
|
420 + 0x19, 0x10, |
|
421 + }, |
|
422 + |
|
423 + // H_LPF_X writing value for 8 MHz bandwidth |
|
424 + { |
|
425 + 0x09, 0xf6, 0xd2, 0xa7, 0x9a, 0xc9, 0x27, 0x77, 0x06, 0xbf, |
|
426 + 0xec, 0xf4, 0x4f, 0x0b, 0xfc, 0x01, 0x63, 0x35, 0x54, 0xa7, |
|
427 + 0x16, 0x66, 0x08, 0xb4, 0x19, 0x6e, 0x19, 0x65, 0x05, 0xc8, |
|
428 + 0x19, 0xe0, |
|
429 + }, |
|
430 + }; |
|
431 + |
|
432 + |
|
433 + unsigned long CrystalFreqHz; |
|
434 + |
|
435 + long ConstWithBandwidthMode; |
|
436 + |
|
437 + MPI MpiCrystalFreqHz; |
|
438 + MPI MpiConst, MpiVar0, MpiVar1, MpiNone; |
|
439 + |
|
440 + unsigned long RsampRatio; |
|
441 + |
|
442 + long CfreqOffRatioInt; |
|
443 + unsigned long CfreqOffRatioBinary; |
|
444 + |
|
445 + |
|
446 + |
|
447 + // Get demod crystal frequency in Hz. |
|
448 + pDemod->GetCrystalFreqHz(pDemod, &CrystalFreqHz); |
|
449 + |
|
450 + |
|
451 + // Set H_LPF_X registers with HlpfxTable according to BandwidthMode. |
|
452 + if(pDemod->SetRegPage(pDemod, RTL2832_H_LPF_X_PAGE) != FUNCTION_SUCCESS) |
|
453 + goto error_status_set_registers; |
|
454 + |
|
455 + if(pDemod->SetRegBytes(pDemod, RTL2832_H_LPF_X_ADDR, HlpfxTable[BandwidthMode], RTL2832_H_LPF_X_LEN) != |
|
456 + FUNCTION_SUCCESS) |
|
457 + goto error_status_set_registers; |
|
458 + |
|
459 + |
|
460 + // Determine constant value with bandwidth mode. |
|
461 + switch(BandwidthMode) |
|
462 + { |
|
463 + default: |
|
464 + case DVBT_BANDWIDTH_6MHZ: ConstWithBandwidthMode = 48000000; break; |
|
465 + case DVBT_BANDWIDTH_7MHZ: ConstWithBandwidthMode = 56000000; break; |
|
466 + case DVBT_BANDWIDTH_8MHZ: ConstWithBandwidthMode = 64000000; break; |
|
467 + } |
|
468 + |
|
469 + |
|
470 + // Calculate RSAMP_RATIO value. |
|
471 + // Note: RSAMP_RATIO = floor(CrystalFreqHz * 7 * pow(2, 22) / ConstWithBandwidthMode) |
|
472 + MpiSetValue(&MpiCrystalFreqHz, CrystalFreqHz); |
|
473 + MpiSetValue(&MpiVar1, ConstWithBandwidthMode); |
|
474 + MpiSetValue(&MpiConst, 7); |
|
475 + |
|
476 + MpiMul(&MpiVar0, MpiCrystalFreqHz, MpiConst); |
|
477 + MpiLeftShift(&MpiVar0, MpiVar0, 22); |
|
478 + MpiDiv(&MpiVar0, &MpiNone, MpiVar0, MpiVar1); |
|
479 + |
|
480 + MpiGetValue(MpiVar0, (long *)&RsampRatio); |
|
481 + |
|
482 + |
|
483 + // Set RSAMP_RATIO with calculated value. |
|
484 + // Note: Use SetRegBitsWithPage() to set register bits with page setting. |
|
485 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_RSAMP_RATIO, RsampRatio) != FUNCTION_SUCCESS) |
|
486 + goto error_status_set_registers; |
|
487 + |
|
488 + |
|
489 + // Calculate CFREQ_OFF_RATIO value. |
|
490 + // Note: CFREQ_OFF_RATIO = - floor(ConstWithBandwidthMode * pow(2, 20) / (CrystalFreqHz * 7)) |
|
491 + MpiSetValue(&MpiCrystalFreqHz, CrystalFreqHz); |
|
492 + MpiSetValue(&MpiVar0, ConstWithBandwidthMode); |
|
493 + MpiSetValue(&MpiConst, 7); |
|
494 + |
|
495 + MpiLeftShift(&MpiVar0, MpiVar0, 20); |
|
496 + MpiMul(&MpiVar1, MpiCrystalFreqHz, MpiConst); |
|
497 + MpiDiv(&MpiVar0, &MpiNone, MpiVar0, MpiVar1); |
|
498 + |
|
499 + MpiGetValue(MpiVar0, &CfreqOffRatioInt); |
|
500 + CfreqOffRatioInt = - CfreqOffRatioInt; |
|
501 + |
|
502 + CfreqOffRatioBinary = SignedIntToBin(CfreqOffRatioInt, RTL2832_CFREQ_OFF_RATIO_BIT_NUM); |
|
503 + |
|
504 + |
|
505 + // Set CFREQ_OFF_RATIO with calculated value. |
|
506 + // Note: Use SetRegBitsWithPage() to set register bits with page setting. |
|
507 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CFREQ_OFF_RATIO, CfreqOffRatioBinary) != FUNCTION_SUCCESS) |
|
508 + goto error_status_set_registers; |
|
509 + |
|
510 + |
|
511 + |
|
512 + // Set demod bandwidth mode parameter. |
|
513 + pDemod->BandwidthMode = BandwidthMode; |
|
514 + pDemod->IsBandwidthModeSet = YES; |
|
515 + |
|
516 + |
|
517 + return FUNCTION_SUCCESS; |
|
518 + |
|
519 + |
|
520 +error_status_set_registers: |
|
521 + return FUNCTION_ERROR; |
|
522 +} |
|
523 + |
|
524 + |
|
525 + |
|
526 + |
|
527 + |
|
528 +/** |
|
529 + |
|
530 +@see DVBT_DEMOD_FP_SET_IF_FREQ_HZ |
|
531 + |
|
532 +*/ |
|
533 +int |
|
534 +rtl2832_SetIfFreqHz( |
|
535 + DVBT_DEMOD_MODULE *pDemod, |
|
536 + unsigned long IfFreqHz |
|
537 + ) |
|
538 +{ |
|
539 + unsigned long CrystalFreqHz; |
|
540 + |
|
541 + unsigned long EnBbin; |
|
542 + |
|
543 + MPI MpiCrystalFreqHz, MpiVar, MpiNone; |
|
544 + |
|
545 + long PsetIffreqInt; |
|
546 + unsigned long PsetIffreqBinary; |
|
547 + |
|
548 + |
|
549 + |
|
550 + // Get demod crystal frequency in Hz. |
|
551 + pDemod->GetCrystalFreqHz(pDemod, &CrystalFreqHz); |
|
552 + |
|
553 + |
|
554 + // Determine and set EN_BBIN value. |
|
555 + EnBbin = (IfFreqHz == IF_FREQ_0HZ) ? 0x1 : 0x0; |
|
556 + |
|
557 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_EN_BBIN, EnBbin) != FUNCTION_SUCCESS) |
|
558 + goto error_status_set_registers; |
|
559 + |
|
560 + |
|
561 + // Calculate PSET_IFFREQ value. |
|
562 + // Note: PSET_IFFREQ = - floor((IfFreqHz % CrystalFreqHz) * pow(2, 22) / CrystalFreqHz) |
|
563 + MpiSetValue(&MpiCrystalFreqHz, CrystalFreqHz); |
|
564 + |
|
565 + MpiSetValue(&MpiVar, (IfFreqHz % CrystalFreqHz)); |
|
566 + MpiLeftShift(&MpiVar, MpiVar, RTL2832_PSET_IFFREQ_BIT_NUM); |
|
567 + MpiDiv(&MpiVar, &MpiNone, MpiVar, MpiCrystalFreqHz); |
|
568 + |
|
569 + MpiGetValue(MpiVar, &PsetIffreqInt); |
|
570 + PsetIffreqInt = - PsetIffreqInt; |
|
571 + |
|
572 + PsetIffreqBinary = SignedIntToBin(PsetIffreqInt, RTL2832_PSET_IFFREQ_BIT_NUM); |
|
573 + |
|
574 + |
|
575 + // Set PSET_IFFREQ with calculated value. |
|
576 + // Note: Use SetRegBitsWithPage() to set register bits with page setting. |
|
577 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_PSET_IFFREQ, PsetIffreqBinary) != FUNCTION_SUCCESS) |
|
578 + goto error_status_set_registers; |
|
579 + |
|
580 + |
|
581 + // Set demod IF frequnecy parameter. |
|
582 + pDemod->IfFreqHz = IfFreqHz; |
|
583 + pDemod->IsIfFreqHzSet = YES; |
|
584 + |
|
585 + |
|
586 + return FUNCTION_SUCCESS; |
|
587 + |
|
588 + |
|
589 +error_status_set_registers: |
|
590 + return FUNCTION_ERROR; |
|
591 +} |
|
592 + |
|
593 + |
|
594 + |
|
595 + |
|
596 + |
|
597 +/** |
|
598 + |
|
599 +@see DVBT_DEMOD_FP_SET_SPECTRUM_MODE |
|
600 + |
|
601 +*/ |
|
602 +int |
|
603 +rtl2832_SetSpectrumMode( |
|
604 + DVBT_DEMOD_MODULE *pDemod, |
|
605 + int SpectrumMode |
|
606 + ) |
|
607 +{ |
|
608 + unsigned long SpecInv; |
|
609 + |
|
610 + |
|
611 + |
|
612 + // Determine SpecInv according to spectrum mode. |
|
613 + switch(SpectrumMode) |
|
614 + { |
|
615 + default: |
|
616 + case SPECTRUM_NORMAL: SpecInv = 0; break; |
|
617 + case SPECTRUM_INVERSE: SpecInv = 1; break; |
|
618 + } |
|
619 + |
|
620 + |
|
621 + // Set SPEC_INV with SpecInv. |
|
622 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SPEC_INV, SpecInv) != FUNCTION_SUCCESS) |
|
623 + goto error_status_set_registers; |
|
624 + |
|
625 + |
|
626 + // Set demod spectrum mode parameter. |
|
627 + pDemod->SpectrumMode = SpectrumMode; |
|
628 + pDemod->IsSpectrumModeSet = YES; |
|
629 + |
|
630 + |
|
631 + return FUNCTION_SUCCESS; |
|
632 + |
|
633 + |
|
634 +error_status_set_registers: |
|
635 + return FUNCTION_ERROR; |
|
636 +} |
|
637 + |
|
638 + |
|
639 + |
|
640 + |
|
641 + |
|
642 +/** |
|
643 + |
|
644 +@see DVBT_DEMOD_FP_IS_TPS_LOCKED |
|
645 + |
|
646 +*/ |
|
647 +int |
|
648 +rtl2832_IsTpsLocked( |
|
649 + DVBT_DEMOD_MODULE *pDemod, |
|
650 + int *pAnswer |
|
651 + ) |
|
652 +{ |
|
653 + unsigned long FsmStage; |
|
654 + |
|
655 + |
|
656 + |
|
657 + // Get FSM stage from FSM_STAGE. |
|
658 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_FSM_STAGE, &FsmStage) != FUNCTION_SUCCESS) |
|
659 + goto error_status_get_registers; |
|
660 + |
|
661 + |
|
662 + // Determine answer according to FSM stage. |
|
663 + if(FsmStage > 9) |
|
664 + *pAnswer = YES; |
|
665 + else |
|
666 + *pAnswer = NO; |
|
667 + |
|
668 + |
|
669 + return FUNCTION_SUCCESS; |
|
670 + |
|
671 + |
|
672 +error_status_get_registers: |
|
673 + return FUNCTION_ERROR; |
|
674 +} |
|
675 + |
|
676 + |
|
677 + |
|
678 + |
|
679 + |
|
680 +/** |
|
681 + |
|
682 +@see DVBT_DEMOD_FP_IS_SIGNAL_LOCKED |
|
683 + |
|
684 +*/ |
|
685 +int |
|
686 +rtl2832_IsSignalLocked( |
|
687 + DVBT_DEMOD_MODULE *pDemod, |
|
688 + int *pAnswer |
|
689 + ) |
|
690 +{ |
|
691 + unsigned long FsmStage; |
|
692 + |
|
693 + |
|
694 + |
|
695 + // Get FSM stage from FSM_STAGE. |
|
696 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_FSM_STAGE, &FsmStage) != FUNCTION_SUCCESS) |
|
697 + goto error_status_get_registers; |
|
698 + |
|
699 + |
|
700 + // Determine answer according to FSM stage. |
|
701 + if(FsmStage == 11) |
|
702 + *pAnswer = YES; |
|
703 + else |
|
704 + *pAnswer = NO; |
|
705 + |
|
706 + |
|
707 + return FUNCTION_SUCCESS; |
|
708 + |
|
709 + |
|
710 +error_status_get_registers: |
|
711 + return FUNCTION_ERROR; |
|
712 +} |
|
713 + |
|
714 + |
|
715 + |
|
716 + |
|
717 + |
|
718 +/** |
|
719 + |
|
720 +@see DVBT_DEMOD_FP_GET_SIGNAL_STRENGTH |
|
721 + |
|
722 +*/ |
|
723 +int |
|
724 +rtl2832_GetSignalStrength( |
|
725 + DVBT_DEMOD_MODULE *pDemod, |
|
726 + unsigned long *pSignalStrength |
|
727 + ) |
|
728 +{ |
|
729 + unsigned long FsmStage; |
|
730 + int IfAgc; |
|
731 + |
|
732 + |
|
733 + |
|
734 + // Get FSM stage and IF AGC value. |
|
735 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_FSM_STAGE, &FsmStage) != FUNCTION_SUCCESS) |
|
736 + goto error_status_get_registers; |
|
737 + |
|
738 + if(pDemod->GetIfAgc(pDemod, &IfAgc) != FUNCTION_SUCCESS) |
|
739 + goto error_status_get_registers; |
|
740 + |
|
741 + |
|
742 + // Determine signal strength according to FSM stage and IF AGC value. |
|
743 + if(FsmStage < 10) |
|
744 + *pSignalStrength = 0; |
|
745 + else |
|
746 + *pSignalStrength = 55 - IfAgc / 182; |
|
747 + |
|
748 + |
|
749 + return FUNCTION_SUCCESS; |
|
750 + |
|
751 + |
|
752 +error_status_get_registers: |
|
753 + return FUNCTION_ERROR; |
|
754 +} |
|
755 + |
|
756 + |
|
757 + |
|
758 + |
|
759 + |
|
760 +/** |
|
761 + |
|
762 +@see DVBT_DEMOD_FP_GET_SIGNAL_QUALITY |
|
763 + |
|
764 +*/ |
|
765 +int |
|
766 +rtl2832_GetSignalQuality( |
|
767 + DVBT_DEMOD_MODULE *pDemod, |
|
768 + unsigned long *pSignalQuality |
|
769 + ) |
|
770 +{ |
|
771 + unsigned long FsmStage, RsdBerEst; |
|
772 + |
|
773 + MPI MpiVar; |
|
774 + long Var; |
|
775 + |
|
776 + |
|
777 + |
|
778 + // Get FSM_STAGE and RSD_BER_EST. |
|
779 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_FSM_STAGE, &FsmStage) != FUNCTION_SUCCESS) |
|
780 + goto error_status_get_registers; |
|
781 + |
|
782 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RSD_BER_EST, &RsdBerEst) != FUNCTION_SUCCESS) |
|
783 + goto error_status_get_registers; |
|
784 + |
|
785 + |
|
786 + // If demod is not signal-locked, set signal quality with zero. |
|
787 + if(FsmStage < 10) |
|
788 + { |
|
789 + *pSignalQuality = 0; |
|
790 + goto success_status_non_signal_lock; |
|
791 + } |
|
792 + |
|
793 + // Determine signal quality according to RSD_BER_EST. |
|
794 + // Note: Map RSD_BER_EST value 8192 ~ 128 to 10 ~ 100 |
|
795 + // Original formula: SignalQuality = 205 - 15 * log2(RSD_BER_EST) |
|
796 + // Adjusted formula: SignalQuality = ((205 << 5) - 15 * (log2(RSD_BER_EST) << 5)) >> 5 |
|
797 + // If RSD_BER_EST > 8192, signal quality is 10. |
|
798 + // If RSD_BER_EST < 128, signal quality is 100. |
|
799 + if(RsdBerEst > 8192) |
|
800 + { |
|
801 + *pSignalQuality = 10; |
|
802 + } |
|
803 + else if(RsdBerEst < 128) |
|
804 + { |
|
805 + *pSignalQuality = 100; |
|
806 + } |
|
807 + else |
|
808 + { |
|
809 + MpiSetValue(&MpiVar, RsdBerEst); |
|
810 + MpiLog2(&MpiVar, MpiVar, RTL2832_SQ_FRAC_BIT_NUM); |
|
811 + MpiGetValue(MpiVar, &Var); |
|
812 + |
|
813 + *pSignalQuality = ((205 << RTL2832_SQ_FRAC_BIT_NUM) - 15 * Var) >> RTL2832_SQ_FRAC_BIT_NUM; |
|
814 + } |
|
815 + |
|
816 + |
|
817 +success_status_non_signal_lock: |
|
818 + return FUNCTION_SUCCESS; |
|
819 + |
|
820 + |
|
821 +error_status_get_registers: |
|
822 + return FUNCTION_ERROR; |
|
823 +} |
|
824 + |
|
825 + |
|
826 + |
|
827 + |
|
828 + |
|
829 +/** |
|
830 + |
|
831 +@see DVBT_DEMOD_FP_GET_BER |
|
832 + |
|
833 +*/ |
|
834 +int |
|
835 +rtl2832_GetBer( |
|
836 + DVBT_DEMOD_MODULE *pDemod, |
|
837 + unsigned long *pBerNum, |
|
838 + unsigned long *pBerDen |
|
839 + ) |
|
840 +{ |
|
841 + unsigned long RsdBerEst; |
|
842 + |
|
843 + |
|
844 + |
|
845 + // Get RSD_BER_EST. |
|
846 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RSD_BER_EST, &RsdBerEst) != FUNCTION_SUCCESS) |
|
847 + goto error_status_get_registers; |
|
848 + |
|
849 + |
|
850 + // Set BER numerator according to RSD_BER_EST. |
|
851 + *pBerNum = RsdBerEst; |
|
852 + |
|
853 + // Set BER denominator. |
|
854 + *pBerDen = RTL2832_BER_DEN_VALUE; |
|
855 + |
|
856 + |
|
857 + return FUNCTION_SUCCESS; |
|
858 + |
|
859 + |
|
860 +error_status_get_registers: |
|
861 + return FUNCTION_ERROR; |
|
862 +} |
|
863 + |
|
864 + |
|
865 + |
|
866 + |
|
867 + |
|
868 +/** |
|
869 + |
|
870 +@see DVBT_DEMOD_FP_GET_SNR_DB |
|
871 + |
|
872 +*/ |
|
873 +int |
|
874 +rtl2832_GetSnrDb( |
|
875 + DVBT_DEMOD_MODULE *pDemod, |
|
876 + long *pSnrDbNum, |
|
877 + long *pSnrDbDen |
|
878 + ) |
|
879 +{ |
|
880 + unsigned long FsmStage; |
|
881 + unsigned long CeEstEvm; |
|
882 + int Constellation, Hierarchy; |
|
883 + |
|
884 + static const long SnrDbNumConst[DVBT_CONSTELLATION_NUM][DVBT_HIERARCHY_NUM] = |
|
885 + { |
|
886 + {122880, 122880, 122880, 122880, }, |
|
887 + {146657, 146657, 156897, 171013, }, |
|
888 + {167857, 167857, 173127, 181810, }, |
|
889 + }; |
|
890 + |
|
891 + long Var; |
|
892 + MPI MpiCeEstEvm, MpiVar; |
|
893 + |
|
894 + |
|
895 + |
|
896 + // Get FSM stage, CE_EST_EVM, constellation, and hierarchy. |
|
897 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_FSM_STAGE, &FsmStage) != FUNCTION_SUCCESS) |
|
898 + goto error_status_get_registers; |
|
899 + |
|
900 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_CE_EST_EVM, &CeEstEvm) != FUNCTION_SUCCESS) |
|
901 + goto error_status_get_registers; |
|
902 + |
|
903 + if(pDemod->GetConstellation(pDemod, &Constellation) != FUNCTION_SUCCESS) |
|
904 + goto error_status_get_registers; |
|
905 + |
|
906 + if(pDemod->GetHierarchy(pDemod, &Hierarchy) != FUNCTION_SUCCESS) |
|
907 + goto error_status_get_registers; |
|
908 + |
|
909 + |
|
910 + |
|
911 + // SNR dB formula |
|
912 + // Original formula: SNR_dB = 10 * log10(Norm * pow(2, 11) / CeEstEvm) |
|
913 + // Adjusted formula: SNR_dB = (SNR_DB_NUM_CONST - 10 * log2(CeEstEvm) * pow(2, SNR_FRAC_BIT_NUM)) / SNR_DB_DEN |
|
914 + // SNR_DB_NUM_CONST = 10 * log2(Norm * pow(2, 11)) * pow(2, SNR_FRAC_BIT_NUM) |
|
915 + // SNR_DB_DEN = log2(10) * pow(2, SNR_FRAC_BIT_NUM) |
|
916 + // Norm: |
|
917 + // None Alpha=1 Alpha=2 Alpha=4 |
|
918 + // 4-QAM 2 2 2 2 |
|
919 + // 16-QAM 10 10 20 52 |
|
920 + // 64-QAM 42 42 60 108 |
|
921 + |
|
922 + |
|
923 + // If FSM stage < 10, set CE_EST_EVM with max value. |
|
924 + if(FsmStage < 10) |
|
925 + CeEstEvm = RTL2832_CE_EST_EVM_MAX_VALUE; |
|
926 + |
|
927 + |
|
928 + // Calculate SNR dB numerator. |
|
929 + MpiSetValue(&MpiCeEstEvm, CeEstEvm); |
|
930 + |
|
931 + MpiLog2(&MpiVar, MpiCeEstEvm, RTL2832_SNR_FRAC_BIT_NUM); |
|
932 + |
|
933 + MpiGetValue(MpiVar, &Var); |
|
934 + |
|
935 + *pSnrDbNum = SnrDbNumConst[Constellation][Hierarchy] - 10 * Var; |
|
936 + |
|
937 + |
|
938 + // Set SNR dB denominator. |
|
939 + *pSnrDbDen = RTL2832_SNR_DB_DEN; |
|
940 + |
|
941 + |
|
942 + return FUNCTION_SUCCESS; |
|
943 + |
|
944 + |
|
945 +error_status_get_registers: |
|
946 + return FUNCTION_ERROR; |
|
947 +} |
|
948 + |
|
949 + |
|
950 + |
|
951 + |
|
952 + |
|
953 +/** |
|
954 + |
|
955 +@see DVBT_DEMOD_FP_GET_RF_AGC |
|
956 + |
|
957 +*/ |
|
958 +int |
|
959 +rtl2832_GetRfAgc( |
|
960 + DVBT_DEMOD_MODULE *pDemod, |
|
961 + int *pRfAgc |
|
962 + ) |
|
963 +{ |
|
964 + unsigned long Value; |
|
965 + |
|
966 + |
|
967 + |
|
968 + // Get RF_AGC_VAL to Value. |
|
969 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RF_AGC_VAL, &Value) != FUNCTION_SUCCESS) |
|
970 + goto error_status_get_registers; |
|
971 + |
|
972 + |
|
973 + // Convert Value to signed integer and store the signed integer to RfAgc. |
|
974 + *pRfAgc = (int)BinToSignedInt(Value, RTL2832_RF_AGC_REG_BIT_NUM); |
|
975 + |
|
976 + |
|
977 + return FUNCTION_SUCCESS; |
|
978 + |
|
979 + |
|
980 +error_status_get_registers: |
|
981 + return FUNCTION_ERROR; |
|
982 +} |
|
983 + |
|
984 + |
|
985 + |
|
986 + |
|
987 + |
|
988 +/** |
|
989 + |
|
990 +@see DVBT_DEMOD_FP_GET_IF_AGC |
|
991 + |
|
992 +*/ |
|
993 +int |
|
994 +rtl2832_GetIfAgc( |
|
995 + DVBT_DEMOD_MODULE *pDemod, |
|
996 + int *pIfAgc |
|
997 + ) |
|
998 +{ |
|
999 + unsigned long Value; |
|
1000 + |
|
1001 + |
|
1002 + |
|
1003 + // Get IF_AGC_VAL to Value. |
|
1004 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_IF_AGC_VAL, &Value) != FUNCTION_SUCCESS) |
|
1005 + goto error_status_get_registers; |
|
1006 + |
|
1007 + |
|
1008 + // Convert Value to signed integer and store the signed integer to IfAgc. |
|
1009 + *pIfAgc = (int)BinToSignedInt(Value, RTL2832_IF_AGC_REG_BIT_NUM); |
|
1010 + |
|
1011 + |
|
1012 + return FUNCTION_SUCCESS; |
|
1013 + |
|
1014 + |
|
1015 +error_status_get_registers: |
|
1016 + return FUNCTION_ERROR; |
|
1017 +} |
|
1018 + |
|
1019 + |
|
1020 + |
|
1021 + |
|
1022 + |
|
1023 +/** |
|
1024 + |
|
1025 +@see DVBT_DEMOD_FP_GET_DI_AGC |
|
1026 + |
|
1027 +*/ |
|
1028 +int |
|
1029 +rtl2832_GetDiAgc( |
|
1030 + DVBT_DEMOD_MODULE *pDemod, |
|
1031 + unsigned char *pDiAgc |
|
1032 + ) |
|
1033 +{ |
|
1034 + unsigned long Value; |
|
1035 + |
|
1036 + |
|
1037 + |
|
1038 + // Get DAGC_VAL to DiAgc. |
|
1039 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_DAGC_VAL, &Value) != FUNCTION_SUCCESS) |
|
1040 + goto error_status_get_registers; |
|
1041 + |
|
1042 + *pDiAgc = (unsigned char)Value; |
|
1043 + |
|
1044 + |
|
1045 + return FUNCTION_SUCCESS; |
|
1046 + |
|
1047 + |
|
1048 +error_status_get_registers: |
|
1049 + return FUNCTION_ERROR; |
|
1050 +} |
|
1051 + |
|
1052 + |
|
1053 + |
|
1054 + |
|
1055 + |
|
1056 +/** |
|
1057 + |
|
1058 +@see DVBT_DEMOD_FP_GET_TR_OFFSET_PPM |
|
1059 + |
|
1060 +*/ |
|
1061 +int |
|
1062 +rtl2832_GetTrOffsetPpm( |
|
1063 + DVBT_DEMOD_MODULE *pDemod, |
|
1064 + long *pTrOffsetPpm |
|
1065 + ) |
|
1066 +{ |
|
1067 + unsigned long SfreqOffBinary; |
|
1068 + long SfreqOffInt; |
|
1069 + |
|
1070 + MPI MpiSfreqOffInt; |
|
1071 + MPI MpiConst, MpiVar; |
|
1072 + |
|
1073 + |
|
1074 + // Get SfreqOff binary value from SFREQ_OFF register bits. |
|
1075 + // Note: The function GetRegBitsWithPage() will set register page automatically. |
|
1076 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_SFREQ_OFF, &SfreqOffBinary) != FUNCTION_SUCCESS) |
|
1077 + goto error_status_get_demod_registers; |
|
1078 + |
|
1079 + // Convert SfreqOff binary value to signed integer. |
|
1080 + SfreqOffInt = BinToSignedInt(SfreqOffBinary, RTL2832_SFREQ_OFF_BIT_NUM); |
|
1081 + |
|
1082 + |
|
1083 + // Get TR offset in ppm. |
|
1084 + // Note: Original formula: TrOffsetPpm = (SfreqOffInt * 1000000) / pow(2, 24) |
|
1085 + // Adjusted formula: TrOffsetPpm = (SfreqOffInt * 1000000) >> 24 |
|
1086 + MpiSetValue(&MpiSfreqOffInt, SfreqOffInt); |
|
1087 + MpiSetValue(&MpiConst, 1000000); |
|
1088 + |
|
1089 + MpiMul(&MpiVar, MpiSfreqOffInt, MpiConst); |
|
1090 + MpiRightShift(&MpiVar, MpiVar, 24); |
|
1091 + |
|
1092 + MpiGetValue(MpiVar, pTrOffsetPpm); |
|
1093 + |
|
1094 + |
|
1095 + return FUNCTION_SUCCESS; |
|
1096 + |
|
1097 + |
|
1098 +error_status_get_demod_registers: |
|
1099 + return FUNCTION_ERROR; |
|
1100 +} |
|
1101 + |
|
1102 + |
|
1103 + |
|
1104 + |
|
1105 + |
|
1106 +/** |
|
1107 + |
|
1108 +@see DVBT_DEMOD_FP_GET_CR_OFFSET_HZ |
|
1109 + |
|
1110 +*/ |
|
1111 +int |
|
1112 +rtl2832_GetCrOffsetHz( |
|
1113 + DVBT_DEMOD_MODULE *pDemod, |
|
1114 + long *pCrOffsetHz |
|
1115 + ) |
|
1116 +{ |
|
1117 + int BandwidthMode; |
|
1118 + int FftMode; |
|
1119 + |
|
1120 + unsigned long CfreqOffBinary; |
|
1121 + long CfreqOffInt; |
|
1122 + |
|
1123 + long ConstWithBandwidthMode, ConstWithFftMode; |
|
1124 + |
|
1125 + MPI MpiCfreqOffInt; |
|
1126 + MPI MpiConstWithBandwidthMode, MpiConstWithFftMode; |
|
1127 + MPI MpiConst, MpiVar0, MpiVar1, MpiNone; |
|
1128 + |
|
1129 + |
|
1130 + |
|
1131 + // Get demod bandwidth mode. |
|
1132 + if(pDemod->GetBandwidthMode(pDemod, &BandwidthMode) != FUNCTION_SUCCESS) |
|
1133 + goto error_status_get_demod_bandwidth_mode; |
|
1134 + |
|
1135 + |
|
1136 + // Get demod FFT mode. |
|
1137 + if(pDemod->GetFftMode(pDemod, &FftMode) != FUNCTION_SUCCESS) |
|
1138 + goto error_status_get_demod_registers; |
|
1139 + |
|
1140 + |
|
1141 + // Get CfreqOff binary value from CFREQ_OFF register bits. |
|
1142 + // Note: The function GetRegBitsWithPage() will set register page automatically. |
|
1143 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_CFREQ_OFF, &CfreqOffBinary) != FUNCTION_SUCCESS) |
|
1144 + goto error_status_get_demod_registers; |
|
1145 + |
|
1146 + // Convert CfreqOff binary value to signed integer. |
|
1147 + CfreqOffInt = BinToSignedInt(CfreqOffBinary, RTL2832_CFREQ_OFF_BIT_NUM); |
|
1148 + |
|
1149 + |
|
1150 + // Determine constant value with bandwidth mode. |
|
1151 + switch(BandwidthMode) |
|
1152 + { |
|
1153 + default: |
|
1154 + case DVBT_BANDWIDTH_6MHZ: ConstWithBandwidthMode = 48000000; break; |
|
1155 + case DVBT_BANDWIDTH_7MHZ: ConstWithBandwidthMode = 56000000; break; |
|
1156 + case DVBT_BANDWIDTH_8MHZ: ConstWithBandwidthMode = 64000000; break; |
|
1157 + } |
|
1158 + |
|
1159 + |
|
1160 + // Determine constant value with FFT mode. |
|
1161 + switch(FftMode) |
|
1162 + { |
|
1163 + default: |
|
1164 + case DVBT_FFT_MODE_2K: ConstWithFftMode = 2048; break; |
|
1165 + case DVBT_FFT_MODE_8K: ConstWithFftMode = 8192; break; |
|
1166 + } |
|
1167 + |
|
1168 + |
|
1169 + // Get Cr offset in Hz. |
|
1170 + // Note: Original formula: CrOffsetHz = (CfreqOffInt * ConstWithBandwidthMode) / (ConstWithFftMode * 7 * 128) |
|
1171 + // Adjusted formula: CrOffsetHz = (CfreqOffInt * ConstWithBandwidthMode) / ((ConstWithFftMode * 7) << 7) |
|
1172 + MpiSetValue(&MpiCfreqOffInt, CfreqOffInt); |
|
1173 + MpiSetValue(&MpiConstWithBandwidthMode, ConstWithBandwidthMode); |
|
1174 + MpiSetValue(&MpiConstWithFftMode, ConstWithFftMode); |
|
1175 + MpiSetValue(&MpiConst, 7); |
|
1176 + |
|
1177 + MpiMul(&MpiVar0, MpiCfreqOffInt, MpiConstWithBandwidthMode); |
|
1178 + MpiMul(&MpiVar1, MpiConstWithFftMode, MpiConst); |
|
1179 + MpiLeftShift(&MpiVar1, MpiVar1, 7); |
|
1180 + MpiDiv(&MpiVar0, &MpiNone, MpiVar0, MpiVar1); |
|
1181 + |
|
1182 + MpiGetValue(MpiVar0, pCrOffsetHz); |
|
1183 + |
|
1184 + |
|
1185 + return FUNCTION_SUCCESS; |
|
1186 + |
|
1187 + |
|
1188 +error_status_get_demod_registers: |
|
1189 +error_status_get_demod_bandwidth_mode: |
|
1190 + return FUNCTION_ERROR; |
|
1191 +} |
|
1192 + |
|
1193 + |
|
1194 + |
|
1195 + |
|
1196 + |
|
1197 +/** |
|
1198 + |
|
1199 +@see DVBT_DEMOD_FP_GET_CONSTELLATION |
|
1200 + |
|
1201 +*/ |
|
1202 +int |
|
1203 +rtl2832_GetConstellation( |
|
1204 + DVBT_DEMOD_MODULE *pDemod, |
|
1205 + int *pConstellation |
|
1206 + ) |
|
1207 +{ |
|
1208 + unsigned long ReadingValue; |
|
1209 + |
|
1210 + |
|
1211 + // Get TPS constellation information from RX_CONSTEL. |
|
1212 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RX_CONSTEL, &ReadingValue) != FUNCTION_SUCCESS) |
|
1213 + goto error_status_get_registers; |
|
1214 + |
|
1215 + switch(ReadingValue) |
|
1216 + { |
|
1217 + default: |
|
1218 + case 0: *pConstellation = DVBT_CONSTELLATION_QPSK; break; |
|
1219 + case 1: *pConstellation = DVBT_CONSTELLATION_16QAM; break; |
|
1220 + case 2: *pConstellation = DVBT_CONSTELLATION_64QAM; break; |
|
1221 + } |
|
1222 + |
|
1223 + |
|
1224 + return FUNCTION_SUCCESS; |
|
1225 + |
|
1226 + |
|
1227 +error_status_get_registers: |
|
1228 + return FUNCTION_ERROR; |
|
1229 +} |
|
1230 + |
|
1231 + |
|
1232 + |
|
1233 + |
|
1234 + |
|
1235 +/** |
|
1236 + |
|
1237 +@see DVBT_DEMOD_FP_GET_HIERARCHY |
|
1238 + |
|
1239 +*/ |
|
1240 +int |
|
1241 +rtl2832_GetHierarchy( |
|
1242 + DVBT_DEMOD_MODULE *pDemod, |
|
1243 + int *pHierarchy |
|
1244 + ) |
|
1245 +{ |
|
1246 + unsigned long ReadingValue; |
|
1247 + |
|
1248 + |
|
1249 + // Get TPS hierarchy infromation from RX_HIER. |
|
1250 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RX_HIER, &ReadingValue) != FUNCTION_SUCCESS) |
|
1251 + goto error_status_get_registers; |
|
1252 + |
|
1253 + switch(ReadingValue) |
|
1254 + { |
|
1255 + default: |
|
1256 + case 0: *pHierarchy = DVBT_HIERARCHY_NONE; break; |
|
1257 + case 1: *pHierarchy = DVBT_HIERARCHY_ALPHA_1; break; |
|
1258 + case 2: *pHierarchy = DVBT_HIERARCHY_ALPHA_2; break; |
|
1259 + case 3: *pHierarchy = DVBT_HIERARCHY_ALPHA_4; break; |
|
1260 + } |
|
1261 + |
|
1262 + |
|
1263 + return FUNCTION_SUCCESS; |
|
1264 + |
|
1265 + |
|
1266 +error_status_get_registers: |
|
1267 + return FUNCTION_ERROR; |
|
1268 +} |
|
1269 + |
|
1270 + |
|
1271 + |
|
1272 + |
|
1273 + |
|
1274 +/** |
|
1275 + |
|
1276 +@see DVBT_DEMOD_FP_GET_CODE_RATE_LP |
|
1277 + |
|
1278 +*/ |
|
1279 +int |
|
1280 +rtl2832_GetCodeRateLp( |
|
1281 + DVBT_DEMOD_MODULE *pDemod, |
|
1282 + int *pCodeRateLp |
|
1283 + ) |
|
1284 +{ |
|
1285 + unsigned long ReadingValue; |
|
1286 + |
|
1287 + |
|
1288 + // Get TPS low-priority code rate infromation from RX_C_RATE_LP. |
|
1289 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RX_C_RATE_LP, &ReadingValue) != FUNCTION_SUCCESS) |
|
1290 + goto error_status_get_registers; |
|
1291 + |
|
1292 + switch(ReadingValue) |
|
1293 + { |
|
1294 + default: |
|
1295 + case 0: *pCodeRateLp = DVBT_CODE_RATE_1_OVER_2; break; |
|
1296 + case 1: *pCodeRateLp = DVBT_CODE_RATE_2_OVER_3; break; |
|
1297 + case 2: *pCodeRateLp = DVBT_CODE_RATE_3_OVER_4; break; |
|
1298 + case 3: *pCodeRateLp = DVBT_CODE_RATE_5_OVER_6; break; |
|
1299 + case 4: *pCodeRateLp = DVBT_CODE_RATE_7_OVER_8; break; |
|
1300 + } |
|
1301 + |
|
1302 + |
|
1303 + return FUNCTION_SUCCESS; |
|
1304 + |
|
1305 + |
|
1306 +error_status_get_registers: |
|
1307 + return FUNCTION_ERROR; |
|
1308 +} |
|
1309 + |
|
1310 + |
|
1311 + |
|
1312 + |
|
1313 + |
|
1314 +/** |
|
1315 + |
|
1316 +@see DVBT_DEMOD_FP_GET_CODE_RATE_HP |
|
1317 + |
|
1318 +*/ |
|
1319 +int |
|
1320 +rtl2832_GetCodeRateHp( |
|
1321 + DVBT_DEMOD_MODULE *pDemod, |
|
1322 + int *pCodeRateHp |
|
1323 + ) |
|
1324 +{ |
|
1325 + unsigned long ReadingValue; |
|
1326 + |
|
1327 + |
|
1328 + // Get TPS high-priority code rate infromation from RX_C_RATE_HP. |
|
1329 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RX_C_RATE_HP, &ReadingValue) != FUNCTION_SUCCESS) |
|
1330 + goto error_status_get_registers; |
|
1331 + |
|
1332 + switch(ReadingValue) |
|
1333 + { |
|
1334 + default: |
|
1335 + case 0: *pCodeRateHp = DVBT_CODE_RATE_1_OVER_2; break; |
|
1336 + case 1: *pCodeRateHp = DVBT_CODE_RATE_2_OVER_3; break; |
|
1337 + case 2: *pCodeRateHp = DVBT_CODE_RATE_3_OVER_4; break; |
|
1338 + case 3: *pCodeRateHp = DVBT_CODE_RATE_5_OVER_6; break; |
|
1339 + case 4: *pCodeRateHp = DVBT_CODE_RATE_7_OVER_8; break; |
|
1340 + } |
|
1341 + |
|
1342 + |
|
1343 + return FUNCTION_SUCCESS; |
|
1344 + |
|
1345 + |
|
1346 +error_status_get_registers: |
|
1347 + return FUNCTION_ERROR; |
|
1348 +} |
|
1349 + |
|
1350 + |
|
1351 + |
|
1352 + |
|
1353 + |
|
1354 +/** |
|
1355 + |
|
1356 +@see DVBT_DEMOD_FP_GET_GUARD_INTERVAL |
|
1357 + |
|
1358 +*/ |
|
1359 +int |
|
1360 +rtl2832_GetGuardInterval( |
|
1361 + DVBT_DEMOD_MODULE *pDemod, |
|
1362 + int *pGuardInterval |
|
1363 + ) |
|
1364 +{ |
|
1365 + unsigned long ReadingValue; |
|
1366 + |
|
1367 + |
|
1368 + // Get TPS guard interval infromation from GI_IDX. |
|
1369 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_GI_IDX, &ReadingValue) != FUNCTION_SUCCESS) |
|
1370 + goto error_status_get_registers; |
|
1371 + |
|
1372 + switch(ReadingValue) |
|
1373 + { |
|
1374 + default: |
|
1375 + case 0: *pGuardInterval = DVBT_GUARD_INTERVAL_1_OVER_32; break; |
|
1376 + case 1: *pGuardInterval = DVBT_GUARD_INTERVAL_1_OVER_16; break; |
|
1377 + case 2: *pGuardInterval = DVBT_GUARD_INTERVAL_1_OVER_8; break; |
|
1378 + case 3: *pGuardInterval = DVBT_GUARD_INTERVAL_1_OVER_4; break; |
|
1379 + } |
|
1380 + |
|
1381 + |
|
1382 + return FUNCTION_SUCCESS; |
|
1383 + |
|
1384 + |
|
1385 +error_status_get_registers: |
|
1386 + return FUNCTION_ERROR; |
|
1387 +} |
|
1388 + |
|
1389 + |
|
1390 + |
|
1391 + |
|
1392 + |
|
1393 +/** |
|
1394 + |
|
1395 +@see DVBT_DEMOD_FP_GET_FFT_MODE |
|
1396 + |
|
1397 +*/ |
|
1398 +int |
|
1399 +rtl2832_GetFftMode( |
|
1400 + DVBT_DEMOD_MODULE *pDemod, |
|
1401 + int *pFftMode |
|
1402 + ) |
|
1403 +{ |
|
1404 + unsigned long ReadingValue; |
|
1405 + |
|
1406 + |
|
1407 + // Get TPS FFT mode infromation from FFT_MODE_IDX. |
|
1408 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_FFT_MODE_IDX, &ReadingValue) != FUNCTION_SUCCESS) |
|
1409 + goto error_status_get_registers; |
|
1410 + |
|
1411 + switch(ReadingValue) |
|
1412 + { |
|
1413 + default: |
|
1414 + case 0: *pFftMode = DVBT_FFT_MODE_2K; break; |
|
1415 + case 1: *pFftMode = DVBT_FFT_MODE_8K; break; |
|
1416 + } |
|
1417 + |
|
1418 + |
|
1419 + return FUNCTION_SUCCESS; |
|
1420 + |
|
1421 + |
|
1422 +error_status_get_registers: |
|
1423 + return FUNCTION_ERROR; |
|
1424 +} |
|
1425 + |
|
1426 + |
|
1427 + |
|
1428 + |
|
1429 + |
|
1430 +/** |
|
1431 + |
|
1432 +@see DVBT_DEMOD_FP_UPDATE_FUNCTION |
|
1433 + |
|
1434 +*/ |
|
1435 +int |
|
1436 +rtl2832_UpdateFunction( |
|
1437 + DVBT_DEMOD_MODULE *pDemod |
|
1438 + ) |
|
1439 +{ |
|
1440 + RTL2832_EXTRA_MODULE *pExtra; |
|
1441 + |
|
1442 + |
|
1443 + // Get demod extra module. |
|
1444 + pExtra = (RTL2832_EXTRA_MODULE *)pDemod->pExtra; |
|
1445 + |
|
1446 + |
|
1447 + // Execute Function 1 according to Function 1 enabling status |
|
1448 + if(pExtra->IsFunc1Enabled == YES) |
|
1449 + { |
|
1450 + if(rtl2832_func1_Update(pDemod) != FUNCTION_SUCCESS) |
|
1451 + goto error_status_execute_function; |
|
1452 + } |
|
1453 + |
|
1454 + |
|
1455 + return FUNCTION_SUCCESS; |
|
1456 + |
|
1457 + |
|
1458 +error_status_execute_function: |
|
1459 + return FUNCTION_ERROR; |
|
1460 +} |
|
1461 + |
|
1462 + |
|
1463 + |
|
1464 + |
|
1465 + |
|
1466 +/** |
|
1467 + |
|
1468 +@see DVBT_DEMOD_FP_RESET_FUNCTION |
|
1469 + |
|
1470 +*/ |
|
1471 +int |
|
1472 +rtl2832_ResetFunction( |
|
1473 + DVBT_DEMOD_MODULE *pDemod |
|
1474 + ) |
|
1475 +{ |
|
1476 + RTL2832_EXTRA_MODULE *pExtra; |
|
1477 + |
|
1478 + |
|
1479 + // Get demod extra module. |
|
1480 + pExtra = (RTL2832_EXTRA_MODULE *)pDemod->pExtra; |
|
1481 + |
|
1482 + |
|
1483 + // Reset Function 1 settings according to Function 1 enabling status. |
|
1484 + if(pExtra->IsFunc1Enabled == YES) |
|
1485 + { |
|
1486 + if(rtl2832_func1_Reset(pDemod) != FUNCTION_SUCCESS) |
|
1487 + goto error_status_execute_function; |
|
1488 + } |
|
1489 + |
|
1490 + |
|
1491 + return FUNCTION_SUCCESS; |
|
1492 + |
|
1493 + |
|
1494 +error_status_execute_function: |
|
1495 + return FUNCTION_ERROR; |
|
1496 +} |
|
1497 + |
|
1498 + |
|
1499 + |
|
1500 + |
|
1501 + |
|
1502 +/** |
|
1503 + |
|
1504 +@see I2C_BRIDGE_FP_FORWARD_I2C_READING_CMD |
|
1505 + |
|
1506 +*/ |
|
1507 +int |
|
1508 +rtl2832_ForwardI2cReadingCmd( |
|
1509 + I2C_BRIDGE_MODULE *pI2cBridge, |
|
1510 + unsigned char *pReadingBytes, |
|
1511 + unsigned char ByteNum |
|
1512 + ) |
|
1513 +{ |
|
1514 + DVBT_DEMOD_MODULE *pDemod; |
|
1515 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
1516 + |
|
1517 + unsigned char TunerDeviceAddr; |
|
1518 + |
|
1519 + |
|
1520 + |
|
1521 + // Get demod module. |
|
1522 + pDemod = (DVBT_DEMOD_MODULE *)pI2cBridge->pPrivateData; |
|
1523 + |
|
1524 + |
|
1525 + // Get base interface. |
|
1526 + pBaseInterface = pDemod->pBaseInterface; |
|
1527 + |
|
1528 + |
|
1529 + // Get tuner device address. |
|
1530 + TunerDeviceAddr = *pI2cBridge->pTunerDeviceAddr; |
|
1531 + |
|
1532 + |
|
1533 + // Send I2C reading command. |
|
1534 + if(pBaseInterface->I2cRead(pBaseInterface, TunerDeviceAddr, pReadingBytes, ByteNum) != FUNCTION_SUCCESS) |
|
1535 + goto error_send_i2c_reading_command; |
|
1536 + |
|
1537 + |
|
1538 + return FUNCTION_SUCCESS; |
|
1539 + |
|
1540 + |
|
1541 +error_send_i2c_reading_command: |
|
1542 + return FUNCTION_ERROR; |
|
1543 +} |
|
1544 + |
|
1545 + |
|
1546 + |
|
1547 + |
|
1548 + |
|
1549 +/** |
|
1550 + |
|
1551 +@see I2C_BRIDGE_FP_FORWARD_I2C_WRITING_CMD |
|
1552 + |
|
1553 +*/ |
|
1554 +int |
|
1555 +rtl2832_ForwardI2cWritingCmd( |
|
1556 + I2C_BRIDGE_MODULE *pI2cBridge, |
|
1557 + const unsigned char *pWritingBytes, |
|
1558 + unsigned char ByteNum |
|
1559 + ) |
|
1560 +{ |
|
1561 + DVBT_DEMOD_MODULE *pDemod; |
|
1562 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
1563 + |
|
1564 + unsigned char TunerDeviceAddr; |
|
1565 + |
|
1566 + |
|
1567 + |
|
1568 + // Get demod module. |
|
1569 + pDemod = (DVBT_DEMOD_MODULE *)pI2cBridge->pPrivateData; |
|
1570 + |
|
1571 + |
|
1572 + // Get base interface. |
|
1573 + pBaseInterface = pDemod->pBaseInterface; |
|
1574 + |
|
1575 + |
|
1576 + // Get tuner device address. |
|
1577 + TunerDeviceAddr = *pI2cBridge->pTunerDeviceAddr; |
|
1578 + |
|
1579 + |
|
1580 + // Send I2C writing command. |
|
1581 + if(pBaseInterface->I2cWrite(pBaseInterface, TunerDeviceAddr, pWritingBytes, ByteNum) != FUNCTION_SUCCESS) |
|
1582 + goto error_send_i2c_writing_command; |
|
1583 + |
|
1584 + |
|
1585 + return FUNCTION_SUCCESS; |
|
1586 + |
|
1587 + |
|
1588 +error_send_i2c_writing_command: |
|
1589 + return FUNCTION_ERROR; |
|
1590 +} |
|
1591 + |
|
1592 + |
|
1593 + |
|
1594 + |
|
1595 + |
|
1596 +/** |
|
1597 + |
|
1598 +@brief Initialize RTL2832 register table. |
|
1599 + |
|
1600 +Use rtl2832_InitRegTable() to initialize RTL2832 register table. |
|
1601 + |
|
1602 + |
|
1603 +@param [in] pDemod RTL2832 demod module pointer |
|
1604 + |
|
1605 + |
|
1606 +@note |
|
1607 + -# The rtl2832_InitRegTable() function will be called by BuildRtl2832Module(). |
|
1608 + |
|
1609 +*/ |
|
1610 +void |
|
1611 +rtl2832_InitRegTable( |
|
1612 + DVBT_DEMOD_MODULE *pDemod |
|
1613 + ) |
|
1614 +{ |
|
1615 + static const DVBT_PRIMARY_REG_ENTRY PrimaryRegTable[RTL2832_REG_TABLE_LEN] = |
|
1616 + { |
|
1617 + // Software reset register |
|
1618 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1619 + {DVBT_SOFT_RST, 0x1, 0x1, 2, 2}, |
|
1620 + |
|
1621 + // Tuner I2C forwording register |
|
1622 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1623 + {DVBT_IIC_REPEAT, 0x1, 0x1, 3, 3}, |
|
1624 + |
|
1625 + // Registers for initialization |
|
1626 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1627 + {DVBT_TR_WAIT_MIN_8K, 0x1, 0x88, 11, 2}, |
|
1628 + {DVBT_RSD_BER_FAIL_VAL, 0x1, 0x8f, 15, 0}, |
|
1629 + {DVBT_EN_BK_TRK, 0x1, 0xa6, 7, 7}, |
|
1630 + {DVBT_AD_EN_REG, 0x0, 0x8, 7, 7}, |
|
1631 + {DVBT_AD_EN_REG1, 0x0, 0x8, 6, 6}, |
|
1632 + {DVBT_EN_BBIN, 0x1, 0xb1, 0, 0}, |
|
1633 + {DVBT_MGD_THD0, 0x1, 0x95, 7, 0}, |
|
1634 + {DVBT_MGD_THD1, 0x1, 0x96, 7, 0}, |
|
1635 + {DVBT_MGD_THD2, 0x1, 0x97, 7, 0}, |
|
1636 + {DVBT_MGD_THD3, 0x1, 0x98, 7, 0}, |
|
1637 + {DVBT_MGD_THD4, 0x1, 0x99, 7, 0}, |
|
1638 + {DVBT_MGD_THD5, 0x1, 0x9a, 7, 0}, |
|
1639 + {DVBT_MGD_THD6, 0x1, 0x9b, 7, 0}, |
|
1640 + {DVBT_MGD_THD7, 0x1, 0x9c, 7, 0}, |
|
1641 + {DVBT_EN_CACQ_NOTCH, 0x1, 0x61, 4, 4}, |
|
1642 + {DVBT_AD_AV_REF, 0x0, 0x9, 6, 0}, |
|
1643 + {DVBT_REG_PI, 0x0, 0xa, 2, 0}, |
|
1644 + {DVBT_PIP_ON, 0x0, 0x21, 3, 3}, |
|
1645 + {DVBT_SCALE1_B92, 0x2, 0x92, 7, 0}, |
|
1646 + {DVBT_SCALE1_B93, 0x2, 0x93, 7, 0}, |
|
1647 + {DVBT_SCALE1_BA7, 0x2, 0xa7, 7, 0}, |
|
1648 + {DVBT_SCALE1_BA9, 0x2, 0xa9, 7, 0}, |
|
1649 + {DVBT_SCALE1_BAA, 0x2, 0xaa, 7, 0}, |
|
1650 + {DVBT_SCALE1_BAB, 0x2, 0xab, 7, 0}, |
|
1651 + {DVBT_SCALE1_BAC, 0x2, 0xac, 7, 0}, |
|
1652 + {DVBT_SCALE1_BB0, 0x2, 0xb0, 7, 0}, |
|
1653 + {DVBT_SCALE1_BB1, 0x2, 0xb1, 7, 0}, |
|
1654 + {DVBT_KB_P1, 0x1, 0x64, 3, 1}, |
|
1655 + {DVBT_KB_P2, 0x1, 0x64, 6, 4}, |
|
1656 + {DVBT_KB_P3, 0x1, 0x65, 2, 0}, |
|
1657 + {DVBT_OPT_ADC_IQ, 0x0, 0x6, 5, 4}, |
|
1658 + {DVBT_AD_AVI, 0x0, 0x9, 1, 0}, |
|
1659 + {DVBT_AD_AVQ, 0x0, 0x9, 3, 2}, |
|
1660 + {DVBT_K1_CR_STEP12, 0x2, 0xad, 9, 4}, |
|
1661 + |
|
1662 + // Registers for initialization according to mode |
|
1663 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1664 + {DVBT_TRK_KS_P2, 0x1, 0x6f, 2, 0}, |
|
1665 + {DVBT_TRK_KS_I2, 0x1, 0x70, 5, 3}, |
|
1666 + {DVBT_TR_THD_SET2, 0x1, 0x72, 3, 0}, |
|
1667 + {DVBT_TRK_KC_P2, 0x1, 0x73, 5, 3}, |
|
1668 + {DVBT_TRK_KC_I2, 0x1, 0x75, 2, 0}, |
|
1669 + {DVBT_CR_THD_SET2, 0x1, 0x76, 7, 6}, |
|
1670 + |
|
1671 + // Registers for IF setting |
|
1672 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1673 + {DVBT_PSET_IFFREQ, 0x1, 0x19, 21, 0}, |
|
1674 + {DVBT_SPEC_INV, 0x1, 0x15, 0, 0}, |
|
1675 + |
|
1676 + // Registers for bandwidth programming |
|
1677 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1678 + {DVBT_RSAMP_RATIO, 0x1, 0x9f, 27, 2}, |
|
1679 + {DVBT_CFREQ_OFF_RATIO, 0x1, 0x9d, 23, 4}, |
|
1680 + |
|
1681 + // FSM stage register |
|
1682 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1683 + {DVBT_FSM_STAGE, 0x3, 0x51, 6, 3}, |
|
1684 + |
|
1685 + // TPS content registers |
|
1686 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1687 + {DVBT_RX_CONSTEL, 0x3, 0x3c, 3, 2}, |
|
1688 + {DVBT_RX_HIER, 0x3, 0x3c, 6, 4}, |
|
1689 + {DVBT_RX_C_RATE_LP, 0x3, 0x3d, 2, 0}, |
|
1690 + {DVBT_RX_C_RATE_HP, 0x3, 0x3d, 5, 3}, |
|
1691 + {DVBT_GI_IDX, 0x3, 0x51, 1, 0}, |
|
1692 + {DVBT_FFT_MODE_IDX, 0x3, 0x51, 2, 2}, |
|
1693 + |
|
1694 + // Performance measurement registers |
|
1695 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1696 + {DVBT_RSD_BER_EST, 0x3, 0x4e, 15, 0}, |
|
1697 + {DVBT_CE_EST_EVM, 0x4, 0xc, 15, 0}, |
|
1698 + |
|
1699 + // AGC registers |
|
1700 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1701 + {DVBT_RF_AGC_VAL, 0x3, 0x5b, 13, 0}, |
|
1702 + {DVBT_IF_AGC_VAL, 0x3, 0x59, 13, 0}, |
|
1703 + {DVBT_DAGC_VAL, 0x3, 0x5, 7, 0}, |
|
1704 + |
|
1705 + // TR offset and CR offset registers |
|
1706 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1707 + {DVBT_SFREQ_OFF, 0x3, 0x18, 13, 0}, |
|
1708 + {DVBT_CFREQ_OFF, 0x3, 0x5f, 17, 0}, |
|
1709 + |
|
1710 + // AGC relative registers |
|
1711 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1712 + {DVBT_POLAR_RF_AGC, 0x0, 0xe, 1, 1}, |
|
1713 + {DVBT_POLAR_IF_AGC, 0x0, 0xe, 0, 0}, |
|
1714 + {DVBT_AAGC_HOLD, 0x1, 0x4, 5, 5}, |
|
1715 + {DVBT_EN_RF_AGC, 0x1, 0x4, 6, 6}, |
|
1716 + {DVBT_EN_IF_AGC, 0x1, 0x4, 7, 7}, |
|
1717 + {DVBT_IF_AGC_MIN, 0x1, 0x8, 7, 0}, |
|
1718 + {DVBT_IF_AGC_MAX, 0x1, 0x9, 7, 0}, |
|
1719 + {DVBT_RF_AGC_MIN, 0x1, 0xa, 7, 0}, |
|
1720 + {DVBT_RF_AGC_MAX, 0x1, 0xb, 7, 0}, |
|
1721 + {DVBT_IF_AGC_MAN, 0x1, 0xc, 6, 6}, |
|
1722 + {DVBT_IF_AGC_MAN_VAL, 0x1, 0xc, 13, 0}, |
|
1723 + {DVBT_RF_AGC_MAN, 0x1, 0xe, 6, 6}, |
|
1724 + {DVBT_RF_AGC_MAN_VAL, 0x1, 0xe, 13, 0}, |
|
1725 + {DVBT_DAGC_TRG_VAL, 0x1, 0x12, 7, 0}, |
|
1726 + {DVBT_AGC_TARG_VAL_0, 0x1, 0x2, 0, 0}, |
|
1727 + {DVBT_AGC_TARG_VAL_8_1, 0x1, 0x3, 7, 0}, |
|
1728 + {DVBT_AAGC_LOOP_GAIN, 0x1, 0xc7, 5, 1}, |
|
1729 + {DVBT_LOOP_GAIN2_3_0, 0x1, 0x4, 4, 1}, |
|
1730 + {DVBT_LOOP_GAIN2_4, 0x1, 0x5, 7, 7}, |
|
1731 + {DVBT_LOOP_GAIN3, 0x1, 0xc8, 4, 0}, |
|
1732 + {DVBT_VTOP1, 0x1, 0x6, 5, 0}, |
|
1733 + {DVBT_VTOP2, 0x1, 0xc9, 5, 0}, |
|
1734 + {DVBT_VTOP3, 0x1, 0xca, 5, 0}, |
|
1735 + {DVBT_KRF1, 0x1, 0xcb, 7, 0}, |
|
1736 + {DVBT_KRF2, 0x1, 0x7, 7, 0}, |
|
1737 + {DVBT_KRF3, 0x1, 0xcd, 7, 0}, |
|
1738 + {DVBT_KRF4, 0x1, 0xce, 7, 0}, |
|
1739 + |
|
1740 + // TS interface registers |
|
1741 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1742 + {DVBT_CKOUTPAR, 0x1, 0x7b, 5, 5}, |
|
1743 + {DVBT_CKOUT_PWR, 0x1, 0x7b, 6, 6}, |
|
1744 + {DVBT_SYNC_DUR, 0x1, 0x7b, 7, 7}, |
|
1745 + {DVBT_ERR_DUR, 0x1, 0x7c, 0, 0}, |
|
1746 + {DVBT_SYNC_LVL, 0x1, 0x7c, 1, 1}, |
|
1747 + {DVBT_ERR_LVL, 0x1, 0x7c, 2, 2}, |
|
1748 + {DVBT_VAL_LVL, 0x1, 0x7c, 3, 3}, |
|
1749 + {DVBT_SERIAL, 0x1, 0x7c, 4, 4}, |
|
1750 + {DVBT_SER_LSB, 0x1, 0x7c, 5, 5}, |
|
1751 + {DVBT_CDIV_PH0, 0x1, 0x7d, 3, 0}, |
|
1752 + {DVBT_CDIV_PH1, 0x1, 0x7d, 7, 4}, |
|
1753 + {DVBT_CKOUTPAR_PIP, 0x0, 0xb7, 4, 4}, |
|
1754 + {DVBT_CKOUT_PWR_PIP, 0x0, 0xb7, 3, 3}, |
|
1755 + {DVBT_SYNC_LVL_PIP, 0x0, 0xb7, 2, 2}, |
|
1756 + {DVBT_ERR_LVL_PIP, 0x0, 0xb7, 1, 1}, |
|
1757 + {DVBT_VAL_LVL_PIP, 0x0, 0xb7, 0, 0}, |
|
1758 + {DVBT_CKOUTPAR_PID, 0x0, 0xb9, 4, 4}, |
|
1759 + {DVBT_CKOUT_PWR_PID, 0x0, 0xb9, 3, 3}, |
|
1760 + {DVBT_SYNC_LVL_PID, 0x0, 0xb9, 2, 2}, |
|
1761 + {DVBT_ERR_LVL_PID, 0x0, 0xb9, 1, 1}, |
|
1762 + {DVBT_VAL_LVL_PID, 0x0, 0xb9, 0, 0}, |
|
1763 + |
|
1764 + // FSM state-holding register |
|
1765 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1766 + {DVBT_SM_PASS, 0x1, 0x93, 11, 0}, |
|
1767 + |
|
1768 + // AD7 registers |
|
1769 + // RegBitName, PageNo, RegStartAddr, MSB, LSB |
|
1770 + {DVBT_AD7_SETTING, 0x0, 0x11, 15, 0}, |
|
1771 + {DVBT_RSSI_R, 0x3, 0x1, 6, 0}, |
|
1772 + |
|
1773 + // ACI detection registers |
|
1774 + {DVBT_ACI_DET_IND, 0x3, 0x12, 0, 0}, |
|
1775 + }; |
|
1776 + |
|
1777 + |
|
1778 + int i; |
|
1779 + int RegBitName; |
|
1780 + |
|
1781 + |
|
1782 + |
|
1783 + // Initialize register table according to primary register table. |
|
1784 + // Note: 1. Register table rows are sorted by register bit name key. |
|
1785 + // 2. The default value of the IsAvailable variable is "NO". |
|
1786 + for(i = 0; i < DVBT_REG_TABLE_LEN_MAX; i++) |
|
1787 + pDemod->RegTable[i].IsAvailable = NO; |
|
1788 + |
|
1789 + for(i = 0; i < RTL2832_REG_TABLE_LEN; i++) |
|
1790 + { |
|
1791 + RegBitName = PrimaryRegTable[i].RegBitName; |
|
1792 + |
|
1793 + pDemod->RegTable[RegBitName].IsAvailable = YES; |
|
1794 + pDemod->RegTable[RegBitName].PageNo = PrimaryRegTable[i].PageNo; |
|
1795 + pDemod->RegTable[RegBitName].RegStartAddr = PrimaryRegTable[i].RegStartAddr; |
|
1796 + pDemod->RegTable[RegBitName].Msb = PrimaryRegTable[i].Msb; |
|
1797 + pDemod->RegTable[RegBitName].Lsb = PrimaryRegTable[i].Lsb; |
|
1798 + } |
|
1799 + |
|
1800 + |
|
1801 + return; |
|
1802 +} |
|
1803 + |
|
1804 + |
|
1805 + |
|
1806 + |
|
1807 + |
|
1808 +/** |
|
1809 + |
|
1810 +@brief Set I2C bridge module demod arguments. |
|
1811 + |
|
1812 +RTL2832 builder will use rtl2832_SetI2cBridgeModuleDemodArg() to set I2C bridge module demod arguments. |
|
1813 + |
|
1814 + |
|
1815 +@param [in] pDemod The demod module pointer |
|
1816 + |
|
1817 + |
|
1818 +@see BuildRtl2832Module() |
|
1819 + |
|
1820 +*/ |
|
1821 +void |
|
1822 +rtl2832_SetI2cBridgeModuleDemodArg( |
|
1823 + DVBT_DEMOD_MODULE *pDemod |
|
1824 + ) |
|
1825 +{ |
|
1826 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
1827 + |
|
1828 + |
|
1829 + |
|
1830 + // Get I2C bridge module. |
|
1831 + pI2cBridge = pDemod->pI2cBridge; |
|
1832 + |
|
1833 + // Set I2C bridge module demod arguments. |
|
1834 + pI2cBridge->pPrivateData = (void *)pDemod; |
|
1835 + pI2cBridge->ForwardI2cReadingCmd = rtl2832_ForwardI2cReadingCmd; |
|
1836 + pI2cBridge->ForwardI2cWritingCmd = rtl2832_ForwardI2cWritingCmd; |
|
1837 + |
|
1838 + |
|
1839 + return; |
|
1840 +} |
|
1841 + |
|
1842 + |
|
1843 + |
|
1844 + |
|
1845 + |
|
1846 +/* |
|
1847 + |
|
1848 +@see RTL2832_FP_GET_APP_MODE |
|
1849 + |
|
1850 +*/ |
|
1851 +void |
|
1852 +rtl2832_GetAppMode( |
|
1853 + DVBT_DEMOD_MODULE *pDemod, |
|
1854 + int *pAppMode |
|
1855 + ) |
|
1856 +{ |
|
1857 + RTL2832_EXTRA_MODULE *pExtra; |
|
1858 + |
|
1859 + |
|
1860 + |
|
1861 + // Get demod extra module. |
|
1862 + pExtra = (RTL2832_EXTRA_MODULE *)pDemod->pExtra; |
|
1863 + |
|
1864 + |
|
1865 + // Get demod type from demod module. |
|
1866 + *pAppMode = pExtra->AppMode; |
|
1867 + |
|
1868 + |
|
1869 + return; |
|
1870 +} |
|
1871 + |
|
1872 + |
|
1873 + |
|
1874 + |
|
1875 + |
|
1876 +/** |
|
1877 + |
|
1878 +@brief Reset Function 1 variables and registers. |
|
1879 + |
|
1880 +One can use rtl2832_func1_Reset() to reset Function 1 variables and registers. |
|
1881 + |
|
1882 + |
|
1883 +@param [in] pDemod The demod module pointer |
|
1884 + |
|
1885 + |
|
1886 +@retval FUNCTION_SUCCESS Reset Function 1 variables and registers successfully. |
|
1887 +@retval FUNCTION_ERROR Reset Function 1 variables and registers unsuccessfully. |
|
1888 + |
|
1889 + |
|
1890 +@note |
|
1891 + -# Need to execute Function 1 reset function when change tuner RF frequency or demod parameters. |
|
1892 + -# Function 1 update flow also employs Function 1 reset function. |
|
1893 + |
|
1894 +*/ |
|
1895 +int |
|
1896 +rtl2832_func1_Reset( |
|
1897 + DVBT_DEMOD_MODULE *pDemod |
|
1898 + ) |
|
1899 +{ |
|
1900 + RTL2832_EXTRA_MODULE *pExtra; |
|
1901 + |
|
1902 + |
|
1903 + |
|
1904 + // Get demod extra module. |
|
1905 + pExtra = (RTL2832_EXTRA_MODULE *)pDemod->pExtra; |
|
1906 + |
|
1907 + // Reset demod Function 1 variables. |
|
1908 + pExtra->Func1State = RTL2832_FUNC1_STATE_NORMAL; |
|
1909 + pExtra->Func1WaitTime = 0; |
|
1910 + pExtra->Func1GettingTime = 0; |
|
1911 + pExtra->Func1RsdBerEstSumNormal = 0; |
|
1912 + pExtra->Func1RsdBerEstSumConfig1 = 0; |
|
1913 + pExtra->Func1RsdBerEstSumConfig2 = 0; |
|
1914 + pExtra->Func1RsdBerEstSumConfig3 = 0; |
|
1915 + |
|
1916 + |
|
1917 + // Reset demod Function 1 registers. |
|
1918 + if(rtl2832_func1_ResetReg(pDemod) != FUNCTION_SUCCESS) |
|
1919 + goto error_status_execute_function; |
|
1920 + |
|
1921 + |
|
1922 + return FUNCTION_SUCCESS; |
|
1923 + |
|
1924 + |
|
1925 +error_status_execute_function: |
|
1926 + return FUNCTION_ERROR; |
|
1927 +} |
|
1928 + |
|
1929 + |
|
1930 + |
|
1931 + |
|
1932 + |
|
1933 +/** |
|
1934 + |
|
1935 +@brief Update demod registers with Function 1. |
|
1936 + |
|
1937 +One can use rtl2832_func1_Update() to update demod registers with Function 1. |
|
1938 + |
|
1939 + |
|
1940 +@param [in] pDemod The demod module pointer |
|
1941 + |
|
1942 + |
|
1943 +@retval FUNCTION_SUCCESS Update demod registers with Function 1 successfully. |
|
1944 +@retval FUNCTION_ERROR Update demod registers with Function 1 unsuccessfully. |
|
1945 + |
|
1946 +*/ |
|
1947 +int |
|
1948 +rtl2832_func1_Update( |
|
1949 + DVBT_DEMOD_MODULE *pDemod |
|
1950 + ) |
|
1951 +{ |
|
1952 + RTL2832_EXTRA_MODULE *pExtra; |
|
1953 + |
|
1954 + int Answer; |
|
1955 + int MinWeightedBerConfigMode; |
|
1956 + |
|
1957 + |
|
1958 + |
|
1959 + // Get demod extra module. |
|
1960 + pExtra = (RTL2832_EXTRA_MODULE *)pDemod->pExtra; |
|
1961 + |
|
1962 + |
|
1963 + // Run FSM. |
|
1964 + switch(pExtra->Func1State) |
|
1965 + { |
|
1966 + case RTL2832_FUNC1_STATE_NORMAL: |
|
1967 + |
|
1968 + // Ask if criterion is matched. |
|
1969 + if(rtl2832_func1_IsCriterionMatched(pDemod, &Answer) != FUNCTION_SUCCESS) |
|
1970 + goto error_status_execute_function; |
|
1971 + |
|
1972 + if(Answer == YES) |
|
1973 + { |
|
1974 + // Accumulate RSD_BER_EST for normal case. |
|
1975 + if(rtl2832_func1_AccumulateRsdBerEst(pDemod, &pExtra->Func1RsdBerEstSumNormal) != FUNCTION_SUCCESS) |
|
1976 + goto error_status_execute_function; |
|
1977 + |
|
1978 + // Reset getting time counter. |
|
1979 + pExtra->Func1GettingTime = 0; |
|
1980 + |
|
1981 + // Go to RTL2832_FUNC1_STATE_NORMAL_GET_BER state. |
|
1982 + pExtra->Func1State = RTL2832_FUNC1_STATE_NORMAL_GET_BER; |
|
1983 + } |
|
1984 + |
|
1985 + break; |
|
1986 + |
|
1987 + |
|
1988 + case RTL2832_FUNC1_STATE_NORMAL_GET_BER: |
|
1989 + |
|
1990 + // Accumulate RSD_BER_EST for normal case. |
|
1991 + if(rtl2832_func1_AccumulateRsdBerEst(pDemod, &pExtra->Func1RsdBerEstSumNormal) != FUNCTION_SUCCESS) |
|
1992 + goto error_status_execute_function; |
|
1993 + |
|
1994 + // Use getting time counter to hold RTL2832_FUNC1_STATE_NORMAL_GET_BER state several times. |
|
1995 + pExtra->Func1GettingTime += 1; |
|
1996 + |
|
1997 + if(pExtra->Func1GettingTime >= pExtra->Func1GettingTimeMax) |
|
1998 + { |
|
1999 + // Set common registers for configuration 1, 2, and 3 case. |
|
2000 + if(rtl2832_func1_SetCommonReg(pDemod) != FUNCTION_SUCCESS) |
|
2001 + goto error_status_execute_function; |
|
2002 + |
|
2003 + // Set registers with FFT mode for configuration 1, 2, and 3 case. |
|
2004 + if(rtl2832_func1_SetRegWithFftMode(pDemod, pExtra->Func1FftBak) != FUNCTION_SUCCESS) |
|
2005 + goto error_status_execute_function; |
|
2006 + |
|
2007 + // Set registers for configuration 1 case. |
|
2008 + if(rtl2832_func1_SetRegWithConfigMode(pDemod, RTL2832_FUNC1_CONFIG_1) != FUNCTION_SUCCESS) |
|
2009 + goto error_status_execute_function; |
|
2010 + |
|
2011 + // Reset demod by software reset. |
|
2012 + if(pDemod->SoftwareReset(pDemod) != FUNCTION_SUCCESS) |
|
2013 + goto error_status_execute_function; |
|
2014 + |
|
2015 + // Reset wait time counter. |
|
2016 + pExtra->Func1WaitTime = 0; |
|
2017 + |
|
2018 + // Go to RTL2832_FUNC1_STATE_CONFIG_1_WAIT state. |
|
2019 + pExtra->Func1State = RTL2832_FUNC1_STATE_CONFIG_1_WAIT; |
|
2020 + } |
|
2021 + |
|
2022 + break; |
|
2023 + |
|
2024 + |
|
2025 + case RTL2832_FUNC1_STATE_CONFIG_1_WAIT: |
|
2026 + |
|
2027 + // Use wait time counter to hold RTL2832_FUNC1_STATE_CONFIG_1_WAIT state several times. |
|
2028 + pExtra->Func1WaitTime += 1; |
|
2029 + |
|
2030 + if(pExtra->Func1WaitTime >= pExtra->Func1WaitTimeMax) |
|
2031 + { |
|
2032 + // Accumulate RSD_BER_EST for configuration 1 case. |
|
2033 + if(rtl2832_func1_AccumulateRsdBerEst(pDemod, &pExtra->Func1RsdBerEstSumConfig1) != FUNCTION_SUCCESS) |
|
2034 + goto error_status_execute_function; |
|
2035 + |
|
2036 + // Reset getting time counter. |
|
2037 + pExtra->Func1GettingTime = 0; |
|
2038 + |
|
2039 + // Go to RTL2832_FUNC1_STATE_CONFIG_1_GET_BER state. |
|
2040 + pExtra->Func1State = RTL2832_FUNC1_STATE_CONFIG_1_GET_BER; |
|
2041 + } |
|
2042 + |
|
2043 + break; |
|
2044 + |
|
2045 + |
|
2046 + case RTL2832_FUNC1_STATE_CONFIG_1_GET_BER: |
|
2047 + |
|
2048 + // Accumulate RSD_BER_EST for configuration 1 case. |
|
2049 + if(rtl2832_func1_AccumulateRsdBerEst(pDemod, &pExtra->Func1RsdBerEstSumConfig1) != FUNCTION_SUCCESS) |
|
2050 + goto error_status_execute_function; |
|
2051 + |
|
2052 + // Use getting time counter to hold RTL2832_FUNC1_STATE_CONFIG_1_GET_BER state several times. |
|
2053 + pExtra->Func1GettingTime += 1; |
|
2054 + |
|
2055 + if(pExtra->Func1GettingTime >= pExtra->Func1GettingTimeMax) |
|
2056 + { |
|
2057 + // Set registers for configuration 2 case. |
|
2058 + if(rtl2832_func1_SetRegWithConfigMode(pDemod, RTL2832_FUNC1_CONFIG_2) != FUNCTION_SUCCESS) |
|
2059 + goto error_status_execute_function; |
|
2060 + |
|
2061 + // Reset demod by software reset. |
|
2062 + if(pDemod->SoftwareReset(pDemod) != FUNCTION_SUCCESS) |
|
2063 + goto error_status_execute_function; |
|
2064 + |
|
2065 + // Reset wait time counter. |
|
2066 + pExtra->Func1WaitTime = 0; |
|
2067 + |
|
2068 + // Go to RTL2832_FUNC1_STATE_CONFIG_2_WAIT state. |
|
2069 + pExtra->Func1State = RTL2832_FUNC1_STATE_CONFIG_2_WAIT; |
|
2070 + } |
|
2071 + |
|
2072 + break; |
|
2073 + |
|
2074 + |
|
2075 + case RTL2832_FUNC1_STATE_CONFIG_2_WAIT: |
|
2076 + |
|
2077 + // Use wait time counter to hold RTL2832_FUNC1_STATE_CONFIG_2_WAIT state several times. |
|
2078 + pExtra->Func1WaitTime += 1; |
|
2079 + |
|
2080 + if(pExtra->Func1WaitTime >= pExtra->Func1WaitTimeMax) |
|
2081 + { |
|
2082 + // Accumulate RSD_BER_EST for configuration 2 case. |
|
2083 + if(rtl2832_func1_AccumulateRsdBerEst(pDemod, &pExtra->Func1RsdBerEstSumConfig2) != FUNCTION_SUCCESS) |
|
2084 + goto error_status_execute_function; |
|
2085 + |
|
2086 + // Reset getting time counter. |
|
2087 + pExtra->Func1GettingTime = 0; |
|
2088 + |
|
2089 + // Go to RTL2832_FUNC1_STATE_CONFIG_2_GET_BER state. |
|
2090 + pExtra->Func1State = RTL2832_FUNC1_STATE_CONFIG_2_GET_BER; |
|
2091 + } |
|
2092 + |
|
2093 + break; |
|
2094 + |
|
2095 + |
|
2096 + case RTL2832_FUNC1_STATE_CONFIG_2_GET_BER: |
|
2097 + |
|
2098 + // Accumulate RSD_BER_EST for configuration 2 case. |
|
2099 + if(rtl2832_func1_AccumulateRsdBerEst(pDemod, &pExtra->Func1RsdBerEstSumConfig2) != FUNCTION_SUCCESS) |
|
2100 + goto error_status_execute_function; |
|
2101 + |
|
2102 + // Use getting time counter to hold RTL2832_FUNC1_STATE_CONFIG_2_GET_BER state several times. |
|
2103 + pExtra->Func1GettingTime += 1; |
|
2104 + |
|
2105 + if(pExtra->Func1GettingTime >= pExtra->Func1GettingTimeMax) |
|
2106 + { |
|
2107 + // Set registers for configuration 3 case. |
|
2108 + if(rtl2832_func1_SetRegWithConfigMode(pDemod, RTL2832_FUNC1_CONFIG_3) != FUNCTION_SUCCESS) |
|
2109 + goto error_status_execute_function; |
|
2110 + |
|
2111 + // Reset demod by software reset. |
|
2112 + if(pDemod->SoftwareReset(pDemod) != FUNCTION_SUCCESS) |
|
2113 + goto error_status_execute_function; |
|
2114 + |
|
2115 + // Reset wait time counter. |
|
2116 + pExtra->Func1WaitTime = 0; |
|
2117 + |
|
2118 + // Go to RTL2832_FUNC1_STATE_CONFIG_3_WAIT state. |
|
2119 + pExtra->Func1State = RTL2832_FUNC1_STATE_CONFIG_3_WAIT; |
|
2120 + } |
|
2121 + |
|
2122 + break; |
|
2123 + |
|
2124 + |
|
2125 + case RTL2832_FUNC1_STATE_CONFIG_3_WAIT: |
|
2126 + |
|
2127 + // Use wait time counter to hold RTL2832_FUNC1_STATE_CONFIG_3_WAIT state several times. |
|
2128 + pExtra->Func1WaitTime += 1; |
|
2129 + |
|
2130 + if(pExtra->Func1WaitTime >= pExtra->Func1WaitTimeMax) |
|
2131 + { |
|
2132 + // Accumulate RSD_BER_EST for configuration 3 case. |
|
2133 + if(rtl2832_func1_AccumulateRsdBerEst(pDemod, &pExtra->Func1RsdBerEstSumConfig3) != FUNCTION_SUCCESS) |
|
2134 + goto error_status_execute_function; |
|
2135 + |
|
2136 + // Reset getting time counter. |
|
2137 + pExtra->Func1GettingTime = 0; |
|
2138 + |
|
2139 + // Go to RTL2832_FUNC1_STATE_CONFIG_3_GET_BER state. |
|
2140 + pExtra->Func1State = RTL2832_FUNC1_STATE_CONFIG_3_GET_BER; |
|
2141 + } |
|
2142 + |
|
2143 + break; |
|
2144 + |
|
2145 + |
|
2146 + case RTL2832_FUNC1_STATE_CONFIG_3_GET_BER: |
|
2147 + |
|
2148 + // Accumulate RSD_BER_EST for configuration 3 case. |
|
2149 + if(rtl2832_func1_AccumulateRsdBerEst(pDemod, &pExtra->Func1RsdBerEstSumConfig3) != FUNCTION_SUCCESS) |
|
2150 + goto error_status_execute_function; |
|
2151 + |
|
2152 + // Use getting time counter to hold RTL2832_FUNC1_STATE_CONFIG_3_GET_BER state several times. |
|
2153 + pExtra->Func1GettingTime += 1; |
|
2154 + |
|
2155 + if(pExtra->Func1GettingTime >= pExtra->Func1GettingTimeMax) |
|
2156 + { |
|
2157 + // Determine minimum-weighted-BER configuration mode. |
|
2158 + rtl2832_func1_GetMinWeightedBerConfigMode(pDemod, &MinWeightedBerConfigMode); |
|
2159 + |
|
2160 + // Set registers with minimum-weighted-BER configuration mode. |
|
2161 + switch(MinWeightedBerConfigMode) |
|
2162 + { |
|
2163 + case RTL2832_FUNC1_CONFIG_NORMAL: |
|
2164 + |
|
2165 + // Reset registers for normal configuration. |
|
2166 + if(rtl2832_func1_ResetReg(pDemod) != FUNCTION_SUCCESS) |
|
2167 + goto error_status_execute_function; |
|
2168 + |
|
2169 + break; |
|
2170 + |
|
2171 + |
|
2172 + case RTL2832_FUNC1_CONFIG_1: |
|
2173 + case RTL2832_FUNC1_CONFIG_2: |
|
2174 + case RTL2832_FUNC1_CONFIG_3: |
|
2175 + |
|
2176 + // Set registers for minimum-weighted-BER configuration. |
|
2177 + if(rtl2832_func1_SetRegWithConfigMode(pDemod, MinWeightedBerConfigMode) != FUNCTION_SUCCESS) |
|
2178 + goto error_status_execute_function; |
|
2179 + |
|
2180 + break; |
|
2181 + |
|
2182 + |
|
2183 + default: |
|
2184 + |
|
2185 + // Get error configuration mode, reset registers. |
|
2186 + if(rtl2832_func1_ResetReg(pDemod) != FUNCTION_SUCCESS) |
|
2187 + goto error_status_execute_function; |
|
2188 + |
|
2189 + break; |
|
2190 + } |
|
2191 + |
|
2192 + // Reset demod by software reset. |
|
2193 + if(pDemod->SoftwareReset(pDemod) != FUNCTION_SUCCESS) |
|
2194 + goto error_status_execute_function; |
|
2195 + |
|
2196 + // Reset wait time counter. |
|
2197 + pExtra->Func1WaitTime = 0; |
|
2198 + |
|
2199 + // Go to RTL2832_FUNC1_STATE_DETERMINED_WAIT state. |
|
2200 + pExtra->Func1State = RTL2832_FUNC1_STATE_DETERMINED_WAIT; |
|
2201 + } |
|
2202 + |
|
2203 + break; |
|
2204 + |
|
2205 + |
|
2206 + case RTL2832_FUNC1_STATE_DETERMINED_WAIT: |
|
2207 + |
|
2208 + // Use wait time counter to hold RTL2832_FUNC1_STATE_CONFIG_3_WAIT state several times. |
|
2209 + pExtra->Func1WaitTime += 1; |
|
2210 + |
|
2211 + if(pExtra->Func1WaitTime >= pExtra->Func1WaitTimeMax) |
|
2212 + { |
|
2213 + // Go to RTL2832_FUNC1_STATE_DETERMINED state. |
|
2214 + pExtra->Func1State = RTL2832_FUNC1_STATE_DETERMINED; |
|
2215 + } |
|
2216 + |
|
2217 + break; |
|
2218 + |
|
2219 + |
|
2220 + case RTL2832_FUNC1_STATE_DETERMINED: |
|
2221 + |
|
2222 + // Ask if criterion is matched. |
|
2223 + if(rtl2832_func1_IsCriterionMatched(pDemod, &Answer) != FUNCTION_SUCCESS) |
|
2224 + goto error_status_execute_function; |
|
2225 + |
|
2226 + if(Answer == NO) |
|
2227 + { |
|
2228 + // Reset FSM. |
|
2229 + // Note: rtl2832_func1_Reset() will set FSM state with RTL2832_FUNC1_STATE_NORMAL. |
|
2230 + if(rtl2832_func1_Reset(pDemod) != FUNCTION_SUCCESS) |
|
2231 + goto error_status_execute_function; |
|
2232 + } |
|
2233 + |
|
2234 + break; |
|
2235 + |
|
2236 + |
|
2237 + default: |
|
2238 + |
|
2239 + // Get error state, reset FSM. |
|
2240 + // Note: rtl2832_func1_Reset() will set FSM state with RTL2832_FUNC1_STATE_NORMAL. |
|
2241 + if(rtl2832_func1_Reset(pDemod) != FUNCTION_SUCCESS) |
|
2242 + goto error_status_execute_function; |
|
2243 + |
|
2244 + break; |
|
2245 + } |
|
2246 + |
|
2247 + |
|
2248 + |
|
2249 + |
|
2250 + return FUNCTION_SUCCESS; |
|
2251 + |
|
2252 + |
|
2253 +error_status_execute_function: |
|
2254 + return FUNCTION_ERROR; |
|
2255 +} |
|
2256 + |
|
2257 + |
|
2258 + |
|
2259 + |
|
2260 + |
|
2261 +/** |
|
2262 + |
|
2263 +@brief Ask if criterion is matched for Function 1. |
|
2264 + |
|
2265 +One can use rtl2832_func1_IsCriterionMatched() to ask if criterion is matched for Function 1. |
|
2266 + |
|
2267 + |
|
2268 +@param [in] pDemod The demod module pointer |
|
2269 +@param [out] pAnswer Pointer to an allocated memory for storing answer |
|
2270 + |
|
2271 + |
|
2272 +@retval FUNCTION_SUCCESS Ask if criterion is matched for Function 1 successfully. |
|
2273 +@retval FUNCTION_ERROR Ask if criterion is matched for Function 1 unsuccessfully. |
|
2274 + |
|
2275 +*/ |
|
2276 +int |
|
2277 +rtl2832_func1_IsCriterionMatched( |
|
2278 + DVBT_DEMOD_MODULE *pDemod, |
|
2279 + int *pAnswer |
|
2280 + ) |
|
2281 +{ |
|
2282 + RTL2832_EXTRA_MODULE *pExtra; |
|
2283 + |
|
2284 + unsigned long FsmStage; |
|
2285 + |
|
2286 + int Qam; |
|
2287 + int Hier; |
|
2288 + int LpCr; |
|
2289 + int HpCr; |
|
2290 + int Gi; |
|
2291 + int Fft; |
|
2292 + |
|
2293 + unsigned long Reg0, Reg1; |
|
2294 + |
|
2295 + int BandwidthMode; |
|
2296 + |
|
2297 + |
|
2298 + |
|
2299 + // Get demod extra module. |
|
2300 + pExtra = (RTL2832_EXTRA_MODULE *)pDemod->pExtra; |
|
2301 + |
|
2302 + |
|
2303 + // Get FSM_STAGE. |
|
2304 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_FSM_STAGE, &FsmStage) != FUNCTION_SUCCESS) |
|
2305 + goto error_status_get_registers; |
|
2306 + |
|
2307 + |
|
2308 + // Get QAM. |
|
2309 + if(pDemod->GetConstellation(pDemod, &Qam) != FUNCTION_SUCCESS) |
|
2310 + goto error_status_execute_function; |
|
2311 + |
|
2312 + // Get hierarchy. |
|
2313 + if(pDemod->GetHierarchy(pDemod, &Hier) != FUNCTION_SUCCESS) |
|
2314 + goto error_status_execute_function; |
|
2315 + |
|
2316 + // Get low-priority code rate. |
|
2317 + if(pDemod->GetCodeRateLp(pDemod, &LpCr) != FUNCTION_SUCCESS) |
|
2318 + goto error_status_execute_function; |
|
2319 + |
|
2320 + // Get high-priority code rate. |
|
2321 + if(pDemod->GetCodeRateHp(pDemod, &HpCr) != FUNCTION_SUCCESS) |
|
2322 + goto error_status_execute_function; |
|
2323 + |
|
2324 + // Get guard interval. |
|
2325 + if(pDemod->GetGuardInterval(pDemod, &Gi) != FUNCTION_SUCCESS) |
|
2326 + goto error_status_execute_function; |
|
2327 + |
|
2328 + // Get FFT mode. |
|
2329 + if(pDemod->GetFftMode(pDemod, &Fft) != FUNCTION_SUCCESS) |
|
2330 + goto error_status_execute_function; |
|
2331 + |
|
2332 + |
|
2333 + // Get REG_0 and REG_1. |
|
2334 + if(pDemod->SetRegPage(pDemod, 0x3) != FUNCTION_SUCCESS) |
|
2335 + goto error_status_set_registers; |
|
2336 + |
|
2337 + if(pDemod->GetRegMaskBits(pDemod, 0x22, 0, 0, &Reg0) != FUNCTION_SUCCESS) |
|
2338 + goto error_status_set_registers; |
|
2339 + |
|
2340 + if(pDemod->GetRegMaskBits(pDemod, 0x1a, 15, 3, &Reg1) != FUNCTION_SUCCESS) |
|
2341 + goto error_status_set_registers; |
|
2342 + |
|
2343 + |
|
2344 + // Get bandwidth mode. |
|
2345 + if(pDemod->GetBandwidthMode(pDemod, &BandwidthMode) != FUNCTION_SUCCESS) |
|
2346 + goto error_status_execute_function; |
|
2347 + |
|
2348 + |
|
2349 + // Determine criterion answer. |
|
2350 + *pAnswer = |
|
2351 + (FsmStage == 11) && |
|
2352 + |
|
2353 + (Qam == pExtra->Func1QamBak) && |
|
2354 + (Hier == pExtra->Func1HierBak) && |
|
2355 + (LpCr == pExtra->Func1LpCrBak) && |
|
2356 + (HpCr == pExtra->Func1HpCrBak) && |
|
2357 + (Gi == pExtra->Func1GiBak) && |
|
2358 + (Fft == pExtra->Func1FftBak) && |
|
2359 + |
|
2360 + (Reg0 == 0x1) && |
|
2361 + |
|
2362 + ((BandwidthMode == DVBT_BANDWIDTH_8MHZ) && |
|
2363 + ( ((Fft == DVBT_FFT_MODE_2K) && (Reg1 > 1424) && (Reg1 < 1440)) || |
|
2364 + ((Fft == DVBT_FFT_MODE_8K) && (Reg1 > 5696) && (Reg1 < 5760)) ) ); |
|
2365 + |
|
2366 + |
|
2367 + // Backup TPS information. |
|
2368 + pExtra->Func1QamBak = Qam; |
|
2369 + pExtra->Func1HierBak = Hier; |
|
2370 + pExtra->Func1LpCrBak = LpCr; |
|
2371 + pExtra->Func1HpCrBak = HpCr; |
|
2372 + pExtra->Func1GiBak = Gi; |
|
2373 + pExtra->Func1FftBak = Fft; |
|
2374 + |
|
2375 + |
|
2376 + return FUNCTION_SUCCESS; |
|
2377 + |
|
2378 + |
|
2379 +error_status_set_registers: |
|
2380 +error_status_execute_function: |
|
2381 +error_status_get_registers: |
|
2382 + return FUNCTION_ERROR; |
|
2383 +} |
|
2384 + |
|
2385 + |
|
2386 + |
|
2387 + |
|
2388 + |
|
2389 +/** |
|
2390 + |
|
2391 +@brief Accumulate RSD_BER_EST value for Function 1. |
|
2392 + |
|
2393 +One can use rtl2832_func1_AccumulateRsdBerEst() to accumulate RSD_BER_EST for Function 1. |
|
2394 + |
|
2395 + |
|
2396 +@param [in] pDemod The demod module pointer |
|
2397 +@param [in] pAccumulativeValue Accumulative RSD_BER_EST value |
|
2398 + |
|
2399 + |
|
2400 +@retval FUNCTION_SUCCESS Accumulate RSD_BER_EST for Function 1 successfully. |
|
2401 +@retval FUNCTION_ERROR Accumulate RSD_BER_EST for Function 1 unsuccessfully. |
|
2402 + |
|
2403 +*/ |
|
2404 +int |
|
2405 +rtl2832_func1_AccumulateRsdBerEst( |
|
2406 + DVBT_DEMOD_MODULE *pDemod, |
|
2407 + unsigned long *pAccumulativeValue |
|
2408 + ) |
|
2409 +{ |
|
2410 + RTL2832_EXTRA_MODULE *pExtra; |
|
2411 + |
|
2412 + int i; |
|
2413 + unsigned long RsdBerEst; |
|
2414 + |
|
2415 + |
|
2416 + |
|
2417 + // Get demod extra module. |
|
2418 + pExtra = (RTL2832_EXTRA_MODULE *)pDemod->pExtra; |
|
2419 + |
|
2420 + |
|
2421 + // Get RSD_BER_EST with assigned times. |
|
2422 + for(i = 0; i < pExtra->Func1GettingNumEachTime; i++) |
|
2423 + { |
|
2424 + // Get RSD_BER_EST. |
|
2425 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RSD_BER_EST, &RsdBerEst) != FUNCTION_SUCCESS) |
|
2426 + goto error_status_get_registers; |
|
2427 + |
|
2428 + // Accumulate RSD_BER_EST to accumulative value. |
|
2429 + *pAccumulativeValue += RsdBerEst; |
|
2430 + } |
|
2431 + |
|
2432 + |
|
2433 + return FUNCTION_SUCCESS; |
|
2434 + |
|
2435 + |
|
2436 +error_status_get_registers: |
|
2437 + return FUNCTION_ERROR; |
|
2438 +} |
|
2439 + |
|
2440 + |
|
2441 + |
|
2442 + |
|
2443 + |
|
2444 +/** |
|
2445 + |
|
2446 +@brief Reset registers for Function 1. |
|
2447 + |
|
2448 +One can use rtl2832_func1_ResetReg() to reset registers for Function 1. |
|
2449 + |
|
2450 + |
|
2451 +@param [in] pDemod The demod module pointer |
|
2452 + |
|
2453 + |
|
2454 +@retval FUNCTION_SUCCESS Reset registers for Function 1 successfully. |
|
2455 +@retval FUNCTION_ERROR Reset registers for Function 1 unsuccessfully. |
|
2456 + |
|
2457 +*/ |
|
2458 +int |
|
2459 +rtl2832_func1_ResetReg( |
|
2460 + DVBT_DEMOD_MODULE *pDemod |
|
2461 + ) |
|
2462 +{ |
|
2463 + // Reset Function 1 registers. |
|
2464 + if(pDemod->SetRegPage(pDemod, 0x1) != FUNCTION_SUCCESS) |
|
2465 + goto error_status_set_registers; |
|
2466 + |
|
2467 + if(pDemod->SetRegMaskBits(pDemod, 0x65, 2, 0, 0x7) != FUNCTION_SUCCESS) |
|
2468 + goto error_status_set_registers; |
|
2469 + |
|
2470 + if(pDemod->SetRegMaskBits(pDemod, 0x68, 5, 4, 0x3) != FUNCTION_SUCCESS) |
|
2471 + goto error_status_set_registers; |
|
2472 + |
|
2473 + if(pDemod->SetRegMaskBits(pDemod, 0x5b, 2, 0, 0x5) != FUNCTION_SUCCESS) |
|
2474 + goto error_status_set_registers; |
|
2475 + |
|
2476 + if(pDemod->SetRegMaskBits(pDemod, 0x5b, 5, 3, 0x5) != FUNCTION_SUCCESS) |
|
2477 + goto error_status_set_registers; |
|
2478 + |
|
2479 + if(pDemod->SetRegMaskBits(pDemod, 0x5c, 2, 0, 0x5) != FUNCTION_SUCCESS) |
|
2480 + goto error_status_set_registers; |
|
2481 + |
|
2482 + if(pDemod->SetRegMaskBits(pDemod, 0x5c, 5, 3, 0x5) != FUNCTION_SUCCESS) |
|
2483 + goto error_status_set_registers; |
|
2484 + |
|
2485 + if(pDemod->SetRegMaskBits(pDemod, 0xd0, 3, 2, 0x0) != FUNCTION_SUCCESS) |
|
2486 + goto error_status_set_registers; |
|
2487 + |
|
2488 + if(pDemod->SetRegMaskBits(pDemod, 0xd1, 14, 0, 0x0) != FUNCTION_SUCCESS) |
|
2489 + goto error_status_set_registers; |
|
2490 + |
|
2491 + if(pDemod->SetRegMaskBits(pDemod, 0xd3, 14, 0, 0x0) != FUNCTION_SUCCESS) |
|
2492 + goto error_status_set_registers; |
|
2493 + |
|
2494 + if(pDemod->SetRegMaskBits(pDemod, 0xd5, 14, 0, 0x0) != FUNCTION_SUCCESS) |
|
2495 + goto error_status_set_registers; |
|
2496 + |
|
2497 + if(pDemod->SetRegPage(pDemod, 0x2) != FUNCTION_SUCCESS) |
|
2498 + goto error_status_set_registers; |
|
2499 + |
|
2500 + if(pDemod->SetRegMaskBits(pDemod, 0x1, 0, 0, 0x1) != FUNCTION_SUCCESS) |
|
2501 + goto error_status_set_registers; |
|
2502 + |
|
2503 + if(pDemod->SetRegMaskBits(pDemod, 0xb4, 7, 6, 0x3) != FUNCTION_SUCCESS) |
|
2504 + goto error_status_set_registers; |
|
2505 + |
|
2506 + if(pDemod->SetRegMaskBits(pDemod, 0xd2, 1, 1, 0x0) != FUNCTION_SUCCESS) |
|
2507 + goto error_status_set_registers; |
|
2508 + |
|
2509 + if(pDemod->SetRegMaskBits(pDemod, 0xb5, 7, 7, 0x1) != FUNCTION_SUCCESS) |
|
2510 + goto error_status_set_registers; |
|
2511 + |
|
2512 + |
|
2513 + return FUNCTION_SUCCESS; |
|
2514 + |
|
2515 + |
|
2516 +error_status_set_registers: |
|
2517 + return FUNCTION_ERROR; |
|
2518 +} |
|
2519 + |
|
2520 + |
|
2521 + |
|
2522 + |
|
2523 + |
|
2524 +/** |
|
2525 + |
|
2526 +@brief Set common registers for Function 1. |
|
2527 + |
|
2528 +One can use rtl2832_func1_SetCommonReg() to set common registers for Function 1. |
|
2529 + |
|
2530 + |
|
2531 +@param [in] pDemod The demod module pointer |
|
2532 + |
|
2533 + |
|
2534 +@retval FUNCTION_SUCCESS Set common registers for Function 1 successfully. |
|
2535 +@retval FUNCTION_ERROR Set common registers for Function 1 unsuccessfully. |
|
2536 + |
|
2537 +*/ |
|
2538 +int |
|
2539 +rtl2832_func1_SetCommonReg( |
|
2540 + DVBT_DEMOD_MODULE *pDemod |
|
2541 + ) |
|
2542 +{ |
|
2543 + // Set common registers for Function 1. |
|
2544 + if(pDemod->SetRegPage(pDemod, 0x1) != FUNCTION_SUCCESS) |
|
2545 + goto error_status_set_registers; |
|
2546 + |
|
2547 + if(pDemod->SetRegMaskBits(pDemod, 0x65, 2, 0, 0x5) != FUNCTION_SUCCESS) |
|
2548 + goto error_status_set_registers; |
|
2549 + |
|
2550 + if(pDemod->SetRegMaskBits(pDemod, 0x68, 5, 4, 0x0) != FUNCTION_SUCCESS) |
|
2551 + goto error_status_set_registers; |
|
2552 + |
|
2553 + if(pDemod->SetRegPage(pDemod, 0x2) != FUNCTION_SUCCESS) |
|
2554 + goto error_status_set_registers; |
|
2555 + |
|
2556 + if(pDemod->SetRegMaskBits(pDemod, 0xd2, 1, 1, 0x1) != FUNCTION_SUCCESS) |
|
2557 + goto error_status_set_registers; |
|
2558 + |
|
2559 + if(pDemod->SetRegMaskBits(pDemod, 0xb5, 7, 7, 0x0) != FUNCTION_SUCCESS) |
|
2560 + goto error_status_set_registers; |
|
2561 + |
|
2562 + |
|
2563 + return FUNCTION_SUCCESS; |
|
2564 + |
|
2565 + |
|
2566 +error_status_set_registers: |
|
2567 + return FUNCTION_ERROR; |
|
2568 +} |
|
2569 + |
|
2570 + |
|
2571 + |
|
2572 + |
|
2573 + |
|
2574 +/** |
|
2575 + |
|
2576 +@brief Set registers with FFT mode for Function 1. |
|
2577 + |
|
2578 +One can use rtl2832_func1_SetRegWithConfigMode() to set registers with FFT mode for Function 1. |
|
2579 + |
|
2580 + |
|
2581 +@param [in] pDemod The demod module pointer |
|
2582 +@param [in] FftMode FFT mode for setting |
|
2583 + |
|
2584 + |
|
2585 +@retval FUNCTION_SUCCESS Set registers with FFT mode for Function 1 successfully. |
|
2586 +@retval FUNCTION_ERROR Set registers with FFT mode for Function 1 unsuccessfully. |
|
2587 + |
|
2588 +*/ |
|
2589 +int |
|
2590 +rtl2832_func1_SetRegWithFftMode( |
|
2591 + DVBT_DEMOD_MODULE *pDemod, |
|
2592 + int FftMode |
|
2593 + ) |
|
2594 +{ |
|
2595 + typedef struct |
|
2596 + { |
|
2597 + unsigned long Reg0[DVBT_FFT_MODE_NUM]; |
|
2598 + unsigned long Reg1[DVBT_FFT_MODE_NUM]; |
|
2599 + } |
|
2600 + FFT_REF_ENTRY; |
|
2601 + |
|
2602 + |
|
2603 + |
|
2604 + static const FFT_REF_ENTRY FftRefTable = |
|
2605 + { |
|
2606 + // 2K mode, 8K mode |
|
2607 + {0x0, 0x1 }, |
|
2608 + {0x3, 0x0 }, |
|
2609 + }; |
|
2610 + |
|
2611 + |
|
2612 + |
|
2613 + // Set registers with FFT mode for Function 1. |
|
2614 + if(pDemod->SetRegPage(pDemod, 0x2) != FUNCTION_SUCCESS) |
|
2615 + goto error_status_set_registers; |
|
2616 + |
|
2617 + if(pDemod->SetRegMaskBits(pDemod, 0x1, 0, 0, FftRefTable.Reg0[FftMode]) != FUNCTION_SUCCESS) |
|
2618 + goto error_status_set_registers; |
|
2619 + |
|
2620 + if(pDemod->SetRegMaskBits(pDemod, 0xb4, 7, 6, FftRefTable.Reg1[FftMode]) != FUNCTION_SUCCESS) |
|
2621 + goto error_status_set_registers; |
|
2622 + |
|
2623 + |
|
2624 + return FUNCTION_SUCCESS; |
|
2625 + |
|
2626 + |
|
2627 +error_status_set_registers: |
|
2628 + return FUNCTION_ERROR; |
|
2629 +} |
|
2630 + |
|
2631 + |
|
2632 + |
|
2633 + |
|
2634 + |
|
2635 +/** |
|
2636 + |
|
2637 +@brief Set registers with configuration mode for Function 1. |
|
2638 + |
|
2639 +One can use rtl2832_func1_SetRegWithConfigMode() to set registers with configuration mode for Function 1. |
|
2640 + |
|
2641 + |
|
2642 +@param [in] pDemod The demod module pointer |
|
2643 +@param [in] ConfigMode Configuration mode for setting |
|
2644 + |
|
2645 + |
|
2646 +@retval FUNCTION_SUCCESS Set registers with configuration mode for Function 1 successfully. |
|
2647 +@retval FUNCTION_ERROR Set registers with configuration mode for Function 1 unsuccessfully. |
|
2648 + |
|
2649 + |
|
2650 +@note |
|
2651 + -# This function can not set RTL2832_FUNC1_CONFIG_NORMAL configuration mode. |
|
2652 + |
|
2653 +*/ |
|
2654 +int |
|
2655 +rtl2832_func1_SetRegWithConfigMode( |
|
2656 + DVBT_DEMOD_MODULE *pDemod, |
|
2657 + int ConfigMode |
|
2658 + ) |
|
2659 +{ |
|
2660 + typedef struct |
|
2661 + { |
|
2662 + unsigned long Reg0[RTL2832_FUNC1_CONFIG_MODE_NUM]; |
|
2663 + unsigned long Reg1[RTL2832_FUNC1_CONFIG_MODE_NUM]; |
|
2664 + unsigned long Reg2[RTL2832_FUNC1_CONFIG_MODE_NUM]; |
|
2665 + unsigned long Reg3[RTL2832_FUNC1_CONFIG_MODE_NUM]; |
|
2666 + unsigned long Reg4[RTL2832_FUNC1_CONFIG_MODE_NUM]; |
|
2667 + |
|
2668 + unsigned long Reg5Ref[RTL2832_FUNC1_CONFIG_MODE_NUM]; |
|
2669 + unsigned long Reg6Ref[RTL2832_FUNC1_CONFIG_MODE_NUM]; |
|
2670 + unsigned long Reg7Ref[RTL2832_FUNC1_CONFIG_MODE_NUM]; |
|
2671 + } |
|
2672 + CONFIG_REF_ENTRY; |
|
2673 + |
|
2674 + |
|
2675 + |
|
2676 + static const CONFIG_REF_ENTRY ConfigRefTable = |
|
2677 + { |
|
2678 + // Config 1, Config 2, Config 3 |
|
2679 + {0x5, 0x4, 0x5 }, |
|
2680 + {0x5, 0x4, 0x7 }, |
|
2681 + {0x5, 0x4, 0x7 }, |
|
2682 + {0x7, 0x6, 0x5 }, |
|
2683 + {0x3, 0x3, 0x2 }, |
|
2684 + |
|
2685 + {4437, 4437, 4325 }, |
|
2686 + {6000, 5500, 6500 }, |
|
2687 + {6552, 5800, 5850 }, |
|
2688 + }; |
|
2689 + |
|
2690 + int BandwidthMode; |
|
2691 + |
|
2692 + static const unsigned long Const[DVBT_BANDWIDTH_MODE_NUM] = |
|
2693 + { |
|
2694 + // 6Mhz, 7Mhz, 8Mhz |
|
2695 + 48, 56, 64, |
|
2696 + }; |
|
2697 + |
|
2698 + unsigned long Reg5, Reg6, Reg7; |
|
2699 + |
|
2700 + |
|
2701 + |
|
2702 + // Get bandwidth mode. |
|
2703 + if(pDemod->GetBandwidthMode(pDemod, &BandwidthMode) != FUNCTION_SUCCESS) |
|
2704 + goto error_status_execute_function; |
|
2705 + |
|
2706 + // Calculate REG_5, REG_6, and REG_7 with bandwidth mode and configuration mode. |
|
2707 + Reg5 = (ConfigRefTable.Reg5Ref[ConfigMode] * 7 * 2048 * 8) / (1000 * Const[BandwidthMode]); |
|
2708 + Reg6 = (ConfigRefTable.Reg6Ref[ConfigMode] * 7 * 2048 * 8) / (1000 * Const[BandwidthMode]); |
|
2709 + Reg7 = (ConfigRefTable.Reg7Ref[ConfigMode] * 7 * 2048 * 8) / (1000 * Const[BandwidthMode]); |
|
2710 + |
|
2711 + |
|
2712 + // Set registers with bandwidth mode and configuration mode. |
|
2713 + if(pDemod->SetRegPage(pDemod, 0x1) != FUNCTION_SUCCESS) |
|
2714 + goto error_status_set_registers; |
|
2715 + |
|
2716 + if(pDemod->SetRegMaskBits(pDemod, 0x5b, 2, 0, ConfigRefTable.Reg0[ConfigMode]) != FUNCTION_SUCCESS) |
|
2717 + goto error_status_set_registers; |
|
2718 + |
|
2719 + if(pDemod->SetRegMaskBits(pDemod, 0x5b, 5, 3, ConfigRefTable.Reg1[ConfigMode]) != FUNCTION_SUCCESS) |
|
2720 + goto error_status_set_registers; |
|
2721 + |
|
2722 + if(pDemod->SetRegMaskBits(pDemod, 0x5c, 2, 0, ConfigRefTable.Reg2[ConfigMode]) != FUNCTION_SUCCESS) |
|
2723 + goto error_status_set_registers; |
|
2724 + |
|
2725 + if(pDemod->SetRegMaskBits(pDemod, 0x5c, 5, 3, ConfigRefTable.Reg3[ConfigMode]) != FUNCTION_SUCCESS) |
|
2726 + goto error_status_set_registers; |
|
2727 + |
|
2728 + if(pDemod->SetRegMaskBits(pDemod, 0xd0, 3, 2, ConfigRefTable.Reg4[ConfigMode]) != FUNCTION_SUCCESS) |
|
2729 + goto error_status_set_registers; |
|
2730 + |
|
2731 + if(pDemod->SetRegMaskBits(pDemod, 0xd1, 14, 0, Reg5) != FUNCTION_SUCCESS) |
|
2732 + goto error_status_set_registers; |
|
2733 + |
|
2734 + if(pDemod->SetRegMaskBits(pDemod, 0xd3, 14, 0, Reg6) != FUNCTION_SUCCESS) |
|
2735 + goto error_status_set_registers; |
|
2736 + |
|
2737 + if(pDemod->SetRegMaskBits(pDemod, 0xd5, 14, 0, Reg7) != FUNCTION_SUCCESS) |
|
2738 + goto error_status_set_registers; |
|
2739 + |
|
2740 + |
|
2741 + return FUNCTION_SUCCESS; |
|
2742 + |
|
2743 + |
|
2744 +error_status_set_registers: |
|
2745 +error_status_execute_function: |
|
2746 + return FUNCTION_ERROR; |
|
2747 +} |
|
2748 + |
|
2749 + |
|
2750 + |
|
2751 + |
|
2752 + |
|
2753 +/** |
|
2754 + |
|
2755 +@brief Get minimum-weighted-BER configuration mode for Function 1. |
|
2756 + |
|
2757 +One can use rtl2832_func1_GetMinWeightedBerConfigMode() to get minimum-weighted-BER configuration mode for Function 1. |
|
2758 + |
|
2759 + |
|
2760 +@param [in] pDemod The demod module pointer |
|
2761 +@param [out] pConfigMode Pointer to an allocated memory for storing configuration mode answer |
|
2762 + |
|
2763 + |
|
2764 +@retval FUNCTION_SUCCESS Get minimum-weighted-BER configuration mode for Function 1 successfully. |
|
2765 +@retval FUNCTION_ERROR Get minimum-weighted-BER configuration mode for Function 1 unsuccessfully. |
|
2766 + |
|
2767 +*/ |
|
2768 +void |
|
2769 +rtl2832_func1_GetMinWeightedBerConfigMode( |
|
2770 + DVBT_DEMOD_MODULE *pDemod, |
|
2771 + int *pConfigMode |
|
2772 + ) |
|
2773 +{ |
|
2774 + RTL2832_EXTRA_MODULE *pExtra; |
|
2775 + |
|
2776 + unsigned long WeightedBerNormal; |
|
2777 + unsigned long WeightedBerConfig1; |
|
2778 + unsigned long WeightedBerConfig2; |
|
2779 + unsigned long WeightedBerConfig3; |
|
2780 + |
|
2781 + |
|
2782 + |
|
2783 + // Get demod extra module. |
|
2784 + pExtra = (RTL2832_EXTRA_MODULE *)pDemod->pExtra; |
|
2785 + |
|
2786 + |
|
2787 + // Calculate weighted BER for all configuration mode |
|
2788 + WeightedBerNormal = pExtra->Func1RsdBerEstSumNormal * 2; |
|
2789 + WeightedBerConfig1 = pExtra->Func1RsdBerEstSumConfig1; |
|
2790 + WeightedBerConfig2 = pExtra->Func1RsdBerEstSumConfig2; |
|
2791 + WeightedBerConfig3 = pExtra->Func1RsdBerEstSumConfig3; |
|
2792 + |
|
2793 + |
|
2794 + // Determine minimum-weighted-BER configuration mode. |
|
2795 + if(WeightedBerNormal <= WeightedBerConfig1 && |
|
2796 + WeightedBerNormal <= WeightedBerConfig2 && |
|
2797 + WeightedBerNormal <= WeightedBerConfig3) |
|
2798 + { |
|
2799 + *pConfigMode = RTL2832_FUNC1_CONFIG_NORMAL; |
|
2800 + } |
|
2801 + else if(WeightedBerConfig1 <= WeightedBerNormal && |
|
2802 + WeightedBerConfig1 <= WeightedBerConfig2 && |
|
2803 + WeightedBerConfig1 <= WeightedBerConfig3) |
|
2804 + { |
|
2805 + *pConfigMode = RTL2832_FUNC1_CONFIG_1; |
|
2806 + } |
|
2807 + else if(WeightedBerConfig2 <= WeightedBerNormal && |
|
2808 + WeightedBerConfig2 <= WeightedBerConfig1 && |
|
2809 + WeightedBerConfig2 <= WeightedBerConfig3) |
|
2810 + { |
|
2811 + *pConfigMode = RTL2832_FUNC1_CONFIG_2; |
|
2812 + } |
|
2813 + else if(WeightedBerConfig3 <= WeightedBerNormal && |
|
2814 + WeightedBerConfig3 <= WeightedBerConfig1 && |
|
2815 + WeightedBerConfig3 <= WeightedBerConfig2) |
|
2816 + { |
|
2817 + *pConfigMode = RTL2832_FUNC1_CONFIG_3; |
|
2818 + } |
|
2819 + |
|
2820 + |
|
2821 + return; |
|
2822 +} |
|
2823 + |
|
2824 + |
|
2825 + |
|
2826 + |
|
2827 + |
|
2828 + |
|
2829 + |
|
2830 + |
|
2831 + |
|
2832 + |
|
2833 + |
|
2834 + |
|
2835 + |
|
2836 + |
|
2837 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/demod_rtl2832.h |
|
2838 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
2839 +++ b/linux/drivers/media/dvb/dvb-usb/demod_rtl2832.h Wed Oct 27 09:16:44 2010 +0200 |
|
2840 @@ -0,0 +1,542 @@ |
|
2841 +#ifndef __DEMOD_RTL2832_H |
|
2842 +#define __DEMOD_RTL2832_H |
|
2843 + |
|
2844 +/** |
|
2845 + |
|
2846 +@file |
|
2847 + |
|
2848 +@brief RTL2832 demod module declaration |
|
2849 + |
|
2850 +One can manipulate RTL2832 demod through RTL2832 module. |
|
2851 +RTL2832 module is derived from DVB-T demod module. |
|
2852 + |
|
2853 + |
|
2854 + |
|
2855 +@par Example: |
|
2856 +@code |
|
2857 + |
|
2858 +// The example is the same as the DVB-T demod example in dvbt_demod_base.h except the listed lines. |
|
2859 + |
|
2860 + |
|
2861 + |
|
2862 +#include "demod_rtl2832.h" |
|
2863 + |
|
2864 + |
|
2865 +... |
|
2866 + |
|
2867 + |
|
2868 + |
|
2869 +int main(void) |
|
2870 +{ |
|
2871 + DVBT_DEMOD_MODULE *pDemod; |
|
2872 + |
|
2873 + DVBT_DEMOD_MODULE DvbtDemodModuleMemory; |
|
2874 + RTL2832_EXTRA_MODULE Rtl2832ExtraModuleMemory; |
|
2875 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
2876 + I2C_BRIDGE_MODULE I2cBridgeModuleMemory; |
|
2877 + |
|
2878 + |
|
2879 + ... |
|
2880 + |
|
2881 + |
|
2882 + |
|
2883 + // Build RTL2832 demod module. |
|
2884 + BuildRtl2832Module( |
|
2885 + &pDemod, |
|
2886 + &DvbtDemodModuleMemory, |
|
2887 + &Rtl2832ExtraModuleMemory, |
|
2888 + &BaseInterfaceModuleMemory, |
|
2889 + &I2cBridgeModuleMemory, |
|
2890 + 0x20, // I2C device address is 0x20 in 8-bit format. |
|
2891 + CRYSTAL_FREQ_28800000HZ, // Crystal frequency is 28.8 MHz. |
|
2892 + RTL2832_APPLICATION_STB // Application mode is STB. |
|
2893 + 50, // Update function reference period is 50 millisecond |
|
2894 + ON // Function 1 enabling status is on. |
|
2895 + ); |
|
2896 + |
|
2897 + |
|
2898 + |
|
2899 + // See the example for other DVB-T demod functions in dvbt_demod_base.h |
|
2900 + |
|
2901 + ... |
|
2902 + |
|
2903 + |
|
2904 + return 0; |
|
2905 +} |
|
2906 + |
|
2907 + |
|
2908 +@endcode |
|
2909 + |
|
2910 +*/ |
|
2911 + |
|
2912 + |
|
2913 +#include "dvbt_demod_base.h" |
|
2914 + |
|
2915 + |
|
2916 + |
|
2917 + |
|
2918 + |
|
2919 +// Definitions |
|
2920 + |
|
2921 +// Initializing |
|
2922 +#define RTL2832_INIT_TABLE_LEN 31 |
|
2923 +#define RTL2832_INIT_TABLE_LEN_WITH_APP_MODE 5 |
|
2924 + |
|
2925 + |
|
2926 +// Bandwidth setting |
|
2927 +#define RTL2832_H_LPF_X_PAGE 1 |
|
2928 +#define RTL2832_H_LPF_X_ADDR 0x1c |
|
2929 +#define RTL2832_H_LPF_X_LEN 32 |
|
2930 +#define RTL2832_RATIO_PAGE 1 |
|
2931 +#define RTL2832_RATIO_ADDR 0x9d |
|
2932 +#define RTL2832_RATIO_LEN 6 |
|
2933 + |
|
2934 + |
|
2935 +// Bandwidth setting |
|
2936 +#define RTL2832_CFREQ_OFF_RATIO_BIT_NUM 20 |
|
2937 + |
|
2938 + |
|
2939 +// IF frequency setting |
|
2940 +#define RTL2832_PSET_IFFREQ_BIT_NUM 22 |
|
2941 + |
|
2942 + |
|
2943 +// Signal quality |
|
2944 +#define RTL2832_SQ_FRAC_BIT_NUM 5 |
|
2945 + |
|
2946 + |
|
2947 +// BER |
|
2948 +#define RTL2832_BER_DEN_VALUE 1000000 |
|
2949 + |
|
2950 + |
|
2951 +// SNR |
|
2952 +#define RTL2832_CE_EST_EVM_MAX_VALUE 65535 |
|
2953 +#define RTL2832_SNR_FRAC_BIT_NUM 10 |
|
2954 +#define RTL2832_SNR_DB_DEN 3402 |
|
2955 + |
|
2956 + |
|
2957 +// AGC |
|
2958 +#define RTL2832_RF_AGC_REG_BIT_NUM 14 |
|
2959 +#define RTL2832_IF_AGC_REG_BIT_NUM 14 |
|
2960 + |
|
2961 + |
|
2962 +// TR offset and CR offset |
|
2963 +#define RTL2832_SFREQ_OFF_BIT_NUM 14 |
|
2964 +#define RTL2832_CFREQ_OFF_BIT_NUM 18 |
|
2965 + |
|
2966 + |
|
2967 +// Register table length |
|
2968 +#define RTL2832_REG_TABLE_LEN 112 |
|
2969 + |
|
2970 + |
|
2971 +// Function 1 |
|
2972 +#define RTL2832_FUNC1_WAIT_TIME_MS 500 |
|
2973 +#define RTL2832_FUNC1_GETTING_TIME_MS 200 |
|
2974 +#define RTL2832_FUNC1_GETTING_NUM_MIN 20 |
|
2975 + |
|
2976 + |
|
2977 + |
|
2978 +/// Demod application modes |
|
2979 +enum RTL2832_APPLICATION_MODE |
|
2980 +{ |
|
2981 + RTL2832_APPLICATION_DONGLE, |
|
2982 + RTL2832_APPLICATION_STB, |
|
2983 +}; |
|
2984 +#define RTL2832_APPLICATION_MODE_NUM 2 |
|
2985 + |
|
2986 + |
|
2987 +// Function 1 |
|
2988 +enum RTL2832_FUNC1_CONFIG_MODE |
|
2989 +{ |
|
2990 + RTL2832_FUNC1_CONFIG_1, |
|
2991 + RTL2832_FUNC1_CONFIG_2, |
|
2992 + RTL2832_FUNC1_CONFIG_3, |
|
2993 +}; |
|
2994 +#define RTL2832_FUNC1_CONFIG_MODE_NUM 3 |
|
2995 +#define RTL2832_FUNC1_CONFIG_NORMAL -1 |
|
2996 + |
|
2997 + |
|
2998 +enum RTL2832_FUNC1_STATE |
|
2999 +{ |
|
3000 + RTL2832_FUNC1_STATE_NORMAL, |
|
3001 + RTL2832_FUNC1_STATE_NORMAL_GET_BER, |
|
3002 + RTL2832_FUNC1_STATE_CONFIG_1_WAIT, |
|
3003 + RTL2832_FUNC1_STATE_CONFIG_1_GET_BER, |
|
3004 + RTL2832_FUNC1_STATE_CONFIG_2_WAIT, |
|
3005 + RTL2832_FUNC1_STATE_CONFIG_2_GET_BER, |
|
3006 + RTL2832_FUNC1_STATE_CONFIG_3_WAIT, |
|
3007 + RTL2832_FUNC1_STATE_CONFIG_3_GET_BER, |
|
3008 + RTL2832_FUNC1_STATE_DETERMINED_WAIT, |
|
3009 + RTL2832_FUNC1_STATE_DETERMINED, |
|
3010 +}; |
|
3011 + |
|
3012 + |
|
3013 + |
|
3014 + |
|
3015 + |
|
3016 +/// RTL2832 extra module |
|
3017 +typedef struct RTL2832_EXTRA_MODULE_TAG RTL2832_EXTRA_MODULE; |
|
3018 + |
|
3019 + |
|
3020 + |
|
3021 + |
|
3022 + |
|
3023 +/* |
|
3024 + |
|
3025 +@brief RTL2832 application mode getting function pointer |
|
3026 + |
|
3027 +One can use RTL2832_FP_GET_APP_MODE() to get RTL2832 application mode. |
|
3028 + |
|
3029 + |
|
3030 +@param [in] pDemod The demod module pointer |
|
3031 +@param [out] pAppMode Pointer to an allocated memory for storing demod application mode |
|
3032 + |
|
3033 + |
|
3034 +@retval FUNCTION_SUCCESS Get demod application mode successfully. |
|
3035 +@retval FUNCTION_ERROR Get demod application mode unsuccessfully. |
|
3036 + |
|
3037 + |
|
3038 +@note |
|
3039 + -# Demod building function will set RTL2832_FP_GET_APP_MODE() with the corresponding function. |
|
3040 + |
|
3041 + |
|
3042 +@see RTL2832_APPLICATION_MODE |
|
3043 + |
|
3044 +*/ |
|
3045 +typedef void |
|
3046 +(*RTL2832_FP_GET_APP_MODE)( |
|
3047 + DVBT_DEMOD_MODULE *pDemod, |
|
3048 + int *pAppMode |
|
3049 + ); |
|
3050 + |
|
3051 + |
|
3052 + |
|
3053 + |
|
3054 + |
|
3055 +struct RTL2832_EXTRA_MODULE_TAG |
|
3056 +{ |
|
3057 + // RTL2832 extra variables |
|
3058 + int AppMode; |
|
3059 + |
|
3060 + // RTL2832 update procedure enabling status |
|
3061 + int IsFunc1Enabled; |
|
3062 + |
|
3063 + // RTL2832 update Function 1 variables |
|
3064 + int Func1State; |
|
3065 + |
|
3066 + int Func1WaitTimeMax; |
|
3067 + int Func1GettingTimeMax; |
|
3068 + int Func1GettingNumEachTime; |
|
3069 + |
|
3070 + int Func1WaitTime; |
|
3071 + int Func1GettingTime; |
|
3072 + |
|
3073 + unsigned long Func1RsdBerEstSumNormal; |
|
3074 + unsigned long Func1RsdBerEstSumConfig1; |
|
3075 + unsigned long Func1RsdBerEstSumConfig2; |
|
3076 + unsigned long Func1RsdBerEstSumConfig3; |
|
3077 + |
|
3078 + int Func1QamBak; |
|
3079 + int Func1HierBak; |
|
3080 + int Func1LpCrBak; |
|
3081 + int Func1HpCrBak; |
|
3082 + int Func1GiBak; |
|
3083 + int Func1FftBak; |
|
3084 + |
|
3085 + |
|
3086 + // RTL2832 extra function pointers |
|
3087 + RTL2832_FP_GET_APP_MODE GetAppMode; |
|
3088 +}; |
|
3089 + |
|
3090 + |
|
3091 + |
|
3092 + |
|
3093 + |
|
3094 +// Demod module builder |
|
3095 +void |
|
3096 +BuildRtl2832Module( |
|
3097 + DVBT_DEMOD_MODULE **ppDemod, |
|
3098 + DVBT_DEMOD_MODULE *pDvbtDemodModuleMemory, |
|
3099 + RTL2832_EXTRA_MODULE *pRtl2832ExtraModuleMemory, |
|
3100 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
3101 + I2C_BRIDGE_MODULE *pI2cBridgeModuleMemory, |
|
3102 + unsigned char DeviceAddr, |
|
3103 + unsigned long CrystalFreqHz, |
|
3104 + int AppMode, |
|
3105 + unsigned long UpdateFuncRefPeriodMs, |
|
3106 + int IsFunc1Enabled |
|
3107 + ); |
|
3108 + |
|
3109 + |
|
3110 + |
|
3111 + |
|
3112 + |
|
3113 +// Manipulating functions |
|
3114 +void |
|
3115 +rtl2832_IsConnectedToI2c( |
|
3116 + DVBT_DEMOD_MODULE *pDemod, |
|
3117 + int *pAnswer |
|
3118 +); |
|
3119 + |
|
3120 +int |
|
3121 +rtl2832_SoftwareReset( |
|
3122 + DVBT_DEMOD_MODULE *pDemod |
|
3123 + ); |
|
3124 + |
|
3125 +int |
|
3126 +rtl2832_Initialize( |
|
3127 + DVBT_DEMOD_MODULE *pDemod |
|
3128 + ); |
|
3129 + |
|
3130 +int |
|
3131 +rtl2832_SetBandwidthMode( |
|
3132 + DVBT_DEMOD_MODULE *pDemod, |
|
3133 + int BandwidthMode |
|
3134 + ); |
|
3135 + |
|
3136 +int |
|
3137 +rtl2832_SetIfFreqHz( |
|
3138 + DVBT_DEMOD_MODULE *pDemod, |
|
3139 + unsigned long IfFreqHz |
|
3140 + ); |
|
3141 + |
|
3142 +int |
|
3143 +rtl2832_SetSpectrumMode( |
|
3144 + DVBT_DEMOD_MODULE *pDemod, |
|
3145 + int SpectrumMode |
|
3146 + ); |
|
3147 + |
|
3148 +int |
|
3149 +rtl2832_IsTpsLocked( |
|
3150 + DVBT_DEMOD_MODULE *pDemod, |
|
3151 + int *pAnswer |
|
3152 + ); |
|
3153 + |
|
3154 +int |
|
3155 +rtl2832_IsSignalLocked( |
|
3156 + DVBT_DEMOD_MODULE *pDemod, |
|
3157 + int *pAnswer |
|
3158 + ); |
|
3159 + |
|
3160 +int |
|
3161 +rtl2832_GetSignalStrength( |
|
3162 + DVBT_DEMOD_MODULE *pDemod, |
|
3163 + unsigned long *pSignalStrength |
|
3164 + ); |
|
3165 + |
|
3166 +int |
|
3167 +rtl2832_GetSignalQuality( |
|
3168 + DVBT_DEMOD_MODULE *pDemod, |
|
3169 + unsigned long *pSignalQuality |
|
3170 + ); |
|
3171 + |
|
3172 +int |
|
3173 +rtl2832_GetBer( |
|
3174 + DVBT_DEMOD_MODULE *pDemod, |
|
3175 + unsigned long *pBerNum, |
|
3176 + unsigned long *pBerDen |
|
3177 + ); |
|
3178 + |
|
3179 +int |
|
3180 +rtl2832_GetSnrDb( |
|
3181 + DVBT_DEMOD_MODULE *pDemod, |
|
3182 + long *pSnrDbNum, |
|
3183 + long *pSnrDbDen |
|
3184 + ); |
|
3185 + |
|
3186 +int |
|
3187 +rtl2832_GetRfAgc( |
|
3188 + DVBT_DEMOD_MODULE *pDemod, |
|
3189 + int *pRfAgc |
|
3190 + ); |
|
3191 + |
|
3192 +int |
|
3193 +rtl2832_GetIfAgc( |
|
3194 + DVBT_DEMOD_MODULE *pDemod, |
|
3195 + int *pIfAgc |
|
3196 + ); |
|
3197 + |
|
3198 +int |
|
3199 +rtl2832_GetDiAgc( |
|
3200 + DVBT_DEMOD_MODULE *pDemod, |
|
3201 + unsigned char *pDiAgc |
|
3202 + ); |
|
3203 + |
|
3204 +int |
|
3205 +rtl2832_GetTrOffsetPpm( |
|
3206 + DVBT_DEMOD_MODULE *pDemod, |
|
3207 + long *pTrOffsetPpm |
|
3208 + ); |
|
3209 + |
|
3210 +int |
|
3211 +rtl2832_GetCrOffsetHz( |
|
3212 + DVBT_DEMOD_MODULE *pDemod, |
|
3213 + long *pCrOffsetHz |
|
3214 + ); |
|
3215 + |
|
3216 +int |
|
3217 +rtl2832_GetConstellation( |
|
3218 + DVBT_DEMOD_MODULE *pDemod, |
|
3219 + int *pConstellation |
|
3220 + ); |
|
3221 + |
|
3222 +int |
|
3223 +rtl2832_GetHierarchy( |
|
3224 + DVBT_DEMOD_MODULE *pDemod, |
|
3225 + int *pHierarchy |
|
3226 + ); |
|
3227 + |
|
3228 +int |
|
3229 +rtl2832_GetCodeRateLp( |
|
3230 + DVBT_DEMOD_MODULE *pDemod, |
|
3231 + int *pCodeRateLp |
|
3232 + ); |
|
3233 + |
|
3234 +int |
|
3235 +rtl2832_GetCodeRateHp( |
|
3236 + DVBT_DEMOD_MODULE *pDemod, |
|
3237 + int *pCodeRateHp |
|
3238 + ); |
|
3239 + |
|
3240 +int |
|
3241 +rtl2832_GetGuardInterval( |
|
3242 + DVBT_DEMOD_MODULE *pDemod, |
|
3243 + int *pGuardInterval |
|
3244 + ); |
|
3245 + |
|
3246 +int |
|
3247 +rtl2832_GetFftMode( |
|
3248 + DVBT_DEMOD_MODULE *pDemod, |
|
3249 + int *pFftMode |
|
3250 + ); |
|
3251 + |
|
3252 +int |
|
3253 +rtl2832_UpdateFunction( |
|
3254 + DVBT_DEMOD_MODULE *pDemod |
|
3255 + ); |
|
3256 + |
|
3257 +int |
|
3258 +rtl2832_ResetFunction( |
|
3259 + DVBT_DEMOD_MODULE *pDemod |
|
3260 + ); |
|
3261 + |
|
3262 + |
|
3263 + |
|
3264 + |
|
3265 + |
|
3266 +// I2C command forwarding functions |
|
3267 +int |
|
3268 +rtl2832_ForwardI2cReadingCmd( |
|
3269 + I2C_BRIDGE_MODULE *pI2cBridge, |
|
3270 + unsigned char *pReadingBytes, |
|
3271 + unsigned char ByteNum |
|
3272 + ); |
|
3273 + |
|
3274 +int |
|
3275 +rtl2832_ForwardI2cWritingCmd( |
|
3276 + I2C_BRIDGE_MODULE *pI2cBridge, |
|
3277 + const unsigned char *pWritingBytes, |
|
3278 + unsigned char ByteNum |
|
3279 + ); |
|
3280 + |
|
3281 + |
|
3282 + |
|
3283 + |
|
3284 + |
|
3285 +// Register table initializing |
|
3286 +void |
|
3287 +rtl2832_InitRegTable( |
|
3288 + DVBT_DEMOD_MODULE *pDemod |
|
3289 + ); |
|
3290 + |
|
3291 + |
|
3292 + |
|
3293 + |
|
3294 + |
|
3295 +// I2C birdge module demod argument setting |
|
3296 +void |
|
3297 +rtl2832_SetI2cBridgeModuleDemodArg( |
|
3298 + DVBT_DEMOD_MODULE *pDemod |
|
3299 + ); |
|
3300 + |
|
3301 + |
|
3302 + |
|
3303 + |
|
3304 + |
|
3305 +// RTL2832 extra functions |
|
3306 +void |
|
3307 +rtl2832_GetAppMode( |
|
3308 + DVBT_DEMOD_MODULE *pDemod, |
|
3309 + int *pAppMode |
|
3310 + ); |
|
3311 + |
|
3312 + |
|
3313 + |
|
3314 + |
|
3315 + |
|
3316 +// RTL2832 dependence |
|
3317 +int |
|
3318 +rtl2832_func1_Reset( |
|
3319 + DVBT_DEMOD_MODULE *pDemod |
|
3320 + ); |
|
3321 + |
|
3322 +int |
|
3323 +rtl2832_func1_Update( |
|
3324 + DVBT_DEMOD_MODULE *pDemod |
|
3325 + ); |
|
3326 + |
|
3327 +int |
|
3328 +rtl2832_func1_IsCriterionMatched( |
|
3329 + DVBT_DEMOD_MODULE *pDemod, |
|
3330 + int *pAnswer |
|
3331 + ); |
|
3332 + |
|
3333 +int |
|
3334 +rtl2832_func1_AccumulateRsdBerEst( |
|
3335 + DVBT_DEMOD_MODULE *pDemod, |
|
3336 + unsigned long *pAccumulativeValue |
|
3337 + ); |
|
3338 + |
|
3339 +int |
|
3340 +rtl2832_func1_ResetReg( |
|
3341 + DVBT_DEMOD_MODULE *pDemod |
|
3342 + ); |
|
3343 + |
|
3344 +int |
|
3345 +rtl2832_func1_SetCommonReg( |
|
3346 + DVBT_DEMOD_MODULE *pDemod |
|
3347 + ); |
|
3348 + |
|
3349 +int |
|
3350 +rtl2832_func1_SetRegWithFftMode( |
|
3351 + DVBT_DEMOD_MODULE *pDemod, |
|
3352 + int FftMode |
|
3353 + ); |
|
3354 + |
|
3355 +int |
|
3356 +rtl2832_func1_SetRegWithConfigMode( |
|
3357 + DVBT_DEMOD_MODULE *pDemod, |
|
3358 + int ConfigMode |
|
3359 + ); |
|
3360 + |
|
3361 +void |
|
3362 +rtl2832_func1_GetMinWeightedBerConfigMode( |
|
3363 + DVBT_DEMOD_MODULE *pDemod, |
|
3364 + int *pConfigMode |
|
3365 + ); |
|
3366 + |
|
3367 + |
|
3368 + |
|
3369 + |
|
3370 + |
|
3371 + |
|
3372 + |
|
3373 + |
|
3374 + |
|
3375 + |
|
3376 + |
|
3377 + |
|
3378 + |
|
3379 + |
|
3380 + |
|
3381 + |
|
3382 +#endif |
|
3383 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/dvbt_demod_base.c |
|
3384 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
3385 +++ b/linux/drivers/media/dvb/dvb-usb/dvbt_demod_base.c Wed Oct 27 09:16:44 2010 +0200 |
|
3386 @@ -0,0 +1,689 @@ |
|
3387 +/** |
|
3388 + |
|
3389 +@file |
|
3390 + |
|
3391 +@brief DVB-T demod default function definition |
|
3392 + |
|
3393 +DVB-T demod default functions. |
|
3394 + |
|
3395 +*/ |
|
3396 + |
|
3397 +#include "dvbt_demod_base.h" |
|
3398 + |
|
3399 + |
|
3400 + |
|
3401 + |
|
3402 + |
|
3403 +/** |
|
3404 + |
|
3405 +@see DVBT_DEMOD_FP_SET_REG_PAGE |
|
3406 + |
|
3407 +*/ |
|
3408 +int |
|
3409 +dvbt_demod_default_SetRegPage( |
|
3410 + DVBT_DEMOD_MODULE *pDemod, |
|
3411 + unsigned long PageNo |
|
3412 + ) |
|
3413 +{ |
|
3414 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
3415 + |
|
3416 + struct dvb_usb_device *d; |
|
3417 + |
|
3418 + // Get base interface. |
|
3419 + pBaseInterface = pDemod->pBaseInterface; |
|
3420 + |
|
3421 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); //add by chialing |
|
3422 + |
|
3423 + if( mutex_lock_interruptible(&d->usb_mutex) ) goto error; |
|
3424 + |
|
3425 + pDemod->PageNo = PageNo; |
|
3426 + |
|
3427 + mutex_unlock(&d->usb_mutex); |
|
3428 + |
|
3429 + return FUNCTION_SUCCESS; |
|
3430 + |
|
3431 +error: |
|
3432 + return FUNCTION_ERROR; |
|
3433 +} |
|
3434 + |
|
3435 + |
|
3436 + |
|
3437 + |
|
3438 + |
|
3439 +/** |
|
3440 + |
|
3441 +@see DVBT_DEMOD_FP_SET_REG_BYTES |
|
3442 + |
|
3443 +*/ |
|
3444 +int |
|
3445 +dvbt_demod_default_SetRegBytes( |
|
3446 + DVBT_DEMOD_MODULE *pDemod, |
|
3447 + unsigned char RegStartAddr, |
|
3448 + const unsigned char *pWritingBytes, |
|
3449 + unsigned char ByteNum |
|
3450 + ) |
|
3451 +{ |
|
3452 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
3453 + |
|
3454 + unsigned int i, j; |
|
3455 + |
|
3456 + unsigned char DeviceAddr; |
|
3457 + unsigned char WritingBuffer[I2C_BUFFER_LEN]; |
|
3458 + unsigned char WritingByteNum, WritingByteNumMax, WritingByteNumRem; |
|
3459 + unsigned char RegWritingAddr; |
|
3460 + |
|
3461 + struct dvb_usb_device *d; |
|
3462 + |
|
3463 + // Get base interface. |
|
3464 + pBaseInterface = pDemod->pBaseInterface; |
|
3465 + |
|
3466 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); //add by chialing |
|
3467 + |
|
3468 + // Get demod I2C device address. |
|
3469 + pDemod->GetDeviceAddr(pDemod, &DeviceAddr); |
|
3470 + |
|
3471 + |
|
3472 + // Calculate maximum writing byte number. |
|
3473 + WritingByteNumMax = pBaseInterface->I2cWritingByteNumMax - LEN_1_BYTE; |
|
3474 + |
|
3475 + |
|
3476 + // Set demod register bytes with writing bytes. |
|
3477 + // Note: Set demod register bytes considering maximum writing byte number. |
|
3478 + for(i = 0; i < ByteNum; i += WritingByteNumMax) |
|
3479 + { |
|
3480 + // Set register writing address. |
|
3481 + RegWritingAddr = RegStartAddr + i; |
|
3482 + |
|
3483 + // Calculate remainder writing byte number. |
|
3484 + WritingByteNumRem = ByteNum - i; |
|
3485 + |
|
3486 + // Determine writing byte number. |
|
3487 + WritingByteNum = (WritingByteNumRem > WritingByteNumMax) ? WritingByteNumMax : WritingByteNumRem; |
|
3488 + |
|
3489 + |
|
3490 + // Set writing buffer. |
|
3491 + // Note: The I2C format of demod register byte setting is as follows: |
|
3492 + // start_bit + (DeviceAddr | writing_bit) + RegWritingAddr + writing_bytes (WritingByteNum bytes) + stop_bit |
|
3493 +// WritingBuffer[0] = RegWritingAddr; |
|
3494 + |
|
3495 + for(j = 0; j < WritingByteNum; j++) |
|
3496 +// WritingBuffer[LEN_1_BYTE + j] = pWritingBytes[i + j]; |
|
3497 + WritingBuffer[j] = pWritingBytes[i + j]; |
|
3498 + |
|
3499 + // Set demod register bytes with writing buffer. |
|
3500 +// if(pBaseInterface->I2cWrite(pBaseInterface, DeviceAddr, WritingBuffer, WritingByteNum + LEN_1_BYTE) != |
|
3501 +// FUNCTION_SUCCESS) |
|
3502 +// goto error_status_set_demod_registers; |
|
3503 + |
|
3504 + if(write_rtl2832_demod_register( d, DeviceAddr, pDemod->PageNo, RegWritingAddr, WritingBuffer, WritingByteNum )) goto error; |
|
3505 + |
|
3506 + |
|
3507 + } |
|
3508 + |
|
3509 + |
|
3510 + return FUNCTION_SUCCESS; |
|
3511 +error: |
|
3512 + return FUNCTION_ERROR; |
|
3513 +} |
|
3514 + |
|
3515 + |
|
3516 + |
|
3517 + |
|
3518 + |
|
3519 +/** |
|
3520 + |
|
3521 +@see DVBT_DEMOD_FP_GET_REG_BYTES |
|
3522 + |
|
3523 +*/ |
|
3524 +int |
|
3525 +dvbt_demod_default_GetRegBytes( |
|
3526 + DVBT_DEMOD_MODULE *pDemod, |
|
3527 + unsigned char RegStartAddr, |
|
3528 + unsigned char *pReadingBytes, |
|
3529 + unsigned char ByteNum |
|
3530 + ) |
|
3531 +{ |
|
3532 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
3533 + |
|
3534 + unsigned int i; |
|
3535 + unsigned char DeviceAddr; |
|
3536 + unsigned char ReadingByteNum, ReadingByteNumMax, ReadingByteNumRem; |
|
3537 + unsigned char RegReadingAddr; |
|
3538 + |
|
3539 + struct dvb_usb_device *d; |
|
3540 + |
|
3541 + // Get base interface. |
|
3542 + pBaseInterface = pDemod->pBaseInterface; |
|
3543 + |
|
3544 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); //add by chialing |
|
3545 + |
|
3546 + // Get demod I2C device address. |
|
3547 + pDemod->GetDeviceAddr(pDemod, &DeviceAddr); |
|
3548 + |
|
3549 + |
|
3550 + // Calculate maximum reading byte number. |
|
3551 + ReadingByteNumMax = pBaseInterface->I2cReadingByteNumMax; |
|
3552 + |
|
3553 + |
|
3554 + // Get demod register bytes. |
|
3555 + // Note: Get demod register bytes considering maximum reading byte number. |
|
3556 + for(i = 0; i < ByteNum; i += ReadingByteNumMax) |
|
3557 + { |
|
3558 + // Set register reading address. |
|
3559 + RegReadingAddr = RegStartAddr + i; |
|
3560 + |
|
3561 + // Calculate remainder reading byte number. |
|
3562 + ReadingByteNumRem = ByteNum - i; |
|
3563 + |
|
3564 + // Determine reading byte number. |
|
3565 + ReadingByteNum = (ReadingByteNumRem > ReadingByteNumMax) ? ReadingByteNumMax : ReadingByteNumRem; |
|
3566 + |
|
3567 + |
|
3568 + // Set demod register reading address. |
|
3569 + // Note: The I2C format of demod register reading address setting is as follows: |
|
3570 + // start_bit + (DeviceAddr | writing_bit) + RegReadingAddr + stop_bit |
|
3571 +// if(pBaseInterface->I2cWrite(pBaseInterface, DeviceAddr, &RegReadingAddr, LEN_1_BYTE) != FUNCTION_SUCCESS) |
|
3572 +// goto error_status_set_demod_register_reading_address; |
|
3573 + |
|
3574 + // Get demod register bytes. |
|
3575 + // Note: The I2C format of demod register byte getting is as follows: |
|
3576 + // start_bit + (DeviceAddr | reading_bit) + reading_bytes (ReadingByteNum bytes) + stop_bit |
|
3577 +// if(pBaseInterface->I2cRead(pBaseInterface, DeviceAddr, &pReadingBytes[i], ReadingByteNum) != FUNCTION_SUCCESS) |
|
3578 +// goto error_status_get_demod_registers; |
|
3579 + |
|
3580 + |
|
3581 + if(read_rtl2832_demod_register(d, DeviceAddr, pDemod->PageNo, RegReadingAddr, &pReadingBytes[i], ReadingByteNum)) goto error; |
|
3582 + |
|
3583 + } |
|
3584 + |
|
3585 + |
|
3586 + return FUNCTION_SUCCESS; |
|
3587 + |
|
3588 +error: |
|
3589 + return FUNCTION_ERROR; |
|
3590 +} |
|
3591 + |
|
3592 + |
|
3593 + |
|
3594 + |
|
3595 + |
|
3596 +/** |
|
3597 + |
|
3598 +@see DVBT_DEMOD_FP_SET_REG_MASK_BITS |
|
3599 + |
|
3600 +*/ |
|
3601 +int |
|
3602 +dvbt_demod_default_SetRegMaskBits( |
|
3603 + DVBT_DEMOD_MODULE *pDemod, |
|
3604 + unsigned char RegStartAddr, |
|
3605 + unsigned char Msb, |
|
3606 + unsigned char Lsb, |
|
3607 + const unsigned long WritingValue |
|
3608 + ) |
|
3609 +{ |
|
3610 + int i; |
|
3611 + |
|
3612 + unsigned char ReadingBytes[LEN_4_BYTE]; |
|
3613 + unsigned char WritingBytes[LEN_4_BYTE]; |
|
3614 + |
|
3615 + unsigned char ByteNum; |
|
3616 + unsigned long Mask; |
|
3617 + unsigned char Shift; |
|
3618 + |
|
3619 + unsigned long Value; |
|
3620 + |
|
3621 + |
|
3622 + // Calculate writing byte number according to MSB. |
|
3623 + ByteNum = Msb / BYTE_BIT_NUM + LEN_1_BYTE; |
|
3624 + |
|
3625 + |
|
3626 + // Generate mask and shift according to MSB and LSB. |
|
3627 + Mask = 0; |
|
3628 + |
|
3629 + for(i = Lsb; i < (unsigned char)(Msb + 1); i++) |
|
3630 + Mask |= 0x1 << i; |
|
3631 + |
|
3632 + Shift = Lsb; |
|
3633 + |
|
3634 + |
|
3635 + // Get demod register bytes according to register start adddress and byte number. |
|
3636 + if(pDemod->GetRegBytes(pDemod, RegStartAddr, ReadingBytes, ByteNum) != FUNCTION_SUCCESS) |
|
3637 + goto error_status_get_demod_registers; |
|
3638 + |
|
3639 + |
|
3640 + // Combine reading bytes into an unsigned integer value. |
|
3641 + // Note: Put lower address byte on value MSB. |
|
3642 + // Put upper address byte on value LSB. |
|
3643 + Value = 0; |
|
3644 + |
|
3645 + for(i = 0; i < ByteNum; i++) |
|
3646 + Value |= (unsigned long)ReadingBytes[i] << (BYTE_SHIFT * (ByteNum - i -1)); |
|
3647 + |
|
3648 + |
|
3649 + // Reserve unsigned integer value unmask bit with mask and inlay writing value into it. |
|
3650 + Value &= ~Mask; |
|
3651 + Value |= (WritingValue << Shift) & Mask; |
|
3652 + |
|
3653 + |
|
3654 + // Separate unsigned integer value into writing bytes. |
|
3655 + // Note: Pick up lower address byte from value MSB. |
|
3656 + // Pick up upper address byte from value LSB. |
|
3657 + for(i = 0; i < ByteNum; i++) |
|
3658 + WritingBytes[i] = (unsigned char)((Value >> (BYTE_SHIFT * (ByteNum - i -1))) & BYTE_MASK); |
|
3659 + |
|
3660 + |
|
3661 + // Write demod register bytes with writing bytes. |
|
3662 + if(pDemod->SetRegBytes(pDemod, RegStartAddr, WritingBytes, ByteNum) != FUNCTION_SUCCESS) |
|
3663 + goto error_status_set_demod_registers; |
|
3664 + |
|
3665 + |
|
3666 + return FUNCTION_SUCCESS; |
|
3667 + |
|
3668 + |
|
3669 +error_status_get_demod_registers: |
|
3670 +error_status_set_demod_registers: |
|
3671 + return FUNCTION_ERROR; |
|
3672 +} |
|
3673 + |
|
3674 + |
|
3675 + |
|
3676 + |
|
3677 + |
|
3678 +/** |
|
3679 + |
|
3680 +@see DVBT_DEMOD_FP_GET_REG_MASK_BITS |
|
3681 + |
|
3682 +*/ |
|
3683 +int |
|
3684 +dvbt_demod_default_GetRegMaskBits( |
|
3685 + DVBT_DEMOD_MODULE *pDemod, |
|
3686 + unsigned char RegStartAddr, |
|
3687 + unsigned char Msb, |
|
3688 + unsigned char Lsb, |
|
3689 + unsigned long *pReadingValue |
|
3690 + ) |
|
3691 +{ |
|
3692 + int i; |
|
3693 + |
|
3694 + unsigned char ReadingBytes[LEN_4_BYTE]; |
|
3695 + |
|
3696 + unsigned char ByteNum; |
|
3697 + unsigned long Mask; |
|
3698 + unsigned char Shift; |
|
3699 + |
|
3700 + unsigned long Value; |
|
3701 + |
|
3702 + |
|
3703 + // Calculate writing byte number according to MSB. |
|
3704 + ByteNum = Msb / BYTE_BIT_NUM + LEN_1_BYTE; |
|
3705 + |
|
3706 + |
|
3707 + // Generate mask and shift according to MSB and LSB. |
|
3708 + Mask = 0; |
|
3709 + |
|
3710 + for(i = Lsb; i < (unsigned char)(Msb + 1); i++) |
|
3711 + Mask |= 0x1 << i; |
|
3712 + |
|
3713 + Shift = Lsb; |
|
3714 + |
|
3715 + |
|
3716 + // Get demod register bytes according to register start adddress and byte number. |
|
3717 + if(pDemod->GetRegBytes(pDemod, RegStartAddr, ReadingBytes, ByteNum) != FUNCTION_SUCCESS) |
|
3718 + goto error_status_get_demod_registers; |
|
3719 + |
|
3720 + |
|
3721 + // Combine reading bytes into an unsigned integer value. |
|
3722 + // Note: Put lower address byte on value MSB. |
|
3723 + // Put upper address byte on value LSB. |
|
3724 + Value = 0; |
|
3725 + |
|
3726 + for(i = 0; i < ByteNum; i++) |
|
3727 + Value |= (unsigned long)ReadingBytes[i] << (BYTE_SHIFT * (ByteNum - i -1)); |
|
3728 + |
|
3729 + |
|
3730 + // Get register bits from unsigned integaer value with mask and shift |
|
3731 + *pReadingValue = (Value & Mask) >> Shift; |
|
3732 + |
|
3733 + |
|
3734 + return FUNCTION_SUCCESS; |
|
3735 + |
|
3736 + |
|
3737 +error_status_get_demod_registers: |
|
3738 + return FUNCTION_ERROR; |
|
3739 +} |
|
3740 + |
|
3741 + |
|
3742 + |
|
3743 + |
|
3744 + |
|
3745 +/** |
|
3746 + |
|
3747 +@see DVBT_DEMOD_FP_SET_REG_BITS |
|
3748 + |
|
3749 +*/ |
|
3750 +int |
|
3751 +dvbt_demod_default_SetRegBits( |
|
3752 + DVBT_DEMOD_MODULE *pDemod, |
|
3753 + int RegBitName, |
|
3754 + const unsigned long WritingValue |
|
3755 + ) |
|
3756 +{ |
|
3757 + unsigned char RegStartAddr; |
|
3758 + unsigned char Msb; |
|
3759 + unsigned char Lsb; |
|
3760 + |
|
3761 + |
|
3762 + // Check if register bit name is available. |
|
3763 + if(pDemod->RegTable[RegBitName].IsAvailable == NO) |
|
3764 + goto error_status_register_bit_name; |
|
3765 + |
|
3766 + |
|
3767 + // Get register start address, MSB, and LSB from register table with register bit name key. |
|
3768 + RegStartAddr = pDemod->RegTable[RegBitName].RegStartAddr; |
|
3769 + Msb = pDemod->RegTable[RegBitName].Msb; |
|
3770 + Lsb = pDemod->RegTable[RegBitName].Lsb; |
|
3771 + |
|
3772 + |
|
3773 + // Set register mask bits. |
|
3774 + if(pDemod->SetRegMaskBits(pDemod, RegStartAddr, Msb, Lsb, WritingValue) != FUNCTION_SUCCESS) |
|
3775 + goto error_status_set_demod_registers; |
|
3776 + |
|
3777 + |
|
3778 + return FUNCTION_SUCCESS; |
|
3779 + |
|
3780 + |
|
3781 +error_status_register_bit_name: |
|
3782 +error_status_set_demod_registers: |
|
3783 + return FUNCTION_ERROR; |
|
3784 +} |
|
3785 + |
|
3786 + |
|
3787 + |
|
3788 + |
|
3789 + |
|
3790 +/** |
|
3791 + |
|
3792 +@see DVBT_DEMOD_FP_GET_REG_BITS |
|
3793 + |
|
3794 +*/ |
|
3795 +int |
|
3796 +dvbt_demod_default_GetRegBits( |
|
3797 + DVBT_DEMOD_MODULE *pDemod, |
|
3798 + int RegBitName, |
|
3799 + unsigned long *pReadingValue |
|
3800 + ) |
|
3801 +{ |
|
3802 + unsigned char RegStartAddr; |
|
3803 + unsigned char Msb; |
|
3804 + unsigned char Lsb; |
|
3805 + |
|
3806 + |
|
3807 + // Check if register bit name is available. |
|
3808 + if(pDemod->RegTable[RegBitName].IsAvailable == NO) |
|
3809 + goto error_status_register_bit_name; |
|
3810 + |
|
3811 + |
|
3812 + // Get register start address, MSB, and LSB from register table with register bit name key. |
|
3813 + RegStartAddr = pDemod->RegTable[RegBitName].RegStartAddr; |
|
3814 + Msb = pDemod->RegTable[RegBitName].Msb; |
|
3815 + Lsb = pDemod->RegTable[RegBitName].Lsb; |
|
3816 + |
|
3817 + |
|
3818 + // Get register mask bits. |
|
3819 + if(pDemod->GetRegMaskBits(pDemod, RegStartAddr, Msb, Lsb, pReadingValue) != FUNCTION_SUCCESS) |
|
3820 + goto error_status_get_demod_registers; |
|
3821 + |
|
3822 + |
|
3823 + return FUNCTION_SUCCESS; |
|
3824 + |
|
3825 + |
|
3826 +error_status_register_bit_name: |
|
3827 +error_status_get_demod_registers: |
|
3828 + return FUNCTION_ERROR; |
|
3829 +} |
|
3830 + |
|
3831 + |
|
3832 + |
|
3833 + |
|
3834 + |
|
3835 +/** |
|
3836 + |
|
3837 +@see DVBT_DEMOD_FP_SET_REG_BITS_WITH_PAGE |
|
3838 + |
|
3839 +*/ |
|
3840 +int |
|
3841 +dvbt_demod_default_SetRegBitsWithPage( |
|
3842 + DVBT_DEMOD_MODULE *pDemod, |
|
3843 + int RegBitName, |
|
3844 + const unsigned long WritingValue |
|
3845 + ) |
|
3846 +{ |
|
3847 + unsigned long PageNo; |
|
3848 + |
|
3849 + |
|
3850 + // Get register page number from register table with register bit name key. |
|
3851 + PageNo = pDemod->RegTable[RegBitName].PageNo; |
|
3852 + |
|
3853 + |
|
3854 + // Set register page number. |
|
3855 + if(pDemod->SetRegPage(pDemod, PageNo) != FUNCTION_SUCCESS) |
|
3856 + goto error_status_set_demod_registers; |
|
3857 + |
|
3858 + |
|
3859 + // Set register mask bits with register bit name key. |
|
3860 + if(pDemod->SetRegBits(pDemod, RegBitName, WritingValue) != FUNCTION_SUCCESS) |
|
3861 + goto error_status_set_demod_registers; |
|
3862 + |
|
3863 + |
|
3864 + return FUNCTION_SUCCESS; |
|
3865 + |
|
3866 + |
|
3867 +error_status_set_demod_registers: |
|
3868 + return FUNCTION_ERROR; |
|
3869 +} |
|
3870 + |
|
3871 + |
|
3872 + |
|
3873 + |
|
3874 + |
|
3875 +/** |
|
3876 + |
|
3877 +@see DVBT_DEMOD_FP_GET_REG_BITS_WITH_PAGE |
|
3878 + |
|
3879 +*/ |
|
3880 +int |
|
3881 +dvbt_demod_default_GetRegBitsWithPage( |
|
3882 + DVBT_DEMOD_MODULE *pDemod, |
|
3883 + int RegBitName, |
|
3884 + unsigned long *pReadingValue |
|
3885 + ) |
|
3886 +{ |
|
3887 + unsigned long PageNo; |
|
3888 + |
|
3889 + |
|
3890 + // Get register page number from register table with register bit name key. |
|
3891 + PageNo = pDemod->RegTable[RegBitName].PageNo; |
|
3892 + |
|
3893 + |
|
3894 + // Set register page number. |
|
3895 + if(pDemod->SetRegPage(pDemod, PageNo) != FUNCTION_SUCCESS) |
|
3896 + goto error_status_set_demod_registers; |
|
3897 + |
|
3898 + |
|
3899 + // Get register mask bits with register bit name key. |
|
3900 + if(pDemod->GetRegBits(pDemod, RegBitName, pReadingValue) != FUNCTION_SUCCESS) |
|
3901 + goto error_status_get_demod_registers; |
|
3902 + |
|
3903 + |
|
3904 + return FUNCTION_SUCCESS; |
|
3905 + |
|
3906 + |
|
3907 +error_status_set_demod_registers: |
|
3908 +error_status_get_demod_registers: |
|
3909 + return FUNCTION_ERROR; |
|
3910 +} |
|
3911 + |
|
3912 + |
|
3913 + |
|
3914 + |
|
3915 + |
|
3916 +/** |
|
3917 + |
|
3918 +@see DVBT_DEMOD_FP_GET_DEMOD_TYPE |
|
3919 + |
|
3920 +*/ |
|
3921 +void |
|
3922 +dvbt_demod_default_GetDemodType( |
|
3923 + DVBT_DEMOD_MODULE *pDemod, |
|
3924 + int *pDemodType |
|
3925 + ) |
|
3926 +{ |
|
3927 + // Get demod type from demod module. |
|
3928 + *pDemodType = pDemod->DemodType; |
|
3929 + |
|
3930 + |
|
3931 + return; |
|
3932 +} |
|
3933 + |
|
3934 + |
|
3935 + |
|
3936 + |
|
3937 + |
|
3938 +/** |
|
3939 + |
|
3940 +@see DVBT_DEMOD_FP_GET_DEVICE_ADDR |
|
3941 + |
|
3942 +*/ |
|
3943 +void |
|
3944 +dvbt_demod_default_GetDeviceAddr( |
|
3945 + DVBT_DEMOD_MODULE *pDemod, |
|
3946 + unsigned char *pDeviceAddr |
|
3947 + ) |
|
3948 +{ |
|
3949 + // Get demod I2C device address from demod module. |
|
3950 + *pDeviceAddr = pDemod->DeviceAddr; |
|
3951 + |
|
3952 + |
|
3953 + return; |
|
3954 +} |
|
3955 + |
|
3956 + |
|
3957 + |
|
3958 + |
|
3959 + |
|
3960 +/** |
|
3961 + |
|
3962 +@see DVBT_DEMOD_FP_GET_CRYSTAL_FREQ_HZ |
|
3963 + |
|
3964 +*/ |
|
3965 +void |
|
3966 +dvbt_demod_default_GetCrystalFreqHz( |
|
3967 + DVBT_DEMOD_MODULE *pDemod, |
|
3968 + unsigned long *pCrystalFreqHz |
|
3969 + ) |
|
3970 +{ |
|
3971 + // Get demod crystal frequency in Hz from demod module. |
|
3972 + *pCrystalFreqHz = pDemod->CrystalFreqHz; |
|
3973 + |
|
3974 + |
|
3975 + return; |
|
3976 +} |
|
3977 + |
|
3978 + |
|
3979 + |
|
3980 + |
|
3981 + |
|
3982 +/** |
|
3983 + |
|
3984 +@see DVBT_DEMOD_FP_GET_BANDWIDTH_MODE |
|
3985 + |
|
3986 +*/ |
|
3987 +int |
|
3988 +dvbt_demod_default_GetBandwidthMode( |
|
3989 + DVBT_DEMOD_MODULE *pDemod, |
|
3990 + int *pBandwidthMode |
|
3991 + ) |
|
3992 +{ |
|
3993 + // Get demod bandwidth mode from demod module. |
|
3994 + if(pDemod->IsBandwidthModeSet != YES) |
|
3995 + goto error_status_get_demod_bandwidth_mode; |
|
3996 + |
|
3997 + *pBandwidthMode = pDemod->BandwidthMode; |
|
3998 + |
|
3999 + |
|
4000 + return FUNCTION_SUCCESS; |
|
4001 + |
|
4002 + |
|
4003 +error_status_get_demod_bandwidth_mode: |
|
4004 + return FUNCTION_ERROR; |
|
4005 +} |
|
4006 + |
|
4007 + |
|
4008 + |
|
4009 + |
|
4010 + |
|
4011 +/** |
|
4012 + |
|
4013 +@see DVBT_DEMOD_FP_GET_IF_FREQ_HZ |
|
4014 + |
|
4015 +*/ |
|
4016 +int |
|
4017 +dvbt_demod_default_GetIfFreqHz( |
|
4018 + DVBT_DEMOD_MODULE *pDemod, |
|
4019 + unsigned long *pIfFreqHz |
|
4020 + ) |
|
4021 +{ |
|
4022 + // Get demod IF frequency in Hz from demod module. |
|
4023 + if(pDemod->IsIfFreqHzSet != YES) |
|
4024 + goto error_status_get_demod_if_frequency; |
|
4025 + |
|
4026 + *pIfFreqHz = pDemod->IfFreqHz; |
|
4027 + |
|
4028 + |
|
4029 + return FUNCTION_SUCCESS; |
|
4030 + |
|
4031 + |
|
4032 +error_status_get_demod_if_frequency: |
|
4033 + return FUNCTION_ERROR; |
|
4034 +} |
|
4035 + |
|
4036 + |
|
4037 + |
|
4038 + |
|
4039 + |
|
4040 +/** |
|
4041 + |
|
4042 +@see DVBT_DEMOD_FP_GET_SPECTRUM_MODE |
|
4043 + |
|
4044 +*/ |
|
4045 +int |
|
4046 +dvbt_demod_default_GetSpectrumMode( |
|
4047 + DVBT_DEMOD_MODULE *pDemod, |
|
4048 + int *pSpectrumMode |
|
4049 + ) |
|
4050 +{ |
|
4051 + // Get demod spectrum mode from demod module. |
|
4052 + if(pDemod->IsSpectrumModeSet != YES) |
|
4053 + goto error_status_get_demod_spectrum_mode; |
|
4054 + |
|
4055 + *pSpectrumMode = pDemod->SpectrumMode; |
|
4056 + |
|
4057 + |
|
4058 + return FUNCTION_SUCCESS; |
|
4059 + |
|
4060 + |
|
4061 +error_status_get_demod_spectrum_mode: |
|
4062 + return FUNCTION_ERROR; |
|
4063 +} |
|
4064 + |
|
4065 + |
|
4066 + |
|
4067 + |
|
4068 + |
|
4069 + |
|
4070 + |
|
4071 + |
|
4072 + |
|
4073 + |
|
4074 + |
|
4075 + |
|
4076 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/dvbt_demod_base.h |
|
4077 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
4078 +++ b/linux/drivers/media/dvb/dvb-usb/dvbt_demod_base.h Wed Oct 27 09:16:44 2010 +0200 |
|
4079 @@ -0,0 +1,2547 @@ |
|
4080 +#ifndef __DVBT_DEMOD_BASE_H |
|
4081 +#define __DVBT_DEMOD_BASE_H |
|
4082 + |
|
4083 +/** |
|
4084 + |
|
4085 +@file |
|
4086 + |
|
4087 +@brief DVB-T demod base module definition |
|
4088 + |
|
4089 +DVB-T demod base module definitions contains demod module structure, demod funciton pointers, and demod definitions. |
|
4090 + |
|
4091 + |
|
4092 + |
|
4093 +@par Example: |
|
4094 +@code |
|
4095 + |
|
4096 + |
|
4097 +#include "demod_xxx.h" |
|
4098 + |
|
4099 + |
|
4100 + |
|
4101 +int |
|
4102 +CustomI2cRead( |
|
4103 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
4104 + unsigned char DeviceAddr, |
|
4105 + unsigned char *pReadingBytes, |
|
4106 + unsigned char ByteNum |
|
4107 + ) |
|
4108 +{ |
|
4109 + ... |
|
4110 + |
|
4111 + return FUNCTION_SUCCESS; |
|
4112 + |
|
4113 +error_status: |
|
4114 + return FUNCTION_ERROR; |
|
4115 +} |
|
4116 + |
|
4117 + |
|
4118 + |
|
4119 +int |
|
4120 +CustomI2cWrite( |
|
4121 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
4122 + unsigned char DeviceAddr, |
|
4123 + const unsigned char *pWritingBytes, |
|
4124 + unsigned char ByteNum |
|
4125 + ) |
|
4126 +{ |
|
4127 + ... |
|
4128 + |
|
4129 + return FUNCTION_SUCCESS; |
|
4130 + |
|
4131 +error_status: |
|
4132 + return FUNCTION_ERROR; |
|
4133 +} |
|
4134 + |
|
4135 + |
|
4136 + |
|
4137 +void |
|
4138 +CustomWaitMs( |
|
4139 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
4140 + unsigned long WaitTimeMs |
|
4141 + ) |
|
4142 +{ |
|
4143 + ... |
|
4144 +} |
|
4145 + |
|
4146 + |
|
4147 + |
|
4148 +int main(void) |
|
4149 +{ |
|
4150 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
4151 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
4152 + |
|
4153 + DVBT_DEMOD_MODULE *pDemod; |
|
4154 + DVBT_DEMOD_MODULE DvbtDemodModuleMemory; |
|
4155 + |
|
4156 + I2C_BRIDGE_MODULE I2cBridgeModuleMemory; |
|
4157 + |
|
4158 + int BandwidthMode; |
|
4159 + unsigned long IfFreqHz; |
|
4160 + int SpectrumMode; |
|
4161 + |
|
4162 + int DemodType; |
|
4163 + unsigned char DeviceAddr; |
|
4164 + unsigned long CrystalFreqHz; |
|
4165 + |
|
4166 + long RfAgc, IfAgc; |
|
4167 + unsigned long DiAgc; |
|
4168 + |
|
4169 + int Answer; |
|
4170 + long TrOffsetPpm, CrOffsetHz; |
|
4171 + unsigned long BerNum, BerDen; |
|
4172 + double Ber; |
|
4173 + long SnrDbNum, SnrDbDen; |
|
4174 + double SnrDb; |
|
4175 + unsigned long SignalStrength, SignalQuality; |
|
4176 + |
|
4177 + int Constellation; |
|
4178 + int Hierarchy; |
|
4179 + int CodeRateLp; |
|
4180 + int CodeRateHp; |
|
4181 + int GuardInterval; |
|
4182 + int FftMode; |
|
4183 + |
|
4184 + |
|
4185 + |
|
4186 + // Build base interface module. |
|
4187 + BuildBaseInterface( |
|
4188 + &pBaseInterface, |
|
4189 + &BaseInterfaceModuleMemory, |
|
4190 + 9, // Set maximum I2C reading byte number with 9. |
|
4191 + 8, // Set maximum I2C writing byte number with 8. |
|
4192 + CustomI2cRead, // Employ CustomI2cRead() as basic I2C reading function. |
|
4193 + CustomI2cWrite, // Employ CustomI2cWrite() as basic I2C writing function. |
|
4194 + CustomWaitMs // Employ CustomWaitMs() as basic waiting function. |
|
4195 + ); |
|
4196 + |
|
4197 + |
|
4198 + // Build DVB-T demod XXX module. |
|
4199 + BuildXxxModule( |
|
4200 + &pDemod, |
|
4201 + &DvbtDemodModuleMemory, |
|
4202 + &BaseInterfaceModuleMemory, |
|
4203 + &I2cBridgeModuleMemory, |
|
4204 + 0x20, // Demod I2C device address is 0x20 in 8-bit format. |
|
4205 + CRYSTAL_FREQ_28800000HZ, // Demod crystal frequency is 28.8 MHz. |
|
4206 + ... // Other arguments by each demod module |
|
4207 + ); |
|
4208 + |
|
4209 + |
|
4210 + |
|
4211 + |
|
4212 + |
|
4213 + // ==== Initialize DVB-T demod and set its parameters ===== |
|
4214 + |
|
4215 + // Initialize demod. |
|
4216 + pDemod->Initialize(pDemod); |
|
4217 + |
|
4218 + |
|
4219 + // Set demod parameters. (bandwidth mode, IF frequency, spectrum mode) |
|
4220 + // Note: In the example: |
|
4221 + // 1. Bandwidth mode is 8 MHz. |
|
4222 + // 2. IF frequency is 36.125 MHz. |
|
4223 + // 3. Spectrum mode is SPECTRUM_INVERSE. |
|
4224 + BandwidthMode = DVBT_BANDWIDTH_8MHZ; |
|
4225 + IfFreqHz = IF_FREQ_36125000HZ; |
|
4226 + SpectrumMode = SPECTRUM_INVERSE; |
|
4227 + |
|
4228 + pDemod->SetBandwidthMode(pDemod, BandwidthMode); |
|
4229 + pDemod->SetIfFreqHz(pDemod, IfFreqHz); |
|
4230 + pDemod->SetSpectrumMode(pDemod, SpectrumMode); |
|
4231 + |
|
4232 + |
|
4233 + // Need to set tuner before demod software reset. |
|
4234 + // The order to set demod and tuner is not important. |
|
4235 + // Note: One can use "pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1);" |
|
4236 + // for tuner I2C command forwarding. |
|
4237 + |
|
4238 + |
|
4239 + // Reset demod by software reset. |
|
4240 + pDemod->SoftwareReset(pDemod); |
|
4241 + |
|
4242 + |
|
4243 + // Wait maximum 1000 ms for demod converge. |
|
4244 + for(i = 0; i < 25; i++) |
|
4245 + { |
|
4246 + // Wait 40 ms. |
|
4247 + pBaseInterface->WaitMs(pBaseInterface, 40); |
|
4248 + |
|
4249 + // Check signal lock status. |
|
4250 + // Note: If Answer is YES, signal is locked. |
|
4251 + // If Answer is NO, signal is not locked. |
|
4252 + pDemod->IsSignalLocked(pDemod, &Answer); |
|
4253 + |
|
4254 + if(Answer == YES) |
|
4255 + { |
|
4256 + // Signal is locked. |
|
4257 + break; |
|
4258 + } |
|
4259 + } |
|
4260 + |
|
4261 + |
|
4262 + |
|
4263 + |
|
4264 + |
|
4265 + // ==== Get DVB-T demod information ===== |
|
4266 + |
|
4267 + // Get demod type. |
|
4268 + // Note: One can find demod type in MODULE_TYPE enumeration. |
|
4269 + pDemod->GetDemodType(pDemod, &DemodType); |
|
4270 + |
|
4271 + // Get demod I2C device address. |
|
4272 + pDemod->GetDeviceAddr(pDemod, &DeviceAddr); |
|
4273 + |
|
4274 + // Get demod crystal frequency in Hz. |
|
4275 + pDemod->GetCrystalFreqHz(pDemod, &CrystalFreqHz); |
|
4276 + |
|
4277 + |
|
4278 + // Ask demod if it is connected to I2C bus. |
|
4279 + // Note: If Answer is YES, demod is connected to I2C bus. |
|
4280 + // If Answer is NO, demod is not connected to I2C bus. |
|
4281 + pDemod->IsConnectedToI2c(pDemod, &Answer); |
|
4282 + |
|
4283 + |
|
4284 + // Get demod parameters. (bandwidth mode, IF frequency, spectrum mode) |
|
4285 + pDemod->GetBandwidthMode(pDemod, &BandwidthMode); |
|
4286 + pDemod->GetIfFreqHz(pDemod, &IfFreqHz); |
|
4287 + pDemod->GetSpectrumMode(pDemod, &SpectrumMode); |
|
4288 + |
|
4289 + |
|
4290 + // Get demod AGC value. |
|
4291 + // Note: The range of RF AGC and IF AGC value is -8192 ~ 8191. |
|
4292 + // The range of digital AGC value is 0 ~ 255. |
|
4293 + pDemod->GetRfAgc(pDemod, &RfAgc); |
|
4294 + pDemod->GetIfAgc(pDemod, &IfAgc); |
|
4295 + pDemod->GetDiAgc(pDemod, &DiAgc); |
|
4296 + |
|
4297 + |
|
4298 + // Get demod lock status. |
|
4299 + // Note: If Answer is YES, it is locked. |
|
4300 + // If Answer is NO, it is not locked. |
|
4301 + pDemod->IsTpsLocked(pDemod, &Answer); |
|
4302 + pDemod->IsSignalLocked(pDemod, &Answer); |
|
4303 + |
|
4304 + |
|
4305 + // Get TR offset (symbol timing offset) in ppm. |
|
4306 + pDemod->GetTrOffsetPpm(pDemod, &TrOffsetPpm); |
|
4307 + |
|
4308 + // Get CR offset (RF frequency offset) in Hz. |
|
4309 + pDemod->GetCrOffsetHz(pDemod, &CrOffsetHz); |
|
4310 + |
|
4311 + |
|
4312 + // Get BER. |
|
4313 + pDemod->GetBer(pDemod, &BerNum, &BerDen); |
|
4314 + Ber = (double)BerNum / (double)BerDen; |
|
4315 + |
|
4316 + // Get SNR in dB. |
|
4317 + pDemod->GetSnrDb(pDemod, &SnrDbNum, &SnrDbDen); |
|
4318 + SnrDb = (double)SnrDbNum / (double)SnrDbDen; |
|
4319 + |
|
4320 + |
|
4321 + // Get signal strength. |
|
4322 + // Note: 1. The range of SignalStrength is 0~100. |
|
4323 + // 2. Need to map SignalStrength value to UI signal strength bar manually. |
|
4324 + pDemod->GetSignalStrength(pDemod, &SignalStrength); |
|
4325 + |
|
4326 + // Get signal quality. |
|
4327 + // Note: 1. The range of SignalQuality is 0~100. |
|
4328 + // 2. Need to map SignalQuality value to UI signal quality bar manually. |
|
4329 + pDemod->GetSignalQuality(pDemod, &SignalQuality); |
|
4330 + |
|
4331 + |
|
4332 + // Get TPS information. |
|
4333 + // Note: One can find TPS information definitions in the enumerations as follows: |
|
4334 + // 1. DVBT_CONSTELLATION_MODE. |
|
4335 + // 2. DVBT_HIERARCHY_MODE. |
|
4336 + // 3. DVBT_CODE_RATE_MODE. (for low-priority and high-priority code rate) |
|
4337 + // 4. DVBT_GUARD_INTERVAL_MODE. |
|
4338 + // 5. DVBT_FFT_MODE_MODE |
|
4339 + pDemod->GetConstellation(pDemod, &Constellation); |
|
4340 + pDemod->GetHierarchy(pDemod, &Hierarchy); |
|
4341 + pDemod->GetCodeRateLp(pDemod, &CodeRateLp); |
|
4342 + pDemod->GetCodeRateHp(pDemod, &CodeRateHp); |
|
4343 + pDemod->GetGuardInterval(pDemod, &GuardInterval); |
|
4344 + pDemod->GetFftMode(pDemod, &FftMode); |
|
4345 + |
|
4346 + |
|
4347 + |
|
4348 + return 0; |
|
4349 +} |
|
4350 + |
|
4351 + |
|
4352 +@endcode |
|
4353 + |
|
4354 +*/ |
|
4355 + |
|
4356 + |
|
4357 +#include "foundation.h" |
|
4358 + |
|
4359 + |
|
4360 + |
|
4361 + |
|
4362 + |
|
4363 +// Definitions |
|
4364 + |
|
4365 +// Page register address |
|
4366 +#define DVBT_DEMOD_PAGE_REG_ADDR 0x00 |
|
4367 + |
|
4368 + |
|
4369 +// Bandwidth modes |
|
4370 +#define DVBT_BANDWIDTH_NONE -1 |
|
4371 +enum DVBT_BANDWIDTH_MODE |
|
4372 +{ |
|
4373 + DVBT_BANDWIDTH_6MHZ, |
|
4374 + DVBT_BANDWIDTH_7MHZ, |
|
4375 + DVBT_BANDWIDTH_8MHZ, |
|
4376 +}; |
|
4377 +#define DVBT_BANDWIDTH_MODE_NUM 3 |
|
4378 + |
|
4379 + |
|
4380 +// Constellation |
|
4381 +enum DVBT_CONSTELLATION_MODE |
|
4382 +{ |
|
4383 + DVBT_CONSTELLATION_QPSK, |
|
4384 + DVBT_CONSTELLATION_16QAM, |
|
4385 + DVBT_CONSTELLATION_64QAM, |
|
4386 +}; |
|
4387 +#define DVBT_CONSTELLATION_NUM 3 |
|
4388 + |
|
4389 + |
|
4390 +// Hierarchy |
|
4391 +enum DVBT_HIERARCHY_MODE |
|
4392 +{ |
|
4393 + DVBT_HIERARCHY_NONE, |
|
4394 + DVBT_HIERARCHY_ALPHA_1, |
|
4395 + DVBT_HIERARCHY_ALPHA_2, |
|
4396 + DVBT_HIERARCHY_ALPHA_4, |
|
4397 +}; |
|
4398 +#define DVBT_HIERARCHY_NUM 4 |
|
4399 + |
|
4400 + |
|
4401 +// Code rate |
|
4402 +enum DVBT_CODE_RATE_MODE |
|
4403 +{ |
|
4404 + DVBT_CODE_RATE_1_OVER_2, |
|
4405 + DVBT_CODE_RATE_2_OVER_3, |
|
4406 + DVBT_CODE_RATE_3_OVER_4, |
|
4407 + DVBT_CODE_RATE_5_OVER_6, |
|
4408 + DVBT_CODE_RATE_7_OVER_8, |
|
4409 +}; |
|
4410 +#define DVBT_CODE_RATE_NUM 5 |
|
4411 + |
|
4412 + |
|
4413 +// Guard interval |
|
4414 +enum DVBT_GUARD_INTERVAL_MODE |
|
4415 +{ |
|
4416 + DVBT_GUARD_INTERVAL_1_OVER_32, |
|
4417 + DVBT_GUARD_INTERVAL_1_OVER_16, |
|
4418 + DVBT_GUARD_INTERVAL_1_OVER_8, |
|
4419 + DVBT_GUARD_INTERVAL_1_OVER_4, |
|
4420 +}; |
|
4421 +#define DVBT_GUARD_INTERVAL_NUM 4 |
|
4422 + |
|
4423 + |
|
4424 +// FFT mode |
|
4425 +enum DVBT_FFT_MODE_MODE |
|
4426 +{ |
|
4427 + DVBT_FFT_MODE_2K, |
|
4428 + DVBT_FFT_MODE_8K, |
|
4429 +}; |
|
4430 +#define DVBT_FFT_MODE_NUM 2 |
|
4431 + |
|
4432 + |
|
4433 + |
|
4434 + |
|
4435 + |
|
4436 +// Register entry definitions |
|
4437 + |
|
4438 +// Register entry |
|
4439 +typedef struct |
|
4440 +{ |
|
4441 + int IsAvailable; |
|
4442 + unsigned long PageNo; |
|
4443 + unsigned char RegStartAddr; |
|
4444 + unsigned char Msb; |
|
4445 + unsigned char Lsb; |
|
4446 +} |
|
4447 +DVBT_REG_ENTRY; |
|
4448 + |
|
4449 + |
|
4450 + |
|
4451 +// Primary register entry |
|
4452 +typedef struct |
|
4453 +{ |
|
4454 + int RegBitName; |
|
4455 + unsigned long PageNo; |
|
4456 + unsigned char RegStartAddr; |
|
4457 + unsigned char Msb; |
|
4458 + unsigned char Lsb; |
|
4459 +} |
|
4460 +DVBT_PRIMARY_REG_ENTRY; |
|
4461 + |
|
4462 + |
|
4463 + |
|
4464 + |
|
4465 + |
|
4466 +// Register table dependence |
|
4467 + |
|
4468 +// Demod register bit names |
|
4469 +enum DVBT_REG_BIT_NAME |
|
4470 +{ |
|
4471 + // Software reset register |
|
4472 + DVBT_SOFT_RST, |
|
4473 + |
|
4474 + // Tuner I2C forwording register |
|
4475 + DVBT_IIC_REPEAT, |
|
4476 + |
|
4477 + |
|
4478 + // Registers for initializing |
|
4479 + DVBT_TR_WAIT_MIN_8K, |
|
4480 + DVBT_RSD_BER_FAIL_VAL, |
|
4481 + DVBT_EN_BK_TRK, |
|
4482 + DVBT_REG_PI, |
|
4483 + |
|
4484 + DVBT_REG_PFREQ_1_0, // For RTL2830 only |
|
4485 + DVBT_PD_DA8, // For RTL2830 only |
|
4486 + DVBT_LOCK_TH, // For RTL2830 only |
|
4487 + DVBT_BER_PASS_SCAL, // For RTL2830 only |
|
4488 + DVBT_CE_FFSM_BYPASS, // For RTL2830 only |
|
4489 + DVBT_ALPHAIIR_N, // For RTL2830 only |
|
4490 + DVBT_ALPHAIIR_DIF, // For RTL2830 only |
|
4491 + DVBT_EN_TRK_SPAN, // For RTL2830 only |
|
4492 + DVBT_LOCK_TH_LEN, // For RTL2830 only |
|
4493 + DVBT_CCI_THRE, // For RTL2830 only |
|
4494 + DVBT_CCI_MON_SCAL, // For RTL2830 only |
|
4495 + DVBT_CCI_M0, // For RTL2830 only |
|
4496 + DVBT_CCI_M1, // For RTL2830 only |
|
4497 + DVBT_CCI_M2, // For RTL2830 only |
|
4498 + DVBT_CCI_M3, // For RTL2830 only |
|
4499 + DVBT_SPEC_INIT_0, // For RTL2830 only |
|
4500 + DVBT_SPEC_INIT_1, // For RTL2830 only |
|
4501 + DVBT_SPEC_INIT_2, // For RTL2830 only |
|
4502 + |
|
4503 + DVBT_AD_EN_REG, // For RTL2832 only |
|
4504 + DVBT_AD_EN_REG1, // For RTL2832 only |
|
4505 + DVBT_EN_BBIN, // For RTL2832 only |
|
4506 + DVBT_MGD_THD0, // For RTL2832 only |
|
4507 + DVBT_MGD_THD1, // For RTL2832 only |
|
4508 + DVBT_MGD_THD2, // For RTL2832 only |
|
4509 + DVBT_MGD_THD3, // For RTL2832 only |
|
4510 + DVBT_MGD_THD4, // For RTL2832 only |
|
4511 + DVBT_MGD_THD5, // For RTL2832 only |
|
4512 + DVBT_MGD_THD6, // For RTL2832 only |
|
4513 + DVBT_MGD_THD7, // For RTL2832 only |
|
4514 + DVBT_EN_CACQ_NOTCH, // For RTL2832 only |
|
4515 + DVBT_AD_AV_REF, // For RTL2832 only |
|
4516 + DVBT_PIP_ON, // For RTL2832 only |
|
4517 + DVBT_SCALE1_B92, // For RTL2832 only |
|
4518 + DVBT_SCALE1_B93, // For RTL2832 only |
|
4519 + DVBT_SCALE1_BA7, // For RTL2832 only |
|
4520 + DVBT_SCALE1_BA9, // For RTL2832 only |
|
4521 + DVBT_SCALE1_BAA, // For RTL2832 only |
|
4522 + DVBT_SCALE1_BAB, // For RTL2832 only |
|
4523 + DVBT_SCALE1_BAC, // For RTL2832 only |
|
4524 + DVBT_SCALE1_BB0, // For RTL2832 only |
|
4525 + DVBT_SCALE1_BB1, // For RTL2832 only |
|
4526 + DVBT_KB_P1, // For RTL2832 only |
|
4527 + DVBT_KB_P2, // For RTL2832 only |
|
4528 + DVBT_KB_P3, // For RTL2832 only |
|
4529 + DVBT_OPT_ADC_IQ, // For RTL2832 only |
|
4530 + DVBT_AD_AVI, // For RTL2832 only |
|
4531 + DVBT_AD_AVQ, // For RTL2832 only |
|
4532 + DVBT_K1_CR_STEP12, // For RTL2832 only |
|
4533 + |
|
4534 + // Registers for initializing according to mode |
|
4535 + DVBT_TRK_KS_P2, |
|
4536 + DVBT_TRK_KS_I2, |
|
4537 + DVBT_TR_THD_SET2, |
|
4538 + DVBT_TRK_KC_P2, |
|
4539 + DVBT_TRK_KC_I2, |
|
4540 + DVBT_CR_THD_SET2, |
|
4541 + |
|
4542 + // Registers for IF setting |
|
4543 + DVBT_PSET_IFFREQ, |
|
4544 + DVBT_SPEC_INV, |
|
4545 + |
|
4546 + |
|
4547 + // Registers for bandwidth programming |
|
4548 + DVBT_BW_INDEX, // For RTL2830 only |
|
4549 + |
|
4550 + DVBT_RSAMP_RATIO, // For RTL2832 only |
|
4551 + DVBT_CFREQ_OFF_RATIO, // For RTL2832 only |
|
4552 + |
|
4553 + |
|
4554 + // FSM stage register |
|
4555 + DVBT_FSM_STAGE, |
|
4556 + |
|
4557 + // TPS content registers |
|
4558 + DVBT_RX_CONSTEL, |
|
4559 + DVBT_RX_HIER, |
|
4560 + DVBT_RX_C_RATE_LP, |
|
4561 + DVBT_RX_C_RATE_HP, |
|
4562 + DVBT_GI_IDX, |
|
4563 + DVBT_FFT_MODE_IDX, |
|
4564 + |
|
4565 + // Performance measurement registers |
|
4566 + DVBT_RSD_BER_EST, |
|
4567 + DVBT_CE_EST_EVM, |
|
4568 + |
|
4569 + // AGC registers |
|
4570 + DVBT_RF_AGC_VAL, |
|
4571 + DVBT_IF_AGC_VAL, |
|
4572 + DVBT_DAGC_VAL, |
|
4573 + |
|
4574 + // TR offset and CR offset registers |
|
4575 + DVBT_SFREQ_OFF, |
|
4576 + DVBT_CFREQ_OFF, |
|
4577 + |
|
4578 + |
|
4579 + // AGC relative registers |
|
4580 + DVBT_POLAR_RF_AGC, |
|
4581 + DVBT_POLAR_IF_AGC, |
|
4582 + DVBT_AAGC_HOLD, |
|
4583 + DVBT_EN_RF_AGC, |
|
4584 + DVBT_EN_IF_AGC, |
|
4585 + DVBT_IF_AGC_MIN, |
|
4586 + DVBT_IF_AGC_MAX, |
|
4587 + DVBT_RF_AGC_MIN, |
|
4588 + DVBT_RF_AGC_MAX, |
|
4589 + DVBT_IF_AGC_MAN, |
|
4590 + DVBT_IF_AGC_MAN_VAL, |
|
4591 + DVBT_RF_AGC_MAN, |
|
4592 + DVBT_RF_AGC_MAN_VAL, |
|
4593 + DVBT_DAGC_TRG_VAL, |
|
4594 + |
|
4595 + DVBT_AGC_TARG_VAL, // For RTL2830 only |
|
4596 + DVBT_LOOP_GAIN_3_0, // For RTL2830 only |
|
4597 + DVBT_LOOP_GAIN_4, // For RTL2830 only |
|
4598 + DVBT_VTOP, // For RTL2830 only |
|
4599 + DVBT_KRF, // For RTL2830 only |
|
4600 + |
|
4601 + DVBT_AGC_TARG_VAL_0, // For RTL2832 only |
|
4602 + DVBT_AGC_TARG_VAL_8_1, // For RTL2832 only |
|
4603 + DVBT_AAGC_LOOP_GAIN, // For RTL2832 only |
|
4604 + DVBT_LOOP_GAIN2_3_0, // For RTL2832 only |
|
4605 + DVBT_LOOP_GAIN2_4, // For RTL2832 only |
|
4606 + DVBT_LOOP_GAIN3, // For RTL2832 only |
|
4607 + DVBT_VTOP1, // For RTL2832 only |
|
4608 + DVBT_VTOP2, // For RTL2832 only |
|
4609 + DVBT_VTOP3, // For RTL2832 only |
|
4610 + DVBT_KRF1, // For RTL2832 only |
|
4611 + DVBT_KRF2, // For RTL2832 only |
|
4612 + DVBT_KRF3, // For RTL2832 only |
|
4613 + DVBT_KRF4, // For RTL2832 only |
|
4614 + |
|
4615 + |
|
4616 + // TS interface registers |
|
4617 + DVBT_CKOUTPAR, |
|
4618 + DVBT_CKOUT_PWR, |
|
4619 + DVBT_SYNC_DUR, |
|
4620 + DVBT_ERR_DUR, |
|
4621 + DVBT_SYNC_LVL, |
|
4622 + DVBT_ERR_LVL, |
|
4623 + DVBT_VAL_LVL, |
|
4624 + DVBT_SERIAL, |
|
4625 + DVBT_SER_LSB, |
|
4626 + DVBT_CDIV_PH0, |
|
4627 + DVBT_CDIV_PH1, |
|
4628 + |
|
4629 + DVBT_CKOUTPAR_PIP, // For RTL2832 only |
|
4630 + DVBT_CKOUT_PWR_PIP, // For RTL2832 only |
|
4631 + DVBT_SYNC_LVL_PIP, // For RTL2832 only |
|
4632 + DVBT_ERR_LVL_PIP, // For RTL2832 only |
|
4633 + DVBT_VAL_LVL_PIP, // For RTL2832 only |
|
4634 + DVBT_CKOUTPAR_PID, // For RTL2832 only |
|
4635 + DVBT_CKOUT_PWR_PID, // For RTL2832 only |
|
4636 + DVBT_SYNC_LVL_PID, // For RTL2832 only |
|
4637 + DVBT_ERR_LVL_PID, // For RTL2832 only |
|
4638 + DVBT_VAL_LVL_PID, // For RTL2832 only |
|
4639 + |
|
4640 + |
|
4641 + // FSM state-holding register |
|
4642 + DVBT_SM_PASS, |
|
4643 + |
|
4644 + // Registers for function 2 (for RTL2830 only) |
|
4645 + DVBT_UPDATE_REG_2, |
|
4646 + |
|
4647 + // Registers for function 3 (for RTL2830 only) |
|
4648 + DVBT_BTHD_P3, |
|
4649 + DVBT_BTHD_D3, |
|
4650 + |
|
4651 + // Registers for function 4 (for RTL2830 only) |
|
4652 + DVBT_FUNC4_REG0, |
|
4653 + DVBT_FUNC4_REG1, |
|
4654 + DVBT_FUNC4_REG2, |
|
4655 + DVBT_FUNC4_REG3, |
|
4656 + DVBT_FUNC4_REG4, |
|
4657 + DVBT_FUNC4_REG5, |
|
4658 + DVBT_FUNC4_REG6, |
|
4659 + DVBT_FUNC4_REG7, |
|
4660 + DVBT_FUNC4_REG8, |
|
4661 + DVBT_FUNC4_REG9, |
|
4662 + DVBT_FUNC4_REG10, |
|
4663 + |
|
4664 + // Registers for functin 5 (for RTL2830 only) |
|
4665 + DVBT_FUNC5_REG0, |
|
4666 + DVBT_FUNC5_REG1, |
|
4667 + DVBT_FUNC5_REG2, |
|
4668 + DVBT_FUNC5_REG3, |
|
4669 + DVBT_FUNC5_REG4, |
|
4670 + DVBT_FUNC5_REG5, |
|
4671 + DVBT_FUNC5_REG6, |
|
4672 + DVBT_FUNC5_REG7, |
|
4673 + DVBT_FUNC5_REG8, |
|
4674 + DVBT_FUNC5_REG9, |
|
4675 + DVBT_FUNC5_REG10, |
|
4676 + DVBT_FUNC5_REG11, |
|
4677 + DVBT_FUNC5_REG12, |
|
4678 + DVBT_FUNC5_REG13, |
|
4679 + DVBT_FUNC5_REG14, |
|
4680 + DVBT_FUNC5_REG15, |
|
4681 + DVBT_FUNC5_REG16, |
|
4682 + DVBT_FUNC5_REG17, |
|
4683 + DVBT_FUNC5_REG18, |
|
4684 + |
|
4685 + // AD7 registers (for RTL2832 only) |
|
4686 + DVBT_AD7_SETTING, |
|
4687 + DVBT_RSSI_R, |
|
4688 + |
|
4689 + // ACI detection registers (for RTL2832 only) |
|
4690 + DVBT_ACI_DET_IND, |
|
4691 + |
|
4692 + // Test registers for test only |
|
4693 + DVBT_TEST_REG_1, |
|
4694 + DVBT_TEST_REG_2, |
|
4695 + DVBT_TEST_REG_3, |
|
4696 + DVBT_TEST_REG_4, |
|
4697 + |
|
4698 + // Item terminator |
|
4699 + DVBT_REG_BIT_NAME_ITEM_TERMINATOR, |
|
4700 +}; |
|
4701 + |
|
4702 + |
|
4703 + |
|
4704 +// Register table length definitions |
|
4705 +#define DVBT_REG_TABLE_LEN_MAX DVBT_REG_BIT_NAME_ITEM_TERMINATOR |
|
4706 + |
|
4707 + |
|
4708 + |
|
4709 + |
|
4710 + |
|
4711 +// DVB-T demod module pre-definition |
|
4712 +typedef struct DVBT_DEMOD_MODULE_TAG DVBT_DEMOD_MODULE; |
|
4713 + |
|
4714 + |
|
4715 + |
|
4716 + |
|
4717 + |
|
4718 +/** |
|
4719 + |
|
4720 +@brief DVB-T demod register page setting function pointer |
|
4721 + |
|
4722 +Demod upper level functions will use DVBT_DEMOD_FP_SET_REG_PAGE() to set demod register page. |
|
4723 + |
|
4724 + |
|
4725 +@param [in] pDemod The demod module pointer |
|
4726 +@param [in] PageNo Page number |
|
4727 + |
|
4728 + |
|
4729 +@retval FUNCTION_SUCCESS Set register page successfully with page number. |
|
4730 +@retval FUNCTION_ERROR Set register page unsuccessfully. |
|
4731 + |
|
4732 + |
|
4733 +@note |
|
4734 + -# Demod building function will set DVBT_DEMOD_FP_SET_REG_PAGE() with the corresponding function. |
|
4735 + |
|
4736 + |
|
4737 +@par Example: |
|
4738 +@code |
|
4739 + |
|
4740 + |
|
4741 +#include "demod_pseudo.h" |
|
4742 + |
|
4743 + |
|
4744 +int main(void) |
|
4745 +{ |
|
4746 + DVBT_DEMOD_MODULE *pDemod; |
|
4747 + DVBT_DEMOD_MODULE AtscDemodModuleMemory; |
|
4748 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
4749 + |
|
4750 + |
|
4751 + // Build pseudo demod module. |
|
4752 + BuildPseudoDemodModule(&pDemod, &AtscDemodModuleMemory, &PseudoExtraModuleMemory); |
|
4753 + |
|
4754 + ... |
|
4755 + |
|
4756 + // Set demod register page with page number 2. |
|
4757 + pDemod->SetRegPage(pDemod, 2); |
|
4758 + |
|
4759 + ... |
|
4760 + |
|
4761 + return 0; |
|
4762 +} |
|
4763 + |
|
4764 + |
|
4765 +@endcode |
|
4766 + |
|
4767 +*/ |
|
4768 +typedef int |
|
4769 +(*DVBT_DEMOD_FP_SET_REG_PAGE)( |
|
4770 + DVBT_DEMOD_MODULE *pDemod, |
|
4771 + unsigned long PageNo |
|
4772 + ); |
|
4773 + |
|
4774 + |
|
4775 + |
|
4776 + |
|
4777 + |
|
4778 +/** |
|
4779 + |
|
4780 +@brief DVB-T demod register byte setting function pointer |
|
4781 + |
|
4782 +Demod upper level functions will use DVBT_DEMOD_FP_SET_REG_BYTES() to set demod register bytes. |
|
4783 + |
|
4784 + |
|
4785 +@param [in] pDemod The demod module pointer |
|
4786 +@param [in] RegStartAddr Demod register start address |
|
4787 +@param [in] pWritingBytes Pointer to writing bytes |
|
4788 +@param [in] ByteNum Writing byte number |
|
4789 + |
|
4790 + |
|
4791 +@retval FUNCTION_SUCCESS Set demod register bytes successfully with writing bytes. |
|
4792 +@retval FUNCTION_ERROR Set demod register bytes unsuccessfully. |
|
4793 + |
|
4794 + |
|
4795 +@note |
|
4796 + -# Demod building function will set DVBT_DEMOD_FP_SET_REG_BYTES() with the corresponding function. |
|
4797 + -# Need to set register page by DVBT_DEMOD_FP_SET_REG_PAGE() before using DVBT_DEMOD_FP_SET_REG_BYTES(). |
|
4798 + |
|
4799 + |
|
4800 +@see DVBT_DEMOD_FP_SET_REG_PAGE, DVBT_DEMOD_FP_GET_REG_BYTES |
|
4801 + |
|
4802 + |
|
4803 + |
|
4804 +@par Example: |
|
4805 +@code |
|
4806 + |
|
4807 + |
|
4808 +#include "demod_pseudo.h" |
|
4809 + |
|
4810 + |
|
4811 +int main(void) |
|
4812 +{ |
|
4813 + DVBT_DEMOD_MODULE *pDemod; |
|
4814 + DVBT_DEMOD_MODULE AtscDemodModuleMemory; |
|
4815 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
4816 + unsigned char WritingBytes[10]; |
|
4817 + |
|
4818 + |
|
4819 + // Build pseudo demod module. |
|
4820 + BuildPseudoDemodModule(&pDemod, &AtscDemodModuleMemory, &PseudoExtraModuleMemory); |
|
4821 + |
|
4822 + ... |
|
4823 + |
|
4824 + // Set demod register bytes (page 1, address 0x17 ~ 0x1b) with 5 writing bytes. |
|
4825 + pDemod->SetRegPage(pDemod, 1); |
|
4826 + pDemod->SetRegBytes(pDemod, 0x17, WritingBytes, 5); |
|
4827 + |
|
4828 + ... |
|
4829 + |
|
4830 + return 0; |
|
4831 +} |
|
4832 + |
|
4833 + |
|
4834 +@endcode |
|
4835 + |
|
4836 +*/ |
|
4837 +typedef int |
|
4838 +(*DVBT_DEMOD_FP_SET_REG_BYTES)( |
|
4839 + DVBT_DEMOD_MODULE *pDemod, |
|
4840 + unsigned char RegStartAddr, |
|
4841 + const unsigned char *pWritingBytes, |
|
4842 + unsigned char ByteNum |
|
4843 + ); |
|
4844 + |
|
4845 + |
|
4846 + |
|
4847 + |
|
4848 + |
|
4849 +/** |
|
4850 + |
|
4851 +@brief DVB-T demod register byte getting function pointer |
|
4852 + |
|
4853 +Demod upper level functions will use DVBT_DEMOD_FP_GET_REG_BYTES() to get demod register bytes. |
|
4854 + |
|
4855 + |
|
4856 +@param [in] pDemod The demod module pointer |
|
4857 +@param [in] RegStartAddr Demod register start address |
|
4858 +@param [out] pReadingBytes Pointer to an allocated memory for storing reading bytes |
|
4859 +@param [in] ByteNum Reading byte number |
|
4860 + |
|
4861 + |
|
4862 +@retval FUNCTION_SUCCESS Get demod register bytes successfully with reading byte number. |
|
4863 +@retval FUNCTION_ERROR Get demod register bytes unsuccessfully. |
|
4864 + |
|
4865 + |
|
4866 +@note |
|
4867 + -# Demod building function will set DVBT_DEMOD_FP_GET_REG_BYTES() with the corresponding function. |
|
4868 + -# Need to set register page by DVBT_DEMOD_FP_SET_REG_PAGE() before using DVBT_DEMOD_FP_GET_REG_BYTES(). |
|
4869 + |
|
4870 + |
|
4871 +@see DVBT_DEMOD_FP_SET_REG_PAGE, DVBT_DEMOD_FP_SET_REG_BYTES |
|
4872 + |
|
4873 + |
|
4874 + |
|
4875 +@par Example: |
|
4876 +@code |
|
4877 + |
|
4878 + |
|
4879 +#include "demod_pseudo.h" |
|
4880 + |
|
4881 + |
|
4882 +int main(void) |
|
4883 +{ |
|
4884 + DVBT_DEMOD_MODULE *pDemod; |
|
4885 + DVBT_DEMOD_MODULE AtscDemodModuleMemory; |
|
4886 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
4887 + unsigned char ReadingBytes[10]; |
|
4888 + |
|
4889 + |
|
4890 + // Build pseudo demod module. |
|
4891 + BuildPseudoDemodModule(&pDemod, &AtscDemodModuleMemory, &PseudoExtraModuleMemory); |
|
4892 + |
|
4893 + ... |
|
4894 + |
|
4895 + // Get demod register bytes (page 1, address 0x17 ~ 0x1b) with reading byte number 5. |
|
4896 + pDemod->SetRegPage(pDemod, 1); |
|
4897 + pDemod->GetRegBytes(pDemod, 0x17, ReadingBytes, 5); |
|
4898 + |
|
4899 + ... |
|
4900 + |
|
4901 + return 0; |
|
4902 +} |
|
4903 + |
|
4904 + |
|
4905 +@endcode |
|
4906 + |
|
4907 +*/ |
|
4908 +typedef int |
|
4909 +(*DVBT_DEMOD_FP_GET_REG_BYTES)( |
|
4910 + DVBT_DEMOD_MODULE *pDemod, |
|
4911 + unsigned char RegStartAddr, |
|
4912 + unsigned char *pReadingBytes, |
|
4913 + unsigned char ByteNum |
|
4914 + ); |
|
4915 + |
|
4916 + |
|
4917 + |
|
4918 + |
|
4919 + |
|
4920 +/** |
|
4921 + |
|
4922 +@brief DVB-T demod register mask bits setting function pointer |
|
4923 + |
|
4924 +Demod upper level functions will use DVBT_DEMOD_FP_SET_REG_MASK_BITS() to set demod register mask bits. |
|
4925 + |
|
4926 + |
|
4927 +@param [in] pDemod The demod module pointer |
|
4928 +@param [in] RegStartAddr Demod register start address |
|
4929 +@param [in] Msb Mask MSB with 0-based index |
|
4930 +@param [in] Lsb Mask LSB with 0-based index |
|
4931 +@param [in] WritingValue The mask bits writing value |
|
4932 + |
|
4933 + |
|
4934 +@retval FUNCTION_SUCCESS Set demod register mask bits successfully with writing value. |
|
4935 +@retval FUNCTION_ERROR Set demod register mask bits unsuccessfully. |
|
4936 + |
|
4937 + |
|
4938 +@note |
|
4939 + -# Demod building function will set DVBT_DEMOD_FP_SET_REG_MASK_BITS() with the corresponding function. |
|
4940 + -# Need to set register page by DVBT_DEMOD_FP_SET_REG_PAGE() before using DVBT_DEMOD_FP_SET_REG_MASK_BITS(). |
|
4941 + -# The constraints of DVBT_DEMOD_FP_SET_REG_MASK_BITS() function usage are described as follows: |
|
4942 + -# The mask MSB and LSB must be 0~31. |
|
4943 + -# The mask MSB must be greater than or equal to LSB. |
|
4944 + |
|
4945 + |
|
4946 +@see DVBT_DEMOD_FP_SET_REG_PAGE, DVBT_DEMOD_FP_GET_REG_MASK_BITS |
|
4947 + |
|
4948 + |
|
4949 + |
|
4950 +@par Example: |
|
4951 +@code |
|
4952 + |
|
4953 + |
|
4954 +#include "demod_pseudo.h" |
|
4955 + |
|
4956 + |
|
4957 +int main(void) |
|
4958 +{ |
|
4959 + DVBT_DEMOD_MODULE *pDemod; |
|
4960 + DVBT_DEMOD_MODULE AtscDemodModuleMemory; |
|
4961 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
4962 + |
|
4963 + |
|
4964 + // Build pseudo demod module. |
|
4965 + BuildPseudoDemodModule(&pDemod, &AtscDemodModuleMemory, &PseudoExtraModuleMemory); |
|
4966 + |
|
4967 + ... |
|
4968 + |
|
4969 + // Set demod register bits (page 1, address {0x18, 0x17} [12:5]) with writing value 0x1d. |
|
4970 + pDemod->SetRegPage(pDemod, 1); |
|
4971 + pDemod->SetRegMaskBits(pDemod, 0x17, 12, 5, 0x1d); |
|
4972 + |
|
4973 + |
|
4974 + // Result: |
|
4975 + // |
|
4976 + // Writing value = 0x1d = 0001 1101 b |
|
4977 + // |
|
4978 + // Page 1 |
|
4979 + // Register address 0x17 0x18 |
|
4980 + // Register value xxx0 0011 b 101x xxxx b |
|
4981 + |
|
4982 + ... |
|
4983 + |
|
4984 + return 0; |
|
4985 +} |
|
4986 + |
|
4987 + |
|
4988 +@endcode |
|
4989 + |
|
4990 +*/ |
|
4991 +typedef int |
|
4992 +(*DVBT_DEMOD_FP_SET_REG_MASK_BITS)( |
|
4993 + DVBT_DEMOD_MODULE *pDemod, |
|
4994 + unsigned char RegStartAddr, |
|
4995 + unsigned char Msb, |
|
4996 + unsigned char Lsb, |
|
4997 + const unsigned long WritingValue |
|
4998 + ); |
|
4999 + |
|
5000 + |
|
5001 + |
|
5002 + |
|
5003 + |
|
5004 +/** |
|
5005 + |
|
5006 +@brief DVB-T demod register mask bits getting function pointer |
|
5007 + |
|
5008 +Demod upper level functions will use DVBT_DEMOD_FP_GET_REG_MASK_BITS() to get demod register mask bits. |
|
5009 + |
|
5010 + |
|
5011 +@param [in] pDemod The demod module pointer |
|
5012 +@param [in] RegStartAddr Demod register start address |
|
5013 +@param [in] Msb Mask MSB with 0-based index |
|
5014 +@param [in] Lsb Mask LSB with 0-based index |
|
5015 +@param [out] pReadingValue Pointer to an allocated memory for storing reading value |
|
5016 + |
|
5017 + |
|
5018 +@retval FUNCTION_SUCCESS Get demod register mask bits successfully. |
|
5019 +@retval FUNCTION_ERROR Get demod register mask bits unsuccessfully. |
|
5020 + |
|
5021 + |
|
5022 +@note |
|
5023 + -# Demod building function will set DVBT_DEMOD_FP_GET_REG_MASK_BITS() with the corresponding function. |
|
5024 + -# Need to set register page by DVBT_DEMOD_FP_SET_REG_PAGE() before using DVBT_DEMOD_FP_GET_REG_MASK_BITS(). |
|
5025 + -# The constraints of DVBT_DEMOD_FP_GET_REG_MASK_BITS() function usage are described as follows: |
|
5026 + -# The mask MSB and LSB must be 0~31. |
|
5027 + -# The mask MSB must be greater than or equal to LSB. |
|
5028 + |
|
5029 + |
|
5030 +@see DVBT_DEMOD_FP_SET_REG_PAGE, DVBT_DEMOD_FP_SET_REG_MASK_BITS |
|
5031 + |
|
5032 + |
|
5033 + |
|
5034 +@par Example: |
|
5035 +@code |
|
5036 + |
|
5037 + |
|
5038 +#include "demod_pseudo.h" |
|
5039 + |
|
5040 + |
|
5041 +int main(void) |
|
5042 +{ |
|
5043 + DVBT_DEMOD_MODULE *pDemod; |
|
5044 + DVBT_DEMOD_MODULE AtscDemodModuleMemory; |
|
5045 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
5046 + unsigned long ReadingValue; |
|
5047 + |
|
5048 + |
|
5049 + // Build pseudo demod module. |
|
5050 + BuildPseudoDemodModule(&pDemod, &AtscDemodModuleMemory, &PseudoExtraModuleMemory); |
|
5051 + |
|
5052 + ... |
|
5053 + |
|
5054 + // Get demod register bits (page 1, address {0x18, 0x17} [12:5]). |
|
5055 + pDemod->SetRegPage(pDemod, 1); |
|
5056 + pDemod->GetRegMaskBits(pDemod, 0x17, 12, 5, &ReadingValue); |
|
5057 + |
|
5058 + |
|
5059 + // Result: |
|
5060 + // |
|
5061 + // Page 1 |
|
5062 + // Register address 0x18 0x17 |
|
5063 + // Register value xxx0 0011 b 101x xxxx b |
|
5064 + // |
|
5065 + // Reading value = 0001 1101 b = 0x1d |
|
5066 + |
|
5067 + ... |
|
5068 + |
|
5069 + return 0; |
|
5070 +} |
|
5071 + |
|
5072 + |
|
5073 +@endcode |
|
5074 + |
|
5075 +*/ |
|
5076 +typedef int |
|
5077 +(*DVBT_DEMOD_FP_GET_REG_MASK_BITS)( |
|
5078 + DVBT_DEMOD_MODULE *pDemod, |
|
5079 + unsigned char RegStartAddr, |
|
5080 + unsigned char Msb, |
|
5081 + unsigned char Lsb, |
|
5082 + unsigned long *pReadingValue |
|
5083 + ); |
|
5084 + |
|
5085 + |
|
5086 + |
|
5087 + |
|
5088 + |
|
5089 +/** |
|
5090 + |
|
5091 +@brief DVB-T demod register bits setting function pointer |
|
5092 + |
|
5093 +Demod upper level functions will use DVBT_DEMOD_FP_SET_REG_BITS() to set demod register bits with bit name. |
|
5094 + |
|
5095 + |
|
5096 +@param [in] pDemod The demod module pointer |
|
5097 +@param [in] RegBitName Pre-defined demod register bit name |
|
5098 +@param [in] WritingValue The mask bits writing value |
|
5099 + |
|
5100 + |
|
5101 +@retval FUNCTION_SUCCESS Set demod register bits successfully with bit name and writing value. |
|
5102 +@retval FUNCTION_ERROR Set demod register bits unsuccessfully. |
|
5103 + |
|
5104 + |
|
5105 +@note |
|
5106 + -# Demod building function will set DVBT_DEMOD_FP_SET_REG_BITS() with the corresponding function. |
|
5107 + -# Need to set register page before using DVBT_DEMOD_FP_SET_REG_BITS(). |
|
5108 + -# Register bit names are pre-defined keys for bit access, and one can find these in demod header file. |
|
5109 + |
|
5110 + |
|
5111 +@see DVBT_DEMOD_FP_SET_REG_PAGE, DVBT_DEMOD_FP_GET_REG_BITS |
|
5112 + |
|
5113 + |
|
5114 + |
|
5115 +@par Example: |
|
5116 +@code |
|
5117 + |
|
5118 + |
|
5119 +#include "demod_pseudo.h" |
|
5120 + |
|
5121 + |
|
5122 +int main(void) |
|
5123 +{ |
|
5124 + DVBT_DEMOD_MODULE *pDemod; |
|
5125 + DVBT_DEMOD_MODULE AtscDemodModuleMemory; |
|
5126 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
5127 + |
|
5128 + |
|
5129 + // Build pseudo demod module. |
|
5130 + BuildPseudoDemodModule(&pDemod, &AtscDemodModuleMemory, &PseudoExtraModuleMemory); |
|
5131 + |
|
5132 + ... |
|
5133 + |
|
5134 + // Set demod register bits with bit name PSEUDO_REG_BIT_NAME and writing value 0x1d. |
|
5135 + // The corresponding information of PSEUDO_REG_BIT_NAME is address {0x18, 0x17} [12:5] on page 1. |
|
5136 + pDemod->SetRegPage(pDemod, 1); |
|
5137 + pDemod->SetRegBits(pDemod, PSEUDO_REG_BIT_NAME, 0x1d); |
|
5138 + |
|
5139 + |
|
5140 + // Result: |
|
5141 + // |
|
5142 + // Writing value = 0x1d = 0001 1101 b |
|
5143 + // |
|
5144 + // Page 1 |
|
5145 + // Register address 0x18 0x17 |
|
5146 + // Register value xxx0 0011 b 101x xxxx b |
|
5147 + |
|
5148 + ... |
|
5149 + |
|
5150 + return 0; |
|
5151 +} |
|
5152 + |
|
5153 + |
|
5154 +@endcode |
|
5155 + |
|
5156 +*/ |
|
5157 +typedef int |
|
5158 +(*DVBT_DEMOD_FP_SET_REG_BITS)( |
|
5159 + DVBT_DEMOD_MODULE *pDemod, |
|
5160 + int RegBitName, |
|
5161 + const unsigned long WritingValue |
|
5162 + ); |
|
5163 + |
|
5164 + |
|
5165 + |
|
5166 + |
|
5167 + |
|
5168 +/** |
|
5169 + |
|
5170 +@brief DVB-T demod register bits getting function pointer |
|
5171 + |
|
5172 +Demod upper level functions will use DVBT_DEMOD_FP_GET_REG_BITS() to get demod register bits with bit name. |
|
5173 + |
|
5174 + |
|
5175 +@param [in] pDemod The demod module pointer |
|
5176 +@param [in] RegBitName Pre-defined demod register bit name |
|
5177 +@param [out] pReadingValue Pointer to an allocated memory for storing reading value |
|
5178 + |
|
5179 + |
|
5180 +@retval FUNCTION_SUCCESS Get demod register bits successfully with bit name. |
|
5181 +@retval FUNCTION_ERROR Get demod register bits unsuccessfully. |
|
5182 + |
|
5183 + |
|
5184 +@note |
|
5185 + -# Demod building function will set DVBT_DEMOD_FP_GET_REG_BITS() with the corresponding function. |
|
5186 + -# Need to set register page before using DVBT_DEMOD_FP_GET_REG_BITS(). |
|
5187 + -# Register bit names are pre-defined keys for bit access, and one can find these in demod header file. |
|
5188 + |
|
5189 + |
|
5190 +@see DVBT_DEMOD_FP_SET_REG_PAGE, DVBT_DEMOD_FP_SET_REG_BITS |
|
5191 + |
|
5192 + |
|
5193 + |
|
5194 +@par Example: |
|
5195 +@code |
|
5196 + |
|
5197 + |
|
5198 +#include "demod_pseudo.h" |
|
5199 + |
|
5200 + |
|
5201 +int main(void) |
|
5202 +{ |
|
5203 + DVBT_DEMOD_MODULE *pDemod; |
|
5204 + DVBT_DEMOD_MODULE AtscDemodModuleMemory; |
|
5205 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
5206 + unsigned long ReadingValue; |
|
5207 + |
|
5208 + |
|
5209 + // Build pseudo demod module. |
|
5210 + BuildPseudoDemodModule(&pDemod, &AtscDemodModuleMemory, &PseudoExtraModuleMemory); |
|
5211 + |
|
5212 + ... |
|
5213 + |
|
5214 + // Get demod register bits with bit name PSEUDO_REG_BIT_NAME. |
|
5215 + // The corresponding information of PSEUDO_REG_BIT_NAME is address {0x18, 0x17} [12:5] on page 1. |
|
5216 + pDemod->SetRegPage(pDemod, 1); |
|
5217 + pDemod->GetRegBits(pDemod, PSEUDO_REG_BIT_NAME, &ReadingValue); |
|
5218 + |
|
5219 + |
|
5220 + // Result: |
|
5221 + // |
|
5222 + // Page 1 |
|
5223 + // Register address 0x18 0x17 |
|
5224 + // Register value xxx0 0011 b 101x xxxx b |
|
5225 + // |
|
5226 + // Reading value = 0001 1101 b = 0x1d |
|
5227 + |
|
5228 + ... |
|
5229 + |
|
5230 + return 0; |
|
5231 +} |
|
5232 + |
|
5233 + |
|
5234 +@endcode |
|
5235 + |
|
5236 +*/ |
|
5237 +typedef int |
|
5238 +(*DVBT_DEMOD_FP_GET_REG_BITS)( |
|
5239 + DVBT_DEMOD_MODULE *pDemod, |
|
5240 + int RegBitName, |
|
5241 + unsigned long *pReadingValue |
|
5242 + ); |
|
5243 + |
|
5244 + |
|
5245 + |
|
5246 + |
|
5247 + |
|
5248 +/** |
|
5249 + |
|
5250 +@brief DVB-T demod register bits setting function pointer (with page setting) |
|
5251 + |
|
5252 +Demod upper level functions will use DVBT_DEMOD_FP_SET_REG_BITS_WITH_PAGE() to set demod register bits with bit name and |
|
5253 +page setting. |
|
5254 + |
|
5255 + |
|
5256 +@param [in] pDemod The demod module pointer |
|
5257 +@param [in] RegBitName Pre-defined demod register bit name |
|
5258 +@param [in] WritingValue The mask bits writing value |
|
5259 + |
|
5260 + |
|
5261 +@retval FUNCTION_SUCCESS Set demod register bits successfully with bit name, page setting, and writing value. |
|
5262 +@retval FUNCTION_ERROR Set demod register bits unsuccessfully. |
|
5263 + |
|
5264 + |
|
5265 +@note |
|
5266 + -# Demod building function will set DVBT_DEMOD_FP_SET_REG_BITS_WITH_PAGE() with the corresponding function. |
|
5267 + -# Don't need to set register page before using DVBT_DEMOD_FP_SET_REG_BITS_WITH_PAGE(). |
|
5268 + -# Register bit names are pre-defined keys for bit access, and one can find these in demod header file. |
|
5269 + |
|
5270 + |
|
5271 +@see DVBT_DEMOD_FP_GET_REG_BITS_WITH_PAGE |
|
5272 + |
|
5273 + |
|
5274 + |
|
5275 +@par Example: |
|
5276 +@code |
|
5277 + |
|
5278 + |
|
5279 +#include "demod_pseudo.h" |
|
5280 + |
|
5281 + |
|
5282 +int main(void) |
|
5283 +{ |
|
5284 + DVBT_DEMOD_MODULE *pDemod; |
|
5285 + DVBT_DEMOD_MODULE AtscDemodModuleMemory; |
|
5286 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
5287 + |
|
5288 + |
|
5289 + // Build pseudo demod module. |
|
5290 + BuildPseudoDemodModule(&pDemod, &AtscDemodModuleMemory, &PseudoExtraModuleMemory); |
|
5291 + |
|
5292 + ... |
|
5293 + |
|
5294 + // Set demod register bits with bit name PSEUDO_REG_BIT_NAME and writing value 0x1d. |
|
5295 + // The corresponding information of PSEUDO_REG_BIT_NAME is address {0x18, 0x17} [12:5] on page 1. |
|
5296 + pDemod->SetRegBitsWithPage(pDemod, PSEUDO_REG_BIT_NAME, 0x1d); |
|
5297 + |
|
5298 + |
|
5299 + // Result: |
|
5300 + // |
|
5301 + // Writing value = 0x1d = 0001 1101 b |
|
5302 + // |
|
5303 + // Page 1 |
|
5304 + // Register address 0x18 0x17 |
|
5305 + // Register value xxx0 0011 b 101x xxxx b |
|
5306 + |
|
5307 + ... |
|
5308 + |
|
5309 + return 0; |
|
5310 +} |
|
5311 + |
|
5312 + |
|
5313 +@endcode |
|
5314 + |
|
5315 +*/ |
|
5316 +typedef int |
|
5317 +(*DVBT_DEMOD_FP_SET_REG_BITS_WITH_PAGE)( |
|
5318 + DVBT_DEMOD_MODULE *pDemod, |
|
5319 + int RegBitName, |
|
5320 + const unsigned long WritingValue |
|
5321 + ); |
|
5322 + |
|
5323 + |
|
5324 + |
|
5325 + |
|
5326 + |
|
5327 +/** |
|
5328 + |
|
5329 +@brief DVB-T demod register bits getting function pointer (with page setting) |
|
5330 + |
|
5331 +Demod upper level functions will use DVBT_DEMOD_FP_GET_REG_BITS_WITH_PAGE() to get demod register bits with bit name and |
|
5332 +page setting. |
|
5333 + |
|
5334 + |
|
5335 +@param [in] pDemod The demod module pointer |
|
5336 +@param [in] RegBitName Pre-defined demod register bit name |
|
5337 +@param [out] pReadingValue Pointer to an allocated memory for storing reading value |
|
5338 + |
|
5339 + |
|
5340 +@retval FUNCTION_SUCCESS Get demod register bits successfully with bit name and page setting. |
|
5341 +@retval FUNCTION_ERROR Get demod register bits unsuccessfully. |
|
5342 + |
|
5343 + |
|
5344 +@note |
|
5345 + -# Demod building function will set DVBT_DEMOD_FP_GET_REG_BITS_WITH_PAGE() with the corresponding function. |
|
5346 + -# Don't need to set register page before using DVBT_DEMOD_FP_GET_REG_BITS_WITH_PAGE(). |
|
5347 + -# Register bit names are pre-defined keys for bit access, and one can find these in demod header file. |
|
5348 + |
|
5349 + |
|
5350 +@see DVBT_DEMOD_FP_SET_REG_BITS_WITH_PAGE |
|
5351 + |
|
5352 + |
|
5353 + |
|
5354 +@par Example: |
|
5355 +@code |
|
5356 + |
|
5357 + |
|
5358 +#include "demod_pseudo.h" |
|
5359 + |
|
5360 + |
|
5361 +int main(void) |
|
5362 +{ |
|
5363 + DVBT_DEMOD_MODULE *pDemod; |
|
5364 + DVBT_DEMOD_MODULE AtscDemodModuleMemory; |
|
5365 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
5366 + unsigned long ReadingValue; |
|
5367 + |
|
5368 + |
|
5369 + // Build pseudo demod module. |
|
5370 + BuildPseudoDemodModule(&pDemod, &AtscDemodModuleMemory, &PseudoExtraModuleMemory); |
|
5371 + |
|
5372 + ... |
|
5373 + |
|
5374 + // Get demod register bits with bit name PSEUDO_REG_BIT_NAME. |
|
5375 + // The corresponding information of PSEUDO_REG_BIT_NAME is address {0x18, 0x17} [12:5] on page 1. |
|
5376 + pDemod->GetRegBitsWithPage(pDemod, PSEUDO_REG_BIT_NAME, &ReadingValue); |
|
5377 + |
|
5378 + |
|
5379 + // Result: |
|
5380 + // |
|
5381 + // Page 1 |
|
5382 + // Register address 0x18 0x17 |
|
5383 + // Register value xxx0 0011 b 101x xxxx b |
|
5384 + // |
|
5385 + // Reading value = 0001 1101 b = 0x1d |
|
5386 + |
|
5387 + ... |
|
5388 + |
|
5389 + return 0; |
|
5390 +} |
|
5391 + |
|
5392 + |
|
5393 +@endcode |
|
5394 + |
|
5395 +*/ |
|
5396 +typedef int |
|
5397 +(*DVBT_DEMOD_FP_GET_REG_BITS_WITH_PAGE)( |
|
5398 + DVBT_DEMOD_MODULE *pDemod, |
|
5399 + int RegBitName, |
|
5400 + unsigned long *pReadingValue |
|
5401 + ); |
|
5402 + |
|
5403 + |
|
5404 + |
|
5405 + |
|
5406 + |
|
5407 +/** |
|
5408 + |
|
5409 +@brief DVB-T demod type getting function pointer |
|
5410 + |
|
5411 +One can use DVBT_DEMOD_FP_GET_DEMOD_TYPE() to get DVB-T demod type. |
|
5412 + |
|
5413 + |
|
5414 +@param [in] pDemod The demod module pointer |
|
5415 +@param [out] pDemodType Pointer to an allocated memory for storing demod type |
|
5416 + |
|
5417 + |
|
5418 +@note |
|
5419 + -# Demod building function will set DVBT_DEMOD_FP_GET_DEMOD_TYPE() with the corresponding function. |
|
5420 + |
|
5421 + |
|
5422 +@see MODULE_TYPE |
|
5423 + |
|
5424 +*/ |
|
5425 +typedef void |
|
5426 +(*DVBT_DEMOD_FP_GET_DEMOD_TYPE)( |
|
5427 + DVBT_DEMOD_MODULE *pDemod, |
|
5428 + int *pDemodType |
|
5429 + ); |
|
5430 + |
|
5431 + |
|
5432 + |
|
5433 + |
|
5434 + |
|
5435 +/** |
|
5436 + |
|
5437 +@brief DVB-T demod I2C device address getting function pointer |
|
5438 + |
|
5439 +One can use DVBT_DEMOD_FP_GET_DEVICE_ADDR() to get DVB-T demod I2C device address. |
|
5440 + |
|
5441 + |
|
5442 +@param [in] pDemod The demod module pointer |
|
5443 +@param [out] pDeviceAddr Pointer to an allocated memory for storing demod I2C device address |
|
5444 + |
|
5445 + |
|
5446 +@retval FUNCTION_SUCCESS Get demod device address successfully. |
|
5447 +@retval FUNCTION_ERROR Get demod device address unsuccessfully. |
|
5448 + |
|
5449 + |
|
5450 +@note |
|
5451 + -# Demod building function will set DVBT_DEMOD_FP_GET_DEVICE_ADDR() with the corresponding function. |
|
5452 + |
|
5453 +*/ |
|
5454 +typedef void |
|
5455 +(*DVBT_DEMOD_FP_GET_DEVICE_ADDR)( |
|
5456 + DVBT_DEMOD_MODULE *pDemod, |
|
5457 + unsigned char *pDeviceAddr |
|
5458 + ); |
|
5459 + |
|
5460 + |
|
5461 + |
|
5462 + |
|
5463 + |
|
5464 +/** |
|
5465 + |
|
5466 +@brief DVB-T demod crystal frequency getting function pointer |
|
5467 + |
|
5468 +One can use DVBT_DEMOD_FP_GET_CRYSTAL_FREQ_HZ() to get DVB-T demod crystal frequency in Hz. |
|
5469 + |
|
5470 + |
|
5471 +@param [in] pDemod The demod module pointer |
|
5472 +@param [out] pCrystalFreqHz Pointer to an allocated memory for storing demod crystal frequency in Hz |
|
5473 + |
|
5474 + |
|
5475 +@retval FUNCTION_SUCCESS Get demod crystal frequency successfully. |
|
5476 +@retval FUNCTION_ERROR Get demod crystal frequency unsuccessfully. |
|
5477 + |
|
5478 + |
|
5479 +@note |
|
5480 + -# Demod building function will set DVBT_DEMOD_FP_GET_CRYSTAL_FREQ_HZ() with the corresponding function. |
|
5481 + |
|
5482 +*/ |
|
5483 +typedef void |
|
5484 +(*DVBT_DEMOD_FP_GET_CRYSTAL_FREQ_HZ)( |
|
5485 + DVBT_DEMOD_MODULE *pDemod, |
|
5486 + unsigned long *pCrystalFreqHz |
|
5487 + ); |
|
5488 + |
|
5489 + |
|
5490 + |
|
5491 + |
|
5492 + |
|
5493 +/** |
|
5494 + |
|
5495 +@brief DVB-T demod I2C bus connection asking function pointer |
|
5496 + |
|
5497 +One can use DVBT_DEMOD_FP_IS_CONNECTED_TO_I2C() to ask DVB-T demod if it is connected to I2C bus. |
|
5498 + |
|
5499 + |
|
5500 +@param [in] pDemod The demod module pointer |
|
5501 +@param [out] pAnswer Pointer to an allocated memory for storing answer |
|
5502 + |
|
5503 + |
|
5504 +@note |
|
5505 + -# Demod building function will set DVBT_DEMOD_FP_IS_CONNECTED_TO_I2C() with the corresponding function. |
|
5506 + |
|
5507 +*/ |
|
5508 +typedef void |
|
5509 +(*DVBT_DEMOD_FP_IS_CONNECTED_TO_I2C)( |
|
5510 + DVBT_DEMOD_MODULE *pDemod, |
|
5511 + int *pAnswer |
|
5512 + ); |
|
5513 + |
|
5514 + |
|
5515 + |
|
5516 + |
|
5517 + |
|
5518 +/** |
|
5519 + |
|
5520 +@brief DVB-T demod software resetting function pointer |
|
5521 + |
|
5522 +One can use DVBT_DEMOD_FP_SOFTWARE_RESET() to reset DVB-T demod by software reset. |
|
5523 + |
|
5524 + |
|
5525 +@param [in] pDemod The demod module pointer |
|
5526 + |
|
5527 + |
|
5528 +@retval FUNCTION_SUCCESS Reset demod by software reset successfully. |
|
5529 +@retval FUNCTION_ERROR Reset demod by software reset unsuccessfully. |
|
5530 + |
|
5531 + |
|
5532 +@note |
|
5533 + -# Demod building function will set DVBT_DEMOD_FP_SOFTWARE_RESET() with the corresponding function. |
|
5534 + |
|
5535 +*/ |
|
5536 +typedef int |
|
5537 +(*DVBT_DEMOD_FP_SOFTWARE_RESET)( |
|
5538 + DVBT_DEMOD_MODULE *pDemod |
|
5539 + ); |
|
5540 + |
|
5541 + |
|
5542 + |
|
5543 + |
|
5544 + |
|
5545 +/** |
|
5546 + |
|
5547 +@brief DVB-T demod initializing function pointer |
|
5548 + |
|
5549 +One can use DVBT_DEMOD_FP_INITIALIZE() to initialie DVB-T demod. |
|
5550 + |
|
5551 + |
|
5552 +@param [in] pDemod The demod module pointer |
|
5553 + |
|
5554 + |
|
5555 +@retval FUNCTION_SUCCESS Initialize demod successfully. |
|
5556 +@retval FUNCTION_ERROR Initialize demod unsuccessfully. |
|
5557 + |
|
5558 + |
|
5559 +@note |
|
5560 + -# Demod building function will set DVBT_DEMOD_FP_INITIALIZE() with the corresponding function. |
|
5561 + |
|
5562 +*/ |
|
5563 +typedef int |
|
5564 +(*DVBT_DEMOD_FP_INITIALIZE)( |
|
5565 + DVBT_DEMOD_MODULE *pDemod |
|
5566 + ); |
|
5567 + |
|
5568 + |
|
5569 + |
|
5570 + |
|
5571 + |
|
5572 +/** |
|
5573 + |
|
5574 +@brief DVB-T demod bandwidth mode setting function pointer |
|
5575 + |
|
5576 +One can use DVBT_DEMOD_FP_SET_DVBT_MODE() to set DVB-T demod bandwidth mode. |
|
5577 + |
|
5578 + |
|
5579 +@param [in] pDemod The demod module pointer |
|
5580 +@param [in] BandwidthMode Bandwidth mode for setting |
|
5581 + |
|
5582 + |
|
5583 +@retval FUNCTION_SUCCESS Set demod bandwidth mode successfully. |
|
5584 +@retval FUNCTION_ERROR Set demod bandwidth mode unsuccessfully. |
|
5585 + |
|
5586 + |
|
5587 +@note |
|
5588 + -# Demod building function will set DVBT_DEMOD_FP_SET_DVBT_MODE() with the corresponding function. |
|
5589 + |
|
5590 + |
|
5591 +@see DVBT_BANDWIDTH_MODE |
|
5592 + |
|
5593 +*/ |
|
5594 +typedef int |
|
5595 +(*DVBT_DEMOD_FP_SET_BANDWIDTH_MODE)( |
|
5596 + DVBT_DEMOD_MODULE *pDemod, |
|
5597 + int BandwidthMode |
|
5598 + ); |
|
5599 + |
|
5600 + |
|
5601 + |
|
5602 + |
|
5603 + |
|
5604 +/** |
|
5605 + |
|
5606 +@brief DVB-T demod IF frequency setting function pointer |
|
5607 + |
|
5608 +One can use DVBT_DEMOD_FP_SET_IF_FREQ_HZ() to set DVB-T demod IF frequency in Hz. |
|
5609 + |
|
5610 + |
|
5611 +@param [in] pDemod The demod module pointer |
|
5612 +@param [in] IfFreqHz IF frequency in Hz for setting |
|
5613 + |
|
5614 + |
|
5615 +@retval FUNCTION_SUCCESS Set demod IF frequency successfully. |
|
5616 +@retval FUNCTION_ERROR Set demod IF frequency unsuccessfully. |
|
5617 + |
|
5618 + |
|
5619 +@note |
|
5620 + -# Demod building function will set DVBT_DEMOD_FP_SET_IF_FREQ_HZ() with the corresponding function. |
|
5621 + |
|
5622 + |
|
5623 +@see IF_FREQ_HZ |
|
5624 + |
|
5625 +*/ |
|
5626 +typedef int |
|
5627 +(*DVBT_DEMOD_FP_SET_IF_FREQ_HZ)( |
|
5628 + DVBT_DEMOD_MODULE *pDemod, |
|
5629 + unsigned long IfFreqHz |
|
5630 + ); |
|
5631 + |
|
5632 + |
|
5633 + |
|
5634 + |
|
5635 + |
|
5636 +/** |
|
5637 + |
|
5638 +@brief DVB-T demod spectrum mode setting function pointer |
|
5639 + |
|
5640 +One can use DVBT_DEMOD_FP_SET_SPECTRUM_MODE() to set DVB-T demod spectrum mode. |
|
5641 + |
|
5642 + |
|
5643 +@param [in] pDemod The demod module pointer |
|
5644 +@param [in] SpectrumMode Spectrum mode for setting |
|
5645 + |
|
5646 + |
|
5647 +@retval FUNCTION_SUCCESS Set demod spectrum mode successfully. |
|
5648 +@retval FUNCTION_ERROR Set demod spectrum mode unsuccessfully. |
|
5649 + |
|
5650 + |
|
5651 +@note |
|
5652 + -# Demod building function will set DVBT_DEMOD_FP_SET_SPECTRUM_MODE() with the corresponding function. |
|
5653 + |
|
5654 + |
|
5655 +@see SPECTRUM_MODE |
|
5656 + |
|
5657 +*/ |
|
5658 +typedef int |
|
5659 +(*DVBT_DEMOD_FP_SET_SPECTRUM_MODE)( |
|
5660 + DVBT_DEMOD_MODULE *pDemod, |
|
5661 + int SpectrumMode |
|
5662 + ); |
|
5663 + |
|
5664 + |
|
5665 + |
|
5666 + |
|
5667 + |
|
5668 +/** |
|
5669 + |
|
5670 +@brief DVB-T demod bandwidth mode getting function pointer |
|
5671 + |
|
5672 +One can use DVBT_DEMOD_FP_GET_DVBT_MODE() to get DVB-T demod bandwidth mode. |
|
5673 + |
|
5674 + |
|
5675 +@param [in] pDemod The demod module pointer |
|
5676 +@param [out] pBandwidthMode Pointer to an allocated memory for storing demod bandwidth mode |
|
5677 + |
|
5678 + |
|
5679 +@retval FUNCTION_SUCCESS Get demod bandwidth mode successfully. |
|
5680 +@retval FUNCTION_ERROR Get demod bandwidth mode unsuccessfully. |
|
5681 + |
|
5682 + |
|
5683 +@note |
|
5684 + -# Demod building function will set DVBT_DEMOD_FP_GET_DVBT_MODE() with the corresponding function. |
|
5685 + |
|
5686 + |
|
5687 +@see DVBT_DVBT_MODE |
|
5688 + |
|
5689 +*/ |
|
5690 +typedef int |
|
5691 +(*DVBT_DEMOD_FP_GET_BANDWIDTH_MODE)( |
|
5692 + DVBT_DEMOD_MODULE *pDemod, |
|
5693 + int *pBandwidthMode |
|
5694 + ); |
|
5695 + |
|
5696 + |
|
5697 + |
|
5698 + |
|
5699 + |
|
5700 +/** |
|
5701 + |
|
5702 +@brief DVB-T demod IF frequency getting function pointer |
|
5703 + |
|
5704 +One can use DVBT_DEMOD_FP_GET_IF_FREQ_HZ() to get DVB-T demod IF frequency in Hz. |
|
5705 + |
|
5706 + |
|
5707 +@param [in] pDemod The demod module pointer |
|
5708 +@param [out] pIfFreqHz Pointer to an allocated memory for storing demod IF frequency in Hz |
|
5709 + |
|
5710 + |
|
5711 +@retval FUNCTION_SUCCESS Get demod IF frequency successfully. |
|
5712 +@retval FUNCTION_ERROR Get demod IF frequency unsuccessfully. |
|
5713 + |
|
5714 + |
|
5715 +@note |
|
5716 + -# Demod building function will set DVBT_DEMOD_FP_GET_IF_FREQ_HZ() with the corresponding function. |
|
5717 + |
|
5718 + |
|
5719 +@see IF_FREQ_HZ |
|
5720 + |
|
5721 +*/ |
|
5722 +typedef int |
|
5723 +(*DVBT_DEMOD_FP_GET_IF_FREQ_HZ)( |
|
5724 + DVBT_DEMOD_MODULE *pDemod, |
|
5725 + unsigned long *pIfFreqHz |
|
5726 + ); |
|
5727 + |
|
5728 + |
|
5729 + |
|
5730 + |
|
5731 + |
|
5732 +/** |
|
5733 + |
|
5734 +@brief DVB-T demod spectrum mode getting function pointer |
|
5735 + |
|
5736 +One can use DVBT_DEMOD_FP_GET_SPECTRUM_MODE() to get DVB-T demod spectrum mode. |
|
5737 + |
|
5738 + |
|
5739 +@param [in] pDemod The demod module pointer |
|
5740 +@param [out] pSpectrumMode Pointer to an allocated memory for storing demod spectrum mode |
|
5741 + |
|
5742 + |
|
5743 +@retval FUNCTION_SUCCESS Get demod spectrum mode successfully. |
|
5744 +@retval FUNCTION_ERROR Get demod spectrum mode unsuccessfully. |
|
5745 + |
|
5746 + |
|
5747 +@note |
|
5748 + -# Demod building function will set DVBT_DEMOD_FP_GET_SPECTRUM_MODE() with the corresponding function. |
|
5749 + |
|
5750 + |
|
5751 +@see SPECTRUM_MODE |
|
5752 + |
|
5753 +*/ |
|
5754 +typedef int |
|
5755 +(*DVBT_DEMOD_FP_GET_SPECTRUM_MODE)( |
|
5756 + DVBT_DEMOD_MODULE *pDemod, |
|
5757 + int *pSpectrumMode |
|
5758 + ); |
|
5759 + |
|
5760 + |
|
5761 + |
|
5762 + |
|
5763 + |
|
5764 +/** |
|
5765 + |
|
5766 +@brief DVB-T demod TPS lock asking function pointer |
|
5767 + |
|
5768 +One can use DVBT_DEMOD_FP_IS_TPS_LOCKED() to ask DVB-T demod if it is TPS-locked. |
|
5769 + |
|
5770 + |
|
5771 +@param [in] pDemod The demod module pointer |
|
5772 +@param [out] pAnswer Pointer to an allocated memory for storing answer |
|
5773 + |
|
5774 + |
|
5775 +@retval FUNCTION_SUCCESS Perform TPS lock asking to demod successfully. |
|
5776 +@retval FUNCTION_ERROR Perform TPS lock asking to demod unsuccessfully. |
|
5777 + |
|
5778 + |
|
5779 +@note |
|
5780 + -# Demod building function will set DVBT_DEMOD_FP_IS_TPS_LOCKED() with the corresponding function. |
|
5781 + |
|
5782 +*/ |
|
5783 +typedef int |
|
5784 +(*DVBT_DEMOD_FP_IS_TPS_LOCKED)( |
|
5785 + DVBT_DEMOD_MODULE *pDemod, |
|
5786 + int *pAnswer |
|
5787 + ); |
|
5788 + |
|
5789 + |
|
5790 + |
|
5791 + |
|
5792 + |
|
5793 +/** |
|
5794 + |
|
5795 +@brief DVB-T demod signal lock asking function pointer |
|
5796 + |
|
5797 +One can use DVBT_DEMOD_FP_IS_SIGNAL_LOCKED() to ask DVB-T demod if it is signal-locked. |
|
5798 + |
|
5799 + |
|
5800 +@param [in] pDemod The demod module pointer |
|
5801 +@param [out] pAnswer Pointer to an allocated memory for storing answer |
|
5802 + |
|
5803 + |
|
5804 +@retval FUNCTION_SUCCESS Perform signal lock asking to demod successfully. |
|
5805 +@retval FUNCTION_ERROR Perform signal lock asking to demod unsuccessfully. |
|
5806 + |
|
5807 + |
|
5808 +@note |
|
5809 + -# Demod building function will set DVBT_DEMOD_FP_IS_SIGNAL_LOCKED() with the corresponding function. |
|
5810 + |
|
5811 +*/ |
|
5812 +typedef int |
|
5813 +(*DVBT_DEMOD_FP_IS_SIGNAL_LOCKED)( |
|
5814 + DVBT_DEMOD_MODULE *pDemod, |
|
5815 + int *pAnswer |
|
5816 + ); |
|
5817 + |
|
5818 + |
|
5819 + |
|
5820 + |
|
5821 + |
|
5822 +/** |
|
5823 + |
|
5824 +@brief DVB-T demod signal strength getting function pointer |
|
5825 + |
|
5826 +One can use DVBT_DEMOD_FP_GET_SIGNAL_STRENGTH() to get signal strength. |
|
5827 + |
|
5828 + |
|
5829 +@param [in] pDemod The demod module pointer |
|
5830 +@param [out] pSignalStrength Pointer to an allocated memory for storing signal strength (value = 0 ~ 100) |
|
5831 + |
|
5832 + |
|
5833 +@retval FUNCTION_SUCCESS Get demod signal strength successfully. |
|
5834 +@retval FUNCTION_ERROR Get demod signal strength unsuccessfully. |
|
5835 + |
|
5836 + |
|
5837 +@note |
|
5838 + -# Demod building function will set DVBT_DEMOD_FP_GET_SIGNAL_STRENGTH() with the corresponding function. |
|
5839 + |
|
5840 +*/ |
|
5841 +typedef int |
|
5842 +(*DVBT_DEMOD_FP_GET_SIGNAL_STRENGTH)( |
|
5843 + DVBT_DEMOD_MODULE *pDemod, |
|
5844 + unsigned long *pSignalStrength |
|
5845 + ); |
|
5846 + |
|
5847 + |
|
5848 + |
|
5849 + |
|
5850 + |
|
5851 +/** |
|
5852 + |
|
5853 +@brief DVB-T demod signal quality getting function pointer |
|
5854 + |
|
5855 +One can use DVBT_DEMOD_FP_GET_SIGNAL_QUALITY() to get signal quality. |
|
5856 + |
|
5857 + |
|
5858 +@param [in] pDemod The demod module pointer |
|
5859 +@param [out] pSignalQuality Pointer to an allocated memory for storing signal quality (value = 0 ~ 100) |
|
5860 + |
|
5861 + |
|
5862 +@retval FUNCTION_SUCCESS Get demod signal quality successfully. |
|
5863 +@retval FUNCTION_ERROR Get demod signal quality unsuccessfully. |
|
5864 + |
|
5865 + |
|
5866 +@note |
|
5867 + -# Demod building function will set DVBT_DEMOD_FP_GET_SIGNAL_QUALITY() with the corresponding function. |
|
5868 + |
|
5869 +*/ |
|
5870 +typedef int |
|
5871 +(*DVBT_DEMOD_FP_GET_SIGNAL_QUALITY)( |
|
5872 + DVBT_DEMOD_MODULE *pDemod, |
|
5873 + unsigned long *pSignalQuality |
|
5874 + ); |
|
5875 + |
|
5876 + |
|
5877 + |
|
5878 + |
|
5879 + |
|
5880 +/** |
|
5881 + |
|
5882 +@brief DVB-T demod BER getting function pointer |
|
5883 + |
|
5884 +One can use DVBT_DEMOD_FP_GET_BER() to get BER. |
|
5885 + |
|
5886 + |
|
5887 +@param [in] pDemod The demod module pointer |
|
5888 +@param [out] pBerNum Pointer to an allocated memory for storing BER numerator |
|
5889 +@param [out] pBerDen Pointer to an allocated memory for storing BER denominator |
|
5890 + |
|
5891 + |
|
5892 +@retval FUNCTION_SUCCESS Get demod error rate value successfully. |
|
5893 +@retval FUNCTION_ERROR Get demod error rate value unsuccessfully. |
|
5894 + |
|
5895 + |
|
5896 +@note |
|
5897 + -# Demod building function will set DVBT_DEMOD_FP_GET_BER() with the corresponding function. |
|
5898 + |
|
5899 +*/ |
|
5900 +typedef int |
|
5901 +(*DVBT_DEMOD_FP_GET_BER)( |
|
5902 + DVBT_DEMOD_MODULE *pDemod, |
|
5903 + unsigned long *pBerNum, |
|
5904 + unsigned long *pBerDen |
|
5905 + ); |
|
5906 + |
|
5907 + |
|
5908 + |
|
5909 + |
|
5910 + |
|
5911 +/** |
|
5912 + |
|
5913 +@brief DVB-T demod SNR getting function pointer |
|
5914 + |
|
5915 +One can use DVBT_DEMOD_FP_GET_SNR_DB() to get SNR in dB. |
|
5916 + |
|
5917 + |
|
5918 +@param [in] pDemod The demod module pointer |
|
5919 +@param [out] pSnrDbNum Pointer to an allocated memory for storing SNR dB numerator |
|
5920 +@param [out] pSnrDbDen Pointer to an allocated memory for storing SNR dB denominator |
|
5921 + |
|
5922 + |
|
5923 +@retval FUNCTION_SUCCESS Get demod SNR successfully. |
|
5924 +@retval FUNCTION_ERROR Get demod SNR unsuccessfully. |
|
5925 + |
|
5926 + |
|
5927 +@note |
|
5928 + -# Demod building function will set DVBT_DEMOD_FP_GET_SNR_DB() with the corresponding function. |
|
5929 + |
|
5930 +*/ |
|
5931 +typedef int |
|
5932 +(*DVBT_DEMOD_FP_GET_SNR_DB)( |
|
5933 + DVBT_DEMOD_MODULE *pDemod, |
|
5934 + long *pSnrDbNum, |
|
5935 + long *pSnrDbDen |
|
5936 + ); |
|
5937 + |
|
5938 + |
|
5939 + |
|
5940 + |
|
5941 + |
|
5942 +/** |
|
5943 + |
|
5944 +@brief DVB-T demod RF AGC getting function pointer |
|
5945 + |
|
5946 +One can use DVBT_DEMOD_FP_GET_RF_AGC() to get DVB-T demod RF AGC value. |
|
5947 + |
|
5948 + |
|
5949 +@param [in] pDemod The demod module pointer |
|
5950 +@param [out] pRfAgc Pointer to an allocated memory for storing RF AGC value |
|
5951 + |
|
5952 + |
|
5953 +@retval FUNCTION_SUCCESS Get demod RF AGC value successfully. |
|
5954 +@retval FUNCTION_ERROR Get demod RF AGC value unsuccessfully. |
|
5955 + |
|
5956 + |
|
5957 +@note |
|
5958 + -# Demod building function will set DVBT_DEMOD_FP_GET_RF_AGC() with the corresponding function. |
|
5959 + -# The range of RF AGC value is (-pow(2, 13)) ~ (pow(2, 13) - 1). |
|
5960 + |
|
5961 +*/ |
|
5962 +typedef int |
|
5963 +(*DVBT_DEMOD_FP_GET_RF_AGC)( |
|
5964 + DVBT_DEMOD_MODULE *pDemod, |
|
5965 + int *pRfAgc |
|
5966 + ); |
|
5967 + |
|
5968 + |
|
5969 + |
|
5970 + |
|
5971 + |
|
5972 +/** |
|
5973 + |
|
5974 +@brief DVB-T demod IF AGC getting function pointer |
|
5975 + |
|
5976 +One can use DVBT_DEMOD_FP_GET_IF_AGC() to get DVB-T demod IF AGC value. |
|
5977 + |
|
5978 + |
|
5979 +@param [in] pDemod The demod module pointer |
|
5980 +@param [out] pIfAgc Pointer to an allocated memory for storing IF AGC value |
|
5981 + |
|
5982 + |
|
5983 +@retval FUNCTION_SUCCESS Get demod IF AGC value successfully. |
|
5984 +@retval FUNCTION_ERROR Get demod IF AGC value unsuccessfully. |
|
5985 + |
|
5986 + |
|
5987 +@note |
|
5988 + -# Demod building function will set DVBT_DEMOD_FP_GET_IF_AGC() with the corresponding function. |
|
5989 + -# The range of IF AGC value is (-pow(2, 13)) ~ (pow(2, 13) - 1). |
|
5990 + |
|
5991 +*/ |
|
5992 +typedef int |
|
5993 +(*DVBT_DEMOD_FP_GET_IF_AGC)( |
|
5994 + DVBT_DEMOD_MODULE *pDemod, |
|
5995 + int *pIfAgc |
|
5996 + ); |
|
5997 + |
|
5998 + |
|
5999 + |
|
6000 + |
|
6001 + |
|
6002 +/** |
|
6003 + |
|
6004 +@brief DVB-T demod digital AGC getting function pointer |
|
6005 + |
|
6006 +One can use DVBT_DEMOD_FP_GET_DI_AGC() to get DVB-T demod digital AGC value. |
|
6007 + |
|
6008 + |
|
6009 +@param [in] pDemod The demod module pointer |
|
6010 +@param [out] pDiAgc Pointer to an allocated memory for storing digital AGC value |
|
6011 + |
|
6012 + |
|
6013 +@retval FUNCTION_SUCCESS Get demod digital AGC value successfully. |
|
6014 +@retval FUNCTION_ERROR Get demod digital AGC value unsuccessfully. |
|
6015 + |
|
6016 + |
|
6017 +@note |
|
6018 + -# Demod building function will set DVBT_DEMOD_FP_GET_DI_AGC() with the corresponding function. |
|
6019 + -# The range of digital AGC value is 0 ~ (pow(2, 8) - 1). |
|
6020 + |
|
6021 +*/ |
|
6022 +typedef int |
|
6023 +(*DVBT_DEMOD_FP_GET_DI_AGC)( |
|
6024 + DVBT_DEMOD_MODULE *pDemod, |
|
6025 + unsigned char *pDiAgc |
|
6026 + ); |
|
6027 + |
|
6028 + |
|
6029 + |
|
6030 + |
|
6031 + |
|
6032 +/** |
|
6033 + |
|
6034 +@brief DVB-T demod TR offset getting function pointer |
|
6035 + |
|
6036 +One can use DVBT_DEMOD_FP_GET_TR_OFFSET_PPM() to get TR offset in ppm. |
|
6037 + |
|
6038 + |
|
6039 +@param [in] pDemod The demod module pointer |
|
6040 +@param [out] pTrOffsetPpm Pointer to an allocated memory for storing TR offset in ppm |
|
6041 + |
|
6042 + |
|
6043 +@retval FUNCTION_SUCCESS Get demod TR offset successfully. |
|
6044 +@retval FUNCTION_ERROR Get demod TR offset unsuccessfully. |
|
6045 + |
|
6046 + |
|
6047 +@note |
|
6048 + -# Demod building function will set DVBT_DEMOD_FP_GET_TR_OFFSET_PPM() with the corresponding function. |
|
6049 + |
|
6050 +*/ |
|
6051 +typedef int |
|
6052 +(*DVBT_DEMOD_FP_GET_TR_OFFSET_PPM)( |
|
6053 + DVBT_DEMOD_MODULE *pDemod, |
|
6054 + long *pTrOffsetPpm |
|
6055 + ); |
|
6056 + |
|
6057 + |
|
6058 + |
|
6059 + |
|
6060 + |
|
6061 +/** |
|
6062 + |
|
6063 +@brief DVB-T demod CR offset getting function pointer |
|
6064 + |
|
6065 +One can use DVBT_DEMOD_FP_GET_CR_OFFSET_HZ() to get CR offset in Hz. |
|
6066 + |
|
6067 + |
|
6068 +@param [in] pDemod The demod module pointer |
|
6069 +@param [out] pCrOffsetHz Pointer to an allocated memory for storing CR offset in Hz |
|
6070 + |
|
6071 + |
|
6072 +@retval FUNCTION_SUCCESS Get demod CR offset successfully. |
|
6073 +@retval FUNCTION_ERROR Get demod CR offset unsuccessfully. |
|
6074 + |
|
6075 + |
|
6076 +@note |
|
6077 + -# Demod building function will set DVBT_DEMOD_FP_GET_CR_OFFSET_HZ() with the corresponding function. |
|
6078 + |
|
6079 +*/ |
|
6080 +typedef int |
|
6081 +(*DVBT_DEMOD_FP_GET_CR_OFFSET_HZ)( |
|
6082 + DVBT_DEMOD_MODULE *pDemod, |
|
6083 + long *pCrOffsetHz |
|
6084 + ); |
|
6085 + |
|
6086 + |
|
6087 + |
|
6088 + |
|
6089 + |
|
6090 +/** |
|
6091 + |
|
6092 +@brief DVB-T demod constellation mode getting function pointer |
|
6093 + |
|
6094 +One can use DVBT_DEMOD_FP_GET_CONSTELLATION() to get DVB-T demod constellation mode. |
|
6095 + |
|
6096 + |
|
6097 +@param [in] pDemod The demod module pointer |
|
6098 +@param [out] pConstellation Pointer to an allocated memory for storing demod constellation mode |
|
6099 + |
|
6100 + |
|
6101 +@retval FUNCTION_SUCCESS Get demod constellation mode successfully. |
|
6102 +@retval FUNCTION_ERROR Get demod constellation mode unsuccessfully. |
|
6103 + |
|
6104 + |
|
6105 +@note |
|
6106 + -# Demod building function will set DVBT_DEMOD_FP_GET_CONSTELLATION() with the corresponding function. |
|
6107 + |
|
6108 + |
|
6109 +@see DVBT_CONSTELLATION_MODE |
|
6110 + |
|
6111 +*/ |
|
6112 +typedef int |
|
6113 +(*DVBT_DEMOD_FP_GET_CONSTELLATION)( |
|
6114 + DVBT_DEMOD_MODULE *pDemod, |
|
6115 + int *pConstellation |
|
6116 + ); |
|
6117 + |
|
6118 + |
|
6119 + |
|
6120 + |
|
6121 + |
|
6122 +/** |
|
6123 + |
|
6124 +@brief DVB-T demod hierarchy mode getting function pointer |
|
6125 + |
|
6126 +One can use DVBT_DEMOD_FP_GET_HIERARCHY() to get DVB-T demod hierarchy mode. |
|
6127 + |
|
6128 + |
|
6129 +@param [in] pDemod The demod module pointer |
|
6130 +@param [out] pHierarchy Pointer to an allocated memory for storing demod hierarchy mode |
|
6131 + |
|
6132 + |
|
6133 +@retval FUNCTION_SUCCESS Get demod hierarchy mode successfully. |
|
6134 +@retval FUNCTION_ERROR Get demod hierarchy mode unsuccessfully. |
|
6135 + |
|
6136 + |
|
6137 +@note |
|
6138 + -# Demod building function will set DVBT_DEMOD_FP_GET_HIERARCHY() with the corresponding function. |
|
6139 + |
|
6140 + |
|
6141 +@see DVBT_HIERARCHY_MODE |
|
6142 + |
|
6143 +*/ |
|
6144 +typedef int |
|
6145 +(*DVBT_DEMOD_FP_GET_HIERARCHY)( |
|
6146 + DVBT_DEMOD_MODULE *pDemod, |
|
6147 + int *pHierarchy |
|
6148 + ); |
|
6149 + |
|
6150 + |
|
6151 + |
|
6152 + |
|
6153 + |
|
6154 +/** |
|
6155 + |
|
6156 +@brief DVB-T demod low-priority code rate mode getting function pointer |
|
6157 + |
|
6158 +One can use DVBT_DEMOD_FP_GET_CODE_RATE_LP() to get DVB-T demod low-priority code rate mode. |
|
6159 + |
|
6160 + |
|
6161 +@param [in] pDemod The demod module pointer |
|
6162 +@param [out] pCodeRateLp Pointer to an allocated memory for storing demod low-priority code rate mode |
|
6163 + |
|
6164 + |
|
6165 +@retval FUNCTION_SUCCESS Get demod low-priority code rate mode successfully. |
|
6166 +@retval FUNCTION_ERROR Get demod low-priority code rate mode unsuccessfully. |
|
6167 + |
|
6168 + |
|
6169 +@note |
|
6170 + -# Demod building function will set DVBT_DEMOD_FP_GET_CODE_RATE_LP() with the corresponding function. |
|
6171 + |
|
6172 + |
|
6173 +@see DVBT_CODE_RATE_MODE |
|
6174 + |
|
6175 +*/ |
|
6176 +typedef int |
|
6177 +(*DVBT_DEMOD_FP_GET_CODE_RATE_LP)( |
|
6178 + DVBT_DEMOD_MODULE *pDemod, |
|
6179 + int *pCodeRateLp |
|
6180 + ); |
|
6181 + |
|
6182 + |
|
6183 + |
|
6184 + |
|
6185 + |
|
6186 +/** |
|
6187 + |
|
6188 +@brief DVB-T demod high-priority code rate mode getting function pointer |
|
6189 + |
|
6190 +One can use DVBT_DEMOD_FP_GET_CODE_RATE_HP() to get DVB-T demod high-priority code rate mode. |
|
6191 + |
|
6192 + |
|
6193 +@param [in] pDemod The demod module pointer |
|
6194 +@param [out] pCodeRateHp Pointer to an allocated memory for storing demod high-priority code rate mode |
|
6195 + |
|
6196 + |
|
6197 +@retval FUNCTION_SUCCESS Get demod high-priority code rate mode successfully. |
|
6198 +@retval FUNCTION_ERROR Get demod high-priority code rate mode unsuccessfully. |
|
6199 + |
|
6200 + |
|
6201 +@note |
|
6202 + -# Demod building function will set DVBT_DEMOD_FP_GET_CODE_RATE_HP() with the corresponding function. |
|
6203 + |
|
6204 + |
|
6205 +@see DVBT_CODE_RATE_MODE |
|
6206 + |
|
6207 +*/ |
|
6208 +typedef int |
|
6209 +(*DVBT_DEMOD_FP_GET_CODE_RATE_HP)( |
|
6210 + DVBT_DEMOD_MODULE *pDemod, |
|
6211 + int *pCodeRateHp |
|
6212 + ); |
|
6213 + |
|
6214 + |
|
6215 + |
|
6216 + |
|
6217 + |
|
6218 +/** |
|
6219 + |
|
6220 +@brief DVB-T demod guard interval mode getting function pointer |
|
6221 + |
|
6222 +One can use DVBT_DEMOD_FP_GET_GUARD_INTERVAL() to get DVB-T demod guard interval mode. |
|
6223 + |
|
6224 + |
|
6225 +@param [in] pDemod The demod module pointer |
|
6226 +@param [out] pGuardInterval Pointer to an allocated memory for storing demod guard interval mode |
|
6227 + |
|
6228 + |
|
6229 +@retval FUNCTION_SUCCESS Get demod guard interval mode successfully. |
|
6230 +@retval FUNCTION_ERROR Get demod guard interval mode unsuccessfully. |
|
6231 + |
|
6232 + |
|
6233 +@note |
|
6234 + -# Demod building function will set DVBT_DEMOD_FP_GET_GUARD_INTERVAL() with the corresponding function. |
|
6235 + |
|
6236 + |
|
6237 +@see DVBT_GUARD_INTERVAL_MODE |
|
6238 + |
|
6239 +*/ |
|
6240 +typedef int |
|
6241 +(*DVBT_DEMOD_FP_GET_GUARD_INTERVAL)( |
|
6242 + DVBT_DEMOD_MODULE *pDemod, |
|
6243 + int *pGuardInterval |
|
6244 + ); |
|
6245 + |
|
6246 + |
|
6247 + |
|
6248 + |
|
6249 + |
|
6250 +/** |
|
6251 + |
|
6252 +@brief DVB-T demod FFT mode getting function pointer |
|
6253 + |
|
6254 +One can use DVBT_DEMOD_FP_GET_FFT_MODE() to get DVB-T demod FFT mode. |
|
6255 + |
|
6256 + |
|
6257 +@param [in] pDemod The demod module pointer |
|
6258 +@param [out] pFftMode Pointer to an allocated memory for storing demod FFT mode |
|
6259 + |
|
6260 + |
|
6261 +@retval FUNCTION_SUCCESS Get demod FFT mode successfully. |
|
6262 +@retval FUNCTION_ERROR Get demod FFT mode unsuccessfully. |
|
6263 + |
|
6264 + |
|
6265 +@note |
|
6266 + -# Demod building function will set DVBT_DEMOD_FP_GET_FFT_MODE() with the corresponding function. |
|
6267 + |
|
6268 + |
|
6269 +@see DVBT_FFT_MODE_MODE |
|
6270 + |
|
6271 +*/ |
|
6272 +typedef int |
|
6273 +(*DVBT_DEMOD_FP_GET_FFT_MODE)( |
|
6274 + DVBT_DEMOD_MODULE *pDemod, |
|
6275 + int *pFftMode |
|
6276 + ); |
|
6277 + |
|
6278 + |
|
6279 + |
|
6280 + |
|
6281 + |
|
6282 +/** |
|
6283 + |
|
6284 +@brief DVB-T demod updating function pointer |
|
6285 + |
|
6286 +One can use DVBT_DEMOD_FP_UPDATE_FUNCTION() to update demod register setting. |
|
6287 + |
|
6288 + |
|
6289 +@param [in] pDemod The demod module pointer |
|
6290 + |
|
6291 + |
|
6292 +@retval FUNCTION_SUCCESS Update demod setting successfully. |
|
6293 +@retval FUNCTION_ERROR Update demod setting unsuccessfully. |
|
6294 + |
|
6295 + |
|
6296 +@note |
|
6297 + -# Demod building function will set DVBT_DEMOD_FP_UPDATE_FUNCTION() with the corresponding function. |
|
6298 + |
|
6299 + |
|
6300 + |
|
6301 +@par Example: |
|
6302 +@code |
|
6303 + |
|
6304 + |
|
6305 +#include "demod_pseudo.h" |
|
6306 + |
|
6307 + |
|
6308 +int main(void) |
|
6309 +{ |
|
6310 + DVBT_DEMOD_MODULE *pDemod; |
|
6311 + DVBT_DEMOD_MODULE DvbtDemodModuleMemory; |
|
6312 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
6313 + |
|
6314 + |
|
6315 + // Build pseudo demod module. |
|
6316 + BuildPseudoDemodModule(&pDemod, &DvbtDemodModuleMemory, &PseudoExtraModuleMemory); |
|
6317 + |
|
6318 + ... |
|
6319 + |
|
6320 + // Execute ResetFunction() before demod software reset. |
|
6321 + pDemod->ResetFunction(pDemod); |
|
6322 + |
|
6323 + // Reset demod by software. |
|
6324 + pDemod->SoftwareReset(pDemod); |
|
6325 + |
|
6326 + ... |
|
6327 + |
|
6328 + return 0; |
|
6329 +} |
|
6330 + |
|
6331 + |
|
6332 +void PeriodicallyExecutingFunction |
|
6333 +{ |
|
6334 + // Executing UpdateFunction() periodically. |
|
6335 + pDemod->UpdateFunction(pDemod); |
|
6336 +} |
|
6337 + |
|
6338 + |
|
6339 +@endcode |
|
6340 + |
|
6341 +*/ |
|
6342 +typedef int |
|
6343 +(*DVBT_DEMOD_FP_UPDATE_FUNCTION)( |
|
6344 + DVBT_DEMOD_MODULE *pDemod |
|
6345 + ); |
|
6346 + |
|
6347 + |
|
6348 + |
|
6349 + |
|
6350 + |
|
6351 +/** |
|
6352 + |
|
6353 +@brief DVB-T demod reseting function pointer |
|
6354 + |
|
6355 +One can use DVBT_DEMOD_FP_RESET_FUNCTION() to reset demod register setting. |
|
6356 + |
|
6357 + |
|
6358 +@param [in] pDemod The demod module pointer |
|
6359 + |
|
6360 + |
|
6361 +@retval FUNCTION_SUCCESS Reset demod setting successfully. |
|
6362 +@retval FUNCTION_ERROR Reset demod setting unsuccessfully. |
|
6363 + |
|
6364 + |
|
6365 +@note |
|
6366 + -# Demod building function will set DVBT_DEMOD_FP_RESET_FUNCTION() with the corresponding function. |
|
6367 + |
|
6368 + |
|
6369 + |
|
6370 +@par Example: |
|
6371 +@code |
|
6372 + |
|
6373 + |
|
6374 +#include "demod_pseudo.h" |
|
6375 + |
|
6376 + |
|
6377 +int main(void) |
|
6378 +{ |
|
6379 + DVBT_DEMOD_MODULE *pDemod; |
|
6380 + DVBT_DEMOD_MODULE DvbtDemodModuleMemory; |
|
6381 + PSEUDO_EXTRA_MODULE PseudoExtraModuleMemory; |
|
6382 + |
|
6383 + |
|
6384 + // Build pseudo demod module. |
|
6385 + BuildPseudoDemodModule(&pDemod, &DvbtDemodModuleMemory, &PseudoExtraModuleMemory); |
|
6386 + |
|
6387 + ... |
|
6388 + |
|
6389 + // Execute ResetFunction() before demod software reset. |
|
6390 + pDemod->ResetFunction(pDemod); |
|
6391 + |
|
6392 + // Reset demod by software. |
|
6393 + pDemod->SoftwareReset(pDemod); |
|
6394 + |
|
6395 + ... |
|
6396 + |
|
6397 + return 0; |
|
6398 +} |
|
6399 + |
|
6400 + |
|
6401 +void PeriodicallyExecutingFunction |
|
6402 +{ |
|
6403 + // Executing UpdateFunction() periodically. |
|
6404 + pDemod->UpdateFunction(pDemod); |
|
6405 +} |
|
6406 + |
|
6407 + |
|
6408 +@endcode |
|
6409 + |
|
6410 +*/ |
|
6411 +typedef int |
|
6412 +(*DVBT_DEMOD_FP_RESET_FUNCTION)( |
|
6413 + DVBT_DEMOD_MODULE *pDemod |
|
6414 + ); |
|
6415 + |
|
6416 + |
|
6417 + |
|
6418 + |
|
6419 + |
|
6420 +/// DVB-T demod module structure |
|
6421 +struct DVBT_DEMOD_MODULE_TAG |
|
6422 +{ |
|
6423 + |
|
6424 + unsigned long PageNo; |
|
6425 + |
|
6426 + // Private variables |
|
6427 + int DemodType; |
|
6428 + unsigned char DeviceAddr; |
|
6429 + unsigned long CrystalFreqHz; |
|
6430 + |
|
6431 + int BandwidthMode; |
|
6432 + unsigned long IfFreqHz; |
|
6433 + int SpectrumMode; |
|
6434 + |
|
6435 + int IsBandwidthModeSet; |
|
6436 + int IsIfFreqHzSet; |
|
6437 + int IsSpectrumModeSet; |
|
6438 + |
|
6439 + void *pExtra; ///< Demod extra module used by driving module |
|
6440 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
6441 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
6442 + |
|
6443 + |
|
6444 + // Demod register table |
|
6445 + DVBT_REG_ENTRY RegTable[DVBT_REG_TABLE_LEN_MAX]; |
|
6446 + |
|
6447 + |
|
6448 + // Demod I2C function pointers |
|
6449 + DVBT_DEMOD_FP_SET_REG_PAGE SetRegPage; |
|
6450 + DVBT_DEMOD_FP_SET_REG_BYTES SetRegBytes; |
|
6451 + DVBT_DEMOD_FP_GET_REG_BYTES GetRegBytes; |
|
6452 + DVBT_DEMOD_FP_SET_REG_MASK_BITS SetRegMaskBits; |
|
6453 + DVBT_DEMOD_FP_GET_REG_MASK_BITS GetRegMaskBits; |
|
6454 + DVBT_DEMOD_FP_SET_REG_BITS SetRegBits; |
|
6455 + DVBT_DEMOD_FP_GET_REG_BITS GetRegBits; |
|
6456 + DVBT_DEMOD_FP_SET_REG_BITS_WITH_PAGE SetRegBitsWithPage; |
|
6457 + DVBT_DEMOD_FP_GET_REG_BITS_WITH_PAGE GetRegBitsWithPage; |
|
6458 + |
|
6459 + |
|
6460 + // Demod manipulating function pointers |
|
6461 + DVBT_DEMOD_FP_GET_DEMOD_TYPE GetDemodType; |
|
6462 + DVBT_DEMOD_FP_GET_DEVICE_ADDR GetDeviceAddr; |
|
6463 + DVBT_DEMOD_FP_GET_CRYSTAL_FREQ_HZ GetCrystalFreqHz; |
|
6464 + |
|
6465 + DVBT_DEMOD_FP_IS_CONNECTED_TO_I2C IsConnectedToI2c; |
|
6466 + |
|
6467 + DVBT_DEMOD_FP_SOFTWARE_RESET SoftwareReset; |
|
6468 + |
|
6469 + DVBT_DEMOD_FP_INITIALIZE Initialize; |
|
6470 + DVBT_DEMOD_FP_SET_BANDWIDTH_MODE SetBandwidthMode; |
|
6471 + DVBT_DEMOD_FP_SET_IF_FREQ_HZ SetIfFreqHz; |
|
6472 + DVBT_DEMOD_FP_SET_SPECTRUM_MODE SetSpectrumMode; |
|
6473 + DVBT_DEMOD_FP_GET_BANDWIDTH_MODE GetBandwidthMode; |
|
6474 + DVBT_DEMOD_FP_GET_IF_FREQ_HZ GetIfFreqHz; |
|
6475 + DVBT_DEMOD_FP_GET_SPECTRUM_MODE GetSpectrumMode; |
|
6476 + |
|
6477 + DVBT_DEMOD_FP_IS_TPS_LOCKED IsTpsLocked; |
|
6478 + DVBT_DEMOD_FP_IS_SIGNAL_LOCKED IsSignalLocked; |
|
6479 + |
|
6480 + DVBT_DEMOD_FP_GET_SIGNAL_STRENGTH GetSignalStrength; |
|
6481 + DVBT_DEMOD_FP_GET_SIGNAL_QUALITY GetSignalQuality; |
|
6482 + |
|
6483 + DVBT_DEMOD_FP_GET_BER GetBer; |
|
6484 + DVBT_DEMOD_FP_GET_SNR_DB GetSnrDb; |
|
6485 + |
|
6486 + DVBT_DEMOD_FP_GET_RF_AGC GetRfAgc; |
|
6487 + DVBT_DEMOD_FP_GET_IF_AGC GetIfAgc; |
|
6488 + DVBT_DEMOD_FP_GET_DI_AGC GetDiAgc; |
|
6489 + |
|
6490 + DVBT_DEMOD_FP_GET_TR_OFFSET_PPM GetTrOffsetPpm; |
|
6491 + DVBT_DEMOD_FP_GET_CR_OFFSET_HZ GetCrOffsetHz; |
|
6492 + |
|
6493 + DVBT_DEMOD_FP_GET_CONSTELLATION GetConstellation; |
|
6494 + DVBT_DEMOD_FP_GET_HIERARCHY GetHierarchy; |
|
6495 + DVBT_DEMOD_FP_GET_CODE_RATE_LP GetCodeRateLp; |
|
6496 + DVBT_DEMOD_FP_GET_CODE_RATE_HP GetCodeRateHp; |
|
6497 + DVBT_DEMOD_FP_GET_GUARD_INTERVAL GetGuardInterval; |
|
6498 + DVBT_DEMOD_FP_GET_FFT_MODE GetFftMode; |
|
6499 + |
|
6500 + DVBT_DEMOD_FP_UPDATE_FUNCTION UpdateFunction; |
|
6501 + DVBT_DEMOD_FP_RESET_FUNCTION ResetFunction; |
|
6502 +}; |
|
6503 + |
|
6504 + |
|
6505 + |
|
6506 + |
|
6507 + |
|
6508 + |
|
6509 + |
|
6510 +// DVB-T demod default I2C functions |
|
6511 +int |
|
6512 +dvbt_demod_default_SetRegPage( |
|
6513 + DVBT_DEMOD_MODULE *pDemod, |
|
6514 + unsigned long PageNo |
|
6515 + ); |
|
6516 + |
|
6517 +int |
|
6518 +dvbt_demod_default_SetRegBytes( |
|
6519 + DVBT_DEMOD_MODULE *pDemod, |
|
6520 + unsigned char RegStartAddr, |
|
6521 + const unsigned char *pWritingBytes, |
|
6522 + unsigned char ByteNum |
|
6523 + ); |
|
6524 + |
|
6525 +int |
|
6526 +dvbt_demod_default_GetRegBytes( |
|
6527 + DVBT_DEMOD_MODULE *pDemod, |
|
6528 + unsigned char RegStartAddr, |
|
6529 + unsigned char *pReadingBytes, |
|
6530 + unsigned char ByteNum |
|
6531 + ); |
|
6532 + |
|
6533 +int |
|
6534 +dvbt_demod_default_SetRegMaskBits( |
|
6535 + DVBT_DEMOD_MODULE *pDemod, |
|
6536 + unsigned char RegStartAddr, |
|
6537 + unsigned char Msb, |
|
6538 + unsigned char Lsb, |
|
6539 + const unsigned long WritingValue |
|
6540 + ); |
|
6541 + |
|
6542 +int |
|
6543 +dvbt_demod_default_GetRegMaskBits( |
|
6544 + DVBT_DEMOD_MODULE *pDemod, |
|
6545 + unsigned char RegStartAddr, |
|
6546 + unsigned char Msb, |
|
6547 + unsigned char Lsb, |
|
6548 + unsigned long *pReadingValue |
|
6549 + ); |
|
6550 + |
|
6551 +int |
|
6552 +dvbt_demod_default_SetRegBits( |
|
6553 + DVBT_DEMOD_MODULE *pDemod, |
|
6554 + int RegBitName, |
|
6555 + const unsigned long WritingValue |
|
6556 + ); |
|
6557 + |
|
6558 +int |
|
6559 +dvbt_demod_default_GetRegBits( |
|
6560 + DVBT_DEMOD_MODULE *pDemod, |
|
6561 + int RegBitName, |
|
6562 + unsigned long *pReadingValue |
|
6563 + ); |
|
6564 + |
|
6565 +int |
|
6566 +dvbt_demod_default_SetRegBitsWithPage( |
|
6567 + DVBT_DEMOD_MODULE *pDemod, |
|
6568 + int RegBitName, |
|
6569 + const unsigned long WritingValue |
|
6570 + ); |
|
6571 + |
|
6572 +int |
|
6573 +dvbt_demod_default_GetRegBitsWithPage( |
|
6574 + DVBT_DEMOD_MODULE *pDemod, |
|
6575 + int RegBitName, |
|
6576 + unsigned long *pReadingValue |
|
6577 + ); |
|
6578 + |
|
6579 + |
|
6580 + |
|
6581 + |
|
6582 + |
|
6583 +// DVB-T demod default manipulating functions |
|
6584 +void |
|
6585 +dvbt_demod_default_GetDemodType( |
|
6586 + DVBT_DEMOD_MODULE *pDemod, |
|
6587 + int *pDemodType |
|
6588 + ); |
|
6589 + |
|
6590 +void |
|
6591 +dvbt_demod_default_GetDeviceAddr( |
|
6592 + DVBT_DEMOD_MODULE *pDemod, |
|
6593 + unsigned char *pDeviceAddr |
|
6594 + ); |
|
6595 + |
|
6596 +void |
|
6597 +dvbt_demod_default_GetCrystalFreqHz( |
|
6598 + DVBT_DEMOD_MODULE *pDemod, |
|
6599 + unsigned long *pCrystalFreqHz |
|
6600 + ); |
|
6601 + |
|
6602 +int |
|
6603 +dvbt_demod_default_GetBandwidthMode( |
|
6604 + DVBT_DEMOD_MODULE *pDemod, |
|
6605 + int *pBandwidthMode |
|
6606 + ); |
|
6607 + |
|
6608 +int |
|
6609 +dvbt_demod_default_GetIfFreqHz( |
|
6610 + DVBT_DEMOD_MODULE *pDemod, |
|
6611 + unsigned long *pIfFreqHz |
|
6612 + ); |
|
6613 + |
|
6614 +int |
|
6615 +dvbt_demod_default_GetSpectrumMode( |
|
6616 + DVBT_DEMOD_MODULE *pDemod, |
|
6617 + int *pSpectrumMode |
|
6618 + ); |
|
6619 + |
|
6620 + |
|
6621 + |
|
6622 + |
|
6623 + |
|
6624 + |
|
6625 + |
|
6626 +#endif |
|
6627 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/dvbt_nim_base.c |
|
6628 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
6629 +++ b/linux/drivers/media/dvb/dvb-usb/dvbt_nim_base.c Wed Oct 27 09:16:44 2010 +0200 |
|
6630 @@ -0,0 +1,531 @@ |
|
6631 +/** |
|
6632 + |
|
6633 +@file |
|
6634 + |
|
6635 +@brief DVB-T NIM base module definition |
|
6636 + |
|
6637 +DVB-T NIM base module definitions contains NIM module structure, NIM funciton pointers, NIM definitions, and NIM default |
|
6638 +functions. |
|
6639 + |
|
6640 +*/ |
|
6641 + |
|
6642 + |
|
6643 +#include "dvbt_nim_base.h" |
|
6644 + |
|
6645 + |
|
6646 + |
|
6647 + |
|
6648 + |
|
6649 +/** |
|
6650 + |
|
6651 +@see DVBT_NIM_FP_GET_NIM_TYPE |
|
6652 + |
|
6653 +*/ |
|
6654 +void |
|
6655 +dvbt_nim_default_GetNimType( |
|
6656 + DVBT_NIM_MODULE *pNim, |
|
6657 + int *pNimType |
|
6658 + ) |
|
6659 +{ |
|
6660 + // Get NIM type from NIM module. |
|
6661 + *pNimType = pNim->NimType; |
|
6662 + |
|
6663 + |
|
6664 + return; |
|
6665 +} |
|
6666 + |
|
6667 + |
|
6668 + |
|
6669 + |
|
6670 + |
|
6671 +/** |
|
6672 + |
|
6673 +@see DVBT_NIM_FP_SET_PARAMETERS |
|
6674 + |
|
6675 +*/ |
|
6676 +int |
|
6677 +dvbt_nim_default_SetParameters( |
|
6678 + DVBT_NIM_MODULE *pNim, |
|
6679 + unsigned long RfFreqHz, |
|
6680 + int BandwidthMode |
|
6681 + ) |
|
6682 +{ |
|
6683 + TUNER_MODULE *pTuner; |
|
6684 + DVBT_DEMOD_MODULE *pDemod; |
|
6685 + |
|
6686 + |
|
6687 + // Get tuner module and demod module. |
|
6688 + pTuner = pNim->pTuner; |
|
6689 + pDemod = pNim->pDemod; |
|
6690 + |
|
6691 + |
|
6692 + // Set tuner RF frequency in Hz. |
|
6693 + if(pTuner->SetRfFreqHz(pTuner, RfFreqHz) != FUNCTION_SUCCESS) |
|
6694 + goto error_status_execute_function; |
|
6695 + |
|
6696 + // Set demod bandwidth mode. |
|
6697 + if(pDemod->SetBandwidthMode(pDemod, BandwidthMode) != FUNCTION_SUCCESS) |
|
6698 + goto error_status_execute_function; |
|
6699 + |
|
6700 + // Reset demod particular registers. |
|
6701 + if(pDemod->ResetFunction(pDemod) != FUNCTION_SUCCESS) |
|
6702 + goto error_status_execute_function; |
|
6703 + |
|
6704 + // Reset demod by software reset. |
|
6705 + if(pDemod->SoftwareReset(pDemod) != FUNCTION_SUCCESS) |
|
6706 + goto error_status_execute_function; |
|
6707 + |
|
6708 + |
|
6709 + return FUNCTION_SUCCESS; |
|
6710 + |
|
6711 + |
|
6712 +error_status_execute_function: |
|
6713 + return FUNCTION_ERROR; |
|
6714 +} |
|
6715 + |
|
6716 + |
|
6717 + |
|
6718 + |
|
6719 + |
|
6720 +/** |
|
6721 + |
|
6722 +@see DVBT_NIM_FP_GET_PARAMETERS |
|
6723 + |
|
6724 +*/ |
|
6725 +int |
|
6726 +dvbt_nim_default_GetParameters( |
|
6727 + DVBT_NIM_MODULE *pNim, |
|
6728 + unsigned long *pRfFreqHz, |
|
6729 + int *pBandwidthMode |
|
6730 + ) |
|
6731 +{ |
|
6732 + TUNER_MODULE *pTuner; |
|
6733 + DVBT_DEMOD_MODULE *pDemod; |
|
6734 + |
|
6735 + |
|
6736 + // Get tuner module and demod module. |
|
6737 + pTuner = pNim->pTuner; |
|
6738 + pDemod = pNim->pDemod; |
|
6739 + |
|
6740 + |
|
6741 + // Get tuner RF frequency in Hz. |
|
6742 + if(pTuner->GetRfFreqHz(pTuner, pRfFreqHz) != FUNCTION_SUCCESS) |
|
6743 + goto error_status_execute_function; |
|
6744 + |
|
6745 + // Get demod bandwidth mode. |
|
6746 + if(pDemod->GetBandwidthMode(pDemod, pBandwidthMode) != FUNCTION_SUCCESS) |
|
6747 + goto error_status_execute_function; |
|
6748 + |
|
6749 + |
|
6750 + return FUNCTION_SUCCESS; |
|
6751 + |
|
6752 + |
|
6753 +error_status_execute_function: |
|
6754 + return FUNCTION_ERROR; |
|
6755 +} |
|
6756 + |
|
6757 + |
|
6758 + |
|
6759 + |
|
6760 + |
|
6761 +/** |
|
6762 + |
|
6763 +@see DVBT_NIM_FP_IS_SIGNAL_PRESENT |
|
6764 + |
|
6765 +*/ |
|
6766 +int |
|
6767 +dvbt_nim_default_IsSignalPresent( |
|
6768 + DVBT_NIM_MODULE *pNim, |
|
6769 + int *pAnswer |
|
6770 + ) |
|
6771 +{ |
|
6772 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
6773 + DVBT_DEMOD_MODULE *pDemod; |
|
6774 + int i; |
|
6775 + |
|
6776 + |
|
6777 + // Get base interface and demod module. |
|
6778 + pBaseInterface = pNim->pBaseInterface; |
|
6779 + pDemod = pNim->pDemod; |
|
6780 + |
|
6781 + |
|
6782 + // Wait for signal present check. |
|
6783 + for(i = 0; i < DEFAULT_DVBT_NIM_SINGAL_PRESENT_CHECK_TIMES_MAX; i++) |
|
6784 + { |
|
6785 + // Wait 20 ms. |
|
6786 + pBaseInterface->WaitMs(pBaseInterface, 20); |
|
6787 + |
|
6788 + // Check TPS present status on demod. |
|
6789 + // Note: If TPS is locked, stop signal present check. |
|
6790 + if(pDemod->IsTpsLocked(pDemod, pAnswer) != FUNCTION_SUCCESS) |
|
6791 + goto error_status_execute_function; |
|
6792 + |
|
6793 + if(*pAnswer == YES) |
|
6794 + break; |
|
6795 + } |
|
6796 + |
|
6797 + |
|
6798 + return FUNCTION_SUCCESS; |
|
6799 + |
|
6800 + |
|
6801 +error_status_execute_function: |
|
6802 + return FUNCTION_ERROR; |
|
6803 +} |
|
6804 + |
|
6805 + |
|
6806 + |
|
6807 + |
|
6808 + |
|
6809 +/** |
|
6810 + |
|
6811 +@see DVBT_NIM_FP_IS_SIGNAL_LOCKED |
|
6812 + |
|
6813 +*/ |
|
6814 +int |
|
6815 +dvbt_nim_default_IsSignalLocked( |
|
6816 + DVBT_NIM_MODULE *pNim, |
|
6817 + int *pAnswer |
|
6818 + ) |
|
6819 +{ |
|
6820 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
6821 + DVBT_DEMOD_MODULE *pDemod; |
|
6822 + int i; |
|
6823 + |
|
6824 + |
|
6825 + // Get base interface and demod module. |
|
6826 + pBaseInterface = pNim->pBaseInterface; |
|
6827 + pDemod = pNim->pDemod; |
|
6828 + |
|
6829 + |
|
6830 + // Wait for signal lock check. |
|
6831 + for(i = 0; i < DEFAULT_DVBT_NIM_SINGAL_LOCK_CHECK_TIMES_MAX; i++) |
|
6832 + { |
|
6833 + // Wait 20 ms. |
|
6834 + pBaseInterface->WaitMs(pBaseInterface, 20); |
|
6835 + |
|
6836 + // Check signal lock status on demod. |
|
6837 + // Note: If signal is locked, stop signal lock check. |
|
6838 + if(pDemod->IsSignalLocked(pDemod, pAnswer) != FUNCTION_SUCCESS) |
|
6839 + goto error_status_execute_function; |
|
6840 + |
|
6841 + if(*pAnswer == YES) |
|
6842 + break; |
|
6843 + } |
|
6844 + |
|
6845 + |
|
6846 + return FUNCTION_SUCCESS; |
|
6847 + |
|
6848 + |
|
6849 +error_status_execute_function: |
|
6850 + return FUNCTION_ERROR; |
|
6851 +} |
|
6852 + |
|
6853 + |
|
6854 + |
|
6855 + |
|
6856 + |
|
6857 +/** |
|
6858 + |
|
6859 +@see DVBT_NIM_FP_GET_SIGNAL_STRENGTH |
|
6860 + |
|
6861 +*/ |
|
6862 +int |
|
6863 +dvbt_nim_default_GetSignalStrength( |
|
6864 + DVBT_NIM_MODULE *pNim, |
|
6865 + unsigned long *pSignalStrength |
|
6866 + ) |
|
6867 +{ |
|
6868 + DVBT_DEMOD_MODULE *pDemod; |
|
6869 + |
|
6870 + |
|
6871 + // Get demod module. |
|
6872 + pDemod = pNim->pDemod; |
|
6873 + |
|
6874 + |
|
6875 + // Get signal strength from demod. |
|
6876 + if(pDemod->GetSignalStrength(pDemod, pSignalStrength) != FUNCTION_SUCCESS) |
|
6877 + goto error_status_execute_function; |
|
6878 + |
|
6879 + |
|
6880 + return FUNCTION_SUCCESS; |
|
6881 + |
|
6882 + |
|
6883 +error_status_execute_function: |
|
6884 + return FUNCTION_ERROR; |
|
6885 +} |
|
6886 + |
|
6887 + |
|
6888 + |
|
6889 + |
|
6890 + |
|
6891 +/** |
|
6892 + |
|
6893 +@see DVBT_NIM_FP_GET_SIGNAL_QUALITY |
|
6894 + |
|
6895 +*/ |
|
6896 +int |
|
6897 +dvbt_nim_default_GetSignalQuality( |
|
6898 + DVBT_NIM_MODULE *pNim, |
|
6899 + unsigned long *pSignalQuality |
|
6900 + ) |
|
6901 +{ |
|
6902 + DVBT_DEMOD_MODULE *pDemod; |
|
6903 + |
|
6904 + |
|
6905 + // Get demod module. |
|
6906 + pDemod = pNim->pDemod; |
|
6907 + |
|
6908 + |
|
6909 + // Get signal quality from demod. |
|
6910 + if(pDemod->GetSignalQuality(pDemod, pSignalQuality) != FUNCTION_SUCCESS) |
|
6911 + goto error_status_execute_function; |
|
6912 + |
|
6913 + |
|
6914 + return FUNCTION_SUCCESS; |
|
6915 + |
|
6916 + |
|
6917 +error_status_execute_function: |
|
6918 + return FUNCTION_ERROR; |
|
6919 +} |
|
6920 + |
|
6921 + |
|
6922 + |
|
6923 + |
|
6924 + |
|
6925 +/** |
|
6926 + |
|
6927 +@see DVBT_NIM_FP_GET_BER |
|
6928 + |
|
6929 +*/ |
|
6930 +int |
|
6931 +dvbt_nim_default_GetBer( |
|
6932 + DVBT_NIM_MODULE *pNim, |
|
6933 + unsigned long *pBerNum, |
|
6934 + unsigned long *pBerDen |
|
6935 + ) |
|
6936 +{ |
|
6937 + DVBT_DEMOD_MODULE *pDemod; |
|
6938 + |
|
6939 + |
|
6940 + // Get demod module. |
|
6941 + pDemod = pNim->pDemod; |
|
6942 + |
|
6943 + |
|
6944 + // Get BER from demod. |
|
6945 + if(pDemod->GetBer(pDemod, pBerNum, pBerDen) != FUNCTION_SUCCESS) |
|
6946 + goto error_status_execute_function; |
|
6947 + |
|
6948 + |
|
6949 + return FUNCTION_SUCCESS; |
|
6950 + |
|
6951 + |
|
6952 +error_status_execute_function: |
|
6953 + return FUNCTION_ERROR; |
|
6954 +} |
|
6955 + |
|
6956 + |
|
6957 + |
|
6958 + |
|
6959 + |
|
6960 +/** |
|
6961 + |
|
6962 +@see DVBT_NIM_FP_GET_SNR_DB |
|
6963 + |
|
6964 +*/ |
|
6965 +int |
|
6966 +dvbt_nim_default_GetSnrDb( |
|
6967 + DVBT_NIM_MODULE *pNim, |
|
6968 + long *pSnrDbNum, |
|
6969 + long *pSnrDbDen |
|
6970 + ) |
|
6971 +{ |
|
6972 + DVBT_DEMOD_MODULE *pDemod; |
|
6973 + |
|
6974 + |
|
6975 + // Get demod module. |
|
6976 + pDemod = pNim->pDemod; |
|
6977 + |
|
6978 + |
|
6979 + // Get SNR in dB from demod. |
|
6980 + if(pDemod->GetSnrDb(pDemod, pSnrDbNum, pSnrDbDen) != FUNCTION_SUCCESS) |
|
6981 + goto error_status_execute_function; |
|
6982 + |
|
6983 + |
|
6984 + return FUNCTION_SUCCESS; |
|
6985 + |
|
6986 + |
|
6987 +error_status_execute_function: |
|
6988 + return FUNCTION_ERROR; |
|
6989 +} |
|
6990 + |
|
6991 + |
|
6992 + |
|
6993 + |
|
6994 + |
|
6995 +/** |
|
6996 + |
|
6997 +@see DVBT_NIM_FP_GET_TR_OFFSET_PPM |
|
6998 + |
|
6999 +*/ |
|
7000 +int |
|
7001 +dvbt_nim_default_GetTrOffsetPpm( |
|
7002 + DVBT_NIM_MODULE *pNim, |
|
7003 + long *pTrOffsetPpm |
|
7004 + ) |
|
7005 +{ |
|
7006 + DVBT_DEMOD_MODULE *pDemod; |
|
7007 + |
|
7008 + |
|
7009 + // Get demod module. |
|
7010 + pDemod = pNim->pDemod; |
|
7011 + |
|
7012 + |
|
7013 + // Get TR offset in ppm from demod. |
|
7014 + if(pDemod->GetTrOffsetPpm(pDemod, pTrOffsetPpm) != FUNCTION_SUCCESS) |
|
7015 + goto error_status_execute_function; |
|
7016 + |
|
7017 + |
|
7018 + return FUNCTION_SUCCESS; |
|
7019 + |
|
7020 + |
|
7021 +error_status_execute_function: |
|
7022 + return FUNCTION_ERROR; |
|
7023 +} |
|
7024 + |
|
7025 + |
|
7026 + |
|
7027 + |
|
7028 + |
|
7029 +/** |
|
7030 + |
|
7031 +@see DVBT_NIM_FP_GET_CR_OFFSET_HZ |
|
7032 + |
|
7033 +*/ |
|
7034 +int |
|
7035 +dvbt_nim_default_GetCrOffsetHz( |
|
7036 + DVBT_NIM_MODULE *pNim, |
|
7037 + long *pCrOffsetHz |
|
7038 + ) |
|
7039 +{ |
|
7040 + DVBT_DEMOD_MODULE *pDemod; |
|
7041 + |
|
7042 + |
|
7043 + // Get demod module. |
|
7044 + pDemod = pNim->pDemod; |
|
7045 + |
|
7046 + |
|
7047 + // Get CR offset in Hz from demod. |
|
7048 + if(pDemod->GetCrOffsetHz(pDemod, pCrOffsetHz) != FUNCTION_SUCCESS) |
|
7049 + goto error_status_execute_function; |
|
7050 + |
|
7051 + |
|
7052 + return FUNCTION_SUCCESS; |
|
7053 + |
|
7054 + |
|
7055 +error_status_execute_function: |
|
7056 + return FUNCTION_ERROR; |
|
7057 +} |
|
7058 + |
|
7059 + |
|
7060 + |
|
7061 + |
|
7062 + |
|
7063 +/** |
|
7064 + |
|
7065 +@see DVBT_NIM_FP_GET_TPS_INFO |
|
7066 + |
|
7067 +*/ |
|
7068 +int |
|
7069 +dvbt_nim_default_GetTpsInfo( |
|
7070 + DVBT_NIM_MODULE *pNim, |
|
7071 + int *pConstellation, |
|
7072 + int *pHierarchy, |
|
7073 + int *pCodeRateLp, |
|
7074 + int *pCodeRateHp, |
|
7075 + int *pGuardInterval, |
|
7076 + int *pFftMode |
|
7077 + ) |
|
7078 +{ |
|
7079 + DVBT_DEMOD_MODULE *pDemod; |
|
7080 + |
|
7081 + |
|
7082 + // Get demod module. |
|
7083 + pDemod = pNim->pDemod; |
|
7084 + |
|
7085 + |
|
7086 + // Get TPS constellation information from demod. |
|
7087 + if(pDemod->GetConstellation(pDemod, pConstellation) != FUNCTION_SUCCESS) |
|
7088 + goto error_status_execute_function; |
|
7089 + |
|
7090 + // Get TPS hierarchy information from demod. |
|
7091 + if(pDemod->GetHierarchy(pDemod, pHierarchy) != FUNCTION_SUCCESS) |
|
7092 + goto error_status_execute_function; |
|
7093 + |
|
7094 + // Get TPS low-priority code rate information from demod. |
|
7095 + if(pDemod->GetCodeRateLp(pDemod, pCodeRateLp) != FUNCTION_SUCCESS) |
|
7096 + goto error_status_execute_function; |
|
7097 + |
|
7098 + // Get TPS high-priority code rate information from demod. |
|
7099 + if(pDemod->GetCodeRateHp(pDemod, pCodeRateHp) != FUNCTION_SUCCESS) |
|
7100 + goto error_status_execute_function; |
|
7101 + |
|
7102 + // Get TPS guard interval information from demod. |
|
7103 + if(pDemod->GetGuardInterval(pDemod, pGuardInterval) != FUNCTION_SUCCESS) |
|
7104 + goto error_status_execute_function; |
|
7105 + |
|
7106 + // Get TPS FFT mode information from demod. |
|
7107 + if(pDemod->GetFftMode(pDemod, pFftMode) != FUNCTION_SUCCESS) |
|
7108 + goto error_status_execute_function; |
|
7109 + |
|
7110 + |
|
7111 + return FUNCTION_SUCCESS; |
|
7112 + |
|
7113 + |
|
7114 +error_status_execute_function: |
|
7115 + return FUNCTION_ERROR; |
|
7116 +} |
|
7117 + |
|
7118 + |
|
7119 + |
|
7120 + |
|
7121 + |
|
7122 +/** |
|
7123 + |
|
7124 +@see DVBT_NIM_FP_UPDATE_FUNCTION |
|
7125 + |
|
7126 +*/ |
|
7127 +int |
|
7128 +dvbt_nim_default_UpdateFunction( |
|
7129 + DVBT_NIM_MODULE *pNim |
|
7130 + ) |
|
7131 +{ |
|
7132 + DVBT_DEMOD_MODULE *pDemod; |
|
7133 + |
|
7134 + |
|
7135 + // Get demod module. |
|
7136 + pDemod = pNim->pDemod; |
|
7137 + |
|
7138 + |
|
7139 + // Update demod particular registers. |
|
7140 + if(pDemod->UpdateFunction(pDemod) != FUNCTION_SUCCESS) |
|
7141 + goto error_status_execute_function; |
|
7142 + |
|
7143 + |
|
7144 + return FUNCTION_SUCCESS; |
|
7145 + |
|
7146 + |
|
7147 +error_status_execute_function: |
|
7148 + return FUNCTION_ERROR; |
|
7149 +} |
|
7150 + |
|
7151 + |
|
7152 + |
|
7153 + |
|
7154 + |
|
7155 + |
|
7156 + |
|
7157 + |
|
7158 + |
|
7159 + |
|
7160 + |
|
7161 + |
|
7162 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/dvbt_nim_base.h |
|
7163 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
7164 +++ b/linux/drivers/media/dvb/dvb-usb/dvbt_nim_base.h Wed Oct 27 09:16:44 2010 +0200 |
|
7165 @@ -0,0 +1,845 @@ |
|
7166 +#ifndef __DVBT_NIM_BASE_H |
|
7167 +#define __DVBT_NIM_BASE_H |
|
7168 + |
|
7169 +/** |
|
7170 + |
|
7171 +@file |
|
7172 + |
|
7173 +@brief DVB-T NIM base module definition |
|
7174 + |
|
7175 +DVB-T NIM base module definitions contains NIM module structure, NIM funciton pointers, NIM definitions, and NIM default |
|
7176 +functions. |
|
7177 + |
|
7178 + |
|
7179 + |
|
7180 +@par Example: |
|
7181 +@code |
|
7182 + |
|
7183 + |
|
7184 +#include "nim_demodx_tunery.h" |
|
7185 + |
|
7186 + |
|
7187 + |
|
7188 +int |
|
7189 +CustomI2cRead( |
|
7190 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
7191 + unsigned char DeviceAddr, |
|
7192 + unsigned char *pReadingBytes, |
|
7193 + unsigned char ByteNum |
|
7194 + ) |
|
7195 +{ |
|
7196 + ... |
|
7197 + |
|
7198 + return FUNCTION_SUCCESS; |
|
7199 + |
|
7200 +error_status: |
|
7201 + return FUNCTION_ERROR; |
|
7202 +} |
|
7203 + |
|
7204 + |
|
7205 + |
|
7206 +int |
|
7207 +CustomI2cWrite( |
|
7208 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
7209 + unsigned char DeviceAddr, |
|
7210 + const unsigned char *pWritingBytes, |
|
7211 + unsigned char ByteNum |
|
7212 + ) |
|
7213 +{ |
|
7214 + ... |
|
7215 + |
|
7216 + return FUNCTION_SUCCESS; |
|
7217 + |
|
7218 +error_status: |
|
7219 + return FUNCTION_ERROR; |
|
7220 +} |
|
7221 + |
|
7222 + |
|
7223 + |
|
7224 +void |
|
7225 +CustomWaitMs( |
|
7226 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
7227 + unsigned long WaitTimeMs |
|
7228 + ) |
|
7229 +{ |
|
7230 + ... |
|
7231 +} |
|
7232 + |
|
7233 + |
|
7234 + |
|
7235 +int main(void) |
|
7236 +{ |
|
7237 + DVBT_NIM_MODULE *pNim; |
|
7238 + DVBT_NIM_MODULE DvbtNimModuleMemory; |
|
7239 + DEMODX_EXTRA_MODULE DemodxExtraModuleMemory; |
|
7240 + TUNERY_EXTRA_MODULE TuneryExtraModuleMemory; |
|
7241 + |
|
7242 + unsigned long RfFreqHz; |
|
7243 + int BandwidthMode; |
|
7244 + |
|
7245 + int Answer; |
|
7246 + unsigned long SignalStrength, SignalQuality; |
|
7247 + unsigned long BerNum, BerDen, PerNum, PerDen; |
|
7248 + double Ber, Per; |
|
7249 + unsigned long SnrDbNum, SnrDbDen; |
|
7250 + double SnrDb; |
|
7251 + long TrOffsetPpm, CrOffsetHz; |
|
7252 + |
|
7253 + int Constellation; |
|
7254 + int Hierarchy; |
|
7255 + int CodeRateLp; |
|
7256 + int CodeRateHp; |
|
7257 + int GuardInterval; |
|
7258 + int FftMode; |
|
7259 + |
|
7260 + |
|
7261 + |
|
7262 + // Build Demod-X Tuner-Y NIM module. |
|
7263 + BuildDemodxTuneryModule( |
|
7264 + &pNim, |
|
7265 + &DvbtNimModuleMemory, |
|
7266 + |
|
7267 + 9, // Maximum I2C reading byte number is 9. |
|
7268 + 8, // Maximum I2C writing byte number is 8. |
|
7269 + CustomI2cRead, // Employ CustomI2cRead() as basic I2C reading function. |
|
7270 + CustomI2cWrite, // Employ CustomI2cWrite() as basic I2C writing function. |
|
7271 + CustomWaitMs // Employ CustomWaitMs() as basic waiting function. |
|
7272 + |
|
7273 + &DemodxExtraModuleMemory, // Employ Demod-X extra module. |
|
7274 + 0x20, // The Demod-X I2C device address is 0x20 in 8-bit format. |
|
7275 + CRYSTAL_FREQ_28800000HZ, // The Demod-X crystal frequency is 28.8 MHz. |
|
7276 + ... // Other arguments for Demod-X |
|
7277 + |
|
7278 + &TunerxExtraModuleMemory, // Employ Tuner-Y extra module. |
|
7279 + 0xc0, // The Tuner-Y I2C device address is 0xc0 in 8-bit format. |
|
7280 + ... // Other arguments for Tuner-Y |
|
7281 + ); |
|
7282 + |
|
7283 + |
|
7284 + |
|
7285 + // Get NIM type. |
|
7286 + // Note: NIM types are defined in the MODULE_TYPE enumeration. |
|
7287 + pNim->GetNimType(pNim, &NimType); |
|
7288 + |
|
7289 + |
|
7290 + |
|
7291 + |
|
7292 + |
|
7293 + |
|
7294 + |
|
7295 + // ==== Initialize NIM and set its parameters ===== |
|
7296 + |
|
7297 + // Initialize NIM. |
|
7298 + pNim->Initialize(pNim); |
|
7299 + |
|
7300 + // Set NIM parameters. (RF frequency, bandwdith mode) |
|
7301 + // Note: In the example: |
|
7302 + // 1. RF frequency is 666 MHz. |
|
7303 + // 2. Bandwidth mode is 8 MHz. |
|
7304 + RfFreqHz = 666000000; |
|
7305 + BandwidthMode = DVBT_BANDWIDTH_8MHZ; |
|
7306 + pNim->SetParameters(pNim, RfFreqHz, BandwidthMode); |
|
7307 + |
|
7308 + |
|
7309 + |
|
7310 + |
|
7311 + |
|
7312 + // ==== Get NIM information ===== |
|
7313 + |
|
7314 + // Get NIM parameters. (RF frequency, bandwdith mode) |
|
7315 + pNim->GetParameters(pNim, &RfFreqHz, &BandwidthMode); |
|
7316 + |
|
7317 + |
|
7318 + // Get signal present status. |
|
7319 + // Note: 1. The IsSignalPresent() function will wait maximum 1000 ms for signal present check. |
|
7320 + // 2. The argument Answer is YES when the NIM module has found DVB-T signal in the RF channel. |
|
7321 + // 3. The argument Answer is NO when the NIM module does not find DVB-T signal in the RF channel. |
|
7322 + // Recommendation: Use the IsSignalPresent() function for channel scan. |
|
7323 + pNim->IsSignalPresent(pNim, &Answer); |
|
7324 + |
|
7325 + // Get signal lock status. |
|
7326 + // Note: 1. The IsSignalLocked() function will wait maximum 1000 ms for signal lock check. |
|
7327 + // 2. The argument Answer is YES when the NIM module has locked DVB-T signal in the RF channel. |
|
7328 + // At the same time, the NIM module sends TS packets through TS interface hardware pins. |
|
7329 + // 3. The argument Answer is NO when the NIM module does not lock DVB-T signal in the RF channel. |
|
7330 + // Recommendation: Use the IsSignalLocked() function for signal lock check. |
|
7331 + pNim->IsSignalLocked(pNim, &Answer); |
|
7332 + |
|
7333 + |
|
7334 + // Get signal strength. |
|
7335 + // Note: 1. The range of SignalStrength is 0~100. |
|
7336 + // 2. Need to map SignalStrength value to UI signal strength bar manually. |
|
7337 + pNim->GetSignalStrength(pNim, &SignalStrength); |
|
7338 + |
|
7339 + // Get signal quality. |
|
7340 + // Note: 1. The range of SignalQuality is 0~100. |
|
7341 + // 2. Need to map SignalQuality value to UI signal quality bar manually. |
|
7342 + pNim->GetSignalQuality(pNim, &SignalQuality); |
|
7343 + |
|
7344 + |
|
7345 + // Get BER. |
|
7346 + pNim->GetBer(pNim, &BerNum, &BerDen); |
|
7347 + Ber = (double)BerNum / (double)BerDen; |
|
7348 + |
|
7349 + // Get SNR in dB. |
|
7350 + pNim->GetSnrDb(pNim, &SnrDbNum, &SnrDbDen); |
|
7351 + SnrDb = (double)SnrDbNum / (double)SnrDbDen; |
|
7352 + |
|
7353 + |
|
7354 + // Get TR offset (symbol timing offset) in ppm. |
|
7355 + pNim->GetTrOffsetPpm(pNim, &TrOffsetPpm); |
|
7356 + |
|
7357 + // Get CR offset (RF frequency offset) in Hz. |
|
7358 + pNim->GetCrOffsetHz(pNim, &CrOffsetHz); |
|
7359 + |
|
7360 + |
|
7361 + // Get TPS information. |
|
7362 + // Note: One can find TPS information definitions in the enumerations as follows: |
|
7363 + // 1. DVBT_CONSTELLATION_MODE. |
|
7364 + // 2. DVBT_HIERARCHY_MODE. |
|
7365 + // 3. DVBT_CODE_RATE_MODE. (for low-priority and high-priority code rate) |
|
7366 + // 4. DVBT_GUARD_INTERVAL_MODE. |
|
7367 + // 5. DVBT_FFT_MODE_MODE |
|
7368 + pNim->GetTpsInfo(pNim, &Constellation, &Hierarchy, &CodeRateLp, &CodeRateHp, &GuardInterval, &FftMode); |
|
7369 + |
|
7370 + |
|
7371 + |
|
7372 + return 0; |
|
7373 +} |
|
7374 + |
|
7375 + |
|
7376 +@endcode |
|
7377 + |
|
7378 +*/ |
|
7379 + |
|
7380 + |
|
7381 +#include "foundation.h" |
|
7382 +#include "tuner_base.h" |
|
7383 +#include "dvbt_demod_base.h" |
|
7384 + |
|
7385 + |
|
7386 + |
|
7387 + |
|
7388 + |
|
7389 +// Definitions |
|
7390 +#define DEFAULT_DVBT_NIM_SINGAL_PRESENT_CHECK_TIMES_MAX 1 |
|
7391 +#define DEFAULT_DVBT_NIM_SINGAL_LOCK_CHECK_TIMES_MAX 1 |
|
7392 + |
|
7393 + |
|
7394 + |
|
7395 + |
|
7396 + |
|
7397 +/// DVB-T NIM module pre-definition |
|
7398 +typedef struct DVBT_NIM_MODULE_TAG DVBT_NIM_MODULE; |
|
7399 + |
|
7400 + |
|
7401 + |
|
7402 + |
|
7403 + |
|
7404 +/** |
|
7405 + |
|
7406 +@brief DVB-T demod type getting function pointer |
|
7407 + |
|
7408 +One can use DVBT_NIM_FP_GET_NIM_TYPE() to get DVB-T NIM type. |
|
7409 + |
|
7410 + |
|
7411 +@param [in] pNim The NIM module pointer |
|
7412 +@param [out] pNimType Pointer to an allocated memory for storing NIM type |
|
7413 + |
|
7414 + |
|
7415 +@note |
|
7416 + -# NIM building function will set DVBT_NIM_FP_GET_NIM_TYPE() with the corresponding function. |
|
7417 + |
|
7418 + |
|
7419 +@see MODULE_TYPE |
|
7420 + |
|
7421 +*/ |
|
7422 +typedef void |
|
7423 +(*DVBT_NIM_FP_GET_NIM_TYPE)( |
|
7424 + DVBT_NIM_MODULE *pNim, |
|
7425 + int *pNimType |
|
7426 + ); |
|
7427 + |
|
7428 + |
|
7429 + |
|
7430 + |
|
7431 + |
|
7432 +/** |
|
7433 + |
|
7434 +@brief DVB-T NIM initializing function pointer |
|
7435 + |
|
7436 +One can use DVBT_NIM_FP_INITIALIZE() to initialie DVB-T NIM. |
|
7437 + |
|
7438 + |
|
7439 +@param [in] pNim The NIM module pointer |
|
7440 + |
|
7441 + |
|
7442 +@retval FUNCTION_SUCCESS Initialize NIM successfully. |
|
7443 +@retval FUNCTION_ERROR Initialize NIM unsuccessfully. |
|
7444 + |
|
7445 + |
|
7446 +@note |
|
7447 + -# NIM building function will set DVBT_NIM_FP_INITIALIZE() with the corresponding function. |
|
7448 + |
|
7449 +*/ |
|
7450 +typedef int |
|
7451 +(*DVBT_NIM_FP_INITIALIZE)( |
|
7452 + DVBT_NIM_MODULE *pNim |
|
7453 + ); |
|
7454 + |
|
7455 + |
|
7456 + |
|
7457 + |
|
7458 + |
|
7459 +/** |
|
7460 + |
|
7461 +@brief DVB-T NIM parameter setting function pointer |
|
7462 + |
|
7463 +One can use DVBT_NIM_FP_SET_PARAMETERS() to set DVB-T NIM parameters. |
|
7464 + |
|
7465 + |
|
7466 +@param [in] pNim The NIM module pointer |
|
7467 +@param [in] RfFreqHz RF frequency in Hz for setting |
|
7468 +@param [in] BandwidthMode Bandwidth mode for setting |
|
7469 + |
|
7470 + |
|
7471 +@retval FUNCTION_SUCCESS Set NIM parameters successfully. |
|
7472 +@retval FUNCTION_ERROR Set NIM parameters unsuccessfully. |
|
7473 + |
|
7474 + |
|
7475 +@note |
|
7476 + -# NIM building function will set DVBT_NIM_FP_SET_PARAMETERS() with the corresponding function. |
|
7477 + |
|
7478 + |
|
7479 +@see DVBT_BANDWIDTH_MODE |
|
7480 + |
|
7481 +*/ |
|
7482 +typedef int |
|
7483 +(*DVBT_NIM_FP_SET_PARAMETERS)( |
|
7484 + DVBT_NIM_MODULE *pNim, |
|
7485 + unsigned long RfFreqHz, |
|
7486 + int BandwidthMode |
|
7487 + ); |
|
7488 + |
|
7489 + |
|
7490 + |
|
7491 + |
|
7492 + |
|
7493 +/** |
|
7494 + |
|
7495 +@brief DVB-T NIM parameter getting function pointer |
|
7496 + |
|
7497 +One can use DVBT_NIM_FP_GET_PARAMETERS() to get DVB-T NIM parameters. |
|
7498 + |
|
7499 + |
|
7500 +@param [in] pNim The NIM module pointer |
|
7501 +@param [out] pRfFreqHz Pointer to an allocated memory for storing NIM RF frequency in Hz |
|
7502 +@param [out] pBandwidthMode Pointer to an allocated memory for storing NIM bandwidth mode |
|
7503 + |
|
7504 + |
|
7505 +@retval FUNCTION_SUCCESS Get NIM parameters successfully. |
|
7506 +@retval FUNCTION_ERROR Get NIM parameters unsuccessfully. |
|
7507 + |
|
7508 + |
|
7509 +@note |
|
7510 + -# NIM building function will set DVBT_NIM_FP_GET_PARAMETERS() with the corresponding function. |
|
7511 + |
|
7512 + |
|
7513 +@see DVBT_BANDWIDTH_MODE |
|
7514 + |
|
7515 +*/ |
|
7516 +typedef int |
|
7517 +(*DVBT_NIM_FP_GET_PARAMETERS)( |
|
7518 + DVBT_NIM_MODULE *pNim, |
|
7519 + unsigned long *pRfFreqHz, |
|
7520 + int *pBandwidthMode |
|
7521 + ); |
|
7522 + |
|
7523 + |
|
7524 + |
|
7525 + |
|
7526 + |
|
7527 +/** |
|
7528 + |
|
7529 +@brief DVB-T NIM signal present asking function pointer |
|
7530 + |
|
7531 +One can use DVBT_NIM_FP_IS_SIGNAL_PRESENT() to ask DVB-T NIM if signal is present. |
|
7532 + |
|
7533 + |
|
7534 +@param [in] pNim The NIM module pointer |
|
7535 +@param [out] pAnswer Pointer to an allocated memory for storing answer |
|
7536 + |
|
7537 + |
|
7538 +@retval FUNCTION_SUCCESS Perform signal present asking to NIM successfully. |
|
7539 +@retval FUNCTION_ERROR Perform signal present asking to NIM unsuccessfully. |
|
7540 + |
|
7541 + |
|
7542 +@note |
|
7543 + -# NIM building function will set DVBT_NIM_FP_IS_SIGNAL_PRESENT() with the corresponding function. |
|
7544 + |
|
7545 +*/ |
|
7546 +typedef int |
|
7547 +(*DVBT_NIM_FP_IS_SIGNAL_PRESENT)( |
|
7548 + DVBT_NIM_MODULE *pNim, |
|
7549 + int *pAnswer |
|
7550 + ); |
|
7551 + |
|
7552 + |
|
7553 + |
|
7554 + |
|
7555 + |
|
7556 +/** |
|
7557 + |
|
7558 +@brief DVB-T NIM signal lock asking function pointer |
|
7559 + |
|
7560 +One can use DVBT_NIM_FP_IS_SIGNAL_LOCKED() to ask DVB-T NIM if signal is locked. |
|
7561 + |
|
7562 + |
|
7563 +@param [in] pNim The NIM module pointer |
|
7564 +@param [out] pAnswer Pointer to an allocated memory for storing answer |
|
7565 + |
|
7566 + |
|
7567 +@retval FUNCTION_SUCCESS Perform signal lock asking to NIM successfully. |
|
7568 +@retval FUNCTION_ERROR Perform signal lock asking to NIM unsuccessfully. |
|
7569 + |
|
7570 + |
|
7571 +@note |
|
7572 + -# NIM building function will set DVBT_NIM_FP_IS_SIGNAL_LOCKED() with the corresponding function. |
|
7573 + |
|
7574 +*/ |
|
7575 +typedef int |
|
7576 +(*DVBT_NIM_FP_IS_SIGNAL_LOCKED)( |
|
7577 + DVBT_NIM_MODULE *pNim, |
|
7578 + int *pAnswer |
|
7579 + ); |
|
7580 + |
|
7581 + |
|
7582 + |
|
7583 + |
|
7584 + |
|
7585 +/** |
|
7586 + |
|
7587 +@brief DVB-T NIM signal strength getting function pointer |
|
7588 + |
|
7589 +One can use DVBT_NIM_FP_GET_SIGNAL_STRENGTH() to get signal strength. |
|
7590 + |
|
7591 + |
|
7592 +@param [in] pNim The NIM module pointer |
|
7593 +@param [out] pSignalStrength Pointer to an allocated memory for storing signal strength (value = 0 ~ 100) |
|
7594 + |
|
7595 + |
|
7596 +@retval FUNCTION_SUCCESS Get NIM signal strength successfully. |
|
7597 +@retval FUNCTION_ERROR Get NIM signal strength unsuccessfully. |
|
7598 + |
|
7599 + |
|
7600 +@note |
|
7601 + -# NIM building function will set DVBT_NIM_FP_GET_SIGNAL_STRENGTH() with the corresponding function. |
|
7602 + |
|
7603 +*/ |
|
7604 +typedef int |
|
7605 +(*DVBT_NIM_FP_GET_SIGNAL_STRENGTH)( |
|
7606 + DVBT_NIM_MODULE *pNim, |
|
7607 + unsigned long *pSignalStrength |
|
7608 + ); |
|
7609 + |
|
7610 + |
|
7611 + |
|
7612 + |
|
7613 + |
|
7614 +/** |
|
7615 + |
|
7616 +@brief DVB-T NIM signal quality getting function pointer |
|
7617 + |
|
7618 +One can use DVBT_NIM_FP_GET_SIGNAL_QUALITY() to get signal quality. |
|
7619 + |
|
7620 + |
|
7621 +@param [in] pNim The NIM module pointer |
|
7622 +@param [out] pSignalQuality Pointer to an allocated memory for storing signal quality (value = 0 ~ 100) |
|
7623 + |
|
7624 + |
|
7625 +@retval FUNCTION_SUCCESS Get NIM signal quality successfully. |
|
7626 +@retval FUNCTION_ERROR Get NIM signal quality unsuccessfully. |
|
7627 + |
|
7628 + |
|
7629 +@note |
|
7630 + -# NIM building function will set DVBT_NIM_FP_GET_SIGNAL_QUALITY() with the corresponding function. |
|
7631 + |
|
7632 +*/ |
|
7633 +typedef int |
|
7634 +(*DVBT_NIM_FP_GET_SIGNAL_QUALITY)( |
|
7635 + DVBT_NIM_MODULE *pNim, |
|
7636 + unsigned long *pSignalQuality |
|
7637 + ); |
|
7638 + |
|
7639 + |
|
7640 + |
|
7641 + |
|
7642 + |
|
7643 +/** |
|
7644 + |
|
7645 +@brief DVB-T NIM BER value getting function pointer |
|
7646 + |
|
7647 +One can use DVBT_NIM_FP_GET_BER() to get BER. |
|
7648 + |
|
7649 + |
|
7650 +@param [in] pNim The NIM module pointer |
|
7651 +@param [out] pBerNum Pointer to an allocated memory for storing BER numerator |
|
7652 +@param [out] pBerDen Pointer to an allocated memory for storing BER denominator |
|
7653 + |
|
7654 + |
|
7655 +@retval FUNCTION_SUCCESS Get NIM BER value successfully. |
|
7656 +@retval FUNCTION_ERROR Get NIM BER value unsuccessfully. |
|
7657 + |
|
7658 + |
|
7659 +@note |
|
7660 + -# NIM building function will set DVBT_NIM_FP_GET_BER() with the corresponding function. |
|
7661 + |
|
7662 +*/ |
|
7663 +typedef int |
|
7664 +(*DVBT_NIM_FP_GET_BER)( |
|
7665 + DVBT_NIM_MODULE *pNim, |
|
7666 + unsigned long *pBerNum, |
|
7667 + unsigned long *pBerDen |
|
7668 + ); |
|
7669 + |
|
7670 + |
|
7671 + |
|
7672 + |
|
7673 + |
|
7674 +/** |
|
7675 + |
|
7676 +@brief DVB-T NIM SNR getting function pointer |
|
7677 + |
|
7678 +One can use DVBT_NIM_FP_GET_SNR_DB() to get SNR in dB. |
|
7679 + |
|
7680 + |
|
7681 +@param [in] pNim The NIM module pointer |
|
7682 +@param [out] pSnrDbNum Pointer to an allocated memory for storing SNR dB numerator |
|
7683 +@param [out] pSnrDbDen Pointer to an allocated memory for storing SNR dB denominator |
|
7684 + |
|
7685 + |
|
7686 +@retval FUNCTION_SUCCESS Get NIM SNR successfully. |
|
7687 +@retval FUNCTION_ERROR Get NIM SNR unsuccessfully. |
|
7688 + |
|
7689 + |
|
7690 +@note |
|
7691 + -# NIM building function will set DVBT_NIM_FP_GET_SNR_DB() with the corresponding function. |
|
7692 + |
|
7693 +*/ |
|
7694 +typedef int |
|
7695 +(*DVBT_NIM_FP_GET_SNR_DB)( |
|
7696 + DVBT_NIM_MODULE *pNim, |
|
7697 + long *pSnrDbNum, |
|
7698 + long *pSnrDbDen |
|
7699 + ); |
|
7700 + |
|
7701 + |
|
7702 + |
|
7703 + |
|
7704 + |
|
7705 +/** |
|
7706 + |
|
7707 +@brief DVB-T NIM TR offset getting function pointer |
|
7708 + |
|
7709 +One can use DVBT_NIM_FP_GET_TR_OFFSET_PPM() to get TR offset in ppm. |
|
7710 + |
|
7711 + |
|
7712 +@param [in] pNim The NIM module pointer |
|
7713 +@param [out] pTrOffsetPpm Pointer to an allocated memory for storing TR offset in ppm |
|
7714 + |
|
7715 + |
|
7716 +@retval FUNCTION_SUCCESS Get NIM TR offset successfully. |
|
7717 +@retval FUNCTION_ERROR Get NIM TR offset unsuccessfully. |
|
7718 + |
|
7719 + |
|
7720 +@note |
|
7721 + -# NIM building function will set DVBT_NIM_FP_GET_TR_OFFSET_PPM() with the corresponding function. |
|
7722 + |
|
7723 +*/ |
|
7724 +typedef int |
|
7725 +(*DVBT_NIM_FP_GET_TR_OFFSET_PPM)( |
|
7726 + DVBT_NIM_MODULE *pNim, |
|
7727 + long *pTrOffsetPpm |
|
7728 + ); |
|
7729 + |
|
7730 + |
|
7731 + |
|
7732 + |
|
7733 + |
|
7734 +/** |
|
7735 + |
|
7736 +@brief DVB-T NIM CR offset getting function pointer |
|
7737 + |
|
7738 +One can use DVBT_NIM_FP_GET_CR_OFFSET_HZ() to get CR offset in Hz. |
|
7739 + |
|
7740 + |
|
7741 +@param [in] pNim The NIM module pointer |
|
7742 +@param [out] pCrOffsetHz Pointer to an allocated memory for storing CR offset in Hz |
|
7743 + |
|
7744 + |
|
7745 +@retval FUNCTION_SUCCESS Get NIM CR offset successfully. |
|
7746 +@retval FUNCTION_ERROR Get NIM CR offset unsuccessfully. |
|
7747 + |
|
7748 + |
|
7749 +@note |
|
7750 + -# NIM building function will set DVBT_NIM_FP_GET_CR_OFFSET_HZ() with the corresponding function. |
|
7751 + |
|
7752 +*/ |
|
7753 +typedef int |
|
7754 +(*DVBT_NIM_FP_GET_CR_OFFSET_HZ)( |
|
7755 + DVBT_NIM_MODULE *pNim, |
|
7756 + long *pCrOffsetHz |
|
7757 + ); |
|
7758 + |
|
7759 + |
|
7760 + |
|
7761 + |
|
7762 + |
|
7763 +/** |
|
7764 + |
|
7765 +@brief DVB-T NIM TPS information getting function pointer |
|
7766 + |
|
7767 +One can use DVBT_NIM_FP_GET_TPS_INFO() to get TPS information. |
|
7768 + |
|
7769 + |
|
7770 +@param [in] pNim The NIM module pointer |
|
7771 +@param [out] pConstellation Pointer to an allocated memory for storing demod constellation mode |
|
7772 +@param [out] pHierarchy Pointer to an allocated memory for storing demod hierarchy mode |
|
7773 +@param [out] pCodeRateLp Pointer to an allocated memory for storing demod low-priority code rate mode |
|
7774 +@param [out] pCodeRateHp Pointer to an allocated memory for storing demod high-priority code rate mode |
|
7775 +@param [out] pGuardInterval Pointer to an allocated memory for storing demod guard interval mode |
|
7776 +@param [out] pFftMode Pointer to an allocated memory for storing demod FFT mode |
|
7777 + |
|
7778 + |
|
7779 +@retval FUNCTION_SUCCESS Get NIM TPS information successfully. |
|
7780 +@retval FUNCTION_ERROR Get NIM TPS information unsuccessfully. |
|
7781 + |
|
7782 + |
|
7783 +@note |
|
7784 + -# NIM building function will set DVBT_NIM_FP_GET_TPS_INFO() with the corresponding function. |
|
7785 + |
|
7786 + |
|
7787 +@see DVBT_CONSTELLATION_MODE, DVBT_HIERARCHY_MODE, DVBT_CODE_RATE_MODE, DVBT_GUARD_INTERVAL_MODE, DVBT_FFT_MODE_MODE |
|
7788 + |
|
7789 +*/ |
|
7790 +typedef int |
|
7791 +(*DVBT_NIM_FP_GET_TPS_INFO)( |
|
7792 + DVBT_NIM_MODULE *pNim, |
|
7793 + int *pConstellation, |
|
7794 + int *pHierarchy, |
|
7795 + int *pCodeRateLp, |
|
7796 + int *pCodeRateHp, |
|
7797 + int *pGuardInterval, |
|
7798 + int *pFftMode |
|
7799 + ); |
|
7800 + |
|
7801 + |
|
7802 + |
|
7803 + |
|
7804 + |
|
7805 +/** |
|
7806 + |
|
7807 +@brief DVB-T NIM updating function pointer |
|
7808 + |
|
7809 +One can use DVBT_NIM_FP_UPDATE_FUNCTION() to update NIM register setting. |
|
7810 + |
|
7811 + |
|
7812 +@param [in] pNim The NIM module pointer |
|
7813 + |
|
7814 + |
|
7815 +@retval FUNCTION_SUCCESS Update NIM setting successfully. |
|
7816 +@retval FUNCTION_ERROR Update NIM setting unsuccessfully. |
|
7817 + |
|
7818 + |
|
7819 +@note |
|
7820 + -# NIM building function will set DVBT_NIM_FP_UPDATE_FUNCTION() with the corresponding function. |
|
7821 + |
|
7822 + |
|
7823 + |
|
7824 +@par Example: |
|
7825 +@code |
|
7826 + |
|
7827 + |
|
7828 +#include "nim_demodx_tunery.h" |
|
7829 + |
|
7830 + |
|
7831 +int main(void) |
|
7832 +{ |
|
7833 + DVBT_NIM_MODULE *pNim; |
|
7834 + DVBT_NIM_MODULE DvbtNimModuleMemory; |
|
7835 + DEMODX_EXTRA_MODULE DemodxExtraModuleMemory; |
|
7836 + TUNERY_EXTRA_MODULE TuneryExtraModuleMemory; |
|
7837 + |
|
7838 + |
|
7839 + // Build Demod-X Tuner-Y NIM module. |
|
7840 + BuildDemodxTuneryModule( |
|
7841 + ... |
|
7842 + ); |
|
7843 + |
|
7844 + ... |
|
7845 + |
|
7846 + |
|
7847 + return 0; |
|
7848 +} |
|
7849 + |
|
7850 + |
|
7851 +void PeriodicallyExecutingFunction |
|
7852 +{ |
|
7853 + // Executing UpdateFunction() periodically. |
|
7854 + pNim->UpdateFunction(pNim); |
|
7855 +} |
|
7856 + |
|
7857 + |
|
7858 +@endcode |
|
7859 + |
|
7860 +*/ |
|
7861 +typedef int |
|
7862 +(*DVBT_NIM_FP_UPDATE_FUNCTION)( |
|
7863 + DVBT_NIM_MODULE *pNim |
|
7864 + ); |
|
7865 + |
|
7866 + |
|
7867 + |
|
7868 + |
|
7869 + |
|
7870 +/// DVB-T NIM module structure |
|
7871 +struct DVBT_NIM_MODULE_TAG |
|
7872 +{ |
|
7873 + // Private variables |
|
7874 + int NimType; |
|
7875 + int DemodTsInterfaceMode; |
|
7876 + |
|
7877 + void *pExtra; ///< NIM extra module used by driving module |
|
7878 + |
|
7879 + |
|
7880 + // Modules |
|
7881 + BASE_INTERFACE_MODULE *pBaseInterface; ///< Base interface module pointer |
|
7882 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; ///< Base interface module memory |
|
7883 + |
|
7884 + I2C_BRIDGE_MODULE *pI2cBridge; ///< I2C bridge module pointer |
|
7885 + I2C_BRIDGE_MODULE I2cBridgeModuleMemory; ///< I2C bridge module memory |
|
7886 + |
|
7887 + TUNER_MODULE *pTuner; ///< Tuner module pointer |
|
7888 + TUNER_MODULE TunerModuleMemory; ///< Tuner module memory |
|
7889 + |
|
7890 + DVBT_DEMOD_MODULE *pDemod; ///< DVB-T demod module pointer |
|
7891 + DVBT_DEMOD_MODULE DvbtDemodModuleMemory; ///< DVB-T demod module memory |
|
7892 + |
|
7893 + |
|
7894 + // NIM manipulating functions |
|
7895 + DVBT_NIM_FP_GET_NIM_TYPE GetNimType; |
|
7896 + DVBT_NIM_FP_INITIALIZE Initialize; |
|
7897 + DVBT_NIM_FP_SET_PARAMETERS SetParameters; |
|
7898 + DVBT_NIM_FP_GET_PARAMETERS GetParameters; |
|
7899 + DVBT_NIM_FP_IS_SIGNAL_PRESENT IsSignalPresent; |
|
7900 + DVBT_NIM_FP_IS_SIGNAL_LOCKED IsSignalLocked; |
|
7901 + DVBT_NIM_FP_GET_SIGNAL_STRENGTH GetSignalStrength; |
|
7902 + DVBT_NIM_FP_GET_SIGNAL_QUALITY GetSignalQuality; |
|
7903 + DVBT_NIM_FP_GET_BER GetBer; |
|
7904 + DVBT_NIM_FP_GET_SNR_DB GetSnrDb; |
|
7905 + DVBT_NIM_FP_GET_TR_OFFSET_PPM GetTrOffsetPpm; |
|
7906 + DVBT_NIM_FP_GET_CR_OFFSET_HZ GetCrOffsetHz; |
|
7907 + DVBT_NIM_FP_GET_TPS_INFO GetTpsInfo; |
|
7908 + DVBT_NIM_FP_UPDATE_FUNCTION UpdateFunction; |
|
7909 +}; |
|
7910 + |
|
7911 + |
|
7912 + |
|
7913 + |
|
7914 + |
|
7915 + |
|
7916 + |
|
7917 +// DVB-T NIM default manipulaing functions |
|
7918 +void |
|
7919 +dvbt_nim_default_GetNimType( |
|
7920 + DVBT_NIM_MODULE *pNim, |
|
7921 + int *pNimType |
|
7922 + ); |
|
7923 + |
|
7924 +int |
|
7925 +dvbt_nim_default_SetParameters( |
|
7926 + DVBT_NIM_MODULE *pNim, |
|
7927 + unsigned long RfFreqHz, |
|
7928 + int BandwidthMode |
|
7929 + ); |
|
7930 + |
|
7931 +int |
|
7932 +dvbt_nim_default_GetParameters( |
|
7933 + DVBT_NIM_MODULE *pNim, |
|
7934 + unsigned long *pRfFreqHz, |
|
7935 + int *pBandwidthMode |
|
7936 + ); |
|
7937 + |
|
7938 +int |
|
7939 +dvbt_nim_default_IsSignalPresent( |
|
7940 + DVBT_NIM_MODULE *pNim, |
|
7941 + int *pAnswer |
|
7942 + ); |
|
7943 + |
|
7944 +int |
|
7945 +dvbt_nim_default_IsSignalLocked( |
|
7946 + DVBT_NIM_MODULE *pNim, |
|
7947 + int *pAnswer |
|
7948 + ); |
|
7949 + |
|
7950 +int |
|
7951 +dvbt_nim_default_GetSignalStrength( |
|
7952 + DVBT_NIM_MODULE *pNim, |
|
7953 + unsigned long *pSignalStrength |
|
7954 + ); |
|
7955 + |
|
7956 +int |
|
7957 +dvbt_nim_default_GetSignalQuality( |
|
7958 + DVBT_NIM_MODULE *pNim, |
|
7959 + unsigned long *pSignalQuality |
|
7960 + ); |
|
7961 + |
|
7962 +int |
|
7963 +dvbt_nim_default_GetBer( |
|
7964 + DVBT_NIM_MODULE *pNim, |
|
7965 + unsigned long *pBerNum, |
|
7966 + unsigned long *pBerDen |
|
7967 + ); |
|
7968 + |
|
7969 +int |
|
7970 +dvbt_nim_default_GetSnrDb( |
|
7971 + DVBT_NIM_MODULE *pNim, |
|
7972 + long *pSnrDbNum, |
|
7973 + long *pSnrDbDen |
|
7974 + ); |
|
7975 + |
|
7976 +int |
|
7977 +dvbt_nim_default_GetTrOffsetPpm( |
|
7978 + DVBT_NIM_MODULE *pNim, |
|
7979 + long *pTrOffsetPpm |
|
7980 + ); |
|
7981 + |
|
7982 +int |
|
7983 +dvbt_nim_default_GetCrOffsetHz( |
|
7984 + DVBT_NIM_MODULE *pNim, |
|
7985 + long *pCrOffsetHz |
|
7986 + ); |
|
7987 + |
|
7988 +int |
|
7989 +dvbt_nim_default_GetTpsInfo( |
|
7990 + DVBT_NIM_MODULE *pNim, |
|
7991 + int *pConstellation, |
|
7992 + int *pHierarchy, |
|
7993 + int *pCodeRateLp, |
|
7994 + int *pCodeRateHp, |
|
7995 + int *pGuardInterval, |
|
7996 + int *pFftMode |
|
7997 + ); |
|
7998 + |
|
7999 +int |
|
8000 +dvbt_nim_default_UpdateFunction( |
|
8001 + DVBT_NIM_MODULE *pNim |
|
8002 + ); |
|
8003 + |
|
8004 + |
|
8005 + |
|
8006 + |
|
8007 + |
|
8008 + |
|
8009 + |
|
8010 +#endif |
|
8011 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/foundation.c |
|
8012 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
8013 +++ b/linux/drivers/media/dvb/dvb-usb/foundation.c Wed Oct 27 09:16:44 2010 +0200 |
|
8014 @@ -0,0 +1,352 @@ |
|
8015 +/** |
|
8016 + |
|
8017 +@file |
|
8018 + |
|
8019 +@brief Fundamental interface definition |
|
8020 + |
|
8021 +Fundamental interface contains base function pointers and some mathematics tools. |
|
8022 + |
|
8023 +*/ |
|
8024 + |
|
8025 + |
|
8026 +#include "foundation.h" |
|
8027 + |
|
8028 + |
|
8029 + |
|
8030 + |
|
8031 + |
|
8032 +// Base interface builder |
|
8033 +void |
|
8034 +BuildBaseInterface( |
|
8035 + BASE_INTERFACE_MODULE **ppBaseInterface, |
|
8036 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
8037 + unsigned char I2cReadingByteNumMax, |
|
8038 + unsigned char I2cWritingByteNumMax, |
|
8039 + BASE_FP_I2C_READ I2cRead, |
|
8040 + BASE_FP_I2C_WRITE I2cWrite, |
|
8041 + BASE_FP_WAIT_MS WaitMs |
|
8042 + ) |
|
8043 +{ |
|
8044 + // Set base interface module pointer. |
|
8045 + *ppBaseInterface = pBaseInterfaceModuleMemory; |
|
8046 + |
|
8047 + |
|
8048 + // Set all base interface function pointers and arguments. |
|
8049 + (*ppBaseInterface)->I2cReadingByteNumMax = I2cReadingByteNumMax; |
|
8050 + (*ppBaseInterface)->I2cWritingByteNumMax = I2cWritingByteNumMax; |
|
8051 + (*ppBaseInterface)->I2cRead = I2cRead; |
|
8052 + (*ppBaseInterface)->I2cWrite = I2cWrite; |
|
8053 + (*ppBaseInterface)->WaitMs = WaitMs; |
|
8054 + (*ppBaseInterface)->SetUserDefinedDataPointer = base_interface_SetUserDefinedDataPointer; |
|
8055 + (*ppBaseInterface)->GetUserDefinedDataPointer = base_interface_GetUserDefinedDataPointer; |
|
8056 + |
|
8057 + |
|
8058 + return; |
|
8059 +} |
|
8060 + |
|
8061 + |
|
8062 + |
|
8063 + |
|
8064 + |
|
8065 +/** |
|
8066 + |
|
8067 +@brief Set user defined data pointer of base interface structure for custom basic function implementation. |
|
8068 + |
|
8069 +@note |
|
8070 + -# Base interface builder will set BASE_FP_SET_USER_DEFINED_DATA_POINTER() function pointer with |
|
8071 + base_interface_SetUserDefinedDataPointer(). |
|
8072 + |
|
8073 +@see BASE_FP_SET_USER_DEFINED_DATA_POINTER |
|
8074 + |
|
8075 +*/ |
|
8076 +void |
|
8077 +base_interface_SetUserDefinedDataPointer( |
|
8078 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8079 + void *pUserDefinedData |
|
8080 + ) |
|
8081 +{ |
|
8082 + // Set user defined data pointer of base interface structure with user defined data pointer argument. |
|
8083 + pBaseInterface->pUserDefinedData = pUserDefinedData; |
|
8084 + |
|
8085 + |
|
8086 + return; |
|
8087 +} |
|
8088 + |
|
8089 + |
|
8090 + |
|
8091 + |
|
8092 + |
|
8093 +/** |
|
8094 + |
|
8095 +@brief Get user defined data pointer of base interface structure for custom basic function implementation. |
|
8096 + |
|
8097 +@note |
|
8098 + -# Base interface builder will set BASE_FP_GET_USER_DEFINED_DATA_POINTER() function pointer with |
|
8099 + base_interface_GetUserDefinedDataPointer(). |
|
8100 + |
|
8101 +@see BASE_FP_GET_USER_DEFINED_DATA_POINTER |
|
8102 + |
|
8103 +*/ |
|
8104 +void |
|
8105 +base_interface_GetUserDefinedDataPointer( |
|
8106 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8107 + void **ppUserDefinedData |
|
8108 + ) |
|
8109 +{ |
|
8110 + // Get user defined data pointer from base interface structure to the caller user defined data pointer. |
|
8111 + *ppUserDefinedData = pBaseInterface->pUserDefinedData; |
|
8112 + |
|
8113 + |
|
8114 + return; |
|
8115 +} |
|
8116 + |
|
8117 + |
|
8118 + |
|
8119 + |
|
8120 + |
|
8121 +/** |
|
8122 + |
|
8123 +@brief Convert signed integer to binary. |
|
8124 + |
|
8125 +Convert 2's complement signed integer to binary with bit number. |
|
8126 + |
|
8127 + |
|
8128 +@param [in] Value the converting value in 2's complement format |
|
8129 +@param [in] BitNum the bit number of the converting value |
|
8130 + |
|
8131 + |
|
8132 +@return Converted binary |
|
8133 + |
|
8134 + |
|
8135 +@note |
|
8136 + The converting value must be -pow(2, BitNum - 1) ~ (pow(2, BitNum - 1) -1). |
|
8137 + |
|
8138 + |
|
8139 + |
|
8140 +@par Example: |
|
8141 +@code |
|
8142 + |
|
8143 + |
|
8144 +#include "foundation.h" |
|
8145 + |
|
8146 + |
|
8147 +int main(void) |
|
8148 +{ |
|
8149 + long Value = -345; |
|
8150 + unsigned long Binary; |
|
8151 + |
|
8152 + |
|
8153 + // Convert 2's complement integer to binary with 10 bit number. |
|
8154 + Binary = SignedIntToBin(Value, 10); |
|
8155 + |
|
8156 + |
|
8157 + // Result in base 2: |
|
8158 + // Value = 1111 1111 1111 1111 1111 1110 1010 0111 b = -345 (in 32-bit 2's complement format) |
|
8159 + // Binary = 0000 0000 0000 0000 0000 0010 1010 0111 b = 679 (in 10-bit binary format) |
|
8160 + |
|
8161 + ... |
|
8162 + |
|
8163 + return 0; |
|
8164 +} |
|
8165 + |
|
8166 + |
|
8167 +@endcode |
|
8168 + |
|
8169 +*/ |
|
8170 +unsigned long |
|
8171 +SignedIntToBin( |
|
8172 + long Value, |
|
8173 + unsigned char BitNum |
|
8174 + ) |
|
8175 +{ |
|
8176 + unsigned int i; |
|
8177 + unsigned long Mask, Binary; |
|
8178 + |
|
8179 + |
|
8180 + |
|
8181 + // Generate Mask according to BitNum. |
|
8182 + Mask = 0; |
|
8183 + for(i = 0; i < BitNum; i++) |
|
8184 + Mask |= 0x1 << i; |
|
8185 + |
|
8186 + |
|
8187 + // Convert signed integer to binary with Mask. |
|
8188 + Binary = Value & Mask; |
|
8189 + |
|
8190 + |
|
8191 + return Binary; |
|
8192 +} |
|
8193 + |
|
8194 + |
|
8195 + |
|
8196 + |
|
8197 + |
|
8198 +/** |
|
8199 + |
|
8200 +@brief Convert binary to signed integer. |
|
8201 + |
|
8202 +Convert binary to 2's complement signed integer with bit number. |
|
8203 + |
|
8204 + |
|
8205 +@param [in] Binary the converting binary |
|
8206 +@param [in] BitNum the bit number of the converting binary |
|
8207 + |
|
8208 + |
|
8209 +@return Converted 2's complement signed integer |
|
8210 + |
|
8211 + |
|
8212 +@note |
|
8213 + The converting binary must be 0 ~ (pow(2, BitNum) - 1). |
|
8214 + |
|
8215 + |
|
8216 + |
|
8217 +@par Example: |
|
8218 +@code |
|
8219 + |
|
8220 + |
|
8221 +#include "foundation.h" |
|
8222 + |
|
8223 + |
|
8224 +int main(void) |
|
8225 +{ |
|
8226 + unsigned long Binary = 679; |
|
8227 + long Value; |
|
8228 + |
|
8229 + |
|
8230 + // Convert binary to 2's complement integer with 10 bit number. |
|
8231 + Value = BinToSignedInt(Binary, 10); |
|
8232 + |
|
8233 + |
|
8234 + // Result in base 2: |
|
8235 + // Binary = 0000 0000 0000 0000 0000 0010 1010 0111 b = 679 (in 10-bit binary format) |
|
8236 + // Value = 1111 1111 1111 1111 1111 1110 1010 0111 b = -345 (in 32-bit 2's complement format) |
|
8237 + |
|
8238 + ... |
|
8239 + |
|
8240 + return 0; |
|
8241 +} |
|
8242 + |
|
8243 + |
|
8244 +@endcode |
|
8245 + |
|
8246 +*/ |
|
8247 +long |
|
8248 +BinToSignedInt( |
|
8249 + unsigned long Binary, |
|
8250 + unsigned char BitNum |
|
8251 + ) |
|
8252 +{ |
|
8253 + int i; |
|
8254 + |
|
8255 + unsigned char SignedBit; |
|
8256 + unsigned long SignedBitExtension; |
|
8257 + |
|
8258 + long Value; |
|
8259 + |
|
8260 + |
|
8261 + |
|
8262 + // Get signed bit. |
|
8263 + SignedBit = (unsigned char)((Binary >> (BitNum - 1)) & BIT_0_MASK); |
|
8264 + |
|
8265 + |
|
8266 + // Generate signed bit extension. |
|
8267 + SignedBitExtension = 0; |
|
8268 + |
|
8269 + for(i = BitNum; i < LONG_BIT_NUM; i++) |
|
8270 + SignedBitExtension |= SignedBit << i; |
|
8271 + |
|
8272 + |
|
8273 + // Combine binary value and signed bit extension to signed integer value. |
|
8274 + Value = (long)(Binary | SignedBitExtension); |
|
8275 + |
|
8276 + |
|
8277 + return Value; |
|
8278 +} |
|
8279 + |
|
8280 + |
|
8281 + |
|
8282 + |
|
8283 + |
|
8284 +/** |
|
8285 + |
|
8286 +@brief Get devision reult with ceiling. |
|
8287 + |
|
8288 +Get unsigned devision reult with ceiling. |
|
8289 + |
|
8290 + |
|
8291 +@param [in] Dividend the dividend |
|
8292 +@param [in] Divisor the divisor |
|
8293 + |
|
8294 + |
|
8295 +@return Result with ceiling |
|
8296 + |
|
8297 + |
|
8298 +@note |
|
8299 + The dividend and divisor must be unsigned integer. |
|
8300 + |
|
8301 + |
|
8302 + |
|
8303 +@par Example: |
|
8304 +@code |
|
8305 + |
|
8306 + |
|
8307 +#include "foundation.h" |
|
8308 + |
|
8309 + |
|
8310 +int main(void) |
|
8311 +{ |
|
8312 + long Value; |
|
8313 + |
|
8314 + |
|
8315 + // Get ceil(100 / 20) reult. |
|
8316 + Value = DivideWithCeiling(100, 20); |
|
8317 + |
|
8318 + // Result: Value = 5 |
|
8319 + |
|
8320 + |
|
8321 + // Get ceil(100 / 30) reult. |
|
8322 + Value = DivideWithCeiling(100, 30); |
|
8323 + |
|
8324 + // Result: Value = 4 |
|
8325 + |
|
8326 + ... |
|
8327 + |
|
8328 + return 0; |
|
8329 +} |
|
8330 + |
|
8331 + |
|
8332 +@endcode |
|
8333 + |
|
8334 +*/ |
|
8335 +unsigned long |
|
8336 +DivideWithCeiling( |
|
8337 + unsigned long Dividend, |
|
8338 + unsigned long Divisor |
|
8339 + ) |
|
8340 +{ |
|
8341 + unsigned long Result; |
|
8342 + |
|
8343 + |
|
8344 + // Get primitive division result. |
|
8345 + Result = Dividend / Divisor; |
|
8346 + |
|
8347 + // Adjust primitive result with ceiling. |
|
8348 + if(Dividend % Divisor > 0) |
|
8349 + Result += 1; |
|
8350 + |
|
8351 + |
|
8352 + return Result; |
|
8353 +} |
|
8354 + |
|
8355 + |
|
8356 + |
|
8357 + |
|
8358 + |
|
8359 + |
|
8360 + |
|
8361 + |
|
8362 + |
|
8363 + |
|
8364 + |
|
8365 + |
|
8366 + |
|
8367 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/foundation.h |
|
8368 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
8369 +++ b/linux/drivers/media/dvb/dvb-usb/foundation.h Wed Oct 27 09:16:44 2010 +0200 |
|
8370 @@ -0,0 +1,891 @@ |
|
8371 +#ifndef __FOUNDATION_H |
|
8372 +#define __FOUNDATION_H |
|
8373 + |
|
8374 +/** |
|
8375 + |
|
8376 +@file |
|
8377 + |
|
8378 +@brief Fundamental interface declaration |
|
8379 + |
|
8380 +Fundamental interface contains base function pointers and some mathematics tools. |
|
8381 + |
|
8382 +*/ |
|
8383 + |
|
8384 + |
|
8385 +#include "i2c_bridge.h" |
|
8386 +#include "math_mpi.h" |
|
8387 +#include "dvb-usb.h" |
|
8388 +#include "rtl2832u_io.h" |
|
8389 + |
|
8390 + |
|
8391 + |
|
8392 +// Definitions |
|
8393 + |
|
8394 +// API version |
|
8395 +#define REALTEK_NIM_API_VERSION "Realtek NIM API 2008.12.04" |
|
8396 + |
|
8397 + |
|
8398 + |
|
8399 +// Constants |
|
8400 +#define INVALID_POINTER_VALUE 0 |
|
8401 +#define NO_USE 0 |
|
8402 + |
|
8403 +#define LEN_1_BYTE 1 |
|
8404 +#define LEN_2_BYTE 2 |
|
8405 +#define LEN_3_BYTE 3 |
|
8406 +#define LEN_4_BYTE 4 |
|
8407 +#define LEN_5_BYTE 5 |
|
8408 +#define LEN_6_BYTE 6 |
|
8409 +#define LEN_11_BYTE 11 |
|
8410 + |
|
8411 +#define LEN_1_BIT 1 |
|
8412 + |
|
8413 +#define BYTE_MASK 0xff |
|
8414 +#define BYTE_SHIFT 8 |
|
8415 +#define BYTE_BIT_NUM 8 |
|
8416 +#define LONG_BIT_NUM 32 |
|
8417 + |
|
8418 +#define BIT_0_MASK 0x1 |
|
8419 +#define BIT_1_MASK 0x2 |
|
8420 +#define BIT_3_MASK 0x8 |
|
8421 +#define BIT_4_MASK 0x10 |
|
8422 +#define BIT_8_MASK 0x100 |
|
8423 +#define BIT_7_SHIFT 7 |
|
8424 +#define BIT_8_SHIFT 8 |
|
8425 + |
|
8426 + |
|
8427 + |
|
8428 +// I2C buffer length |
|
8429 +// Note: I2C_BUFFER_LEN must be greater than I2cReadingByteNumMax and I2cWritingByteNumMax in BASE_INTERFACE_MODULE. |
|
8430 +#define I2C_BUFFER_LEN 128 |
|
8431 + |
|
8432 + |
|
8433 + |
|
8434 + |
|
8435 + |
|
8436 +/// Module types |
|
8437 +enum MODULE_TYPE |
|
8438 +{ |
|
8439 + // DVB-T demod |
|
8440 + DVBT_DEMOD_TYPE_RTL2830, ///< RTL2830 DVB-T demod |
|
8441 + DVBT_DEMOD_TYPE_RTL2832, ///< RTL2832 DVB-T demod |
|
8442 + |
|
8443 + // QAM demod |
|
8444 + QAM_DEMOD_TYPE_RTL2840, ///< RTL2840 DVB-C demod |
|
8445 + QAM_DEMOD_TYPE_RTL2810_OC, ///< RTL2810 OpenCable demod |
|
8446 + QAM_DEMOD_TYPE_RTL2820_OC, ///< RTL2820 OpenCable demod |
|
8447 + QAM_DEMOD_TYPE_RTD2885_QAM, ///< RTD2885 QAM demod |
|
8448 + |
|
8449 + // OOB demod |
|
8450 + OOB_DEMOD_TYPE_RTL2820_OOB, ///< RTL2820 OOB demod |
|
8451 + |
|
8452 + // ATSC demod |
|
8453 + ATSC_DEMOD_TYPE_RTL2820_ATSC, ///< RTL2820 ATSC demod |
|
8454 + ATSC_DEMOD_TYPE_RTD2885_ATSC, ///< RTD2885 ATSC demod |
|
8455 + |
|
8456 + // DTMB demod |
|
8457 + DTMB_DEMOD_TYPE_RTL2836, ///< RTL2836 DTMB demod |
|
8458 + |
|
8459 + // Tuner |
|
8460 + TUNER_TYPE_TDCGG052D, ///< TDCG-G052D tuner (QAM) |
|
8461 + TUNER_TYPE_TDCHG001D, ///< TDCH-G001D tuner (QAM) |
|
8462 + TUNER_TYPE_TDQE3003A, ///< TDQE3-003A tuner (QAM) |
|
8463 + TUNER_TYPE_DCT7045, ///< DCT-7045 tuner (QAM) |
|
8464 + TUNER_TYPE_MT2062, ///< MT2062 tuner (QAM) |
|
8465 + TUNER_TYPE_MXL5005S, ///< MxL5005S tuner (DVB-T, ATSC) |
|
8466 + TUNER_TYPE_TDVMH715P, ///< TDVM-H751P tuner (QAM, OOB, ATSC) |
|
8467 + TUNER_TYPE_UBA00AL, ///< UBA00AL tuner (QAM, ATSC) |
|
8468 + TUNER_TYPE_MT2266, ///< MT2266 tuner (DVB-T) |
|
8469 + TUNER_TYPE_FC2580, ///< FC2580 tuner (DVB-T) |
|
8470 + TUNER_TYPE_TUA9001, ///< TUA9001 tuner (DVB-T) |
|
8471 + TUNER_TYPE_DTT75300, ///< DTT-75300 tuner (DVB-T) |
|
8472 + TUNER_TYPE_MXL5007T, ///< MxL5007T tuner (DVB-T, ATSC) |
|
8473 + |
|
8474 + // DVB-T NIM |
|
8475 + DVBT_NIM_USER_DEFINITION, ///< DVB-T NIM: User definition |
|
8476 + DVBT_NIM_RTL2832_MT2266, ///< DVB-T NIM: RTL2832 + MT2266 |
|
8477 + DVBT_NIM_RTL2832_FC2580, ///< DVB-T NIM: RTL2832 + FC2580 |
|
8478 + DVBT_NIM_RTL2832_TUA9001, ///< DVB-T NIM: RTL2832 + TUA9001 |
|
8479 + DVBT_NIM_RTL2832_MXL5005S, ///< DVB-T NIM: RTL2832 + MxL5005S |
|
8480 + DVBT_NIM_RTL2832_DTT75300, ///< DVB-T NIM: RTL2832 + DTT-75300 |
|
8481 + DVBT_NIM_RTL2832_MXL5007T, ///< DVB-T NIM: RTL2832 + MxL5007T |
|
8482 + |
|
8483 + // QAM NIM |
|
8484 + QAM_NIM_USER_DEFINITION, ///< QAM NIM: User definition |
|
8485 + QAM_NIM_RTL2840_TDQE3003A, ///< QAM NIM: RTL2840 + TDQE3-003A |
|
8486 + QAM_NIM_RTL2840_DCT7045, ///< QAM NIM: RTL2840 + DCT-7045 |
|
8487 + QAM_NIM_RTL2840_DCT7046, ///< QAM NIM: RTL2840 + DCT-7046 |
|
8488 + QAM_NIM_RTL2840_MT2062, ///< QAM NIM: RTL2840 + MT2062 |
|
8489 + |
|
8490 + // DCR NIM |
|
8491 + DCR_NIM_RTL2820_TDVMH715P, ///< DCR NIM: RTL2820 + TDVM-H751P |
|
8492 + DCR_NIM_RTD2885_UBA00AL, ///< DCR NIM: RTD2885 + UBA00AL |
|
8493 + |
|
8494 + // DTMB NIM |
|
8495 + DTMB_NIM_RTL2836_FC2580, ///< DTMB NIM: RTL2836 + FC2580 |
|
8496 +}; |
|
8497 + |
|
8498 + |
|
8499 + |
|
8500 + |
|
8501 + |
|
8502 +/// On/off status |
|
8503 +enum ON_OFF_STATUS |
|
8504 +{ |
|
8505 + OFF, ///< Off |
|
8506 + ON, ///< On |
|
8507 +}; |
|
8508 + |
|
8509 + |
|
8510 +/// Yes/no status |
|
8511 +enum YES_NO_STATUS |
|
8512 +{ |
|
8513 + NO, ///< No |
|
8514 + YES, ///< Yes |
|
8515 +}; |
|
8516 + |
|
8517 + |
|
8518 +/// Lock status |
|
8519 +enum LOCK_STATUS |
|
8520 +{ |
|
8521 + NOT_LOCKED, ///< Not locked |
|
8522 + LOCKED, ///< Locked |
|
8523 +}; |
|
8524 + |
|
8525 + |
|
8526 +/// Loss status |
|
8527 +enum LOSS_STATUS |
|
8528 +{ |
|
8529 + NOT_LOST, ///< Not lost |
|
8530 + LOST, ///< Lost |
|
8531 +}; |
|
8532 + |
|
8533 + |
|
8534 +/// Function return status |
|
8535 +enum FUNCTION_RETURN_STATUS |
|
8536 +{ |
|
8537 + FUNCTION_SUCCESS, ///< Execute function successfully. |
|
8538 + FUNCTION_ERROR, ///< Execute function unsuccessfully. |
|
8539 +}; |
|
8540 + |
|
8541 + |
|
8542 +/// Crystal frequency |
|
8543 +enum CRYSTAL_FREQ_HZ |
|
8544 +{ |
|
8545 + CRYSTAL_FREQ_4000000HZ = 4000000, ///< Crystal frequency = 4.0 MHz |
|
8546 + CRYSTAL_FREQ_16000000HZ = 16000000, ///< Crystal frequency = 16.0 MHz |
|
8547 + CRYSTAL_FREQ_16384000HZ = 16384000, ///< Crystal frequency = 16.384 MHz |
|
8548 + CRYSTAL_FREQ_16457143HZ = 16457143, ///< Crystal frequency = 16.457 MHz |
|
8549 + CRYSTAL_FREQ_25000000HZ = 25000000, ///< Crystal frequency = 25.0 MHz |
|
8550 + CRYSTAL_FREQ_27000000HZ = 27000000, ///< Crystal frequency = 27.0 MHz |
|
8551 + CRYSTAL_FREQ_28800000HZ = 28800000, ///< Crystal frequency = 28.8 MHz |
|
8552 +}; |
|
8553 + |
|
8554 + |
|
8555 +/// IF frequency |
|
8556 +enum IF_FREQ_HZ |
|
8557 +{ |
|
8558 + IF_FREQ_0HZ = 0, ///< IF frequency = 0 MHz |
|
8559 + IF_FREQ_4570000HZ = 4570000, ///< IF frequency = 4.57 MHz |
|
8560 + IF_FREQ_4571429HZ = 4571429, ///< IF frequency = 4.571 MHz |
|
8561 + IF_FREQ_36000000HZ = 36000000, ///< IF frequency = 36.0 MHz |
|
8562 + IF_FREQ_36125000HZ = 36125000, ///< IF frequency = 36.125 MHz |
|
8563 + IF_FREQ_36166667HZ = 36166667, ///< IF frequency = 36.167 MHz |
|
8564 + IF_FREQ_43750000HZ = 43750000, ///< IF frequency = 43.75 MHz |
|
8565 + IF_FREQ_44000000HZ = 44000000, ///< IF frequency = 44.0 MHz |
|
8566 +}; |
|
8567 + |
|
8568 + |
|
8569 +/// Spectrum mode |
|
8570 +enum SPECTRUM_MODE |
|
8571 +{ |
|
8572 + SPECTRUM_NORMAL, ///< Normal spectrum |
|
8573 + SPECTRUM_INVERSE, ///< Inverse spectrum |
|
8574 +}; |
|
8575 +#define SPECTRUM_MODE_NUM 2 |
|
8576 + |
|
8577 + |
|
8578 +/// TS interface mode |
|
8579 +enum TS_INTERFACE_MODE |
|
8580 +{ |
|
8581 + TS_INTERFACE_PARALLEL, ///< Parallel TS interface |
|
8582 + TS_INTERFACE_SERIAL, ///< Serial TS interface |
|
8583 +}; |
|
8584 +#define TS_INTERFACE_MODE_NUM 2 |
|
8585 + |
|
8586 + |
|
8587 + |
|
8588 + |
|
8589 + |
|
8590 +/// Base interface module alias |
|
8591 +typedef struct BASE_INTERFACE_MODULE_TAG BASE_INTERFACE_MODULE; |
|
8592 + |
|
8593 + |
|
8594 + |
|
8595 + |
|
8596 + |
|
8597 +/** |
|
8598 + |
|
8599 +@brief Basic I2C reading function pointer |
|
8600 + |
|
8601 +Upper layer functions will use BASE_FP_I2C_READ() to read ByteNum bytes from I2C device to pReadingBytes buffer. |
|
8602 + |
|
8603 + |
|
8604 +@param [in] pBaseInterface The base interface module pointer |
|
8605 +@param [in] DeviceAddr I2C device address in 8-bit format |
|
8606 +@param [out] pReadingBytes Buffer pointer to an allocated memory for storing reading bytes |
|
8607 +@param [in] ByteNum Reading byte number |
|
8608 + |
|
8609 + |
|
8610 +@retval FUNCTION_SUCCESS Read bytes from I2C device with reading byte number successfully. |
|
8611 +@retval FUNCTION_ERROR Read bytes from I2C device unsuccessfully. |
|
8612 + |
|
8613 + |
|
8614 +@note |
|
8615 + The requirements of BASE_FP_I2C_READ() function are described as follows: |
|
8616 + -# Follow the I2C format for BASE_FP_I2C_READ(). \n |
|
8617 + start_bit + (DeviceAddr | reading_bit) + reading_byte * ByteNum + stop_bit |
|
8618 + -# Don't allocate memory on pReadingBytes. |
|
8619 + -# Upper layer functions should allocate memory on pReadingBytes before using BASE_FP_I2C_READ(). |
|
8620 + -# Need to assign I2C reading funtion to BASE_FP_I2C_READ() for upper layer functions. |
|
8621 + |
|
8622 + |
|
8623 + |
|
8624 +@par Example: |
|
8625 +@code |
|
8626 + |
|
8627 + |
|
8628 +#include "foundation.h" |
|
8629 + |
|
8630 + |
|
8631 +// Implement I2C reading funciton for BASE_FP_I2C_READ function pointer. |
|
8632 +int |
|
8633 +CustomI2cRead( |
|
8634 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8635 + unsigned char DeviceAddr, |
|
8636 + unsigned char *pReadingBytes, |
|
8637 + unsigned char ByteNum |
|
8638 + ) |
|
8639 +{ |
|
8640 + ... |
|
8641 + |
|
8642 + return FUNCTION_SUCCESS; |
|
8643 + |
|
8644 +error_status: |
|
8645 + |
|
8646 + return FUNCTION_ERROR; |
|
8647 +} |
|
8648 + |
|
8649 + |
|
8650 +int main(void) |
|
8651 +{ |
|
8652 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
8653 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
8654 + unsigned char ReadingBytes[100]; |
|
8655 + |
|
8656 + |
|
8657 + // Assign implemented I2C reading funciton to BASE_FP_I2C_READ in base interface module. |
|
8658 + BuildBaseInterface(&pBaseInterface, &BaseInterfaceModuleMemory, ..., ..., CustomI2cRead, ..., ...); |
|
8659 + |
|
8660 + ... |
|
8661 + |
|
8662 + // Use I2cRead() to read 33 bytes from I2C device and store reading bytes to ReadingBytes. |
|
8663 + pBaseInterface->I2cRead(pBaseInterface, 0x20, ReadingBytes, 33); |
|
8664 + |
|
8665 + ... |
|
8666 + |
|
8667 + return 0; |
|
8668 +} |
|
8669 + |
|
8670 + |
|
8671 +@endcode |
|
8672 + |
|
8673 +*/ |
|
8674 +typedef int |
|
8675 +(*BASE_FP_I2C_READ)( |
|
8676 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8677 + unsigned char DeviceAddr, |
|
8678 + unsigned char *pReadingBytes, |
|
8679 + unsigned char ByteNum |
|
8680 + ); |
|
8681 + |
|
8682 + |
|
8683 + |
|
8684 + |
|
8685 + |
|
8686 +/** |
|
8687 + |
|
8688 +@brief Basic I2C writing function pointer |
|
8689 + |
|
8690 +Upper layer functions will use BASE_FP_I2C_WRITE() to write ByteNum bytes from pWritingBytes buffer to I2C device. |
|
8691 + |
|
8692 + |
|
8693 +@param [in] pBaseInterface The base interface module pointer |
|
8694 +@param [in] DeviceAddr I2C device address in 8-bit format |
|
8695 +@param [in] pWritingBytes Buffer pointer to writing bytes |
|
8696 +@param [in] ByteNum Writing byte number |
|
8697 + |
|
8698 + |
|
8699 +@retval FUNCTION_SUCCESS Write bytes to I2C device with writing bytes successfully. |
|
8700 +@retval FUNCTION_ERROR Write bytes to I2C device unsuccessfully. |
|
8701 + |
|
8702 + |
|
8703 +@note |
|
8704 + The requirements of BASE_FP_I2C_WRITE() function are described as follows: |
|
8705 + -# Follow the I2C format for BASE_FP_I2C_WRITE(). \n |
|
8706 + start_bit + (DeviceAddr | writing_bit) + writing_byte * ByteNum + stop_bit |
|
8707 + -# Need to assign I2C writing funtion to BASE_FP_I2C_WRITE() for upper layer functions. |
|
8708 + |
|
8709 + |
|
8710 + |
|
8711 +@par Example: |
|
8712 +@code |
|
8713 + |
|
8714 + |
|
8715 +#include "foundation.h" |
|
8716 + |
|
8717 + |
|
8718 +// Implement I2C writing funciton for BASE_FP_I2C_WRITE function pointer. |
|
8719 +int |
|
8720 +CustomI2cWrite( |
|
8721 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8722 + unsigned char DeviceAddr, |
|
8723 + const unsigned char *pWritingBytes, |
|
8724 + unsigned char ByteNum |
|
8725 + ) |
|
8726 +{ |
|
8727 + ... |
|
8728 + |
|
8729 + return FUNCTION_SUCCESS; |
|
8730 + |
|
8731 +error_status: |
|
8732 + |
|
8733 + return FUNCTION_ERROR; |
|
8734 +} |
|
8735 + |
|
8736 + |
|
8737 +int main(void) |
|
8738 +{ |
|
8739 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
8740 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
8741 + unsigned char WritingBytes[100]; |
|
8742 + |
|
8743 + |
|
8744 + // Assign implemented I2C writing funciton to BASE_FP_I2C_WRITE in base interface module. |
|
8745 + BuildBaseInterface(&pBaseInterface, &BaseInterfaceModuleMemory, ..., ..., ..., CustomI2cWrite, ...); |
|
8746 + |
|
8747 + ... |
|
8748 + |
|
8749 + // Use I2cWrite() to write 33 bytes from WritingBytes to I2C device. |
|
8750 + pBaseInterface->I2cWrite(pBaseInterface, 0x20, WritingBytes, 33); |
|
8751 + |
|
8752 + ... |
|
8753 + |
|
8754 + return 0; |
|
8755 +} |
|
8756 + |
|
8757 + |
|
8758 +@endcode |
|
8759 + |
|
8760 +*/ |
|
8761 +typedef int |
|
8762 +(*BASE_FP_I2C_WRITE)( |
|
8763 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8764 + unsigned char DeviceAddr, |
|
8765 + const unsigned char *pWritingBytes, |
|
8766 + unsigned char ByteNum |
|
8767 + ); |
|
8768 + |
|
8769 + |
|
8770 + |
|
8771 + |
|
8772 + |
|
8773 +/** |
|
8774 + |
|
8775 +@brief Basic waiting function pointer |
|
8776 + |
|
8777 +Upper layer functions will use BASE_FP_WAIT_MS() to wait WaitTimeMs millisecond. |
|
8778 + |
|
8779 + |
|
8780 +@param [in] pBaseInterface The base interface module pointer |
|
8781 +@param [in] WaitTimeMs Waiting time in millisecond |
|
8782 + |
|
8783 + |
|
8784 +@note |
|
8785 + The requirements of BASE_FP_WAIT_MS() function are described as follows: |
|
8786 + -# Need to assign a waiting function to BASE_FP_WAIT_MS() for upper layer functions. |
|
8787 + |
|
8788 + |
|
8789 + |
|
8790 +@par Example: |
|
8791 +@code |
|
8792 + |
|
8793 + |
|
8794 +#include "foundation.h" |
|
8795 + |
|
8796 + |
|
8797 +// Implement waiting funciton for BASE_FP_WAIT_MS function pointer. |
|
8798 +void |
|
8799 +CustomWaitMs( |
|
8800 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8801 + unsigned long WaitTimeMs |
|
8802 + ) |
|
8803 +{ |
|
8804 + ... |
|
8805 + |
|
8806 + return; |
|
8807 +} |
|
8808 + |
|
8809 + |
|
8810 +int main(void) |
|
8811 +{ |
|
8812 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
8813 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
8814 + |
|
8815 + |
|
8816 + // Assign implemented waiting funciton to BASE_FP_WAIT_MS in base interface module. |
|
8817 + BuildBaseInterface(&pBaseInterface, &BaseInterfaceModuleMemory, ..., ..., ..., ..., CustomWaitMs); |
|
8818 + |
|
8819 + ... |
|
8820 + |
|
8821 + // Use WaitMs() to wait 30 millisecond. |
|
8822 + pBaseInterface->WaitMs(pBaseInterface, 30); |
|
8823 + |
|
8824 + ... |
|
8825 + |
|
8826 + return 0; |
|
8827 +} |
|
8828 + |
|
8829 + |
|
8830 +@endcode |
|
8831 + |
|
8832 +*/ |
|
8833 +typedef void |
|
8834 +(*BASE_FP_WAIT_MS)( |
|
8835 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8836 + unsigned long WaitTimeMs |
|
8837 + ); |
|
8838 + |
|
8839 + |
|
8840 + |
|
8841 + |
|
8842 + |
|
8843 +/** |
|
8844 + |
|
8845 +@brief User defined data pointer setting function pointer |
|
8846 + |
|
8847 +One can use BASE_FP_SET_USER_DEFINED_DATA_POINTER() to set user defined data pointer of base interface structure for |
|
8848 +custom basic function implementation. |
|
8849 + |
|
8850 + |
|
8851 +@param [in] pBaseInterface The base interface module pointer |
|
8852 +@param [in] pUserDefinedData Pointer to user defined data |
|
8853 + |
|
8854 + |
|
8855 +@note |
|
8856 + One can use BASE_FP_GET_USER_DEFINED_DATA_POINTER() to get user defined data pointer of base interface structure for |
|
8857 + custom basic function implementation. |
|
8858 + |
|
8859 + |
|
8860 + |
|
8861 +@par Example: |
|
8862 +@code |
|
8863 + |
|
8864 + |
|
8865 +#include "foundation.h" |
|
8866 + |
|
8867 + |
|
8868 +// Implement I2C reading funciton for BASE_FP_I2C_READ function pointer. |
|
8869 +int |
|
8870 +CustomI2cRead( |
|
8871 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8872 + unsigned char DeviceAddr, |
|
8873 + unsigned char *pReadingBytes, |
|
8874 + unsigned char ByteNum |
|
8875 + ) |
|
8876 +{ |
|
8877 + CUSTOM_USER_DEFINED_DATA *pUserDefinedData; |
|
8878 + |
|
8879 + |
|
8880 + // Get user defined data pointer of base interface structure for custom I2C reading function. |
|
8881 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&pUserDefinedData); |
|
8882 + |
|
8883 + ... |
|
8884 + |
|
8885 + return FUNCTION_SUCCESS; |
|
8886 + |
|
8887 +error_status: |
|
8888 + |
|
8889 + return FUNCTION_ERROR; |
|
8890 +} |
|
8891 + |
|
8892 + |
|
8893 +int main(void) |
|
8894 +{ |
|
8895 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
8896 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
8897 + unsigned char ReadingBytes[100]; |
|
8898 + |
|
8899 + CUSTOM_USER_DEFINED_DATA UserDefinedData; |
|
8900 + |
|
8901 + |
|
8902 + // Assign implemented I2C reading funciton to BASE_FP_I2C_READ in base interface module. |
|
8903 + BuildBaseInterface(&pBaseInterface, &BaseInterfaceModuleMemory, ..., ..., CustomI2cRead, ..., ...); |
|
8904 + |
|
8905 + ... |
|
8906 + |
|
8907 + // Set user defined data pointer of base interface structure for custom basic functions. |
|
8908 + pBaseInterface->SetUserDefinedDataPointer(pBaseInterface, &UserDefinedData); |
|
8909 + |
|
8910 + // Use I2cRead() to read 33 bytes from I2C device and store reading bytes to ReadingBytes. |
|
8911 + pBaseInterface->I2cRead(pBaseInterface, 0x20, ReadingBytes, 33); |
|
8912 + |
|
8913 + ... |
|
8914 + |
|
8915 + return 0; |
|
8916 +} |
|
8917 + |
|
8918 + |
|
8919 +@endcode |
|
8920 + |
|
8921 +*/ |
|
8922 +typedef void |
|
8923 +(*BASE_FP_SET_USER_DEFINED_DATA_POINTER)( |
|
8924 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8925 + void *pUserDefinedData |
|
8926 + ); |
|
8927 + |
|
8928 + |
|
8929 + |
|
8930 + |
|
8931 + |
|
8932 +/** |
|
8933 + |
|
8934 +@brief User defined data pointer getting function pointer |
|
8935 + |
|
8936 +One can use BASE_FP_GET_USER_DEFINED_DATA_POINTER() to get user defined data pointer of base interface structure for |
|
8937 +custom basic function implementation. |
|
8938 + |
|
8939 + |
|
8940 +@param [in] pBaseInterface The base interface module pointer |
|
8941 +@param [in] ppUserDefinedData Pointer to user defined data pointer |
|
8942 + |
|
8943 + |
|
8944 +@note |
|
8945 + One can use BASE_FP_SET_USER_DEFINED_DATA_POINTER() to set user defined data pointer of base interface structure for |
|
8946 + custom basic function implementation. |
|
8947 + |
|
8948 + |
|
8949 + |
|
8950 +@par Example: |
|
8951 +@code |
|
8952 + |
|
8953 + |
|
8954 +#include "foundation.h" |
|
8955 + |
|
8956 + |
|
8957 +// Implement I2C reading funciton for BASE_FP_I2C_READ function pointer. |
|
8958 +int |
|
8959 +CustomI2cRead( |
|
8960 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
8961 + unsigned char DeviceAddr, |
|
8962 + unsigned char *pReadingBytes, |
|
8963 + unsigned char ByteNum |
|
8964 + ) |
|
8965 +{ |
|
8966 + CUSTOM_USER_DEFINED_DATA *pUserDefinedData; |
|
8967 + |
|
8968 + |
|
8969 + // Get user defined data pointer of base interface structure for custom I2C reading function. |
|
8970 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&pUserDefinedData); |
|
8971 + |
|
8972 + ... |
|
8973 + |
|
8974 + return FUNCTION_SUCCESS; |
|
8975 + |
|
8976 +error_status: |
|
8977 + |
|
8978 + return FUNCTION_ERROR; |
|
8979 +} |
|
8980 + |
|
8981 + |
|
8982 +int main(void) |
|
8983 +{ |
|
8984 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
8985 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
8986 + unsigned char ReadingBytes[100]; |
|
8987 + |
|
8988 + CUSTOM_USER_DEFINED_DATA UserDefinedData; |
|
8989 + |
|
8990 + |
|
8991 + // Assign implemented I2C reading funciton to BASE_FP_I2C_READ in base interface module. |
|
8992 + BuildBaseInterface(&pBaseInterface, &BaseInterfaceModuleMemory, ..., ..., CustomI2cRead, ..., ...); |
|
8993 + |
|
8994 + ... |
|
8995 + |
|
8996 + // Set user defined data pointer of base interface structure for custom basic functions. |
|
8997 + pBaseInterface->SetUserDefinedDataPointer(pBaseInterface, &UserDefinedData); |
|
8998 + |
|
8999 + // Use I2cRead() to read 33 bytes from I2C device and store reading bytes to ReadingBytes. |
|
9000 + pBaseInterface->I2cRead(pBaseInterface, 0x20, ReadingBytes, 33); |
|
9001 + |
|
9002 + ... |
|
9003 + |
|
9004 + return 0; |
|
9005 +} |
|
9006 + |
|
9007 + |
|
9008 +@endcode |
|
9009 + |
|
9010 +*/ |
|
9011 +typedef void |
|
9012 +(*BASE_FP_GET_USER_DEFINED_DATA_POINTER)( |
|
9013 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
9014 + void **ppUserDefinedData |
|
9015 + ); |
|
9016 + |
|
9017 + |
|
9018 + |
|
9019 + |
|
9020 + |
|
9021 +/// Base interface module structure |
|
9022 +struct BASE_INTERFACE_MODULE_TAG |
|
9023 +{ |
|
9024 + // Variables and function pointers |
|
9025 + unsigned char I2cReadingByteNumMax; |
|
9026 + unsigned char I2cWritingByteNumMax; |
|
9027 + |
|
9028 + BASE_FP_I2C_READ I2cRead; |
|
9029 + BASE_FP_I2C_WRITE I2cWrite; |
|
9030 + BASE_FP_WAIT_MS WaitMs; |
|
9031 + |
|
9032 + BASE_FP_SET_USER_DEFINED_DATA_POINTER SetUserDefinedDataPointer; |
|
9033 + BASE_FP_GET_USER_DEFINED_DATA_POINTER GetUserDefinedDataPointer; |
|
9034 + |
|
9035 + |
|
9036 + // User defined data |
|
9037 + void *pUserDefinedData; |
|
9038 +}; |
|
9039 + |
|
9040 + |
|
9041 + |
|
9042 + |
|
9043 + |
|
9044 +/** |
|
9045 + |
|
9046 +@brief Base interface builder |
|
9047 + |
|
9048 +Use BuildBaseInterface() to build base interface for module functions to access basic functions. |
|
9049 + |
|
9050 + |
|
9051 +@param [in] ppBaseInterface Pointer to base interface module pointer |
|
9052 +@param [in] pBaseInterfaceModuleMemory Pointer to an allocated base interface module memory |
|
9053 +@param [in] I2cReadingByteNumMax Maximum I2C reading byte number for basic I2C reading function |
|
9054 +@param [in] I2cWritingByteNumMax Maximum I2C writing byte number for basic I2C writing function |
|
9055 +@param [in] I2cRead Basic I2C reading function pointer |
|
9056 +@param [in] I2cWrite Basic I2C writing function pointer |
|
9057 +@param [in] WaitMs Basic waiting function pointer |
|
9058 + |
|
9059 + |
|
9060 +@note |
|
9061 + -# One should build base interface before using module functions. |
|
9062 + -# The I2C reading format is described as follows: |
|
9063 + start_bit + (device_addr | reading_bit) + reading_byte * byte_num + stop_bit |
|
9064 + -# The I2cReadingByteNumMax is the maximum byte_num of the I2C reading format. |
|
9065 + -# The I2C writing format is described as follows: |
|
9066 + start_bit + (device_addr | writing_bit) + writing_byte * byte_num + stop_bit |
|
9067 + -# The I2cWritingByteNumMax is the maximum byte_num of the I2C writing format. |
|
9068 + |
|
9069 + |
|
9070 + |
|
9071 +@par Example: |
|
9072 +@code |
|
9073 + |
|
9074 + |
|
9075 +#include "foundation.h" |
|
9076 + |
|
9077 + |
|
9078 +// Implement I2C reading funciton for BASE_FP_I2C_READ function pointer. |
|
9079 +int |
|
9080 +CustomI2cRead( |
|
9081 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
9082 + unsigned char DeviceAddr, |
|
9083 + unsigned char *pReadingBytes, |
|
9084 + unsigned char ByteNum |
|
9085 + ) |
|
9086 +{ |
|
9087 + ... |
|
9088 + |
|
9089 + return FUNCTION_SUCCESS; |
|
9090 + |
|
9091 +error_status: |
|
9092 + |
|
9093 + return FUNCTION_ERROR; |
|
9094 +} |
|
9095 + |
|
9096 + |
|
9097 +// Implement I2C writing funciton for BASE_FP_I2C_WRITE function pointer. |
|
9098 +int |
|
9099 +CustomI2cWrite( |
|
9100 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
9101 + unsigned char DeviceAddr, |
|
9102 + const unsigned char *pWritingBytes, |
|
9103 + unsigned char ByteNum |
|
9104 + ) |
|
9105 +{ |
|
9106 + ... |
|
9107 + |
|
9108 + return FUNCTION_SUCCESS; |
|
9109 + |
|
9110 +error_status: |
|
9111 + |
|
9112 + return FUNCTION_ERROR; |
|
9113 +} |
|
9114 + |
|
9115 + |
|
9116 +// Implement waiting funciton for BASE_FP_WAIT_MS function pointer. |
|
9117 +void |
|
9118 +CustomWaitMs( |
|
9119 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
9120 + unsigned long WaitTimeMs |
|
9121 + ) |
|
9122 +{ |
|
9123 + ... |
|
9124 + |
|
9125 + return; |
|
9126 +} |
|
9127 + |
|
9128 + |
|
9129 +int main(void) |
|
9130 +{ |
|
9131 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
9132 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
9133 + |
|
9134 + |
|
9135 + // Build base interface with the following settings. |
|
9136 + // |
|
9137 + // 1. Assign 9 to maximum I2C reading byte number. |
|
9138 + // 2. Assign 8 to maximum I2C writing byte number. |
|
9139 + // 3. Assign CustomI2cRead() to basic I2C reading function pointer. |
|
9140 + // 4. Assign CustomI2cWrite() to basic I2C writing function pointer. |
|
9141 + // 5. Assign CustomWaitMs() to basic waiting function pointer. |
|
9142 + // |
|
9143 + BuildBaseInterface( |
|
9144 + &pBaseInterface, |
|
9145 + &BaseInterfaceModuleMemory, |
|
9146 + 9, |
|
9147 + 8, |
|
9148 + CustomI2cRead, |
|
9149 + CustomI2cWrite, |
|
9150 + CustomWaitMs |
|
9151 + ); |
|
9152 + |
|
9153 + ... |
|
9154 + |
|
9155 + return 0; |
|
9156 +} |
|
9157 + |
|
9158 + |
|
9159 +@endcode |
|
9160 + |
|
9161 +*/ |
|
9162 +void |
|
9163 +BuildBaseInterface( |
|
9164 + BASE_INTERFACE_MODULE **ppBaseInterface, |
|
9165 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
9166 + unsigned char I2cReadingByteNumMax, |
|
9167 + unsigned char I2cWritingByteNumMax, |
|
9168 + BASE_FP_I2C_READ I2cRead, |
|
9169 + BASE_FP_I2C_WRITE I2cWrite, |
|
9170 + BASE_FP_WAIT_MS WaitMs |
|
9171 + ); |
|
9172 + |
|
9173 + |
|
9174 + |
|
9175 + |
|
9176 + |
|
9177 +// User data pointer of base interface structure setting and getting functions |
|
9178 +void |
|
9179 +base_interface_SetUserDefinedDataPointer( |
|
9180 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
9181 + void *pUserDefinedData |
|
9182 + ); |
|
9183 + |
|
9184 +void |
|
9185 +base_interface_GetUserDefinedDataPointer( |
|
9186 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
9187 + void **ppUserDefinedData |
|
9188 + ); |
|
9189 + |
|
9190 + |
|
9191 + |
|
9192 + |
|
9193 + |
|
9194 +// Math functions |
|
9195 + |
|
9196 +// Binary and signed integer converter |
|
9197 +unsigned long |
|
9198 +SignedIntToBin( |
|
9199 + long Value, |
|
9200 + unsigned char BitNum |
|
9201 + ); |
|
9202 + |
|
9203 +long |
|
9204 +BinToSignedInt( |
|
9205 + unsigned long Binary, |
|
9206 + unsigned char BitNum |
|
9207 + ); |
|
9208 + |
|
9209 + |
|
9210 + |
|
9211 +// Arithmetic |
|
9212 +unsigned long |
|
9213 +DivideWithCeiling( |
|
9214 + unsigned long Dividend, |
|
9215 + unsigned long Divisor |
|
9216 + ); |
|
9217 + |
|
9218 + |
|
9219 + |
|
9220 + |
|
9221 + |
|
9222 + |
|
9223 + |
|
9224 + |
|
9225 + |
|
9226 + |
|
9227 + |
|
9228 +/** |
|
9229 + |
|
9230 +@mainpage Realtek demod Source Code Manual |
|
9231 + |
|
9232 +@note |
|
9233 + -# The Realtek demod API source code is designed for demod IC driver porting. |
|
9234 + -# The API source code is written in C language without floating-point arithmetic. |
|
9235 + -# One can use the API to manipulate Realtek demod IC. |
|
9236 + -# The API will call custom underlayer functions through API base interface module. |
|
9237 + |
|
9238 + |
|
9239 +@par Important: |
|
9240 + -# Please assign API base interface module with custom underlayer functions instead of modifying API source code. |
|
9241 + -# Please see the example code to understand the relation bewteen API and custom system. |
|
9242 + |
|
9243 +*/ |
|
9244 + |
|
9245 + |
|
9246 + |
|
9247 + |
|
9248 + |
|
9249 + |
|
9250 + |
|
9251 + |
|
9252 + |
|
9253 + |
|
9254 + |
|
9255 + |
|
9256 + |
|
9257 + |
|
9258 + |
|
9259 + |
|
9260 + |
|
9261 +#endif |
|
9262 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/history.txt |
|
9263 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
9264 +++ b/linux/drivers/media/dvb/dvb-usb/history.txt Wed Oct 27 09:16:44 2010 +0200 |
|
9265 @@ -0,0 +1,11 @@ |
|
9266 + |
|
9267 +History of Realtek RTL2832U DVB-T Linux Driver: |
|
9268 + |
|
9269 + |
|
9270 +Ver 1.1 a. add customers' VID&PID |
|
9271 + b. solve the bug that our module cann't be removed when the device is plugged out. |
|
9272 + |
|
9273 +Ver 1.0 support tuners--MT2266 FC2580 TUA9001 and MXL5007T |
|
9274 + |
|
9275 + |
|
9276 + |
|
9277 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/i2c_bridge.h |
|
9278 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
9279 +++ b/linux/drivers/media/dvb/dvb-usb/i2c_bridge.h Wed Oct 27 09:16:44 2010 +0200 |
|
9280 @@ -0,0 +1,119 @@ |
|
9281 +#ifndef __I2C_BRIDGE_H |
|
9282 +#define __I2C_BRIDGE_H |
|
9283 + |
|
9284 +/** |
|
9285 + |
|
9286 +@file |
|
9287 + |
|
9288 +@brief I2C bridge module |
|
9289 + |
|
9290 +I2C bridge module contains I2C forwarding function pointers. |
|
9291 + |
|
9292 +*/ |
|
9293 + |
|
9294 + |
|
9295 + |
|
9296 + |
|
9297 + |
|
9298 +/// I2C bridge module pre-definition |
|
9299 +typedef struct I2C_BRIDGE_MODULE_TAG I2C_BRIDGE_MODULE; |
|
9300 + |
|
9301 + |
|
9302 + |
|
9303 + |
|
9304 + |
|
9305 +/** |
|
9306 + |
|
9307 +@brief I2C reading command forwarding function pointer |
|
9308 + |
|
9309 +Tuner upper level functions will use I2C_BRIDGE_FP_FORWARD_I2C_READING_CMD() to send tuner I2C reading command through |
|
9310 +demod. |
|
9311 + |
|
9312 + |
|
9313 +@param [in] pI2cBridge The I2C bridge module pointer |
|
9314 +@param [out] pReadingBytes Pointer to an allocated memory for storing reading bytes |
|
9315 +@param [in] ByteNum Reading byte number |
|
9316 + |
|
9317 + |
|
9318 +@retval FUNCTION_SUCCESS Forwarding I2C reading command successfully. |
|
9319 +@retval FUNCTION_ERROR Forwarding I2C reading command unsuccessfully. |
|
9320 + |
|
9321 + |
|
9322 +@note |
|
9323 + -# Demod building function will set I2C_BRIDGE_FP_FORWARD_I2C_READING_CMD() with the corresponding function. |
|
9324 + |
|
9325 +*/ |
|
9326 +typedef int |
|
9327 +(*I2C_BRIDGE_FP_FORWARD_I2C_READING_CMD)( |
|
9328 + I2C_BRIDGE_MODULE *pI2cBridge, |
|
9329 + unsigned char *pReadingBytes, |
|
9330 + unsigned char ByteNum |
|
9331 + ); |
|
9332 + |
|
9333 + |
|
9334 + |
|
9335 + |
|
9336 + |
|
9337 +/** |
|
9338 + |
|
9339 +@brief I2C writing command forwarding function pointer |
|
9340 + |
|
9341 +Tuner upper level functions will use I2C_BRIDGE_FP_FORWARD_I2C_WRITING_CMD() to send tuner I2C writing command through |
|
9342 +demod. |
|
9343 + |
|
9344 + |
|
9345 +@param [in] pI2cBridge The I2C bridge module pointer |
|
9346 +@param [out] pWritingBytes Pointer to writing bytes |
|
9347 +@param [in] ByteNum Writing byte number |
|
9348 + |
|
9349 + |
|
9350 +@retval FUNCTION_SUCCESS Forwarding I2C writing command successfully. |
|
9351 +@retval FUNCTION_ERROR Forwarding I2C writing command unsuccessfully. |
|
9352 + |
|
9353 + |
|
9354 +@note |
|
9355 + -# Demod building function will set I2C_BRIDGE_FP_FORWARD_I2C_WRITING_CMD() with the corresponding function. |
|
9356 + |
|
9357 +*/ |
|
9358 +typedef int |
|
9359 +(*I2C_BRIDGE_FP_FORWARD_I2C_WRITING_CMD)( |
|
9360 + I2C_BRIDGE_MODULE *pI2cBridge, |
|
9361 + const unsigned char *pWritingBytes, |
|
9362 + unsigned char ByteNum |
|
9363 + ); |
|
9364 + |
|
9365 + |
|
9366 + |
|
9367 + |
|
9368 + |
|
9369 +/// I2C bridge module structure |
|
9370 +struct I2C_BRIDGE_MODULE_TAG |
|
9371 +{ |
|
9372 + // Private variables |
|
9373 + void *pPrivateData; |
|
9374 + unsigned char *pTunerDeviceAddr; |
|
9375 + |
|
9376 + |
|
9377 + // I2C bridge function pointers |
|
9378 + I2C_BRIDGE_FP_FORWARD_I2C_READING_CMD ForwardI2cReadingCmd; ///< I2C reading command forwading function pointer |
|
9379 + I2C_BRIDGE_FP_FORWARD_I2C_WRITING_CMD ForwardI2cWritingCmd; ///< I2C writing command forwading function pointer |
|
9380 + |
|
9381 +}; |
|
9382 + |
|
9383 + |
|
9384 + |
|
9385 + |
|
9386 + |
|
9387 + |
|
9388 + |
|
9389 + |
|
9390 + |
|
9391 + |
|
9392 + |
|
9393 + |
|
9394 + |
|
9395 + |
|
9396 + |
|
9397 + |
|
9398 + |
|
9399 +#endif |
|
9400 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/math_mpi.c |
|
9401 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
9402 +++ b/linux/drivers/media/dvb/dvb-usb/math_mpi.c Wed Oct 27 09:16:44 2010 +0200 |
|
9403 @@ -0,0 +1,1054 @@ |
|
9404 +/** |
|
9405 + |
|
9406 +@file |
|
9407 + |
|
9408 +@brief Mutliple precision integer (MPI) arithmetic definition |
|
9409 + |
|
9410 +One can use to mutliple precision arithmetic to manipulate large signed integers. |
|
9411 + |
|
9412 +*/ |
|
9413 + |
|
9414 + |
|
9415 +#include "math_mpi.h" |
|
9416 + |
|
9417 + |
|
9418 + |
|
9419 + |
|
9420 + |
|
9421 +/** |
|
9422 + |
|
9423 +@brief Set multiple precision signed integer value. |
|
9424 + |
|
9425 +Use MpiSetValue() to set multiple precision signed integer MPI value. |
|
9426 + |
|
9427 + |
|
9428 +@param [in] pMpiVar Pointer to an MPI variable |
|
9429 +@param [in] Value Value for setting |
|
9430 + |
|
9431 + |
|
9432 +@note |
|
9433 + The MPI bit number will be minimized in MpiSetValue(). |
|
9434 + |
|
9435 +*/ |
|
9436 +void |
|
9437 +MpiSetValue( |
|
9438 + MPI *pMpiVar, |
|
9439 + long Value |
|
9440 + ) |
|
9441 +{ |
|
9442 + int i; |
|
9443 + unsigned char SignedBit; |
|
9444 + unsigned char ExtensionByte; |
|
9445 + |
|
9446 + |
|
9447 + |
|
9448 + // Set MPI value according to ansigned value. |
|
9449 + for(i = 0; i < MPI_LONG_BYTE_NUM; i++) |
|
9450 + pMpiVar->Value[i] = (unsigned char)((Value >> (MPI_BYTE_SHIFT * i)) & MPI_BYTE_MASK); |
|
9451 + |
|
9452 + |
|
9453 + // Get extension byte according to signed bit. |
|
9454 + SignedBit = (unsigned char)((Value >> (MPI_LONG_BIT_NUM - 1)) & MPI_BIT_0_MASK); |
|
9455 + ExtensionByte = (SignedBit == 0x0) ? 0x00 : 0xff; |
|
9456 + |
|
9457 + |
|
9458 + // Extend MPI signed bit with extension byte stuff. |
|
9459 + for(i = MPI_LONG_BYTE_NUM; i < MPI_VALUE_BYTE_NUM_MAX; i++) |
|
9460 + pMpiVar->Value[i] = ExtensionByte; |
|
9461 + |
|
9462 + |
|
9463 + // Minimize MPI bit number. |
|
9464 + MpiMinimizeBitNum(pMpiVar); |
|
9465 + |
|
9466 + |
|
9467 + return; |
|
9468 +} |
|
9469 + |
|
9470 + |
|
9471 + |
|
9472 + |
|
9473 + |
|
9474 +/** |
|
9475 + |
|
9476 +@brief Get multiple precision signed integer value. |
|
9477 + |
|
9478 +Use MpiGetValue() to get multiple precision unsigned integer MPI value. |
|
9479 + |
|
9480 + |
|
9481 +@param [in] MpiVar Pointer to an MPI variable |
|
9482 +@param [out] pValue Pointer to an allocated memory for getting MPI value |
|
9483 + |
|
9484 + |
|
9485 +@note |
|
9486 + The necessary bit number of MPI value must be less than or equal to 32 bits. |
|
9487 + |
|
9488 +*/ |
|
9489 +void |
|
9490 +MpiGetValue( |
|
9491 + MPI MpiVar, |
|
9492 + long *pValue |
|
9493 + ) |
|
9494 +{ |
|
9495 + int i; |
|
9496 + unsigned long Value; |
|
9497 + |
|
9498 + |
|
9499 + |
|
9500 + // Set value with zero. |
|
9501 + Value = 0x0; |
|
9502 + |
|
9503 + |
|
9504 + // Combine MPI value bytes into value. |
|
9505 + for(i = 0; i < MPI_LONG_BYTE_NUM; i++) |
|
9506 + Value |= MpiVar.Value[i] << (MPI_BYTE_SHIFT * i); |
|
9507 + |
|
9508 + |
|
9509 + // Assigned value to value pointer. |
|
9510 + *pValue = (long)Value; |
|
9511 + |
|
9512 + |
|
9513 + return; |
|
9514 +} |
|
9515 + |
|
9516 + |
|
9517 + |
|
9518 + |
|
9519 + |
|
9520 +/** |
|
9521 + |
|
9522 +@brief Set multiple precision signed integer bit value. |
|
9523 + |
|
9524 +Use MpiSetBit() to set multiple precision signed integer MPI bit value. |
|
9525 + |
|
9526 + |
|
9527 +@param [in] pMpiVar Pointer to an MPI variable |
|
9528 +@param [in] BitPosition Bit position with zero-based index |
|
9529 +@param [in] BitValue Bit value for setting |
|
9530 + |
|
9531 + |
|
9532 +@note |
|
9533 + Bit position must be 0 ~ (MPI bit number). |
|
9534 + |
|
9535 +*/ |
|
9536 +void |
|
9537 +MpiSetBit( |
|
9538 + MPI *pMpiVar, |
|
9539 + unsigned long BitPosition, |
|
9540 + unsigned char BitValue |
|
9541 + ) |
|
9542 +{ |
|
9543 + unsigned long TargetBytePos, TargetBitPos; |
|
9544 + |
|
9545 + |
|
9546 + |
|
9547 + // Calculate target byte and bit position. |
|
9548 + TargetBytePos = BitPosition / MPI_BYTE_BIT_NUM; |
|
9549 + TargetBitPos = BitPosition % MPI_BYTE_BIT_NUM; |
|
9550 + |
|
9551 + |
|
9552 + // Set MPI bit value according to calculated target byte and bit position. |
|
9553 + pMpiVar->Value[TargetBytePos] &= (unsigned char)(~(0x1 << TargetBitPos)); |
|
9554 + pMpiVar->Value[TargetBytePos] |= (BitValue & MPI_BIT_0_MASK) << TargetBitPos; |
|
9555 + |
|
9556 + |
|
9557 + return; |
|
9558 +} |
|
9559 + |
|
9560 + |
|
9561 + |
|
9562 + |
|
9563 + |
|
9564 + |
|
9565 +/** |
|
9566 + |
|
9567 +@brief Get multiple precision signed integer bit value. |
|
9568 + |
|
9569 +Use MpiGetBit() to get multiple precision unsigned integer MPI bit value. |
|
9570 + |
|
9571 + |
|
9572 +@param [in] MpiVar Pointer to an MPI variable |
|
9573 +@param [in] BitPosition Bit position with zero-based index |
|
9574 +@param [out] pBitValue Pointer to an allocated memory for getting MPI bit value |
|
9575 + |
|
9576 + |
|
9577 +@note |
|
9578 + Bit position must be 0 ~ (MPI bit number). |
|
9579 + |
|
9580 +*/ |
|
9581 +void |
|
9582 +MpiGetBit( |
|
9583 + MPI MpiVar, |
|
9584 + unsigned long BitPosition, |
|
9585 + unsigned char *pBitValue |
|
9586 + ) |
|
9587 +{ |
|
9588 + unsigned long TargetBytePos, TargetBitPos; |
|
9589 + |
|
9590 + |
|
9591 + |
|
9592 + // Calculate target byte and bit position. |
|
9593 + TargetBytePos = BitPosition / MPI_BYTE_BIT_NUM; |
|
9594 + TargetBitPos = BitPosition % MPI_BYTE_BIT_NUM; |
|
9595 + |
|
9596 + |
|
9597 + // Get MPI bit value according to calculated target byte and bit position. |
|
9598 + *pBitValue = (MpiVar.Value[TargetBytePos] >> TargetBitPos) & MPI_BIT_0_MASK; |
|
9599 + |
|
9600 + |
|
9601 + return; |
|
9602 +} |
|
9603 + |
|
9604 + |
|
9605 + |
|
9606 + |
|
9607 + |
|
9608 +/** |
|
9609 + |
|
9610 +@brief Get multiple precision signed integer signed bit value. |
|
9611 + |
|
9612 +Use MpiGetBit() to get multiple precision unsigned integer MPI signed bit value. |
|
9613 + |
|
9614 + |
|
9615 +@param [in] MpiVar Pointer to an MPI variable |
|
9616 +@param [out] pSignedBitValue Pointer to an allocated memory for getting MPI signed bit value |
|
9617 + |
|
9618 +*/ |
|
9619 +void |
|
9620 +MpiGetSignedBit( |
|
9621 + MPI MpiVar, |
|
9622 + unsigned char *pSignedBitValue |
|
9623 + ) |
|
9624 +{ |
|
9625 + // Get MPI variable signed bit. |
|
9626 + MpiGetBit(MpiVar, MPI_VALUE_BIT_NUM_MAX - 1, pSignedBitValue); |
|
9627 + |
|
9628 + |
|
9629 + return; |
|
9630 +} |
|
9631 + |
|
9632 + |
|
9633 + |
|
9634 + |
|
9635 + |
|
9636 +/** |
|
9637 + |
|
9638 +@brief Assign multiple precision signed integer with another one. |
|
9639 + |
|
9640 +Use MpiAssign() to assign multiple precision signed integer with another one. |
|
9641 + |
|
9642 + |
|
9643 +@param [out] pResult Pointer to an allocated memory for storing result |
|
9644 +@param [in] Operand Operand |
|
9645 + |
|
9646 + |
|
9647 +@note |
|
9648 + The result bit number will be minimized in MpiAssign(). |
|
9649 + |
|
9650 +*/ |
|
9651 +void |
|
9652 +MpiAssign( |
|
9653 + MPI *pResult, |
|
9654 + MPI Operand |
|
9655 + ) |
|
9656 +{ |
|
9657 + unsigned int i; |
|
9658 + |
|
9659 + |
|
9660 + |
|
9661 + // Copy value bytes from operand to result. |
|
9662 + for(i = 0; i < MPI_VALUE_BYTE_NUM_MAX; i++) |
|
9663 + pResult->Value[i] = Operand.Value[i]; |
|
9664 + |
|
9665 + |
|
9666 + // Minimize result bit nubmer. |
|
9667 + MpiMinimizeBitNum(pResult); |
|
9668 + |
|
9669 + |
|
9670 + return; |
|
9671 +} |
|
9672 + |
|
9673 + |
|
9674 + |
|
9675 + |
|
9676 + |
|
9677 +/** |
|
9678 + |
|
9679 +@brief Minus unary multiple precision signed integer. |
|
9680 + |
|
9681 +Use MpiUnaryMinus() to minus unary multiple precision signed integer. |
|
9682 + |
|
9683 + |
|
9684 +@param [out] pResult Pointer to an allocated memory for storing result |
|
9685 +@param [in] Operand Operand |
|
9686 + |
|
9687 + |
|
9688 +@note |
|
9689 + The result bit number will be minimized in MpiUnaryMinus(). |
|
9690 + |
|
9691 +*/ |
|
9692 +void |
|
9693 +MpiUnaryMinus( |
|
9694 + MPI *pResult, |
|
9695 + MPI Operand |
|
9696 + ) |
|
9697 +{ |
|
9698 + unsigned int i; |
|
9699 + MPI Const; |
|
9700 + |
|
9701 + |
|
9702 + |
|
9703 + // Set result value byte with operand bitwise complement value byte. |
|
9704 + for(i = 0; i < MPI_VALUE_BYTE_NUM_MAX; i++) |
|
9705 + pResult->Value[i] = ~Operand.Value[i]; |
|
9706 + |
|
9707 + |
|
9708 + // Add result with 0x1. |
|
9709 + // Note: MpiAdd() will minimize result bit number. |
|
9710 + MpiSetValue(&Const, 0x1); |
|
9711 + MpiAdd(pResult, *pResult, Const); |
|
9712 + |
|
9713 + |
|
9714 + return; |
|
9715 +} |
|
9716 + |
|
9717 + |
|
9718 + |
|
9719 + |
|
9720 + |
|
9721 +/** |
|
9722 + |
|
9723 +@brief Add multiple precision signed integers. |
|
9724 + |
|
9725 +Use MpiAdd() to add multiple precision signed integers. |
|
9726 + |
|
9727 + |
|
9728 +@param [out] pSum Pointer to an allocated memory for storing sum |
|
9729 +@param [in] Augend Augend |
|
9730 +@param [in] Addend Addend |
|
9731 + |
|
9732 + |
|
9733 +@note |
|
9734 + The sum bit number will be minimized in MpiAdd(). |
|
9735 + |
|
9736 +*/ |
|
9737 +void |
|
9738 +MpiAdd( |
|
9739 + MPI *pSum, |
|
9740 + MPI Augend, |
|
9741 + MPI Addend |
|
9742 + ) |
|
9743 +{ |
|
9744 + unsigned int i; |
|
9745 + unsigned long MiddleResult; |
|
9746 + unsigned char Carry; |
|
9747 + |
|
9748 + |
|
9749 + // Add augend and addend to sum form value LSB byte to value MSB byte. |
|
9750 + Carry = 0; |
|
9751 + |
|
9752 + for(i = 0; i < MPI_VALUE_BYTE_NUM_MAX; i++) |
|
9753 + { |
|
9754 + // Set current sum value byte and determine carry. |
|
9755 + MiddleResult = Augend.Value[i] + Addend.Value[i] + Carry; |
|
9756 + pSum->Value[i] = (unsigned char)(MiddleResult & MPI_BYTE_MASK); |
|
9757 + Carry = (unsigned char)((MiddleResult >> MPI_BYTE_SHIFT) & MPI_BYTE_MASK); |
|
9758 + } |
|
9759 + |
|
9760 + |
|
9761 + // Minimize sum bit nubmer. |
|
9762 + MpiMinimizeBitNum(pSum); |
|
9763 + |
|
9764 + |
|
9765 + return; |
|
9766 +} |
|
9767 + |
|
9768 + |
|
9769 + |
|
9770 + |
|
9771 + |
|
9772 +/** |
|
9773 + |
|
9774 +@brief subtract multiple precision signed integers. |
|
9775 + |
|
9776 +Use MpiSub() to subtract multiple precision signed integers. |
|
9777 + |
|
9778 + |
|
9779 +@param [out] pDifference Pointer to an allocated memory for storing difference |
|
9780 +@param [in] Minuend Minuend |
|
9781 +@param [in] Subtrahend Subtrahend |
|
9782 + |
|
9783 + |
|
9784 +@note |
|
9785 + The difference bit number will be minimized in MpiSub(). |
|
9786 + |
|
9787 +*/ |
|
9788 +void |
|
9789 +MpiSub( |
|
9790 + MPI *pDifference, |
|
9791 + MPI Minuend, |
|
9792 + MPI Subtrahend |
|
9793 + ) |
|
9794 +{ |
|
9795 + MPI MiddleResult; |
|
9796 + |
|
9797 + |
|
9798 + |
|
9799 + // Take subtrahend unary minus value. |
|
9800 + MpiUnaryMinus(&MiddleResult, Subtrahend); |
|
9801 + |
|
9802 + |
|
9803 + // Add minuend and subtrahend unary minus value to difference. |
|
9804 + // Note: MpiAdd() will minimize result bit number. |
|
9805 + MpiAdd(pDifference, Minuend, MiddleResult); |
|
9806 + |
|
9807 + |
|
9808 + return; |
|
9809 +} |
|
9810 + |
|
9811 + |
|
9812 + |
|
9813 + |
|
9814 + |
|
9815 +/** |
|
9816 + |
|
9817 +@brief Multiply arbitrary precision signed integers. |
|
9818 + |
|
9819 +Use MpiMul() to multiply arbitrary precision signed integers. |
|
9820 + |
|
9821 + |
|
9822 +@param [out] pProduct Pointer to an allocated memory for storing product |
|
9823 +@param [in] Multiplicand Multiplicand |
|
9824 +@param [in] Multiplicator Multiplicator |
|
9825 + |
|
9826 + |
|
9827 +@note |
|
9828 + -# The sum of multiplicand and multiplicator bit number must be less MPI_VALUE_BIT_NUM_MAX. |
|
9829 + -# The product bit number will be minimized in MpiMul(). |
|
9830 + |
|
9831 +*/ |
|
9832 +void |
|
9833 +MpiMul( |
|
9834 + MPI *pProduct, |
|
9835 + MPI Multiplicand, |
|
9836 + MPI Multiplicator |
|
9837 + ) |
|
9838 +{ |
|
9839 + int i; |
|
9840 + |
|
9841 + unsigned char MultiplicandSignedBit, MultiplicatorSignedBit; |
|
9842 + MPI MultiplicandAbs, MultiplicatorAbs; |
|
9843 + |
|
9844 + unsigned char CurrentBit; |
|
9845 + |
|
9846 + |
|
9847 + |
|
9848 + // Get multiplicand signed bit. |
|
9849 + MpiGetSignedBit(Multiplicand, &MultiplicandSignedBit); |
|
9850 + |
|
9851 + // Take absolute value of multiplicand. |
|
9852 + if(MultiplicandSignedBit == 0x0) |
|
9853 + MpiAssign(&MultiplicandAbs, Multiplicand); |
|
9854 + else |
|
9855 + MpiUnaryMinus(&MultiplicandAbs, Multiplicand); |
|
9856 + |
|
9857 + |
|
9858 + // Get multiplicator signed bit. |
|
9859 + MpiGetSignedBit(Multiplicator, &MultiplicatorSignedBit); |
|
9860 + |
|
9861 + // Take absolute value of multiplicator. |
|
9862 + if(MultiplicatorSignedBit == 0x0) |
|
9863 + MpiAssign(&MultiplicatorAbs, Multiplicator); |
|
9864 + else |
|
9865 + MpiUnaryMinus(&MultiplicatorAbs, Multiplicator); |
|
9866 + |
|
9867 + |
|
9868 + // Multiply multiplicand and multiplicator from LSB bit to MSB bit. |
|
9869 + MpiSetValue(pProduct, 0x0); |
|
9870 + |
|
9871 + for(i = MPI_VALUE_BIT_NUM_MAX - 1; i > -1; i--) |
|
9872 + { |
|
9873 + // Shift product toward left with one bit. |
|
9874 + MpiLeftShift(pProduct, *pProduct, 1); |
|
9875 + |
|
9876 + // Get current absolute multiplicator bit value. |
|
9877 + MpiGetBit(MultiplicatorAbs, i, &CurrentBit); |
|
9878 + |
|
9879 + // If current multiplicator bit is 0x1, add absolute multiplicand value to product. |
|
9880 + // Note: MpiAdd() will minimize result bit number. |
|
9881 + if(CurrentBit == 0x1) |
|
9882 + MpiAdd(pProduct, *pProduct, MultiplicandAbs); |
|
9883 + } |
|
9884 + |
|
9885 + |
|
9886 + // Determine the signed bit of product according to signed bits of multiplicand and multiplicator. |
|
9887 + // Note: MpiUnaryMinus() will minimize result bit number. |
|
9888 + if(MultiplicandSignedBit != MultiplicatorSignedBit) |
|
9889 + MpiUnaryMinus(pProduct, *pProduct); |
|
9890 + |
|
9891 + |
|
9892 + return; |
|
9893 +} |
|
9894 + |
|
9895 + |
|
9896 + |
|
9897 + |
|
9898 + |
|
9899 +/** |
|
9900 + |
|
9901 +@brief Divide arbitrary precision signed integers. |
|
9902 + |
|
9903 +Use MpiDiv() to divide arbitrary precision signed integers. |
|
9904 + |
|
9905 + |
|
9906 +@param [out] pQuotient Pointer to an allocated memory for storing quotient |
|
9907 +@param [out] pRemainder Pointer to an allocated memory for storing remainder |
|
9908 +@param [in] Dividend Dividend |
|
9909 +@param [in] Divisor Divisor |
|
9910 + |
|
9911 + |
|
9912 +@note |
|
9913 + -# The dividend bit number must be minimized. |
|
9914 + -# The divisor must be not equal to zero. |
|
9915 + -# The product bit number will be minimized in MpiDiv(). |
|
9916 + |
|
9917 +*/ |
|
9918 +void |
|
9919 +MpiDiv( |
|
9920 + MPI *pQuotient, |
|
9921 + MPI *pRemainder, |
|
9922 + MPI Dividend, |
|
9923 + MPI Divisor |
|
9924 + ) |
|
9925 +{ |
|
9926 + unsigned int i; |
|
9927 + |
|
9928 + unsigned char DividendSignedBit, DivisorSignedBit; |
|
9929 + MPI DividendAbs, DivisorAbs; |
|
9930 + |
|
9931 + unsigned long PrimaryDividendBitNum; |
|
9932 + unsigned char ShiftBit; |
|
9933 + |
|
9934 + MPI Const; |
|
9935 + MPI MiddleResult; |
|
9936 + |
|
9937 + |
|
9938 + |
|
9939 + // Get dividend signed bit. |
|
9940 + MpiGetSignedBit(Dividend, &DividendSignedBit); |
|
9941 + |
|
9942 + // Take absolute value of dividend. |
|
9943 + if(DividendSignedBit == 0x0) |
|
9944 + MpiAssign(&DividendAbs, Dividend); |
|
9945 + else |
|
9946 + MpiUnaryMinus(&DividendAbs, Dividend); |
|
9947 + |
|
9948 + |
|
9949 + // Get divisor signed bit. |
|
9950 + MpiGetSignedBit(Divisor, &DivisorSignedBit); |
|
9951 + |
|
9952 + // Take absolute value of divisor. |
|
9953 + if(DivisorSignedBit == 0x0) |
|
9954 + MpiAssign(&DivisorAbs, Divisor); |
|
9955 + else |
|
9956 + MpiUnaryMinus(&DivisorAbs, Divisor); |
|
9957 + |
|
9958 + |
|
9959 + // Get primary absolute dividend bit number. |
|
9960 + PrimaryDividendBitNum = DividendAbs.BitNum; |
|
9961 + |
|
9962 + |
|
9963 + // Get quotient and remainder by division algorithm. |
|
9964 + MpiSetValue(pQuotient, 0x0); |
|
9965 + MpiSetValue(pRemainder, 0x0); |
|
9966 + |
|
9967 + for(i = 0; i < PrimaryDividendBitNum; i++) |
|
9968 + { |
|
9969 + // Shift quotient toward left with one bit. |
|
9970 + // Note: MpiLeftShift() will minimize result bit number. |
|
9971 + MpiLeftShift(pQuotient, *pQuotient, 1); |
|
9972 + |
|
9973 + // Shift remainder toward left with one bit. |
|
9974 + MpiLeftShift(pRemainder, *pRemainder, 1); |
|
9975 + |
|
9976 + // Shift absolute dividend toward left with one bit. |
|
9977 + MpiLeftShift(&DividendAbs, DividendAbs, 1); |
|
9978 + |
|
9979 + // Set remainder LSB according to absolute dividend. |
|
9980 + MpiGetBit(DividendAbs, PrimaryDividendBitNum, &ShiftBit); |
|
9981 + MpiSetBit(pRemainder, 0, ShiftBit); |
|
9982 + |
|
9983 + // If remainder is greater than or equal to absolute divisor, |
|
9984 + // substract absolute divisor from remainder and set quotient LSB with one. |
|
9985 + if(MpiGreaterThan(*pRemainder, DivisorAbs) || MpiEqualTo(*pRemainder, DivisorAbs)) |
|
9986 + { |
|
9987 + MpiSub(pRemainder, *pRemainder, DivisorAbs); |
|
9988 + MpiSetBit(pQuotient, 0, 0x1); |
|
9989 + } |
|
9990 + } |
|
9991 + |
|
9992 + |
|
9993 + // Modify quotient according to dividend signed bit, divisor signed bit, and remainder. |
|
9994 + |
|
9995 + // Determine the signed bit of quotient. |
|
9996 + if(DividendSignedBit != DivisorSignedBit) |
|
9997 + { |
|
9998 + // Take unary minus quotient. |
|
9999 + // Note: MpiUnaryMinus() will minimize result bit number. |
|
10000 + MpiUnaryMinus(pQuotient, *pQuotient); |
|
10001 + |
|
10002 + // If remainder is greater than zero, subtract 1 from quotient. |
|
10003 + // Note: MpiSub() will minimize result bit number. |
|
10004 + MpiSetValue(&Const, 0x0); |
|
10005 + |
|
10006 + if(MpiGreaterThan(*pRemainder, Const)) |
|
10007 + { |
|
10008 + MpiSetValue(&Const, 0x1); |
|
10009 + MpiSub(pQuotient, *pQuotient, Const); |
|
10010 + } |
|
10011 + } |
|
10012 + |
|
10013 + |
|
10014 + // Modify remainder according to dividend, divisor, and quotient. |
|
10015 + |
|
10016 + // Remainder = dividend - divisor * quotient; |
|
10017 + // Note: MpiSub() will minimize result bit number. |
|
10018 + MpiMul(&MiddleResult, Divisor, *pQuotient); |
|
10019 + MpiSub(pRemainder, Dividend, MiddleResult); |
|
10020 + |
|
10021 + |
|
10022 + return; |
|
10023 +} |
|
10024 + |
|
10025 + |
|
10026 + |
|
10027 + |
|
10028 + |
|
10029 +/** |
|
10030 + |
|
10031 +@brief Shift multiple precision signed integer toward right. |
|
10032 + |
|
10033 +Use MpiRightShift() to shift arbitrary precision signed integer toward right with assigned bit number. |
|
10034 + |
|
10035 + |
|
10036 +@param [out] pResult Pointer to an allocated memory for storing result |
|
10037 +@param [in] Operand Operand |
|
10038 +@param [in] ShiftBitNum Shift bit number |
|
10039 + |
|
10040 + |
|
10041 +@note |
|
10042 + -# The result MSB bits will be stuffed with signed bit |
|
10043 + -# The result bit number will be minimized in MpiRightShift(). |
|
10044 + |
|
10045 +*/ |
|
10046 +void |
|
10047 +MpiRightShift( |
|
10048 + MPI *pResult, |
|
10049 + MPI Operand, |
|
10050 + unsigned long ShiftBitNum |
|
10051 + ) |
|
10052 +{ |
|
10053 + unsigned int i; |
|
10054 + unsigned long StuffBitNum; |
|
10055 + unsigned char CurrentBit; |
|
10056 + unsigned char SignedBit; |
|
10057 + |
|
10058 + |
|
10059 + |
|
10060 + // Determine stuff bit number according to shift bit nubmer. |
|
10061 + StuffBitNum = (ShiftBitNum < MPI_VALUE_BIT_NUM_MAX) ? ShiftBitNum : MPI_VALUE_BIT_NUM_MAX; |
|
10062 + |
|
10063 + |
|
10064 + // Copy operand bits to result with stuff bit number. |
|
10065 + for(i = 0; i < (MPI_VALUE_BIT_NUM_MAX - StuffBitNum); i++) |
|
10066 + { |
|
10067 + MpiGetBit(Operand, i + StuffBitNum, &CurrentBit); |
|
10068 + MpiSetBit(pResult, i, CurrentBit); |
|
10069 + } |
|
10070 + |
|
10071 + |
|
10072 + // Get operand signed bit. |
|
10073 + MpiGetSignedBit(Operand, &SignedBit); |
|
10074 + |
|
10075 + |
|
10076 + // Stuff result MSB bits with signed bit. |
|
10077 + for(i = (MPI_VALUE_BIT_NUM_MAX - StuffBitNum); i < MPI_VALUE_BIT_NUM_MAX; i++) |
|
10078 + MpiSetBit(pResult, i, SignedBit); |
|
10079 + |
|
10080 + |
|
10081 + // Minimize result bit number. |
|
10082 + MpiMinimizeBitNum(pResult); |
|
10083 + |
|
10084 + |
|
10085 + return; |
|
10086 +} |
|
10087 + |
|
10088 + |
|
10089 + |
|
10090 + |
|
10091 + |
|
10092 +/** |
|
10093 + |
|
10094 +@brief Shift multiple precision signed integer toward left. |
|
10095 + |
|
10096 +Use MpiLeftShift() to shift arbitrary precision signed integer toward left with assigned bit number. |
|
10097 + |
|
10098 + |
|
10099 +@param [out] pResult Pointer to an allocated memory for storing result |
|
10100 +@param [in] Operand Operand |
|
10101 +@param [in] ShiftBitNum Shift bit number |
|
10102 + |
|
10103 + |
|
10104 +@note |
|
10105 + The result bit number will be minimized in MpiLeftShift(). |
|
10106 + |
|
10107 +*/ |
|
10108 +void |
|
10109 +MpiLeftShift( |
|
10110 + MPI *pResult, |
|
10111 + MPI Operand, |
|
10112 + unsigned long ShiftBitNum |
|
10113 + ) |
|
10114 +{ |
|
10115 + unsigned int i; |
|
10116 + unsigned long StuffBitNum; |
|
10117 + unsigned char CurrentBit; |
|
10118 + |
|
10119 + |
|
10120 + // Determine stuff bit number according to shift bit nubmer. |
|
10121 + StuffBitNum = (ShiftBitNum < MPI_VALUE_BIT_NUM_MAX) ? ShiftBitNum : MPI_VALUE_BIT_NUM_MAX; |
|
10122 + |
|
10123 + |
|
10124 + // Stuff result LSB bits with zeros |
|
10125 + for(i = 0; i < StuffBitNum; i++) |
|
10126 + MpiSetBit(pResult, i, 0x0); |
|
10127 + |
|
10128 + |
|
10129 + // Copy operand bits to result with stuff bit number. |
|
10130 + for(i = StuffBitNum; i < MPI_VALUE_BIT_NUM_MAX; i++) |
|
10131 + { |
|
10132 + MpiGetBit(Operand, i - StuffBitNum, &CurrentBit); |
|
10133 + MpiSetBit(pResult, i, CurrentBit); |
|
10134 + } |
|
10135 + |
|
10136 + |
|
10137 + // Minimize result bit number. |
|
10138 + MpiMinimizeBitNum(pResult); |
|
10139 + |
|
10140 + |
|
10141 + return; |
|
10142 +} |
|
10143 + |
|
10144 + |
|
10145 + |
|
10146 + |
|
10147 + |
|
10148 +/** |
|
10149 + |
|
10150 +@brief Compare multiple precision signed integes with equal-to criterion. |
|
10151 + |
|
10152 +Use MpiEqualTo() to compare multiple precision signed integes with equal-to criterion. |
|
10153 + |
|
10154 + |
|
10155 +@param [in] MpiLeft Left MPI |
|
10156 +@param [in] MpiRight Right MPI |
|
10157 + |
|
10158 + |
|
10159 +@retval MPI_NO "Left MPI == Right MPI" is false. |
|
10160 +@retval MPI_YES "Left MPI == Right MPI" is true. |
|
10161 + |
|
10162 + |
|
10163 +@note |
|
10164 + The constants MPI_YES and MPI_NO are defined in MPI_YES_NO_STATUS enumeration. |
|
10165 + |
|
10166 +*/ |
|
10167 +int |
|
10168 +MpiEqualTo( |
|
10169 + MPI MpiLeft, |
|
10170 + MPI MpiRight |
|
10171 + ) |
|
10172 +{ |
|
10173 + unsigned int i; |
|
10174 + |
|
10175 + |
|
10176 + |
|
10177 + // Check not-equal-to condition. |
|
10178 + for(i = 0; i < MPI_VALUE_BYTE_NUM_MAX; i++) |
|
10179 + { |
|
10180 + if(MpiLeft.Value[i] != MpiRight.Value[i]) |
|
10181 + goto condition_others; |
|
10182 + } |
|
10183 + |
|
10184 + |
|
10185 + // Right MPI is greater than left MPI. |
|
10186 + return MPI_YES; |
|
10187 + |
|
10188 + |
|
10189 +condition_others: |
|
10190 + |
|
10191 + |
|
10192 + // Other conditions. |
|
10193 + return MPI_NO; |
|
10194 +} |
|
10195 + |
|
10196 + |
|
10197 + |
|
10198 + |
|
10199 + |
|
10200 +/** |
|
10201 + |
|
10202 +@brief Compare multiple precision signed integes with greater-than criterion. |
|
10203 + |
|
10204 +Use MpiGreaterThan() to compare multiple precision signed integes with greater-than criterion. |
|
10205 + |
|
10206 + |
|
10207 +@param [in] MpiLeft Left MPI |
|
10208 +@param [in] MpiRight Right MPI |
|
10209 + |
|
10210 + |
|
10211 +@retval MPI_NO "Left MPI > Right MPI" is false. |
|
10212 +@retval MPI_YES "Left MPI > Right MPI" is true. |
|
10213 + |
|
10214 + |
|
10215 +@note |
|
10216 + The constants MPI_YES and MPI_NO are defined in MPI_YES_NO_STATUS enumeration. |
|
10217 + |
|
10218 +*/ |
|
10219 +int |
|
10220 +MpiGreaterThan( |
|
10221 + MPI MpiLeft, |
|
10222 + MPI MpiRight |
|
10223 + ) |
|
10224 +{ |
|
10225 + MPI MiddleResult; |
|
10226 + unsigned char SignedBit; |
|
10227 + |
|
10228 + |
|
10229 + |
|
10230 + // Check equal-to condition. |
|
10231 + if(MpiEqualTo(MpiLeft, MpiRight) == MPI_YES) |
|
10232 + goto condition_others; |
|
10233 + |
|
10234 + |
|
10235 + // Subtract right MPI form left MPI. |
|
10236 + MpiSub(&MiddleResult, MpiLeft, MpiRight); |
|
10237 + |
|
10238 + |
|
10239 + // Check less-than condition. |
|
10240 + MpiGetSignedBit(MiddleResult, &SignedBit); |
|
10241 + |
|
10242 + if(SignedBit == 0x1) |
|
10243 + goto condition_others; |
|
10244 + |
|
10245 + |
|
10246 + // Right MPI is greater than left MPI. |
|
10247 + return MPI_YES; |
|
10248 + |
|
10249 + |
|
10250 +condition_others: |
|
10251 + |
|
10252 + |
|
10253 + // Other conditions. |
|
10254 + return MPI_NO; |
|
10255 +} |
|
10256 + |
|
10257 + |
|
10258 + |
|
10259 + |
|
10260 + |
|
10261 +/** |
|
10262 + |
|
10263 +@brief Compare multiple precision signed integes with less-than criterion. |
|
10264 + |
|
10265 +Use MpiLessThan() to compare multiple precision signed integes with less-than criterion. |
|
10266 + |
|
10267 + |
|
10268 +@param [in] MpiLeft Left MPI |
|
10269 +@param [in] MpiRight Right MPI |
|
10270 + |
|
10271 + |
|
10272 +@retval MPI_NO "Left MPI < Right MPI" is false. |
|
10273 +@retval MPI_YES "Left MPI < Right MPI" is true. |
|
10274 + |
|
10275 + |
|
10276 +@note |
|
10277 + The constants MPI_YES and MPI_NO are defined in MPI_YES_NO_STATUS enumeration. |
|
10278 + |
|
10279 +*/ |
|
10280 +int |
|
10281 +MpiLessThan( |
|
10282 + MPI MpiLeft, |
|
10283 + MPI MpiRight |
|
10284 + ) |
|
10285 +{ |
|
10286 + MPI MiddleResult; |
|
10287 + unsigned char SignedBit; |
|
10288 + |
|
10289 + |
|
10290 + |
|
10291 + // Check equal-to condition. |
|
10292 + if(MpiEqualTo(MpiLeft, MpiRight) == MPI_YES) |
|
10293 + goto condition_others; |
|
10294 + |
|
10295 + |
|
10296 + // Subtract right MPI form left MPI. |
|
10297 + MpiSub(&MiddleResult, MpiLeft, MpiRight); |
|
10298 + |
|
10299 + |
|
10300 + // Check greater-than condition. |
|
10301 + MpiGetSignedBit(MiddleResult, &SignedBit); |
|
10302 + |
|
10303 + if(SignedBit == 0x0) |
|
10304 + goto condition_others; |
|
10305 + |
|
10306 + |
|
10307 + // Right MPI is less than left MPI. |
|
10308 + return MPI_YES; |
|
10309 + |
|
10310 + |
|
10311 +condition_others: |
|
10312 + |
|
10313 + |
|
10314 + // Other conditions. |
|
10315 + return MPI_NO; |
|
10316 +} |
|
10317 + |
|
10318 + |
|
10319 + |
|
10320 + |
|
10321 + |
|
10322 +/** |
|
10323 + |
|
10324 +@brief Minimize multiple precision signed integer bit number. |
|
10325 + |
|
10326 +Use MpiMinimizeBitNum() to minimize multiple precision signed integer MPI bit number. |
|
10327 + |
|
10328 + |
|
10329 +@param [in] pMpiVar Pointer to an allocated memory for storing result |
|
10330 + |
|
10331 +*/ |
|
10332 +void |
|
10333 +MpiMinimizeBitNum( |
|
10334 + MPI *pMpiVar |
|
10335 + ) |
|
10336 +{ |
|
10337 + int i; |
|
10338 + unsigned char SignedBit; |
|
10339 + unsigned char BitValue; |
|
10340 + |
|
10341 + |
|
10342 + |
|
10343 + // Get signed bit form MPI; |
|
10344 + MpiGetSignedBit(*pMpiVar, &SignedBit); |
|
10345 + |
|
10346 + |
|
10347 + // Find MPI MSB position. |
|
10348 + // Note: The MSB of signed integer is the rightest signed bit. |
|
10349 + for(i = (MPI_VALUE_BIT_NUM_MAX - 2); i > -1; i--) |
|
10350 + { |
|
10351 + // Get current bit value. |
|
10352 + MpiGetBit(*pMpiVar, i, &BitValue); |
|
10353 + |
|
10354 + // Compare current bit with signed bit. |
|
10355 + if(BitValue != SignedBit) |
|
10356 + break; |
|
10357 + } |
|
10358 + |
|
10359 + |
|
10360 + // Set MPI bit number. |
|
10361 + // Note: MPI bit number must be greater than one. |
|
10362 + pMpiVar->BitNum = (i == -1) ? 2 : (i + 2); |
|
10363 + |
|
10364 + |
|
10365 + return; |
|
10366 +} |
|
10367 + |
|
10368 + |
|
10369 + |
|
10370 + |
|
10371 + |
|
10372 + |
|
10373 +/** |
|
10374 + |
|
10375 +@brief Calculate multiple precision signed integer logarithm with base 2. |
|
10376 + |
|
10377 +Use MpiMinimizeBitNum() to calculate multiple precision signed integer logarithm with base 2. |
|
10378 + |
|
10379 + |
|
10380 +@param [out] pResult Pointer to an allocated memory for storing result (unit: pow(2, - ResultFracBitNum)) |
|
10381 +@param [in] MpiVar MPI variable for calculating |
|
10382 +@param [in] ResultFracBitNum Result fraction bit number |
|
10383 + |
|
10384 + |
|
10385 +@note |
|
10386 + -# MPI variable bit number must be minimized. |
|
10387 + -# MPI variable bit number must be less than (MPI_VALUE_BIT_NUM_MAX / 2 + 1). |
|
10388 + -# MPI variable must be greater than zero. |
|
10389 + -# If MPI variable is zero, the result is zero in MpiLog2(). |
|
10390 + -# The result bit number will be minimized in MpiLog2(). |
|
10391 + |
|
10392 +*/ |
|
10393 +void |
|
10394 +MpiLog2( |
|
10395 + MPI *pResult, |
|
10396 + MPI MpiVar, |
|
10397 + unsigned long ResultFracBitNum |
|
10398 + ) |
|
10399 +{ |
|
10400 + unsigned int i; |
|
10401 + MPI MiddleResult; |
|
10402 + unsigned char BitValue; |
|
10403 + |
|
10404 + |
|
10405 + |
|
10406 + // Get integer part of MPI logarithm result with base 2. |
|
10407 + MpiSetValue(pResult, (long)(MpiVar.BitNum - 2)); |
|
10408 + |
|
10409 + |
|
10410 + // Get fraction part of MPI logarithm result with base 2 by logarithm algorithm. |
|
10411 + // Note: Take middle result format as follows: |
|
10412 + // x x . x x ~ x |
|
10413 + // (integer part 2 bits) . (fraction part MPI_LOG_MIDDLE_RESULT_FRAC_BIT_NUM bits) |
|
10414 + |
|
10415 + // Set middle result with initial value. |
|
10416 + MpiLeftShift(&MiddleResult, MpiVar, (MPI_LOG_MIDDLE_RESULT_FRAC_BIT_NUM - MpiVar.BitNum + 2)); |
|
10417 + |
|
10418 + // Calculate result fraction bits. |
|
10419 + for(i = 0; i < ResultFracBitNum; i++) |
|
10420 + { |
|
10421 + // Shift result toward left with one bit. |
|
10422 + // Note: MpiLeftShift() will minimize result bit number. |
|
10423 + MpiLeftShift(pResult, *pResult, 1); |
|
10424 + |
|
10425 + // Square middle result. |
|
10426 + MpiMul(&MiddleResult, MiddleResult, MiddleResult); |
|
10427 + |
|
10428 + // Shift middle result toward right with fraction bit num. |
|
10429 + MpiRightShift(&MiddleResult, MiddleResult, MPI_LOG_MIDDLE_RESULT_FRAC_BIT_NUM); |
|
10430 + |
|
10431 + // Get middle result integer part bit 1. |
|
10432 + MpiGetBit(MiddleResult, MPI_LOG_MIDDLE_RESULT_FRAC_BIT_NUM + 1, &BitValue); |
|
10433 + |
|
10434 + // If middle result integer part bit 1 is equal to 0x1, |
|
10435 + // shift middle result with one bit toward right and set result LSB with one. |
|
10436 + if(BitValue == 0x1) |
|
10437 + { |
|
10438 + MpiRightShift(&MiddleResult, MiddleResult, 1); |
|
10439 + MpiSetBit(pResult, 0, 0x1); |
|
10440 + } |
|
10441 + } |
|
10442 + |
|
10443 + |
|
10444 + return; |
|
10445 +} |
|
10446 + |
|
10447 + |
|
10448 + |
|
10449 + |
|
10450 + |
|
10451 + |
|
10452 + |
|
10453 + |
|
10454 + |
|
10455 + |
|
10456 + |
|
10457 + |
|
10458 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/math_mpi.h |
|
10459 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
10460 +++ b/linux/drivers/media/dvb/dvb-usb/math_mpi.h Wed Oct 27 09:16:44 2010 +0200 |
|
10461 @@ -0,0 +1,201 @@ |
|
10462 +#ifndef __MATH_MPI_H |
|
10463 +#define __MATH_MPI_H |
|
10464 + |
|
10465 +/** |
|
10466 + |
|
10467 +@file |
|
10468 + |
|
10469 +@brief Mutliple precision integer (MPI) arithmetic declaration |
|
10470 + |
|
10471 +One can use to mutliple precision arithmetic to manipulate large signed integers. |
|
10472 + |
|
10473 +*/ |
|
10474 + |
|
10475 + |
|
10476 + |
|
10477 + |
|
10478 + |
|
10479 +// Constant |
|
10480 +#define MPI_BYTE_BIT_NUM 8 |
|
10481 +#define MPI_LONG_BYTE_NUM 4 |
|
10482 +#define MPI_LONG_BIT_NUM 32 |
|
10483 + |
|
10484 + |
|
10485 + |
|
10486 +// Mask and shift |
|
10487 +#define MPI_BYTE_MASK 0xff |
|
10488 +#define MPI_BYTE_SHIFT 8 |
|
10489 + |
|
10490 +#define MPI_BIT_0_MASK 0x1 |
|
10491 +#define MPI_BIT_7_SHIFT 7 |
|
10492 + |
|
10493 + |
|
10494 + |
|
10495 +// Multiple precision integer definition |
|
10496 +#define MPI_VALUE_BYTE_NUM_MAX 10 ///< Maximum MPI value byte number |
|
10497 +#define MPI_VALUE_BIT_NUM_MAX (MPI_VALUE_BYTE_NUM_MAX * MPI_BYTE_BIT_NUM) ///< Maximum MPI value bit number |
|
10498 + |
|
10499 +/// Multiple precision integer structure |
|
10500 +typedef struct |
|
10501 +{ |
|
10502 + unsigned long BitNum; |
|
10503 + unsigned char Value[MPI_VALUE_BYTE_NUM_MAX]; |
|
10504 +} |
|
10505 +MPI; |
|
10506 + |
|
10507 + |
|
10508 + |
|
10509 +/// MPI yes/no status |
|
10510 +enum MPI_YES_NO_STATUS |
|
10511 +{ |
|
10512 + MPI_NO, ///< No |
|
10513 + MPI_YES, ///< Yes |
|
10514 +}; |
|
10515 + |
|
10516 + |
|
10517 + |
|
10518 +// Logarithm with base 2 |
|
10519 +#define MPI_LOG_MIDDLE_RESULT_FRAC_BIT_NUM (MPI_VALUE_BIT_NUM_MAX / 2 - 2) |
|
10520 + |
|
10521 + |
|
10522 + |
|
10523 + |
|
10524 + |
|
10525 +// MPI access |
|
10526 +void |
|
10527 +MpiSetValue( |
|
10528 + MPI *pMpiVar, |
|
10529 + long Value |
|
10530 + ); |
|
10531 + |
|
10532 +void |
|
10533 +MpiGetValue( |
|
10534 + MPI MpiVar, |
|
10535 + long *pValue |
|
10536 + ); |
|
10537 + |
|
10538 +void |
|
10539 +MpiSetBit( |
|
10540 + MPI *pMpiVar, |
|
10541 + unsigned long BitPosition, |
|
10542 + unsigned char BitValue |
|
10543 + ); |
|
10544 + |
|
10545 +void |
|
10546 +MpiGetBit( |
|
10547 + MPI MpiVar, |
|
10548 + unsigned long BitPosition, |
|
10549 + unsigned char *pBitValue |
|
10550 + ); |
|
10551 + |
|
10552 +void |
|
10553 +MpiGetSignedBit( |
|
10554 + MPI MpiVar, |
|
10555 + unsigned char *pSignedBit |
|
10556 + ); |
|
10557 + |
|
10558 + |
|
10559 + |
|
10560 +// MPI operator |
|
10561 +void |
|
10562 +MpiAssign( |
|
10563 + MPI *pResult, |
|
10564 + MPI Operand |
|
10565 + ); |
|
10566 + |
|
10567 +void |
|
10568 +MpiUnaryMinus( |
|
10569 + MPI *pResult, |
|
10570 + MPI Operand |
|
10571 + ); |
|
10572 + |
|
10573 +void |
|
10574 +MpiAdd( |
|
10575 + MPI *pSum, |
|
10576 + MPI Augend, |
|
10577 + MPI Addend |
|
10578 + ); |
|
10579 + |
|
10580 +void |
|
10581 +MpiSub( |
|
10582 + MPI *pDifference, |
|
10583 + MPI Minuend, |
|
10584 + MPI Subtrahend |
|
10585 + ); |
|
10586 + |
|
10587 +void |
|
10588 +MpiMul( |
|
10589 + MPI *pProduct, |
|
10590 + MPI Multiplicand, |
|
10591 + MPI Multiplicator |
|
10592 + ); |
|
10593 + |
|
10594 +void |
|
10595 +MpiDiv( |
|
10596 + MPI *pQuotient, |
|
10597 + MPI *pRemainder, |
|
10598 + MPI Dividend, |
|
10599 + MPI Divisor |
|
10600 + ); |
|
10601 + |
|
10602 +void |
|
10603 +MpiRightShift( |
|
10604 + MPI *pResult, |
|
10605 + MPI Operand, |
|
10606 + unsigned long ShiftBitNum |
|
10607 + ); |
|
10608 + |
|
10609 +void |
|
10610 +MpiLeftShift( |
|
10611 + MPI *pResult, |
|
10612 + MPI Operand, |
|
10613 + unsigned long ShiftBitNum |
|
10614 + ); |
|
10615 + |
|
10616 +int |
|
10617 +MpiEqualTo( |
|
10618 + MPI MpiLeft, |
|
10619 + MPI MpiRight |
|
10620 + ); |
|
10621 + |
|
10622 +int |
|
10623 +MpiGreaterThan( |
|
10624 + MPI MpiLeft, |
|
10625 + MPI MpiRight |
|
10626 + ); |
|
10627 + |
|
10628 +int |
|
10629 +MpiLessThan( |
|
10630 + MPI MpiLeft, |
|
10631 + MPI MpiRight |
|
10632 + ); |
|
10633 + |
|
10634 +void |
|
10635 +MpiMinimizeBitNum( |
|
10636 + MPI *pMpiVar |
|
10637 + ); |
|
10638 + |
|
10639 + |
|
10640 + |
|
10641 +// MPI special function |
|
10642 +void |
|
10643 +MpiLog2( |
|
10644 + MPI *pResult, |
|
10645 + MPI MpiVar, |
|
10646 + unsigned long ResultFracBitNum |
|
10647 + ); |
|
10648 + |
|
10649 + |
|
10650 + |
|
10651 + |
|
10652 + |
|
10653 + |
|
10654 + |
|
10655 + |
|
10656 + |
|
10657 + |
|
10658 + |
|
10659 + |
|
10660 + |
|
10661 + |
|
10662 +#endif |
|
10663 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/nim_rtl2832_fc2580.c |
|
10664 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
10665 +++ b/linux/drivers/media/dvb/dvb-usb/nim_rtl2832_fc2580.c Wed Oct 27 09:16:44 2010 +0200 |
|
10666 @@ -0,0 +1,387 @@ |
|
10667 +/** |
|
10668 + |
|
10669 +@file |
|
10670 + |
|
10671 +@brief RTL2832 FC2580 NIM module definition |
|
10672 + |
|
10673 +One can manipulate RTL2832 FC2580 NIM through RTL2832 FC2580 NIM module. |
|
10674 +RTL2832 FC2580 NIM module is derived from DVB-T NIM module. |
|
10675 + |
|
10676 +*/ |
|
10677 + |
|
10678 + |
|
10679 +#include "nim_rtl2832_fc2580.h" |
|
10680 + |
|
10681 + |
|
10682 + |
|
10683 + |
|
10684 + |
|
10685 +/** |
|
10686 + |
|
10687 +@brief RTL2832 FC2580 NIM module builder |
|
10688 + |
|
10689 +Use BuildRtl2832Fc2580Module() to build RTL2832 FC2580 NIM module, set all module function pointers with the |
|
10690 +corresponding functions, and initialize module private variables. |
|
10691 + |
|
10692 + |
|
10693 +@param [in] ppNim Pointer to RTL2832 FC2580 NIM module pointer |
|
10694 +@param [in] pDvbtNimModuleMemory Pointer to an allocated DVB-T NIM module memory |
|
10695 +@param [in] I2cReadingByteNumMax Maximum I2C reading byte number for basic I2C reading function |
|
10696 +@param [in] I2cWritingByteNumMax Maximum I2C writing byte number for basic I2C writing function |
|
10697 +@param [in] I2cRead Basic I2C reading function pointer |
|
10698 +@param [in] I2cWrite Basic I2C writing function pointer |
|
10699 +@param [in] WaitMs Basic waiting function pointer |
|
10700 +@param [in] pRtl2832ExtraModuleMemory Pointer to an allocated RTL2832 extra module memory |
|
10701 +@param [in] DemodDeviceAddr RTL2832 I2C device address |
|
10702 +@param [in] DemodCrystalFreqHz RTL2832 crystal frequency in Hz |
|
10703 +@param [in] DemodAppMode RTL2832 application mode for setting |
|
10704 +@param [in] DemodTsInterfaceMode RTL2832 TS interface mode for setting |
|
10705 +@param [in] pFc2580ExtraModuleMemory Pointer to an allocated FC2580 extra module memory |
|
10706 +@param [in] TunerDeviceAddr FC2580 I2C device address |
|
10707 +@param [in] TunerAgcMode FC2580 AGC mode |
|
10708 + |
|
10709 + |
|
10710 +@note |
|
10711 + -# One should call BuildRtl2832Fc2580Module() to build RTL2832 FC2580 NIM module before using it. |
|
10712 + |
|
10713 +*/ |
|
10714 +void |
|
10715 +BuildRtl2832Fc2580Module( |
|
10716 + DVBT_NIM_MODULE **ppNim, // DVB-T NIM dependence |
|
10717 + DVBT_NIM_MODULE *pDvbtNimModuleMemory, |
|
10718 + |
|
10719 + unsigned char I2cReadingByteNumMax, // Base interface dependence |
|
10720 + unsigned char I2cWritingByteNumMax, |
|
10721 + BASE_FP_I2C_READ I2cRead, |
|
10722 + BASE_FP_I2C_WRITE I2cWrite, |
|
10723 + BASE_FP_WAIT_MS WaitMs, |
|
10724 + |
|
10725 + RTL2832_EXTRA_MODULE *pRtl2832ExtraModuleMemory, // Demod dependence |
|
10726 + unsigned char DemodDeviceAddr, |
|
10727 + unsigned long DemodCrystalFreqHz, |
|
10728 + int DemodAppMode, |
|
10729 + int DemodTsInterfaceMode, |
|
10730 + unsigned long DemodUpdateFuncRefPeriodMs, |
|
10731 + int DemodIsFunc1Enabled, |
|
10732 + |
|
10733 + FC2580_EXTRA_MODULE *pFc2580ExtraModuleMemory, // Tuner dependence |
|
10734 + unsigned char TunerDeviceAddr, |
|
10735 + unsigned long TunerCrystalFreqHz, |
|
10736 + int TunerAgcMode |
|
10737 + ) |
|
10738 +{ |
|
10739 + DVBT_NIM_MODULE *pNim; |
|
10740 + |
|
10741 + |
|
10742 + |
|
10743 + // Set NIM module pointer with NIM module memory. |
|
10744 + *ppNim = pDvbtNimModuleMemory; |
|
10745 + |
|
10746 + // Get NIM module. |
|
10747 + pNim = *ppNim; |
|
10748 + |
|
10749 + // Set I2C bridge module pointer with I2C bridge module memory. |
|
10750 + pNim->pI2cBridge = &pNim->I2cBridgeModuleMemory; |
|
10751 + |
|
10752 + // Set NIM extra module pointer. |
|
10753 + pNim->pExtra = INVALID_POINTER_VALUE; |
|
10754 + |
|
10755 + |
|
10756 + // Set NIM type. |
|
10757 + pNim->NimType = DVBT_NIM_RTL2832_FC2580; |
|
10758 + |
|
10759 + |
|
10760 + // Build base interface module. |
|
10761 + BuildBaseInterface( |
|
10762 + &pNim->pBaseInterface, |
|
10763 + &pNim->BaseInterfaceModuleMemory, |
|
10764 + I2cReadingByteNumMax, |
|
10765 + I2cWritingByteNumMax, |
|
10766 + I2cRead, |
|
10767 + I2cWrite, |
|
10768 + WaitMs |
|
10769 + ); |
|
10770 + |
|
10771 + // Build RTL2832 demod module. |
|
10772 + BuildRtl2832Module( |
|
10773 + &pNim->pDemod, |
|
10774 + &pNim->DvbtDemodModuleMemory, |
|
10775 + pRtl2832ExtraModuleMemory, |
|
10776 + &pNim->BaseInterfaceModuleMemory, |
|
10777 + &pNim->I2cBridgeModuleMemory, |
|
10778 + DemodDeviceAddr, |
|
10779 + DemodCrystalFreqHz, |
|
10780 + DemodAppMode, |
|
10781 + DemodUpdateFuncRefPeriodMs, |
|
10782 + DemodIsFunc1Enabled |
|
10783 + ); |
|
10784 + |
|
10785 + // Build FC2580 tuner module. |
|
10786 + BuildFc2580Module( |
|
10787 + &pNim->pTuner, |
|
10788 + &pNim->TunerModuleMemory, |
|
10789 + pFc2580ExtraModuleMemory, |
|
10790 + &pNim->BaseInterfaceModuleMemory, |
|
10791 + &pNim->I2cBridgeModuleMemory, |
|
10792 + TunerDeviceAddr, |
|
10793 + TunerCrystalFreqHz, |
|
10794 + TunerAgcMode |
|
10795 + ); |
|
10796 + |
|
10797 + |
|
10798 + // Set NIM module variables. |
|
10799 + pNim->DemodTsInterfaceMode = DemodTsInterfaceMode; |
|
10800 + |
|
10801 + |
|
10802 + // Set NIM module function pointers with default functions. |
|
10803 + pNim->GetNimType = dvbt_nim_default_GetNimType; |
|
10804 + pNim->GetParameters = dvbt_nim_default_GetParameters; |
|
10805 + pNim->IsSignalPresent = dvbt_nim_default_IsSignalPresent; |
|
10806 + pNim->IsSignalLocked = dvbt_nim_default_IsSignalLocked; |
|
10807 + pNim->GetSignalStrength = dvbt_nim_default_GetSignalStrength; |
|
10808 + pNim->GetSignalQuality = dvbt_nim_default_GetSignalQuality; |
|
10809 + pNim->GetBer = dvbt_nim_default_GetBer; |
|
10810 + pNim->GetSnrDb = dvbt_nim_default_GetSnrDb; |
|
10811 + pNim->GetTrOffsetPpm = dvbt_nim_default_GetTrOffsetPpm; |
|
10812 + pNim->GetCrOffsetHz = dvbt_nim_default_GetCrOffsetHz; |
|
10813 + pNim->GetTpsInfo = dvbt_nim_default_GetTpsInfo; |
|
10814 + pNim->UpdateFunction = dvbt_nim_default_UpdateFunction; |
|
10815 + |
|
10816 + // Set NIM module function pointers with particular functions. |
|
10817 + pNim->Initialize = rtl2832_fc2580_Initialize; |
|
10818 + pNim->SetParameters = rtl2832_fc2580_SetParameters; |
|
10819 + |
|
10820 + |
|
10821 + return; |
|
10822 +} |
|
10823 + |
|
10824 + |
|
10825 + |
|
10826 + |
|
10827 + |
|
10828 +/** |
|
10829 + |
|
10830 +@see DVBT_NIM_FP_INITIALIZE |
|
10831 + |
|
10832 +*/ |
|
10833 +int |
|
10834 +rtl2832_fc2580_Initialize( |
|
10835 + DVBT_NIM_MODULE *pNim |
|
10836 + ) |
|
10837 +{ |
|
10838 + typedef struct |
|
10839 + { |
|
10840 + int RegBitName; |
|
10841 + unsigned long Value; |
|
10842 + } |
|
10843 + REG_VALUE_ENTRY; |
|
10844 + |
|
10845 + |
|
10846 + static const REG_VALUE_ENTRY AdditionalInitRegValueTable[RTL2832_FC2580_ADDITIONAL_INIT_REG_TABLE_LEN] = |
|
10847 + { |
|
10848 + // RegBitName, Value |
|
10849 + {DVBT_DAGC_TRG_VAL, 0x39 }, |
|
10850 + {DVBT_AGC_TARG_VAL_0, 0x0 }, |
|
10851 + {DVBT_AGC_TARG_VAL_8_1, 0x5a }, |
|
10852 + {DVBT_AAGC_LOOP_GAIN, 0x16 }, |
|
10853 + {DVBT_LOOP_GAIN2_3_0, 0x6 }, |
|
10854 + {DVBT_LOOP_GAIN2_4, 0x1 }, |
|
10855 + {DVBT_LOOP_GAIN3, 0x16 }, |
|
10856 + {DVBT_VTOP1, 0x35 }, |
|
10857 + {DVBT_VTOP2, 0x21 }, |
|
10858 + {DVBT_VTOP3, 0x21 }, |
|
10859 + {DVBT_KRF1, 0x0 }, |
|
10860 + {DVBT_KRF2, 0x40 }, |
|
10861 + {DVBT_KRF3, 0x10 }, |
|
10862 + {DVBT_KRF4, 0x10 }, |
|
10863 + {DVBT_IF_AGC_MIN, 0x80 }, |
|
10864 + {DVBT_IF_AGC_MAX, 0x7f }, |
|
10865 + {DVBT_RF_AGC_MIN, 0x9c }, |
|
10866 + {DVBT_RF_AGC_MAX, 0x7f }, |
|
10867 + {DVBT_POLAR_RF_AGC, 0x0 }, |
|
10868 + {DVBT_POLAR_IF_AGC, 0x0 }, |
|
10869 + {DVBT_AD7_SETTING, 0xe9f4 }, |
|
10870 + }; |
|
10871 + |
|
10872 + |
|
10873 + TUNER_MODULE *pTuner; |
|
10874 + DVBT_DEMOD_MODULE *pDemod; |
|
10875 + |
|
10876 + int i; |
|
10877 + |
|
10878 + int RegBitName; |
|
10879 + unsigned long Value; |
|
10880 + |
|
10881 + |
|
10882 + |
|
10883 + // Get tuner module and demod module. |
|
10884 + pTuner = pNim->pTuner; |
|
10885 + pDemod = pNim->pDemod; |
|
10886 + |
|
10887 + |
|
10888 + // Enable demod DVBT_IIC_REPEAT. |
|
10889 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS) |
|
10890 + goto error_status_set_registers; |
|
10891 + |
|
10892 + // Initialize tuner. |
|
10893 + if(pTuner->Initialize(pTuner) != FUNCTION_SUCCESS) |
|
10894 + goto error_status_execute_function; |
|
10895 + |
|
10896 + // Disable demod DVBT_IIC_REPEAT. |
|
10897 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS) |
|
10898 + goto error_status_set_registers; |
|
10899 + |
|
10900 + |
|
10901 + // Initialize demod. |
|
10902 + if(pDemod->Initialize(pDemod) != FUNCTION_SUCCESS) |
|
10903 + goto error_status_execute_function; |
|
10904 + |
|
10905 + // Set demod IF frequency with 0 Hz. |
|
10906 + if(pDemod->SetIfFreqHz(pDemod, IF_FREQ_0HZ) != FUNCTION_SUCCESS) |
|
10907 + goto error_status_execute_function; |
|
10908 + |
|
10909 + // Set demod spectrum mode with SPECTRUM_NORMAL. |
|
10910 + if(pDemod->SetSpectrumMode(pDemod, SPECTRUM_NORMAL) != FUNCTION_SUCCESS) |
|
10911 + goto error_status_execute_function; |
|
10912 + |
|
10913 + |
|
10914 + // Set demod registers. |
|
10915 + for(i = 0; i < RTL2832_FC2580_ADDITIONAL_INIT_REG_TABLE_LEN; i++) |
|
10916 + { |
|
10917 + // Get register bit name and its value. |
|
10918 + RegBitName = AdditionalInitRegValueTable[i].RegBitName; |
|
10919 + Value = AdditionalInitRegValueTable[i].Value; |
|
10920 + |
|
10921 + // Set demod registers |
|
10922 + if(pDemod->SetRegBitsWithPage(pDemod, RegBitName, Value) != FUNCTION_SUCCESS) |
|
10923 + goto error_status_set_registers; |
|
10924 + } |
|
10925 + |
|
10926 + |
|
10927 + // Set TS interface according to TS interface mode. |
|
10928 + switch(pNim->DemodTsInterfaceMode) |
|
10929 + { |
|
10930 + case TS_INTERFACE_PARALLEL: |
|
10931 + |
|
10932 + // Set demod TS interface with parallel mode. |
|
10933 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SERIAL, 0) != FUNCTION_SUCCESS) |
|
10934 + goto error_status_set_registers; |
|
10935 + |
|
10936 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH0, 9) != FUNCTION_SUCCESS) |
|
10937 + goto error_status_set_registers; |
|
10938 + |
|
10939 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH1, 9) != FUNCTION_SUCCESS) |
|
10940 + goto error_status_set_registers; |
|
10941 + |
|
10942 + break; |
|
10943 + |
|
10944 + |
|
10945 + default: |
|
10946 + case TS_INTERFACE_SERIAL: |
|
10947 + |
|
10948 + // Set demod TS interface with serial mode. |
|
10949 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SERIAL, 1) != FUNCTION_SUCCESS) |
|
10950 + goto error_status_set_registers; |
|
10951 + |
|
10952 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH0, 2) != FUNCTION_SUCCESS) |
|
10953 + goto error_status_set_registers; |
|
10954 + |
|
10955 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH1, 2) != FUNCTION_SUCCESS) |
|
10956 + goto error_status_set_registers; |
|
10957 + |
|
10958 + break; |
|
10959 + } |
|
10960 + |
|
10961 + |
|
10962 + return FUNCTION_SUCCESS; |
|
10963 + |
|
10964 + |
|
10965 +error_status_execute_function: |
|
10966 +error_status_set_registers: |
|
10967 + return FUNCTION_ERROR; |
|
10968 +} |
|
10969 + |
|
10970 + |
|
10971 + |
|
10972 + |
|
10973 + |
|
10974 +/** |
|
10975 + |
|
10976 +@see DVBT_NIM_FP_SET_PARAMETERS |
|
10977 + |
|
10978 +*/ |
|
10979 +int |
|
10980 +rtl2832_fc2580_SetParameters( |
|
10981 + DVBT_NIM_MODULE *pNim, |
|
10982 + unsigned long RfFreqHz, |
|
10983 + int BandwidthMode |
|
10984 + ) |
|
10985 +{ |
|
10986 + TUNER_MODULE *pTuner; |
|
10987 + DVBT_DEMOD_MODULE *pDemod; |
|
10988 + |
|
10989 + FC2580_EXTRA_MODULE *pTunerExtra; |
|
10990 + int TunerBandwidthMode; |
|
10991 + |
|
10992 + |
|
10993 + |
|
10994 + // Get tuner module and demod module. |
|
10995 + pTuner = pNim->pTuner; |
|
10996 + pDemod = pNim->pDemod; |
|
10997 + |
|
10998 + // Get tuner extra module. |
|
10999 + pTunerExtra = (FC2580_EXTRA_MODULE *)pTuner->pExtra; |
|
11000 + |
|
11001 + |
|
11002 + // Enable demod DVBT_IIC_REPEAT. |
|
11003 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS) |
|
11004 + goto error_status_set_registers; |
|
11005 + |
|
11006 + // Set tuner RF frequency in Hz. |
|
11007 + if(pTuner->SetRfFreqHz(pTuner, RfFreqHz) != FUNCTION_SUCCESS) |
|
11008 + goto error_status_execute_function; |
|
11009 + |
|
11010 + // Determine TunerBandwidthMode according to bandwidth mode. |
|
11011 + switch(BandwidthMode) |
|
11012 + { |
|
11013 + default: |
|
11014 + case DVBT_BANDWIDTH_6MHZ: TunerBandwidthMode = FC2580_BANDWIDTH_6000000HZ; break; |
|
11015 + case DVBT_BANDWIDTH_7MHZ: TunerBandwidthMode = FC2580_BANDWIDTH_7000000HZ; break; |
|
11016 + case DVBT_BANDWIDTH_8MHZ: TunerBandwidthMode = FC2580_BANDWIDTH_8000000HZ; break; |
|
11017 + } |
|
11018 + |
|
11019 + // Set tuner bandwidth mode with TunerBandwidthMode. |
|
11020 + if(pTunerExtra->SetBandwidthMode(pTuner, TunerBandwidthMode) != FUNCTION_SUCCESS) |
|
11021 + goto error_status_execute_function; |
|
11022 + |
|
11023 + // Disable demod DVBT_IIC_REPEAT. |
|
11024 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS) |
|
11025 + goto error_status_set_registers; |
|
11026 + |
|
11027 + |
|
11028 + // Set demod bandwidth mode. |
|
11029 + if(pDemod->SetBandwidthMode(pDemod, BandwidthMode) != FUNCTION_SUCCESS) |
|
11030 + goto error_status_execute_function; |
|
11031 + |
|
11032 + // Reset demod particular registers. |
|
11033 + if(pDemod->ResetFunction(pDemod) != FUNCTION_SUCCESS) |
|
11034 + goto error_status_execute_function; |
|
11035 + |
|
11036 + |
|
11037 + // Reset demod by software reset. |
|
11038 + if(pDemod->SoftwareReset(pDemod) != FUNCTION_SUCCESS) |
|
11039 + goto error_status_execute_function; |
|
11040 + |
|
11041 + |
|
11042 + return FUNCTION_SUCCESS; |
|
11043 + |
|
11044 + |
|
11045 +error_status_execute_function: |
|
11046 +error_status_set_registers: |
|
11047 + return FUNCTION_ERROR; |
|
11048 +} |
|
11049 + |
|
11050 + |
|
11051 + |
|
11052 + |
|
11053 + |
|
11054 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/nim_rtl2832_fc2580.h |
|
11055 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
11056 +++ b/linux/drivers/media/dvb/dvb-usb/nim_rtl2832_fc2580.h Wed Oct 27 09:16:44 2010 +0200 |
|
11057 @@ -0,0 +1,146 @@ |
|
11058 +#ifndef __NIM_RTL2832_FC2580 |
|
11059 +#define __NIM_RTL2832_FC2580 |
|
11060 + |
|
11061 +/** |
|
11062 + |
|
11063 +@file |
|
11064 + |
|
11065 +@brief RTL2832 FC2580 NIM module declaration |
|
11066 + |
|
11067 +One can manipulate RTL2832 FC2580 NIM through RTL2832 FC2580 NIM module. |
|
11068 +RTL2832 FC2580 NIM module is derived from DVB-T NIM module. |
|
11069 + |
|
11070 + |
|
11071 + |
|
11072 +@par Example: |
|
11073 +@code |
|
11074 + |
|
11075 +// The example is the same as the NIM example in dvbt_nim_base.h except the listed lines. |
|
11076 + |
|
11077 + |
|
11078 + |
|
11079 +#include "nim_rtl2832_fc2580.h" |
|
11080 + |
|
11081 + |
|
11082 +... |
|
11083 + |
|
11084 + |
|
11085 + |
|
11086 +int main(void) |
|
11087 +{ |
|
11088 + DVBT_NIM_MODULE *pNim; |
|
11089 + DVBT_NIM_MODULE DvbtNimModuleMemory; |
|
11090 + RTL2832_EXTRA_MODULE Rtl2832ExtraModuleMemory; |
|
11091 + FC2580_EXTRA_MODULE Fc2580ExtraModuleMemory; |
|
11092 + |
|
11093 + ... |
|
11094 + |
|
11095 + |
|
11096 + |
|
11097 + // Build RTL2832 FC2580 NIM module. |
|
11098 + BuildRtl2832Fc2580Module( |
|
11099 + &pNim, |
|
11100 + &DvbtNimModuleMemory, |
|
11101 + |
|
11102 + 9, // Maximum I2C reading byte number is 9. |
|
11103 + 8, // Maximum I2C writing byte number is 8. |
|
11104 + CustomI2cRead, // Employ CustomI2cRead() as basic I2C reading function. |
|
11105 + CustomI2cWrite, // Employ CustomI2cWrite() as basic I2C writing function. |
|
11106 + CustomWaitMs, // Employ CustomWaitMs() as basic waiting function. |
|
11107 + |
|
11108 + &Rtl2832ExtraModuleMemory, // Employ RTL2832 extra module for RTL2832 module. |
|
11109 + 0x20, // The RTL2832 I2C device address is 0x20 in 8-bit format. |
|
11110 + CRYSTAL_FREQ_28800000HZ, // The RTL2832 crystal frequency is 28.8 MHz. |
|
11111 + RTL2832_APPLICATION_STB, // The RTL2832 application mode is STB mode. |
|
11112 + 50, // The RTL2832 update function reference period is 50 millisecond |
|
11113 + ON, // The RTL2832 Function 1 enabling status is on. |
|
11114 + |
|
11115 + &Fc2580ExtraModuleMemory, // Employ FC2580 extra module for FC2580 module. |
|
11116 + 0xac, // The FC2580 I2C device address is 0xac in 8-bit format. |
|
11117 + CRYSTAL_FREQ_16384000HZ, // The FC2580 crystal frequency is 16.384 MHz. |
|
11118 + FC2580_AGC_EXTERNAL // The FC2580 AGC mode is external AGC mode. |
|
11119 + ); |
|
11120 + |
|
11121 + |
|
11122 + |
|
11123 + // See the example for other NIM functions in dvbt_nim_base.h |
|
11124 + |
|
11125 + ... |
|
11126 + |
|
11127 + |
|
11128 + return 0; |
|
11129 +} |
|
11130 + |
|
11131 + |
|
11132 +@endcode |
|
11133 + |
|
11134 +*/ |
|
11135 + |
|
11136 + |
|
11137 +#include "demod_rtl2832.h" |
|
11138 +#include "tuner_fc2580.h" |
|
11139 +#include "dvbt_nim_base.h" |
|
11140 + |
|
11141 + |
|
11142 + |
|
11143 + |
|
11144 + |
|
11145 +// Definitions |
|
11146 +#define RTL2832_FC2580_ADDITIONAL_INIT_REG_TABLE_LEN 21 |
|
11147 + |
|
11148 + |
|
11149 + |
|
11150 + |
|
11151 + |
|
11152 +// Builder |
|
11153 +void |
|
11154 +BuildRtl2832Fc2580Module( |
|
11155 + DVBT_NIM_MODULE **ppNim, // DVB-T NIM dependence |
|
11156 + DVBT_NIM_MODULE *pDvbtNimModuleMemory, |
|
11157 + |
|
11158 + unsigned char I2cReadingByteNumMax, // Base interface dependence |
|
11159 + unsigned char I2cWritingByteNumMax, |
|
11160 + BASE_FP_I2C_READ I2cRead, |
|
11161 + BASE_FP_I2C_WRITE I2cWrite, |
|
11162 + BASE_FP_WAIT_MS WaitMs, |
|
11163 + |
|
11164 + RTL2832_EXTRA_MODULE *pRtl2832ExtraModuleMemory, // Demod dependence |
|
11165 + unsigned char DemodDeviceAddr, |
|
11166 + unsigned long DemodCrystalFreqHz, |
|
11167 + int DemodAppMode, |
|
11168 + int DemodTsInterfaceMode, |
|
11169 + unsigned long DemodUpdateFuncRefPeriodMs, |
|
11170 + int DemodIsFunc1Enabled, |
|
11171 + |
|
11172 + FC2580_EXTRA_MODULE *pFc2580ExtraModuleMemory, // Tuner dependence |
|
11173 + unsigned char TunerDeviceAddr, |
|
11174 + unsigned long TunerCrystalFreqHz, |
|
11175 + int TunerAgcMode |
|
11176 + ); |
|
11177 + |
|
11178 + |
|
11179 + |
|
11180 + |
|
11181 + |
|
11182 +// RTL2832 FC2580 NIM manipulaing functions |
|
11183 +int |
|
11184 +rtl2832_fc2580_Initialize( |
|
11185 + DVBT_NIM_MODULE *pNim |
|
11186 + ); |
|
11187 + |
|
11188 +int |
|
11189 +rtl2832_fc2580_SetParameters( |
|
11190 + DVBT_NIM_MODULE *pNim, |
|
11191 + unsigned long RfFreqHz, |
|
11192 + int BandwidthMode |
|
11193 + ); |
|
11194 + |
|
11195 + |
|
11196 + |
|
11197 + |
|
11198 + |
|
11199 + |
|
11200 + |
|
11201 +#endif |
|
11202 + |
|
11203 + |
|
11204 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/nim_rtl2832_mt2266.c |
|
11205 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
11206 +++ b/linux/drivers/media/dvb/dvb-usb/nim_rtl2832_mt2266.c Wed Oct 27 09:16:44 2010 +0200 |
|
11207 @@ -0,0 +1,1108 @@ |
|
11208 +/** |
|
11209 + |
|
11210 +@file |
|
11211 + |
|
11212 +@brief RTL2832 MT2266 NIM module definition |
|
11213 + |
|
11214 +One can manipulate RTL2832 MT2266 NIM through RTL2832 MT2266 NIM module. |
|
11215 +RTL2832 MT2266 NIM module is derived from DVB-T NIM module. |
|
11216 + |
|
11217 +*/ |
|
11218 + |
|
11219 + |
|
11220 +#include "nim_rtl2832_mt2266.h" |
|
11221 + |
|
11222 + |
|
11223 + |
|
11224 + |
|
11225 + |
|
11226 +/** |
|
11227 + |
|
11228 +@brief RTL2832 MT2266 NIM module builder |
|
11229 + |
|
11230 +Use BuildRtl2832Mt2266Module() to build RTL2832 MT2266 NIM module, set all module function pointers with the |
|
11231 +corresponding functions, and initialize module private variables. |
|
11232 + |
|
11233 + |
|
11234 +@param [in] ppNim Pointer to RTL2832 MT2266 NIM module pointer |
|
11235 +@param [in] pDvbtNimModuleMemory Pointer to an allocated DVB-T NIM module memory |
|
11236 +@param [in] I2cReadingByteNumMax Maximum I2C reading byte number for basic I2C reading function |
|
11237 +@param [in] I2cWritingByteNumMax Maximum I2C writing byte number for basic I2C writing function |
|
11238 +@param [in] I2cRead Basic I2C reading function pointer |
|
11239 +@param [in] I2cWrite Basic I2C writing function pointer |
|
11240 +@param [in] WaitMs Basic waiting function pointer |
|
11241 +@param [in] pRtl2832ExtraModuleMemory Pointer to an allocated RTL2832 extra module memory |
|
11242 +@param [in] DemodDeviceAddr RTL2832 I2C device address |
|
11243 +@param [in] DemodCrystalFreqHz RTL2832 crystal frequency in Hz |
|
11244 +@param [in] DemodAppMode RTL2832 application mode for setting |
|
11245 +@param [in] DemodTsInterfaceMode RTL2832 TS interface mode for setting |
|
11246 +@param [in] pMt2266ExtraModuleMemory Pointer to an allocated MT2266 extra module memory |
|
11247 +@param [in] TunerDeviceAddr MT2266 I2C device address |
|
11248 + |
|
11249 + |
|
11250 +@note |
|
11251 + -# One should call BuildRtl2832Mt2266Module() to build RTL2832 MT2266 NIM module before using it. |
|
11252 + |
|
11253 +*/ |
|
11254 +void |
|
11255 +BuildRtl2832Mt2266Module( |
|
11256 + DVBT_NIM_MODULE **ppNim, // DVB-T NIM dependence |
|
11257 + DVBT_NIM_MODULE *pDvbtNimModuleMemory, |
|
11258 + RTL2832_MT2266_EXTRA_MODULE *pRtl2832Mt2266ExtraModuleMemory, |
|
11259 + |
|
11260 + unsigned char I2cReadingByteNumMax, // Base interface dependence |
|
11261 + unsigned char I2cWritingByteNumMax, |
|
11262 + BASE_FP_I2C_READ I2cRead, |
|
11263 + BASE_FP_I2C_WRITE I2cWrite, |
|
11264 + BASE_FP_WAIT_MS WaitMs, |
|
11265 + |
|
11266 + RTL2832_EXTRA_MODULE *pRtl2832ExtraModuleMemory, // Demod dependence |
|
11267 + unsigned char DemodDeviceAddr, |
|
11268 + unsigned long DemodCrystalFreqHz, |
|
11269 + int DemodAppMode, |
|
11270 + int DemodTsInterfaceMode, |
|
11271 + unsigned long DemodUpdateFuncRefPeriodMs, |
|
11272 + int DemodIsFunc1Enabled, |
|
11273 + |
|
11274 + MT2266_EXTRA_MODULE *pMt2266ExtraModuleMemory, // Tuner dependence |
|
11275 + unsigned char TunerDeviceAddr |
|
11276 + ) |
|
11277 +{ |
|
11278 + DVBT_NIM_MODULE *pNim; |
|
11279 + RTL2832_MT2266_EXTRA_MODULE *pExtra; |
|
11280 + |
|
11281 + |
|
11282 + |
|
11283 + // Set NIM module pointer with NIM module memory. |
|
11284 + *ppNim = pDvbtNimModuleMemory; |
|
11285 + |
|
11286 + // Get NIM module. |
|
11287 + pNim = *ppNim; |
|
11288 + |
|
11289 + // Set I2C bridge module pointer with I2C bridge module memory. |
|
11290 + pNim->pI2cBridge = &pNim->I2cBridgeModuleMemory; |
|
11291 + |
|
11292 + // Set NIM extra module pointer. |
|
11293 + pNim->pExtra = pRtl2832Mt2266ExtraModuleMemory; |
|
11294 + |
|
11295 + // Get NIM extra module. |
|
11296 + pExtra = (RTL2832_MT2266_EXTRA_MODULE *)pNim->pExtra; |
|
11297 + |
|
11298 + |
|
11299 + // Set NIM type. |
|
11300 + pNim->NimType = DVBT_NIM_RTL2832_MT2266; |
|
11301 + |
|
11302 + |
|
11303 + // Build base interface module. |
|
11304 + BuildBaseInterface( |
|
11305 + &pNim->pBaseInterface, |
|
11306 + &pNim->BaseInterfaceModuleMemory, |
|
11307 + I2cReadingByteNumMax, |
|
11308 + I2cWritingByteNumMax, |
|
11309 + I2cRead, |
|
11310 + I2cWrite, |
|
11311 + WaitMs |
|
11312 + ); |
|
11313 + |
|
11314 + // Build RTL2832 demod module. |
|
11315 + BuildRtl2832Module( |
|
11316 + &pNim->pDemod, |
|
11317 + &pNim->DvbtDemodModuleMemory, |
|
11318 + pRtl2832ExtraModuleMemory, |
|
11319 + &pNim->BaseInterfaceModuleMemory, |
|
11320 + &pNim->I2cBridgeModuleMemory, |
|
11321 + DemodDeviceAddr, |
|
11322 + DemodCrystalFreqHz, |
|
11323 + DemodAppMode, |
|
11324 + DemodUpdateFuncRefPeriodMs, |
|
11325 + DemodIsFunc1Enabled |
|
11326 + ); |
|
11327 + |
|
11328 + // Build MT2266 tuner module. |
|
11329 + BuildMt2266Module( |
|
11330 + &pNim->pTuner, |
|
11331 + &pNim->TunerModuleMemory, |
|
11332 + pMt2266ExtraModuleMemory, |
|
11333 + &pNim->BaseInterfaceModuleMemory, |
|
11334 + &pNim->I2cBridgeModuleMemory, |
|
11335 + TunerDeviceAddr |
|
11336 + ); |
|
11337 + |
|
11338 + |
|
11339 + // Set NIM module variables. |
|
11340 + pNim->DemodTsInterfaceMode = DemodTsInterfaceMode; |
|
11341 + |
|
11342 + |
|
11343 + // Set NIM module function pointers with default functions. |
|
11344 + pNim->GetNimType = dvbt_nim_default_GetNimType; |
|
11345 + pNim->GetParameters = dvbt_nim_default_GetParameters; |
|
11346 + pNim->IsSignalPresent = dvbt_nim_default_IsSignalPresent; |
|
11347 + pNim->IsSignalLocked = dvbt_nim_default_IsSignalLocked; |
|
11348 + pNim->GetSignalStrength = dvbt_nim_default_GetSignalStrength; |
|
11349 + pNim->GetSignalQuality = dvbt_nim_default_GetSignalQuality; |
|
11350 + pNim->GetBer = dvbt_nim_default_GetBer; |
|
11351 + pNim->GetSnrDb = dvbt_nim_default_GetSnrDb; |
|
11352 + pNim->GetTrOffsetPpm = dvbt_nim_default_GetTrOffsetPpm; |
|
11353 + pNim->GetCrOffsetHz = dvbt_nim_default_GetCrOffsetHz; |
|
11354 + pNim->GetTpsInfo = dvbt_nim_default_GetTpsInfo; |
|
11355 + |
|
11356 + // Set NIM module function pointers with particular functions. |
|
11357 + pNim->Initialize = rtl2832_mt2266_Initialize; |
|
11358 + pNim->SetParameters = rtl2832_mt2266_SetParameters; |
|
11359 + pNim->UpdateFunction = rtl2832_mt2266_UpdateFunction; |
|
11360 + |
|
11361 + |
|
11362 + // Initialize NIM extra module variables. |
|
11363 + pExtra->LnaConfig = 0xff; |
|
11364 + pExtra->UhfSens = 0xff; |
|
11365 + pExtra->AgcCurrentState = 0xff; |
|
11366 + pExtra->LnaGainOld = 0xffffffff; |
|
11367 + |
|
11368 + |
|
11369 + return; |
|
11370 +} |
|
11371 + |
|
11372 + |
|
11373 + |
|
11374 + |
|
11375 + |
|
11376 +/** |
|
11377 + |
|
11378 +@see DVBT_NIM_FP_INITIALIZE |
|
11379 + |
|
11380 +*/ |
|
11381 +int |
|
11382 +rtl2832_mt2266_Initialize( |
|
11383 + DVBT_NIM_MODULE *pNim |
|
11384 + ) |
|
11385 +{ |
|
11386 + typedef struct |
|
11387 + { |
|
11388 + int RegBitName; |
|
11389 + unsigned long Value; |
|
11390 + } |
|
11391 + REG_VALUE_ENTRY; |
|
11392 + |
|
11393 + |
|
11394 + static const REG_VALUE_ENTRY AdditionalInitRegValueTable[RTL2832_MT2266_ADDITIONAL_INIT_REG_TABLE_LEN] = |
|
11395 + { |
|
11396 + // RegBitName, Value |
|
11397 + {DVBT_DAGC_TRG_VAL, 0x39 }, |
|
11398 + {DVBT_AGC_TARG_VAL_0, 0x0 }, |
|
11399 + {DVBT_AGC_TARG_VAL_8_1, 0x5a }, |
|
11400 + {DVBT_AAGC_LOOP_GAIN, 0x16 }, |
|
11401 + {DVBT_LOOP_GAIN2_3_0, 0x6 }, |
|
11402 + {DVBT_LOOP_GAIN2_4, 0x1 }, |
|
11403 + {DVBT_LOOP_GAIN3, 0x16 }, |
|
11404 + {DVBT_VTOP1, 0x35 }, |
|
11405 + {DVBT_VTOP2, 0x21 }, |
|
11406 + {DVBT_VTOP3, 0x21 }, |
|
11407 + {DVBT_KRF1, 0x0 }, |
|
11408 + {DVBT_KRF2, 0x40 }, |
|
11409 + {DVBT_KRF3, 0x10 }, |
|
11410 + {DVBT_KRF4, 0x10 }, |
|
11411 + {DVBT_IF_AGC_MIN, 0xc0 }, // Note: The IF_AGC_MIN value will be set again by demod_pdcontrol_reset(). |
|
11412 + {DVBT_IF_AGC_MAX, 0x7f }, |
|
11413 + {DVBT_RF_AGC_MIN, 0x9c }, |
|
11414 + {DVBT_RF_AGC_MAX, 0x7f }, |
|
11415 + {DVBT_POLAR_RF_AGC, 0x1 }, |
|
11416 + {DVBT_POLAR_IF_AGC, 0x1 }, |
|
11417 + {DVBT_AD7_SETTING, 0xe9f4 }, |
|
11418 + }; |
|
11419 + |
|
11420 + |
|
11421 + TUNER_MODULE *pTuner; |
|
11422 + DVBT_DEMOD_MODULE *pDemod; |
|
11423 + |
|
11424 + int i; |
|
11425 + |
|
11426 + int RegBitName; |
|
11427 + unsigned long Value; |
|
11428 + |
|
11429 + |
|
11430 + |
|
11431 + // Get tuner module and demod module. |
|
11432 + pTuner = pNim->pTuner; |
|
11433 + pDemod = pNim->pDemod; |
|
11434 + |
|
11435 + |
|
11436 + // Enable demod DVBT_IIC_REPEAT. |
|
11437 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS) |
|
11438 + goto error_status_set_registers; |
|
11439 + |
|
11440 + // Initialize tuner. |
|
11441 + if(pTuner->Initialize(pTuner) != FUNCTION_SUCCESS) |
|
11442 + goto error_status_execute_function; |
|
11443 + |
|
11444 + // Disable demod DVBT_IIC_REPEAT. |
|
11445 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS) |
|
11446 + goto error_status_set_registers; |
|
11447 + |
|
11448 + |
|
11449 + // Initialize demod. |
|
11450 + if(pDemod->Initialize(pDemod) != FUNCTION_SUCCESS) |
|
11451 + goto error_status_execute_function; |
|
11452 + |
|
11453 + // Set demod IF frequency with 0 Hz. |
|
11454 + if(pDemod->SetIfFreqHz(pDemod, IF_FREQ_0HZ) != FUNCTION_SUCCESS) |
|
11455 + goto error_status_execute_function; |
|
11456 + |
|
11457 + // Set demod spectrum mode with SPECTRUM_NORMAL. |
|
11458 + if(pDemod->SetSpectrumMode(pDemod, SPECTRUM_NORMAL) != FUNCTION_SUCCESS) |
|
11459 + goto error_status_execute_function; |
|
11460 + |
|
11461 + |
|
11462 + // Set demod registers. |
|
11463 + for(i = 0; i < RTL2832_MT2266_ADDITIONAL_INIT_REG_TABLE_LEN; i++) |
|
11464 + { |
|
11465 + // Get register bit name and its value. |
|
11466 + RegBitName = AdditionalInitRegValueTable[i].RegBitName; |
|
11467 + Value = AdditionalInitRegValueTable[i].Value; |
|
11468 + |
|
11469 + // Set demod registers |
|
11470 + if(pDemod->SetRegBitsWithPage(pDemod, RegBitName, Value) != FUNCTION_SUCCESS) |
|
11471 + goto error_status_set_registers; |
|
11472 + } |
|
11473 + |
|
11474 + |
|
11475 + // Set TS interface according to TS interface mode. |
|
11476 + switch(pNim->DemodTsInterfaceMode) |
|
11477 + { |
|
11478 + case TS_INTERFACE_PARALLEL: |
|
11479 + |
|
11480 + // Set demod TS interface with parallel mode. |
|
11481 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SERIAL, 0) != FUNCTION_SUCCESS) |
|
11482 + goto error_status_set_registers; |
|
11483 + |
|
11484 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH0, 9) != FUNCTION_SUCCESS) |
|
11485 + goto error_status_set_registers; |
|
11486 + |
|
11487 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH1, 9) != FUNCTION_SUCCESS) |
|
11488 + goto error_status_set_registers; |
|
11489 + |
|
11490 + break; |
|
11491 + |
|
11492 + |
|
11493 + default: |
|
11494 + case TS_INTERFACE_SERIAL: |
|
11495 + |
|
11496 + // Set demod TS interface with serial mode. |
|
11497 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SERIAL, 1) != FUNCTION_SUCCESS) |
|
11498 + goto error_status_set_registers; |
|
11499 + |
|
11500 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH0, 2) != FUNCTION_SUCCESS) |
|
11501 + goto error_status_set_registers; |
|
11502 + |
|
11503 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH1, 2) != FUNCTION_SUCCESS) |
|
11504 + goto error_status_set_registers; |
|
11505 + |
|
11506 + break; |
|
11507 + } |
|
11508 + |
|
11509 + |
|
11510 + return FUNCTION_SUCCESS; |
|
11511 + |
|
11512 + |
|
11513 +error_status_execute_function: |
|
11514 +error_status_set_registers: |
|
11515 + return FUNCTION_ERROR; |
|
11516 +} |
|
11517 + |
|
11518 + |
|
11519 + |
|
11520 + |
|
11521 + |
|
11522 +/** |
|
11523 + |
|
11524 +@see DVBT_NIM_FP_SET_PARAMETERS |
|
11525 + |
|
11526 +*/ |
|
11527 +int |
|
11528 +rtl2832_mt2266_SetParameters( |
|
11529 + DVBT_NIM_MODULE *pNim, |
|
11530 + unsigned long RfFreqHz, |
|
11531 + int BandwidthMode |
|
11532 + ) |
|
11533 +{ |
|
11534 + TUNER_MODULE *pTuner; |
|
11535 + DVBT_DEMOD_MODULE *pDemod; |
|
11536 + |
|
11537 + MT2266_EXTRA_MODULE *pMt2266Extra; |
|
11538 + Handle_t Mt2266Handle; |
|
11539 + unsigned long BandwidthHz; |
|
11540 + |
|
11541 + RTL2832_MT2266_EXTRA_MODULE *pRtl2832Mt2266Extra; |
|
11542 + |
|
11543 + UData_t Status; |
|
11544 + |
|
11545 + |
|
11546 + |
|
11547 + // Get tuner module and demod module. |
|
11548 + pTuner = pNim->pTuner; |
|
11549 + pDemod = pNim->pDemod; |
|
11550 + |
|
11551 + // Get tuner extra module. |
|
11552 + pMt2266Extra = (MT2266_EXTRA_MODULE *)pTuner->pExtra; |
|
11553 + |
|
11554 + // Get tuner handle. |
|
11555 + Mt2266Handle = pMt2266Extra->DeviceHandle; |
|
11556 + |
|
11557 + // Get NIM extra module. |
|
11558 + pRtl2832Mt2266Extra = (RTL2832_MT2266_EXTRA_MODULE *)pNim->pExtra; |
|
11559 + |
|
11560 + |
|
11561 + // Enable demod DVBT_IIC_REPEAT. |
|
11562 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS) |
|
11563 + goto error_status_set_registers; |
|
11564 + |
|
11565 + // Set tuner RF frequency in Hz. |
|
11566 + if(pTuner->SetRfFreqHz(pTuner, RfFreqHz) != FUNCTION_SUCCESS) |
|
11567 + goto error_status_execute_function; |
|
11568 + |
|
11569 + // Determine BandwidthHz according to bandwidth mode. |
|
11570 + switch(BandwidthMode) |
|
11571 + { |
|
11572 + default: |
|
11573 + case DVBT_BANDWIDTH_6MHZ: BandwidthHz = MT2266_BANDWIDTH_6MHZ; break; |
|
11574 + case DVBT_BANDWIDTH_7MHZ: BandwidthHz = MT2266_BANDWIDTH_7MHZ; break; |
|
11575 + case DVBT_BANDWIDTH_8MHZ: BandwidthHz = MT2266_BANDWIDTH_8MHZ; break; |
|
11576 + } |
|
11577 + |
|
11578 + // Set tuner bandwidth in Hz with BandwidthHz. |
|
11579 + if(pMt2266Extra->SetBandwidthHz(pTuner, BandwidthHz) != FUNCTION_SUCCESS) |
|
11580 + goto error_status_execute_function; |
|
11581 + |
|
11582 + // Disable demod DVBT_IIC_REPEAT. |
|
11583 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS) |
|
11584 + goto error_status_set_registers; |
|
11585 + |
|
11586 + |
|
11587 + // Set demod bandwidth mode. |
|
11588 + if(pDemod->SetBandwidthMode(pDemod, BandwidthMode) != FUNCTION_SUCCESS) |
|
11589 + goto error_status_execute_function; |
|
11590 + |
|
11591 + // Reset demod particular registers. |
|
11592 + if(pDemod->ResetFunction(pDemod) != FUNCTION_SUCCESS) |
|
11593 + goto error_status_execute_function; |
|
11594 + |
|
11595 + |
|
11596 + // Reset demod by software reset. |
|
11597 + if(pDemod->SoftwareReset(pDemod) != FUNCTION_SUCCESS) |
|
11598 + goto error_status_execute_function; |
|
11599 + |
|
11600 + // Enable demod DVBT_IIC_REPEAT. |
|
11601 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS) |
|
11602 + goto error_status_set_registers; |
|
11603 + |
|
11604 + // Reset MT2266 update procedure. |
|
11605 + Status = demod_pdcontrol_reset(pDemod, Mt2266Handle, &pRtl2832Mt2266Extra->AgcCurrentState); |
|
11606 + |
|
11607 + if(MT_IS_ERROR(Status)) |
|
11608 + goto error_status_execute_function; |
|
11609 + |
|
11610 + // Disable demod DVBT_IIC_REPEAT. |
|
11611 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS) |
|
11612 + goto error_status_set_registers; |
|
11613 + |
|
11614 + |
|
11615 + return FUNCTION_SUCCESS; |
|
11616 + |
|
11617 + |
|
11618 +error_status_execute_function: |
|
11619 +error_status_set_registers: |
|
11620 + return FUNCTION_ERROR; |
|
11621 +} |
|
11622 + |
|
11623 + |
|
11624 + |
|
11625 + |
|
11626 + |
|
11627 +/** |
|
11628 + |
|
11629 +@see DVBT_NIM_FP_UPDATE_FUNCTION |
|
11630 + |
|
11631 +*/ |
|
11632 +int |
|
11633 +rtl2832_mt2266_UpdateFunction( |
|
11634 + DVBT_NIM_MODULE *pNim |
|
11635 + ) |
|
11636 +{ |
|
11637 + TUNER_MODULE *pTuner; |
|
11638 + DVBT_DEMOD_MODULE *pDemod; |
|
11639 + MT2266_EXTRA_MODULE *pMt2266Extra; |
|
11640 + RTL2832_MT2266_EXTRA_MODULE *pRtl2832Mt2266Extra; |
|
11641 + |
|
11642 + Handle_t Mt2266Handle; |
|
11643 + UData_t Status; |
|
11644 + |
|
11645 + |
|
11646 + |
|
11647 + // Get tuner module and demod module. |
|
11648 + pTuner = pNim->pTuner; |
|
11649 + pDemod = pNim->pDemod; |
|
11650 + |
|
11651 + // Get tuner extra module and tuner handle. |
|
11652 + pMt2266Extra = (MT2266_EXTRA_MODULE *)pTuner->pExtra; |
|
11653 + pMt2266Extra->GetHandle(pTuner, &Mt2266Handle); |
|
11654 + |
|
11655 + // Get NIM extra module. |
|
11656 + pRtl2832Mt2266Extra = (RTL2832_MT2266_EXTRA_MODULE *)pNim->pExtra; |
|
11657 + |
|
11658 + |
|
11659 + // Update demod particular registers. |
|
11660 + if(pDemod->UpdateFunction(pDemod) != FUNCTION_SUCCESS) |
|
11661 + goto error_status_execute_function; |
|
11662 + |
|
11663 + |
|
11664 + // Enable demod DVBT_IIC_REPEAT. |
|
11665 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS) |
|
11666 + goto error_status_set_registers; |
|
11667 + |
|
11668 + // Update demod and tuner register setting. |
|
11669 + Status = demod_pdcontrol( |
|
11670 + pDemod, |
|
11671 + Mt2266Handle, |
|
11672 + &pRtl2832Mt2266Extra->LnaConfig, |
|
11673 + &pRtl2832Mt2266Extra->UhfSens, |
|
11674 + &pRtl2832Mt2266Extra->AgcCurrentState, |
|
11675 + (u32t *)&pRtl2832Mt2266Extra->LnaGainOld |
|
11676 + ); |
|
11677 + |
|
11678 + if(MT_IS_ERROR(Status)) |
|
11679 + goto error_status_execute_function; |
|
11680 + |
|
11681 + // Disable demod DVBT_IIC_REPEAT. |
|
11682 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS) |
|
11683 + goto error_status_set_registers; |
|
11684 + |
|
11685 + |
|
11686 + return FUNCTION_SUCCESS; |
|
11687 + |
|
11688 + |
|
11689 +error_status_execute_function: |
|
11690 +error_status_set_registers: |
|
11691 + return FUNCTION_ERROR; |
|
11692 +} |
|
11693 + |
|
11694 + |
|
11695 + |
|
11696 + |
|
11697 + |
|
11698 +// The following context is source code provided by Microtune. |
|
11699 + |
|
11700 + |
|
11701 + |
|
11702 + |
|
11703 + |
|
11704 +// Additional definition for mt_control.c |
|
11705 +UData_t |
|
11706 +demod_get_pd( |
|
11707 + handle_t demod_handle, |
|
11708 + u16t *pd_value |
|
11709 + ) |
|
11710 +{ |
|
11711 + DVBT_DEMOD_MODULE *pDemod; |
|
11712 + unsigned long RssiR; |
|
11713 + |
|
11714 + |
|
11715 + // Get demod module. |
|
11716 + pDemod = (DVBT_DEMOD_MODULE *)demod_handle; |
|
11717 + |
|
11718 + // Get RSSI_R value. |
|
11719 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_RSSI_R, &RssiR) != FUNCTION_SUCCESS) |
|
11720 + goto error_status_get_registers; |
|
11721 + |
|
11722 + // Set pd_value according to RSSI_R. |
|
11723 + *pd_value = (u16t)RssiR; |
|
11724 + |
|
11725 + |
|
11726 + return MT_OK; |
|
11727 + |
|
11728 + |
|
11729 +error_status_get_registers: |
|
11730 + return MT_COMM_ERR; |
|
11731 +} |
|
11732 + |
|
11733 + |
|
11734 + |
|
11735 +UData_t |
|
11736 +demod_get_agc( |
|
11737 + handle_t demod_handle, |
|
11738 + u16t *rf_level, |
|
11739 + u16t *bb_level |
|
11740 + ) |
|
11741 +{ |
|
11742 + DVBT_DEMOD_MODULE *pDemod; |
|
11743 + int RfAgc; |
|
11744 + int IfAgc; |
|
11745 + |
|
11746 + |
|
11747 + // Get demod module. |
|
11748 + pDemod = (DVBT_DEMOD_MODULE *)demod_handle; |
|
11749 + |
|
11750 + // Get RF and IF AGC value. |
|
11751 + if(pDemod->GetRfAgc(pDemod, &RfAgc) != FUNCTION_SUCCESS) |
|
11752 + goto error_status_get_registers; |
|
11753 + |
|
11754 + if(pDemod->GetIfAgc(pDemod, &IfAgc) != FUNCTION_SUCCESS) |
|
11755 + goto error_status_get_registers; |
|
11756 + |
|
11757 + // Convert RF and IF AGC value to proper format. |
|
11758 + *rf_level = (u16t)((RfAgc + (1 << (RTL2832_RF_AGC_REG_BIT_NUM - 1))) * |
|
11759 + (1 << (MT2266_DEMOD_ASSUMED_AGC_REG_BIT_NUM - RTL2832_RF_AGC_REG_BIT_NUM))); |
|
11760 + |
|
11761 + *bb_level = (u16t)((IfAgc + (1 << (RTL2832_IF_AGC_REG_BIT_NUM - 1))) * |
|
11762 + (1 << (MT2266_DEMOD_ASSUMED_AGC_REG_BIT_NUM - RTL2832_IF_AGC_REG_BIT_NUM))); |
|
11763 + |
|
11764 + |
|
11765 + return MT_OK; |
|
11766 + |
|
11767 + |
|
11768 +error_status_get_registers: |
|
11769 + return MT_COMM_ERR; |
|
11770 +} |
|
11771 + |
|
11772 + |
|
11773 + |
|
11774 +UData_t |
|
11775 +demod_set_bbagclim( |
|
11776 + handle_t demod_handle, |
|
11777 + int on_off_status |
|
11778 + ) |
|
11779 +{ |
|
11780 + DVBT_DEMOD_MODULE *pDemod; |
|
11781 + unsigned long IfAgcMinBinary; |
|
11782 + long IfAgcMinInt; |
|
11783 + |
|
11784 + |
|
11785 + // Get demod module. |
|
11786 + pDemod = (DVBT_DEMOD_MODULE *)demod_handle; |
|
11787 + |
|
11788 + // Get IF_AGC_MIN binary value. |
|
11789 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_IF_AGC_MIN, &IfAgcMinBinary) != FUNCTION_SUCCESS) |
|
11790 + goto error_status_get_registers; |
|
11791 + |
|
11792 + // Convert IF_AGC_MIN binary value to integer. |
|
11793 + IfAgcMinInt = BinToSignedInt(IfAgcMinBinary, RTL2832_MT2266_IF_AGC_MIN_BIT_NUM); |
|
11794 + |
|
11795 + // Modify IF_AGC_MIN integer according to on_off_status. |
|
11796 + switch(on_off_status) |
|
11797 + { |
|
11798 + case 1: |
|
11799 + |
|
11800 + IfAgcMinInt += RTL2832_MT2266_IF_AGC_MIN_INT_STEP; |
|
11801 + |
|
11802 + if(IfAgcMinInt > RTL2832_MT2266_IF_AGC_MIN_INT_MAX) |
|
11803 + IfAgcMinInt = RTL2832_MT2266_IF_AGC_MIN_INT_MAX; |
|
11804 + |
|
11805 + break; |
|
11806 + |
|
11807 + default: |
|
11808 + case 0: |
|
11809 + |
|
11810 + IfAgcMinInt -= RTL2832_MT2266_IF_AGC_MIN_INT_STEP; |
|
11811 + |
|
11812 + if(IfAgcMinInt < RTL2832_MT2266_IF_AGC_MIN_INT_MIN) |
|
11813 + IfAgcMinInt = RTL2832_MT2266_IF_AGC_MIN_INT_MIN; |
|
11814 + |
|
11815 + break; |
|
11816 + } |
|
11817 + |
|
11818 + // Convert modified IF_AGC_MIN integer to binary value. |
|
11819 + IfAgcMinBinary = SignedIntToBin(IfAgcMinInt, RTL2832_MT2266_IF_AGC_MIN_BIT_NUM); |
|
11820 + |
|
11821 + // Set IF_AGC_MIN with modified binary value. |
|
11822 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IF_AGC_MIN, IfAgcMinBinary) != FUNCTION_SUCCESS) |
|
11823 + goto error_status_set_registers; |
|
11824 + |
|
11825 + |
|
11826 + return MT_OK; |
|
11827 + |
|
11828 + |
|
11829 +error_status_set_registers: |
|
11830 +error_status_get_registers: |
|
11831 + return MT_COMM_ERR; |
|
11832 +} |
|
11833 + |
|
11834 + |
|
11835 + |
|
11836 + |
|
11837 + |
|
11838 +UData_t |
|
11839 +tuner_set_bw_normal( |
|
11840 + handle_t tuner_handle, |
|
11841 + handle_t demod_handle |
|
11842 + ) |
|
11843 +{ |
|
11844 + DVBT_DEMOD_MODULE *pDemod; |
|
11845 + |
|
11846 + int DemodBandwidthMode; |
|
11847 + unsigned int TunerBandwidthHz; |
|
11848 + unsigned int TargetTunerBandwidthHz; |
|
11849 + |
|
11850 + |
|
11851 + // Get demod module. |
|
11852 + pDemod = (DVBT_DEMOD_MODULE *)demod_handle; |
|
11853 + |
|
11854 + // Get demod bandwidth mode. |
|
11855 + if(pDemod->GetBandwidthMode(pDemod, &DemodBandwidthMode) != FUNCTION_SUCCESS) |
|
11856 + goto error_status_execute_function; |
|
11857 + |
|
11858 + // Determine tuner target bandwidth. |
|
11859 + switch(DemodBandwidthMode) |
|
11860 + { |
|
11861 + case DVBT_BANDWIDTH_6MHZ: TargetTunerBandwidthHz = MT2266_BANDWIDTH_6MHZ; break; |
|
11862 + case DVBT_BANDWIDTH_7MHZ: TargetTunerBandwidthHz = MT2266_BANDWIDTH_7MHZ; break; |
|
11863 + default: |
|
11864 + case DVBT_BANDWIDTH_8MHZ: TargetTunerBandwidthHz = MT2266_BANDWIDTH_8MHZ; break; |
|
11865 + } |
|
11866 + |
|
11867 + // Get tuner bandwidth. |
|
11868 + if(MT_IS_ERROR(MT2266_GetParam(tuner_handle, MT2266_OUTPUT_BW, &TunerBandwidthHz))) |
|
11869 + goto error_status_get_tuner_bandwidth; |
|
11870 + |
|
11871 + // Set tuner bandwidth with normal setting according to demod bandwidth mode. |
|
11872 + if(TunerBandwidthHz != TargetTunerBandwidthHz) |
|
11873 + { |
|
11874 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle, MT2266_OUTPUT_BW, TargetTunerBandwidthHz))) |
|
11875 + goto error_status_set_tuner_bandwidth; |
|
11876 + } |
|
11877 + |
|
11878 + |
|
11879 + return MT_OK; |
|
11880 + |
|
11881 + |
|
11882 +error_status_set_tuner_bandwidth: |
|
11883 +error_status_get_tuner_bandwidth: |
|
11884 +error_status_execute_function: |
|
11885 + return MT_COMM_ERR; |
|
11886 +} |
|
11887 + |
|
11888 + |
|
11889 + |
|
11890 + |
|
11891 + |
|
11892 +UData_t |
|
11893 +tuner_set_bw_narrow( |
|
11894 + handle_t tuner_handle, |
|
11895 + handle_t demod_handle |
|
11896 + ) |
|
11897 +{ |
|
11898 + DVBT_DEMOD_MODULE *pDemod; |
|
11899 + |
|
11900 + int DemodBandwidthMode; |
|
11901 + unsigned long AciDetInd; |
|
11902 + unsigned int TunerBandwidthHz; |
|
11903 + unsigned int TargetTunerBandwidthHz; |
|
11904 + |
|
11905 + |
|
11906 + // Get demod module. |
|
11907 + pDemod = (DVBT_DEMOD_MODULE *)demod_handle; |
|
11908 + |
|
11909 + // Get demod bandwidth mode. |
|
11910 + if(pDemod->GetBandwidthMode(pDemod, &DemodBandwidthMode) != FUNCTION_SUCCESS) |
|
11911 + goto error_status_execute_function; |
|
11912 + |
|
11913 + // Get demod ACI_DET_IND. |
|
11914 + if(pDemod->GetRegBitsWithPage(pDemod, DVBT_ACI_DET_IND, &AciDetInd) != FUNCTION_SUCCESS) |
|
11915 + goto error_status_get_registers; |
|
11916 + |
|
11917 + // Determine tuner target bandwidth according to ACI_DET_IND. |
|
11918 + if(AciDetInd == 0x1) |
|
11919 + { |
|
11920 + // Choose narrow target bandwidth. |
|
11921 + switch(DemodBandwidthMode) |
|
11922 + { |
|
11923 + case DVBT_BANDWIDTH_6MHZ: TargetTunerBandwidthHz = MT2266_BANDWIDTH_5MHZ; break; |
|
11924 + case DVBT_BANDWIDTH_7MHZ: TargetTunerBandwidthHz = MT2266_BANDWIDTH_6MHZ; break; |
|
11925 + default: |
|
11926 + case DVBT_BANDWIDTH_8MHZ: TargetTunerBandwidthHz = MT2266_BANDWIDTH_7MHZ; break; |
|
11927 + } |
|
11928 + } |
|
11929 + else |
|
11930 + { |
|
11931 + // Choose normal target bandwidth. |
|
11932 + switch(DemodBandwidthMode) |
|
11933 + { |
|
11934 + case DVBT_BANDWIDTH_6MHZ: TargetTunerBandwidthHz = MT2266_BANDWIDTH_6MHZ; break; |
|
11935 + case DVBT_BANDWIDTH_7MHZ: TargetTunerBandwidthHz = MT2266_BANDWIDTH_7MHZ; break; |
|
11936 + default: |
|
11937 + case DVBT_BANDWIDTH_8MHZ: TargetTunerBandwidthHz = MT2266_BANDWIDTH_8MHZ; break; |
|
11938 + } |
|
11939 + } |
|
11940 + |
|
11941 + // Get tuner bandwidth. |
|
11942 + if(MT_IS_ERROR(MT2266_GetParam(tuner_handle, MT2266_OUTPUT_BW, &TunerBandwidthHz))) |
|
11943 + goto error_status_get_tuner_bandwidth; |
|
11944 + |
|
11945 + // Set tuner bandwidth with normal setting according to demod bandwidth mode. |
|
11946 + if(TunerBandwidthHz != TargetTunerBandwidthHz) |
|
11947 + { |
|
11948 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle, MT2266_OUTPUT_BW, TargetTunerBandwidthHz))) |
|
11949 + goto error_status_set_tuner_bandwidth; |
|
11950 + } |
|
11951 + |
|
11952 + |
|
11953 + return MT_OK; |
|
11954 + |
|
11955 + |
|
11956 +error_status_set_tuner_bandwidth: |
|
11957 +error_status_get_tuner_bandwidth: |
|
11958 +error_status_get_registers: |
|
11959 +error_status_execute_function: |
|
11960 + return MT_COMM_ERR; |
|
11961 +} |
|
11962 + |
|
11963 + |
|
11964 + |
|
11965 + |
|
11966 + |
|
11967 +// Microtune source code - mt_control.c |
|
11968 + |
|
11969 + |
|
11970 + |
|
11971 +UData_t demod_pdcontrol_reset(handle_t demod_handle, handle_t tuner_handle, u8t *agc_current_state) { |
|
11972 + |
|
11973 + DVBT_DEMOD_MODULE *pDemod; |
|
11974 + unsigned long BinaryValue; |
|
11975 + |
|
11976 + |
|
11977 + // Get demod module. |
|
11978 + pDemod = (DVBT_DEMOD_MODULE *)demod_handle; |
|
11979 + |
|
11980 + // Reset AGC current state. |
|
11981 + *agc_current_state = AGC_STATE_START; |
|
11982 + |
|
11983 + // Calculate RTL2832_MT2266_IF_AGC_MIN_INT_MIN binary value. |
|
11984 + BinaryValue = SignedIntToBin(RTL2832_MT2266_IF_AGC_MIN_INT_MIN, RTL2832_MT2266_IF_AGC_MIN_BIT_NUM); |
|
11985 + |
|
11986 + // Set IF_AGC_MIN with binary value. |
|
11987 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IF_AGC_MIN, BinaryValue) != FUNCTION_SUCCESS) |
|
11988 + goto error_status_set_registers; |
|
11989 + |
|
11990 + // Set tuner bandwidth with normal setting. |
|
11991 + if(MT_IS_ERROR(tuner_set_bw_normal(tuner_handle, demod_handle))) |
|
11992 + goto error_status_set_tuner_bandwidth; |
|
11993 + |
|
11994 + |
|
11995 + return MT_OK; |
|
11996 + |
|
11997 + |
|
11998 +error_status_set_tuner_bandwidth: |
|
11999 +error_status_set_registers: |
|
12000 + return MT_COMM_ERR; |
|
12001 +} |
|
12002 + |
|
12003 + |
|
12004 + |
|
12005 +UData_t demod_pdcontrol(handle_t demod_handle, handle_t tuner_handle, u8t* lna_config, u8t* uhf_sens, |
|
12006 + u8t *agc_current_state, u32t *lna_gain_old) { |
|
12007 + |
|
12008 + u16t pd_value; |
|
12009 + u16t rf_level, bb_level; |
|
12010 + u32t lna_gain; |
|
12011 + u8t zin=0; |
|
12012 + |
|
12013 +// u8t temp[2]; |
|
12014 +// u8t agc_bb_min; |
|
12015 +// demod_data_t* local_data; |
|
12016 + |
|
12017 + |
|
12018 + u8t band=1; /* band=0: vhf, band=1: uhf low, band=2: uhf high */ |
|
12019 + u32t freq; |
|
12020 + |
|
12021 + // AGC threshold values |
|
12022 + u16t sens_on[] = {11479, 11479, 32763}; |
|
12023 + u16t sens_off[] = {36867, 36867, 44767}; |
|
12024 + u16t lin_off[] = {23619, 23619, 23619}; |
|
12025 + u16t lin_on[] = {38355, 38355, 38355}; |
|
12026 + u16t pd_upper[] = {85, 85, 85}; |
|
12027 + u16t pd_lower[] = {74, 74, 74}; |
|
12028 + u8t next_state; |
|
12029 + |
|
12030 + // demod_data_t* local_data = (demod_data_t*)demod_handle; |
|
12031 + |
|
12032 + if(MT_IS_ERROR(MT2266_GetParam(tuner_handle, MT2266_INPUT_FREQ, &freq))) goto error_status; |
|
12033 + if(MT_IS_ERROR(MT2266_GetParam(tuner_handle, MT2266_LNA_GAIN, &lna_gain))) goto error_status; |
|
12034 + if(MT_IS_ERROR(MT2266_GetReg(tuner_handle,0x1e,&zin))) goto error_status; |
|
12035 + |
|
12036 + if (freq <= 250000000) band=0; |
|
12037 + else if (freq < 660000000) band=1; |
|
12038 + else band=2; |
|
12039 + |
|
12040 + if(MT_IS_ERROR(demod_get_pd(demod_handle, &pd_value))) goto error_status; |
|
12041 + if(MT_IS_ERROR(demod_get_agc(demod_handle, &rf_level, &bb_level))) goto error_status; |
|
12042 + |
|
12043 + rf_level=0xffff-rf_level; |
|
12044 + bb_level=0xffff-bb_level; |
|
12045 + |
|
12046 +/* |
|
12047 +#ifndef _HOST_DLL |
|
12048 + uart_write_nr("St:"); |
|
12049 + uart_writedez(agc_current_state[num]); |
|
12050 + |
|
12051 + uart_write_nr(" PD: "); |
|
12052 + uart_writehex16(pd_value); |
|
12053 + |
|
12054 + uart_write_nr(" AGC: "); |
|
12055 + uart_writehex16(rf_level); |
|
12056 + uart_writehex16(bb_level); |
|
12057 +#endif |
|
12058 +*/ |
|
12059 + |
|
12060 + next_state = *agc_current_state; |
|
12061 + |
|
12062 + switch (*agc_current_state) { |
|
12063 + |
|
12064 + case AGC_STATE_START : { |
|
12065 + if ((int)lna_gain < LNAGAIN_MIN) |
|
12066 + next_state=AGC_STATE_LNAGAIN_BELOW_MIN; |
|
12067 + else if (lna_gain > LNAGAIN_MAX) |
|
12068 + next_state=AGC_STATE_LNAGAIN_ABOVE_MAX; |
|
12069 + else |
|
12070 + next_state=AGC_STATE_NORMAL; |
|
12071 + break; |
|
12072 + } |
|
12073 + |
|
12074 + case AGC_STATE_LNAGAIN_BELOW_MIN : { |
|
12075 + if ((int)lna_gain < LNAGAIN_MIN ) |
|
12076 + next_state=AGC_STATE_LNAGAIN_BELOW_MIN; |
|
12077 + else next_state=AGC_STATE_NORMAL; |
|
12078 + |
|
12079 + break; |
|
12080 + } |
|
12081 + |
|
12082 + case AGC_STATE_LNAGAIN_ABOVE_MAX : { |
|
12083 + if (lna_gain > LNAGAIN_MAX ) |
|
12084 + next_state=AGC_STATE_LNAGAIN_ABOVE_MAX; |
|
12085 + else next_state=AGC_STATE_NORMAL; |
|
12086 + break; |
|
12087 + } |
|
12088 + |
|
12089 + case AGC_STATE_NORMAL : { |
|
12090 + if (rf_level > lin_on[band] ) { |
|
12091 + *lna_gain_old = lna_gain; |
|
12092 + next_state = AGC_STATE_MAS_GRANDE_SIGNAL; |
|
12093 + } |
|
12094 + else if (pd_value > pd_upper[band]) { |
|
12095 + next_state = AGC_STATE_GRANDE_INTERFERER; |
|
12096 + } |
|
12097 + else if ( (pd_value < pd_lower[band]) && (lna_gain < LNAGAIN_MAX) ) { |
|
12098 + next_state = AGC_STATE_NO_INTERFERER; |
|
12099 + } |
|
12100 + else if ( bb_level < sens_on[band]) { |
|
12101 + next_state = AGC_STATE_SMALL_SIGNAL; |
|
12102 + } |
|
12103 + break; |
|
12104 + } |
|
12105 + |
|
12106 + case AGC_STATE_NO_INTERFERER : { |
|
12107 + if (pd_value > pd_lower[band] ) |
|
12108 + next_state = AGC_STATE_MEDIUM_INTERFERER; |
|
12109 + else if (pd_value < pd_lower[band] ) |
|
12110 + next_state = AGC_STATE_NORMAL; |
|
12111 + else if ( lna_gain == LNAGAIN_MAX ) |
|
12112 + next_state = AGC_STATE_NORMAL; |
|
12113 + break; |
|
12114 + } |
|
12115 + |
|
12116 + case AGC_STATE_MEDIUM_INTERFERER : { |
|
12117 + if (pd_value > pd_upper[band] ) |
|
12118 + next_state = AGC_STATE_GRANDE_INTERFERER; |
|
12119 + else if (pd_value < pd_lower[band] ) |
|
12120 + next_state = AGC_STATE_NO_INTERFERER; |
|
12121 + break; |
|
12122 + } |
|
12123 + |
|
12124 + |
|
12125 + case AGC_STATE_GRANDE_INTERFERER : { |
|
12126 + if (pd_value < pd_upper[band] ) |
|
12127 + next_state = AGC_STATE_MEDIUM_INTERFERER; |
|
12128 + break; |
|
12129 + } |
|
12130 + |
|
12131 + case AGC_STATE_MAS_GRANDE_SIGNAL : { |
|
12132 + if (rf_level < lin_on[band]) |
|
12133 + next_state = AGC_STATE_GRANDE_SIGNAL; |
|
12134 + else if (pd_value > pd_upper[band]) { |
|
12135 + next_state = AGC_STATE_GRANDE_INTERFERER; |
|
12136 + } |
|
12137 + break; |
|
12138 + } |
|
12139 + |
|
12140 + case AGC_STATE_MEDIUM_SIGNAL : { |
|
12141 + if (rf_level > lin_off[band]) |
|
12142 + next_state = AGC_STATE_GRANDE_SIGNAL; |
|
12143 + else if (lna_gain >= *lna_gain_old) |
|
12144 + next_state = AGC_STATE_NORMAL; |
|
12145 + else if (pd_value > pd_upper[band]) |
|
12146 + next_state = AGC_STATE_GRANDE_INTERFERER; |
|
12147 + break; |
|
12148 + } |
|
12149 + |
|
12150 + case AGC_STATE_GRANDE_SIGNAL : { |
|
12151 + if (rf_level > lin_on[band]) |
|
12152 + next_state = AGC_STATE_MAS_GRANDE_SIGNAL; |
|
12153 + else if (rf_level < lin_off[band]) |
|
12154 + next_state = AGC_STATE_MEDIUM_SIGNAL; |
|
12155 + else if (pd_value > pd_upper[band]) |
|
12156 + next_state = AGC_STATE_GRANDE_INTERFERER; |
|
12157 + break; |
|
12158 + } |
|
12159 + |
|
12160 + case AGC_STATE_SMALL_SIGNAL : { |
|
12161 + if (pd_value > pd_upper[band] ) |
|
12162 + next_state = AGC_STATE_GRANDE_INTERFERER; |
|
12163 + else if (bb_level > sens_off[band]) |
|
12164 + next_state = AGC_STATE_NORMAL; |
|
12165 + else if ( (bb_level < sens_on[band]) && (lna_gain == LNAGAIN_MAX) ) |
|
12166 + next_state = AGC_STATE_MAX_SENSITIVITY; |
|
12167 + break; |
|
12168 + } |
|
12169 + |
|
12170 + case AGC_STATE_MAX_SENSITIVITY : { |
|
12171 + if (bb_level > sens_off[band]) |
|
12172 + next_state = AGC_STATE_SMALL_SIGNAL; |
|
12173 + break; |
|
12174 + } |
|
12175 + |
|
12176 + } |
|
12177 + |
|
12178 + *agc_current_state = next_state; |
|
12179 + |
|
12180 + |
|
12181 + switch (*agc_current_state) { |
|
12182 + |
|
12183 + case AGC_STATE_LNAGAIN_BELOW_MIN : { |
|
12184 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_INCR, LNAGAIN_MAX))) goto error_status; |
|
12185 + break; |
|
12186 + } |
|
12187 + |
|
12188 + case AGC_STATE_LNAGAIN_ABOVE_MAX : { |
|
12189 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_DECR, LNAGAIN_MIN))) goto error_status; |
|
12190 + break; |
|
12191 + } |
|
12192 + |
|
12193 + case AGC_STATE_NORMAL : { |
|
12194 + if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status; |
|
12195 + if (zin >= 2) { |
|
12196 + zin -= 2; |
|
12197 + if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status; |
|
12198 + } |
|
12199 + break; |
|
12200 + } |
|
12201 + |
|
12202 + case AGC_STATE_NO_INTERFERER : { |
|
12203 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_INCR, LNAGAIN_MAX))) goto error_status; |
|
12204 + if (zin >= 2) { |
|
12205 + zin -= 2; |
|
12206 + if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status; |
|
12207 + } |
|
12208 + |
|
12209 + if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status; |
|
12210 + break; |
|
12211 + } |
|
12212 + |
|
12213 + case AGC_STATE_MEDIUM_INTERFERER : { |
|
12214 + if (zin >= 2) { |
|
12215 + zin -= 2; |
|
12216 + if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status; |
|
12217 + } |
|
12218 + |
|
12219 + // Additional setting |
|
12220 + // Set tuner with normal bandwidth. |
|
12221 + if(MT_IS_ERROR(tuner_set_bw_normal(tuner_handle, demod_handle))) goto error_status; |
|
12222 + |
|
12223 + break; |
|
12224 + } |
|
12225 + |
|
12226 + case AGC_STATE_GRANDE_INTERFERER : { |
|
12227 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_DECR, LNAGAIN_MIN))) goto error_status; |
|
12228 + if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,1))) goto error_status; |
|
12229 + |
|
12230 + // Additional setting |
|
12231 + // Set tuner with narrow bandwidth. |
|
12232 + if(MT_IS_ERROR(tuner_set_bw_narrow(tuner_handle, demod_handle))) goto error_status; |
|
12233 + |
|
12234 + break; |
|
12235 + } |
|
12236 + |
|
12237 + case AGC_STATE_MEDIUM_SIGNAL : { |
|
12238 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_INCR, LNAGAIN_MAX))) goto error_status; |
|
12239 + if (zin >= 2) { |
|
12240 + zin -= 2; |
|
12241 + if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status; |
|
12242 + } |
|
12243 + if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status; |
|
12244 + break; |
|
12245 + } |
|
12246 + |
|
12247 + case AGC_STATE_GRANDE_SIGNAL : { |
|
12248 + if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status; |
|
12249 + break; |
|
12250 + } |
|
12251 + |
|
12252 + case AGC_STATE_MAS_GRANDE_SIGNAL : { |
|
12253 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_DECR, LNAGAIN_MIN))) goto error_status; |
|
12254 + if (lna_gain==0) { |
|
12255 + if (zin <= 64) { |
|
12256 + zin += 2; |
|
12257 + if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status; |
|
12258 + } |
|
12259 + } |
|
12260 + if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status; |
|
12261 + break; |
|
12262 + } |
|
12263 + |
|
12264 + case AGC_STATE_SMALL_SIGNAL : { |
|
12265 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_LNA_GAIN_INCR, LNAGAIN_MAX))) goto error_status; |
|
12266 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_UHF_NORMAL,1))) goto error_status; |
|
12267 + if (zin >= 2) { |
|
12268 + zin -= 2; |
|
12269 + if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status; |
|
12270 + } |
|
12271 + |
|
12272 + if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status; |
|
12273 + *uhf_sens=0; |
|
12274 + break; |
|
12275 + } |
|
12276 + |
|
12277 + case AGC_STATE_MAX_SENSITIVITY : { |
|
12278 + if(MT_IS_ERROR(MT2266_SetParam(tuner_handle,MT2266_UHF_MAXSENS,1))) goto error_status; |
|
12279 + if (zin >= 2) { |
|
12280 + zin -= 2; |
|
12281 + if(MT_IS_ERROR(MT2266_SetReg(tuner_handle,0x1e,zin))) goto error_status; |
|
12282 + } |
|
12283 + if(MT_IS_ERROR(demod_set_bbagclim(demod_handle,0))) goto error_status; |
|
12284 + *uhf_sens=1; |
|
12285 + break; |
|
12286 + } |
|
12287 + } |
|
12288 + |
|
12289 + if(MT_IS_ERROR(MT2266_GetParam(tuner_handle, MT2266_LNA_GAIN,&lna_gain))) goto error_status; |
|
12290 + |
|
12291 + *lna_config=(u8t)lna_gain; |
|
12292 + |
|
12293 +/* |
|
12294 +#ifndef _HOST_DLL |
|
12295 + uart_write_nr(" LNA "); |
|
12296 + uart_writedez(lna_gain); |
|
12297 + uart_write_nr(" SENS "); |
|
12298 + uart_writedez(*uhf_sens); |
|
12299 + uart_write_nr(" Z "); |
|
12300 + uart_writedez(zin); |
|
12301 + uart_write(" "); |
|
12302 +#endif |
|
12303 +*/ |
|
12304 + |
|
12305 + |
|
12306 + |
|
12307 + return MT_OK; |
|
12308 + |
|
12309 + |
|
12310 +error_status: |
|
12311 + return MT_COMM_ERR; |
|
12312 +} |
|
12313 + |
|
12314 + |
|
12315 + |
|
12316 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/nim_rtl2832_mt2266.h |
|
12317 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
12318 +++ b/linux/drivers/media/dvb/dvb-usb/nim_rtl2832_mt2266.h Wed Oct 27 09:16:44 2010 +0200 |
|
12319 @@ -0,0 +1,266 @@ |
|
12320 +#ifndef __NIM_RTL2832_MT2266 |
|
12321 +#define __NIM_RTL2832_MT2266 |
|
12322 + |
|
12323 +/** |
|
12324 + |
|
12325 +@file |
|
12326 + |
|
12327 +@brief RTL2832 MT2266 NIM module declaration |
|
12328 + |
|
12329 +One can manipulate RTL2832 MT2266 NIM through RTL2832 MT2266 NIM module. |
|
12330 +RTL2832 MT2266 NIM module is derived from DVB-T NIM module. |
|
12331 + |
|
12332 + |
|
12333 + |
|
12334 +@par Example: |
|
12335 +@code |
|
12336 + |
|
12337 +// The example is the same as the NIM example in dvbt_nim_base.h except the listed lines. |
|
12338 + |
|
12339 + |
|
12340 + |
|
12341 +#include "nim_rtl2832_mt2266.h" |
|
12342 + |
|
12343 + |
|
12344 +... |
|
12345 + |
|
12346 + |
|
12347 + |
|
12348 +int main(void) |
|
12349 +{ |
|
12350 + DVBT_NIM_MODULE *pNim; |
|
12351 + DVBT_NIM_MODULE DvbtNimModuleMemory; |
|
12352 + RTL2832_EXTRA_MODULE Rtl2832ExtraModuleMemory; |
|
12353 + MT2266_EXTRA_MODULE Mt2266ExtraModuleMemory; |
|
12354 + |
|
12355 + ... |
|
12356 + |
|
12357 + |
|
12358 + |
|
12359 + // Build RTL2832 MT2266 NIM module. |
|
12360 + BuildRtl2832Mt2266Module( |
|
12361 + &pNim, |
|
12362 + &DvbtNimModuleMemory, |
|
12363 + |
|
12364 + 9, // Maximum I2C reading byte number is 9. |
|
12365 + 8, // Maximum I2C writing byte number is 8. |
|
12366 + CustomI2cRead, // Employ CustomI2cRead() as basic I2C reading function. |
|
12367 + CustomI2cWrite, // Employ CustomI2cWrite() as basic I2C writing function. |
|
12368 + CustomWaitMs, // Employ CustomWaitMs() as basic waiting function. |
|
12369 + |
|
12370 + &Rtl2832ExtraModuleMemory, // Employ RTL2832 extra module for RTL2832 module. |
|
12371 + 0x20, // The RTL2832 I2C device address is 0x20 in 8-bit format. |
|
12372 + CRYSTAL_FREQ_28800000HZ, // The RTL2832 crystal frequency is 28.8 MHz. |
|
12373 + RTL2832_APPLICATION_STB, // The RTL2832 application mode is STB mode. |
|
12374 + 50, // The RTL2832 update function reference period is 50 millisecond |
|
12375 + ON, // The RTL2832 Function 1 enabling status is on. |
|
12376 + |
|
12377 + &Mt2266ExtraModuleMemory, // Employ MT2266 extra module for MT2266 module. |
|
12378 + 0xc0 // The MT2266 I2C device address is 0xc0 in 8-bit format. |
|
12379 + ); |
|
12380 + |
|
12381 + |
|
12382 + |
|
12383 + // See the example for other NIM functions in dvbt_nim_base.h |
|
12384 + |
|
12385 + ... |
|
12386 + |
|
12387 + |
|
12388 + return 0; |
|
12389 +} |
|
12390 + |
|
12391 + |
|
12392 +@endcode |
|
12393 + |
|
12394 +*/ |
|
12395 + |
|
12396 + |
|
12397 +#include "demod_rtl2832.h" |
|
12398 +#include "tuner_mt2266.h" |
|
12399 +#include "dvbt_nim_base.h" |
|
12400 + |
|
12401 + |
|
12402 + |
|
12403 + |
|
12404 + |
|
12405 +// Definitions |
|
12406 +#define RTL2832_MT2266_ADDITIONAL_INIT_REG_TABLE_LEN 21 |
|
12407 + |
|
12408 +#define RTL2832_MT2266_IF_AGC_MIN_BIT_NUM 8 |
|
12409 +#define RTL2832_MT2266_IF_AGC_MIN_INT_MAX 36 |
|
12410 +#define RTL2832_MT2266_IF_AGC_MIN_INT_MIN -64 |
|
12411 +#define RTL2832_MT2266_IF_AGC_MIN_INT_STEP 0 |
|
12412 + |
|
12413 + |
|
12414 + |
|
12415 + |
|
12416 + |
|
12417 +// RTL2832 MT2266 extra module |
|
12418 +typedef struct RTL2832_MT2266_EXTRA_MODULE_TAG RTL2832_MT2266_EXTRA_MODULE; |
|
12419 +struct RTL2832_MT2266_EXTRA_MODULE_TAG |
|
12420 +{ |
|
12421 + // Extra variables |
|
12422 + unsigned char LnaConfig; |
|
12423 + unsigned char UhfSens; |
|
12424 + unsigned char AgcCurrentState; |
|
12425 + unsigned long LnaGainOld; |
|
12426 +}; |
|
12427 + |
|
12428 + |
|
12429 + |
|
12430 + |
|
12431 + |
|
12432 +// Builder |
|
12433 +void |
|
12434 +BuildRtl2832Mt2266Module( |
|
12435 + DVBT_NIM_MODULE **ppNim, // DVB-T NIM dependence |
|
12436 + DVBT_NIM_MODULE *pDvbtNimModuleMemory, |
|
12437 + RTL2832_MT2266_EXTRA_MODULE *pRtl2832Mt2266ExtraModuleMemory, |
|
12438 + |
|
12439 + unsigned char I2cReadingByteNumMax, // Base interface dependence |
|
12440 + unsigned char I2cWritingByteNumMax, |
|
12441 + BASE_FP_I2C_READ I2cRead, |
|
12442 + BASE_FP_I2C_WRITE I2cWrite, |
|
12443 + BASE_FP_WAIT_MS WaitMs, |
|
12444 + |
|
12445 + RTL2832_EXTRA_MODULE *pRtl2832ExtraModuleMemory, // Demod dependence |
|
12446 + unsigned char DemodDeviceAddr, |
|
12447 + unsigned long DemodCrystalFreqHz, |
|
12448 + int DemodAppMode, |
|
12449 + int DemodTsInterfaceMode, |
|
12450 + unsigned long DemodUpdateFuncRefPeriodMs, |
|
12451 + int DemodIsFunc1Enabled, |
|
12452 + |
|
12453 + MT2266_EXTRA_MODULE *pMt2266ExtraModuleMemory, // Tuner dependence |
|
12454 + unsigned char TunerDeviceAddr |
|
12455 + ); |
|
12456 + |
|
12457 + |
|
12458 + |
|
12459 + |
|
12460 + |
|
12461 +// RTL2832 MT2266 NIM manipulaing functions |
|
12462 +int |
|
12463 +rtl2832_mt2266_Initialize( |
|
12464 + DVBT_NIM_MODULE *pNim |
|
12465 + ); |
|
12466 + |
|
12467 +int |
|
12468 +rtl2832_mt2266_SetParameters( |
|
12469 + DVBT_NIM_MODULE *pNim, |
|
12470 + unsigned long RfFreqHz, |
|
12471 + int BandwidthMode |
|
12472 + ); |
|
12473 + |
|
12474 +int |
|
12475 +rtl2832_mt2266_UpdateFunction( |
|
12476 + DVBT_NIM_MODULE *pNim |
|
12477 + ); |
|
12478 + |
|
12479 + |
|
12480 + |
|
12481 + |
|
12482 + |
|
12483 +// The following context is source code provided by Microtune. |
|
12484 + |
|
12485 + |
|
12486 + |
|
12487 + |
|
12488 + |
|
12489 +// Additional definition for mt_control.c |
|
12490 +typedef unsigned char u8t; |
|
12491 +typedef unsigned short u16t; |
|
12492 +typedef unsigned long u32t; |
|
12493 +typedef void * handle_t; |
|
12494 + |
|
12495 +#define MT2266_DEMOD_ASSUMED_AGC_REG_BIT_NUM 16 |
|
12496 + |
|
12497 + |
|
12498 + |
|
12499 +// Microtune source code - mt_control.c |
|
12500 + |
|
12501 + |
|
12502 + |
|
12503 +/* $Id: mt_control.c,v 1.6 2008/01/02 12:04:39 tune\tpinz Exp $ */ |
|
12504 +/*! |
|
12505 + * \file mt_control.c |
|
12506 + * \author Thomas Pinz, Microtune GmbH&Co KG |
|
12507 + * \author Marie-Curie-Str. 1, 85055 Ingolstadt |
|
12508 + * \author E-Mail: thomas.pinz@microtune.com |
|
12509 + */ |
|
12510 + |
|
12511 + |
|
12512 +#define LNAGAIN_MIN 0 |
|
12513 +#define LNAGAIN_MAX 14 |
|
12514 + |
|
12515 +#define AGC_STATE_START 0 |
|
12516 +#define AGC_STATE_LNAGAIN_BELOW_MIN 1 |
|
12517 +#define AGC_STATE_LNAGAIN_ABOVE_MAX 2 |
|
12518 +#define AGC_STATE_NORMAL 3 |
|
12519 +#define AGC_STATE_NO_INTERFERER 4 |
|
12520 +#define AGC_STATE_MEDIUM_INTERFERER 5 |
|
12521 +#define AGC_STATE_GRANDE_INTERFERER 6 |
|
12522 +#define AGC_STATE_MEDIUM_SIGNAL 7 |
|
12523 +#define AGC_STATE_GRANDE_SIGNAL 8 |
|
12524 +#define AGC_STATE_MAS_GRANDE_SIGNAL 9 |
|
12525 +#define AGC_STATE_MAX_SENSITIVITY 10 |
|
12526 +#define AGC_STATE_SMALL_SIGNAL 11 |
|
12527 + |
|
12528 + |
|
12529 +UData_t |
|
12530 +demod_get_pd( |
|
12531 + handle_t demod_handle, |
|
12532 + u16t *pd_value |
|
12533 + ); |
|
12534 + |
|
12535 +UData_t |
|
12536 +demod_get_agc( |
|
12537 + handle_t demod_handle, |
|
12538 + u16t *rf_level, |
|
12539 + u16t *bb_level |
|
12540 + ); |
|
12541 + |
|
12542 +UData_t |
|
12543 +demod_set_bbagclim( |
|
12544 + handle_t demod_handle, |
|
12545 + int on_off_status |
|
12546 + ); |
|
12547 + |
|
12548 +UData_t |
|
12549 +tuner_set_bw_normal( |
|
12550 + handle_t tuner_handle, |
|
12551 + handle_t demod_handle |
|
12552 + ); |
|
12553 + |
|
12554 +UData_t |
|
12555 +tuner_set_bw_narrow( |
|
12556 + handle_t tuner_handle, |
|
12557 + handle_t demod_handle |
|
12558 + ); |
|
12559 + |
|
12560 +UData_t |
|
12561 +demod_pdcontrol_reset( |
|
12562 + handle_t demod_handle, |
|
12563 + handle_t tuner_handle, |
|
12564 + u8t *agc_current_state |
|
12565 + ); |
|
12566 + |
|
12567 +UData_t |
|
12568 +demod_pdcontrol( |
|
12569 + handle_t demod_handle, |
|
12570 + handle_t tuner_handle, |
|
12571 + u8t* lna_config, |
|
12572 + u8t* uhf_sens, |
|
12573 + u8t *agc_current_state, |
|
12574 + u32t *lna_gain_old |
|
12575 + ); |
|
12576 + |
|
12577 + |
|
12578 + |
|
12579 + |
|
12580 + |
|
12581 + |
|
12582 + |
|
12583 +#endif |
|
12584 + |
|
12585 + |
|
12586 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/nim_rtl2832_mxl5007t.c |
|
12587 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
12588 +++ b/linux/drivers/media/dvb/dvb-usb/nim_rtl2832_mxl5007t.c Wed Oct 27 09:16:44 2010 +0200 |
|
12589 @@ -0,0 +1,397 @@ |
|
12590 +/** |
|
12591 + |
|
12592 +@file |
|
12593 + |
|
12594 +@brief RTL2832 MxL5007T NIM module definition |
|
12595 + |
|
12596 +One can manipulate RTL2832 MxL5007T NIM through RTL2832 MxL5007T NIM module. |
|
12597 +RTL2832 MxL5007T NIM module is derived from DVB-T NIM module. |
|
12598 + |
|
12599 +*/ |
|
12600 + |
|
12601 + |
|
12602 +#include "nim_rtl2832_mxl5007t.h" |
|
12603 + |
|
12604 + |
|
12605 + |
|
12606 + |
|
12607 + |
|
12608 +/** |
|
12609 + |
|
12610 +@brief RTL2832 MxL5007T NIM module builder |
|
12611 + |
|
12612 +Use BuildRtl2832Mxl5007tModule() to build RTL2832 MxL5007T NIM module, set all module function pointers with the |
|
12613 +corresponding functions, and initialize module private variables. |
|
12614 + |
|
12615 + |
|
12616 +@param [in] ppNim Pointer to RTL2832 MxL5007T NIM module pointer |
|
12617 +@param [in] pDvbtNimModuleMemory Pointer to an allocated DVB-T NIM module memory |
|
12618 +@param [in] I2cReadingByteNumMax Maximum I2C reading byte number for basic I2C reading function |
|
12619 +@param [in] I2cWritingByteNumMax Maximum I2C writing byte number for basic I2C writing function |
|
12620 +@param [in] I2cRead Basic I2C reading function pointer |
|
12621 +@param [in] I2cWrite Basic I2C writing function pointer |
|
12622 +@param [in] WaitMs Basic waiting function pointer |
|
12623 +@param [in] pRtl2832ExtraModuleMemory Pointer to an allocated RTL2832 extra module memory |
|
12624 +@param [in] DemodDeviceAddr RTL2832 I2C device address |
|
12625 +@param [in] DemodCrystalFreqHz RTL2832 crystal frequency in Hz |
|
12626 +@param [in] DemodAppMode RTL2832 application mode for setting |
|
12627 +@param [in] DemodTsInterfaceMode RTL2832 TS interface mode for setting |
|
12628 +@param [in] DemodUpdateFuncRefPeriodMs RTL2832 update function reference period in millisecond for setting |
|
12629 +@param [in] DemodIsFunc1Enabled RTL2832 Function 1 enabling status for setting |
|
12630 +@param [in] pMxl5007tExtraModuleMemory Pointer to an allocated Mxl5007T extra module memory |
|
12631 +@param [in] TunerDeviceAddr Mxl5007T I2C device address |
|
12632 +@param [in] TunerAgcMode Mxl5007T AGC mode |
|
12633 + |
|
12634 + |
|
12635 +@note |
|
12636 + -# One should call BuildRtl2832Mxl5007tModule() to build RTL2832 MxL5007T NIM module before using it. |
|
12637 + |
|
12638 +*/ |
|
12639 +void |
|
12640 +BuildRtl2832Mxl5007tModule( |
|
12641 + DVBT_NIM_MODULE **ppNim, // DVB-T NIM dependence |
|
12642 + DVBT_NIM_MODULE *pDvbtNimModuleMemory, |
|
12643 + |
|
12644 + unsigned char I2cReadingByteNumMax, // Base interface dependence |
|
12645 + unsigned char I2cWritingByteNumMax, |
|
12646 + BASE_FP_I2C_READ I2cRead, |
|
12647 + BASE_FP_I2C_WRITE I2cWrite, |
|
12648 + BASE_FP_WAIT_MS WaitMs, |
|
12649 + |
|
12650 + RTL2832_EXTRA_MODULE *pRtl2832ExtraModuleMemory, // Demod dependence |
|
12651 + unsigned char DemodDeviceAddr, |
|
12652 + unsigned long DemodCrystalFreqHz, |
|
12653 + int DemodAppMode, |
|
12654 + int DemodTsInterfaceMode, |
|
12655 + unsigned long DemodUpdateFuncRefPeriodMs, |
|
12656 + int DemodIsFunc1Enabled, |
|
12657 + |
|
12658 + MXL5007T_EXTRA_MODULE *pMxl5007tExtraModuleMemory, // Tuner dependence |
|
12659 + unsigned char TunerDeviceAddr, |
|
12660 + unsigned long TunerCrystalFreqHz, |
|
12661 + int TunerClkOutMode, |
|
12662 + int TunerClkOutAmpMode |
|
12663 + ) |
|
12664 +{ |
|
12665 + DVBT_NIM_MODULE *pNim; |
|
12666 + |
|
12667 + |
|
12668 + |
|
12669 + // Set NIM module pointer with NIM module memory. |
|
12670 + *ppNim = pDvbtNimModuleMemory; |
|
12671 + |
|
12672 + // Get NIM module. |
|
12673 + pNim = *ppNim; |
|
12674 + |
|
12675 + // Set I2C bridge module pointer with I2C bridge module memory. |
|
12676 + pNim->pI2cBridge = &pNim->I2cBridgeModuleMemory; |
|
12677 + |
|
12678 + // Set NIM extra module pointer. |
|
12679 + pNim->pExtra = INVALID_POINTER_VALUE; |
|
12680 + |
|
12681 + |
|
12682 + // Set NIM type. |
|
12683 + pNim->NimType = DVBT_NIM_RTL2832_MXL5007T; |
|
12684 + |
|
12685 + |
|
12686 + // Build base interface module. |
|
12687 + BuildBaseInterface( |
|
12688 + &pNim->pBaseInterface, |
|
12689 + &pNim->BaseInterfaceModuleMemory, |
|
12690 + I2cReadingByteNumMax, |
|
12691 + I2cWritingByteNumMax, |
|
12692 + I2cRead, |
|
12693 + I2cWrite, |
|
12694 + WaitMs |
|
12695 + ); |
|
12696 + |
|
12697 + // Build RTL2832 demod module. |
|
12698 + BuildRtl2832Module( |
|
12699 + &pNim->pDemod, |
|
12700 + &pNim->DvbtDemodModuleMemory, |
|
12701 + pRtl2832ExtraModuleMemory, |
|
12702 + &pNim->BaseInterfaceModuleMemory, |
|
12703 + &pNim->I2cBridgeModuleMemory, |
|
12704 + DemodDeviceAddr, |
|
12705 + DemodCrystalFreqHz, |
|
12706 + DemodAppMode, |
|
12707 + DemodUpdateFuncRefPeriodMs, |
|
12708 + DemodIsFunc1Enabled |
|
12709 + ); |
|
12710 + |
|
12711 + // Build Mxl5007T tuner module. |
|
12712 + BuildMxl5007tModule( |
|
12713 + &pNim->pTuner, |
|
12714 + &pNim->TunerModuleMemory, |
|
12715 + pMxl5007tExtraModuleMemory, |
|
12716 + &pNim->BaseInterfaceModuleMemory, |
|
12717 + &pNim->I2cBridgeModuleMemory, |
|
12718 + TunerDeviceAddr, |
|
12719 + TunerCrystalFreqHz, |
|
12720 + RTL2832_MXL5007T_STANDARD_MODE_DEFAULT, |
|
12721 + RTL2832_MXL5007T_IF_FREQ_HZ_DEFAULT, |
|
12722 + RTL2832_MXL5007T_SPECTRUM_MODE_DEFAULT, |
|
12723 + TunerClkOutMode, |
|
12724 + TunerClkOutAmpMode, |
|
12725 + RTL2832_MXL5007T_QAM_IF_DIFF_OUT_LEVEL_DEFAULT |
|
12726 + ); |
|
12727 + |
|
12728 + |
|
12729 + // Set NIM module variables. |
|
12730 + pNim->DemodTsInterfaceMode = DemodTsInterfaceMode; |
|
12731 + |
|
12732 + |
|
12733 + // Set NIM module function pointers with default functions. |
|
12734 + pNim->GetNimType = dvbt_nim_default_GetNimType; |
|
12735 + pNim->GetParameters = dvbt_nim_default_GetParameters; |
|
12736 + pNim->IsSignalPresent = dvbt_nim_default_IsSignalPresent; |
|
12737 + pNim->IsSignalLocked = dvbt_nim_default_IsSignalLocked; |
|
12738 + pNim->GetSignalStrength = dvbt_nim_default_GetSignalStrength; |
|
12739 + pNim->GetSignalQuality = dvbt_nim_default_GetSignalQuality; |
|
12740 + pNim->GetBer = dvbt_nim_default_GetBer; |
|
12741 + pNim->GetSnrDb = dvbt_nim_default_GetSnrDb; |
|
12742 + pNim->GetTrOffsetPpm = dvbt_nim_default_GetTrOffsetPpm; |
|
12743 + pNim->GetCrOffsetHz = dvbt_nim_default_GetCrOffsetHz; |
|
12744 + pNim->GetTpsInfo = dvbt_nim_default_GetTpsInfo; |
|
12745 + pNim->UpdateFunction = dvbt_nim_default_UpdateFunction; |
|
12746 + |
|
12747 + // Set NIM module function pointers with particular functions. |
|
12748 + pNim->Initialize = rtl2832_mxl5007t_Initialize; |
|
12749 + pNim->SetParameters = rtl2832_mxl5007t_SetParameters; |
|
12750 + |
|
12751 + |
|
12752 + return; |
|
12753 +} |
|
12754 + |
|
12755 + |
|
12756 + |
|
12757 + |
|
12758 + |
|
12759 +/** |
|
12760 + |
|
12761 +@see DVBT_NIM_FP_INITIALIZE |
|
12762 + |
|
12763 +*/ |
|
12764 +int |
|
12765 +rtl2832_mxl5007t_Initialize( |
|
12766 + DVBT_NIM_MODULE *pNim |
|
12767 + ) |
|
12768 +{ |
|
12769 + typedef struct |
|
12770 + { |
|
12771 + int RegBitName; |
|
12772 + unsigned long Value; |
|
12773 + } |
|
12774 + REG_VALUE_ENTRY; |
|
12775 + |
|
12776 + |
|
12777 + static const REG_VALUE_ENTRY AdditionalInitRegValueTable[RTL2832_MXL5007T_ADDITIONAL_INIT_REG_TABLE_LEN] = |
|
12778 + { |
|
12779 + // RegBitName, Value |
|
12780 + {DVBT_DAGC_TRG_VAL, 0x39 }, |
|
12781 + {DVBT_AGC_TARG_VAL_0, 0x0 }, |
|
12782 + {DVBT_AGC_TARG_VAL_8_1, 0x32 }, |
|
12783 + {DVBT_AAGC_LOOP_GAIN, 0x16 }, |
|
12784 + {DVBT_LOOP_GAIN2_3_0, 0x6 }, |
|
12785 + {DVBT_LOOP_GAIN2_4, 0x1 }, |
|
12786 + {DVBT_LOOP_GAIN3, 0x16 }, |
|
12787 + {DVBT_VTOP1, 0x35 }, |
|
12788 + {DVBT_VTOP2, 0x21 }, |
|
12789 + {DVBT_VTOP3, 0x21 }, |
|
12790 + {DVBT_KRF1, 0x0 }, |
|
12791 + {DVBT_KRF2, 0x40 }, |
|
12792 + {DVBT_KRF3, 0x10 }, |
|
12793 + {DVBT_KRF4, 0x10 }, |
|
12794 + {DVBT_IF_AGC_MIN, 0x80 }, |
|
12795 + {DVBT_IF_AGC_MAX, 0x7f }, |
|
12796 + {DVBT_RF_AGC_MIN, 0x80 }, |
|
12797 + {DVBT_RF_AGC_MAX, 0x7f }, |
|
12798 + {DVBT_POLAR_RF_AGC, 0x0 }, |
|
12799 + {DVBT_POLAR_IF_AGC, 0x0 }, |
|
12800 + {DVBT_AD7_SETTING, 0xe9d4 }, |
|
12801 + {DVBT_AD_EN_REG1, 0x0 }, |
|
12802 + {DVBT_CKOUT_PWR_PID, 0x0 }, |
|
12803 + }; |
|
12804 + |
|
12805 + |
|
12806 + TUNER_MODULE *pTuner; |
|
12807 + DVBT_DEMOD_MODULE *pDemod; |
|
12808 + |
|
12809 + int i; |
|
12810 + |
|
12811 + int RegBitName; |
|
12812 + unsigned long Value; |
|
12813 + |
|
12814 + |
|
12815 + |
|
12816 + // Get tuner module and demod module. |
|
12817 + pTuner = pNim->pTuner; |
|
12818 + pDemod = pNim->pDemod; |
|
12819 + |
|
12820 + |
|
12821 + // Enable demod DVBT_IIC_REPEAT. |
|
12822 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS) |
|
12823 + goto error_status_set_registers; |
|
12824 + |
|
12825 + // Initialize tuner. |
|
12826 + if(pTuner->Initialize(pTuner) != FUNCTION_SUCCESS) |
|
12827 + goto error_status_execute_function; |
|
12828 + |
|
12829 + // Disable demod DVBT_IIC_REPEAT. |
|
12830 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS) |
|
12831 + goto error_status_set_registers; |
|
12832 + |
|
12833 + |
|
12834 + // Initialize demod. |
|
12835 + if(pDemod->Initialize(pDemod) != FUNCTION_SUCCESS) |
|
12836 + goto error_status_execute_function; |
|
12837 + |
|
12838 + // Set demod IF frequency with NIM default. |
|
12839 + if(pDemod->SetIfFreqHz(pDemod, RTL2832_MXL5007T_IF_FREQ_HZ_DEFAULT) != FUNCTION_SUCCESS) |
|
12840 + goto error_status_execute_function; |
|
12841 + |
|
12842 + // Set demod spectrum mode with NIM default. |
|
12843 + if(pDemod->SetSpectrumMode(pDemod, RTL2832_MXL5007T_SPECTRUM_MODE_DEFAULT) != FUNCTION_SUCCESS) |
|
12844 + goto error_status_execute_function; |
|
12845 + |
|
12846 + |
|
12847 + // Set demod registers. |
|
12848 + for(i = 0; i < RTL2832_MXL5007T_ADDITIONAL_INIT_REG_TABLE_LEN; i++) |
|
12849 + { |
|
12850 + // Get register bit name and its value. |
|
12851 + RegBitName = AdditionalInitRegValueTable[i].RegBitName; |
|
12852 + Value = AdditionalInitRegValueTable[i].Value; |
|
12853 + |
|
12854 + // Set demod registers |
|
12855 + if(pDemod->SetRegBitsWithPage(pDemod, RegBitName, Value) != FUNCTION_SUCCESS) |
|
12856 + goto error_status_set_registers; |
|
12857 + } |
|
12858 + |
|
12859 + |
|
12860 + // Set TS interface according to TS interface mode. |
|
12861 + switch(pNim->DemodTsInterfaceMode) |
|
12862 + { |
|
12863 + case TS_INTERFACE_PARALLEL: |
|
12864 + |
|
12865 + // Set demod TS interface with parallel mode. |
|
12866 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SERIAL, 0) != FUNCTION_SUCCESS) |
|
12867 + goto error_status_set_registers; |
|
12868 + |
|
12869 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH0, 9) != FUNCTION_SUCCESS) |
|
12870 + goto error_status_set_registers; |
|
12871 + |
|
12872 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH1, 9) != FUNCTION_SUCCESS) |
|
12873 + goto error_status_set_registers; |
|
12874 + |
|
12875 + break; |
|
12876 + |
|
12877 + |
|
12878 + default: |
|
12879 + case TS_INTERFACE_SERIAL: |
|
12880 + |
|
12881 + // Set demod TS interface with serial mode. |
|
12882 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SERIAL, 1) != FUNCTION_SUCCESS) |
|
12883 + goto error_status_set_registers; |
|
12884 + |
|
12885 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH0, 2) != FUNCTION_SUCCESS) |
|
12886 + goto error_status_set_registers; |
|
12887 + |
|
12888 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH1, 2) != FUNCTION_SUCCESS) |
|
12889 + goto error_status_set_registers; |
|
12890 + |
|
12891 + break; |
|
12892 + } |
|
12893 + |
|
12894 + |
|
12895 + return FUNCTION_SUCCESS; |
|
12896 + |
|
12897 + |
|
12898 +error_status_execute_function: |
|
12899 +error_status_set_registers: |
|
12900 + return FUNCTION_ERROR; |
|
12901 +} |
|
12902 + |
|
12903 + |
|
12904 + |
|
12905 + |
|
12906 + |
|
12907 +/** |
|
12908 + |
|
12909 +@see DVBT_NIM_FP_SET_PARAMETERS |
|
12910 + |
|
12911 +*/ |
|
12912 +int |
|
12913 +rtl2832_mxl5007t_SetParameters( |
|
12914 + DVBT_NIM_MODULE *pNim, |
|
12915 + unsigned long RfFreqHz, |
|
12916 + int BandwidthMode |
|
12917 + ) |
|
12918 +{ |
|
12919 + TUNER_MODULE *pTuner; |
|
12920 + DVBT_DEMOD_MODULE *pDemod; |
|
12921 + |
|
12922 + MXL5007T_EXTRA_MODULE *pTunerExtra; |
|
12923 + int TunerBandwidthMode; |
|
12924 + |
|
12925 + |
|
12926 + |
|
12927 + // Get tuner module and demod module. |
|
12928 + pTuner = pNim->pTuner; |
|
12929 + pDemod = pNim->pDemod; |
|
12930 + |
|
12931 + // Get tuner extra module. |
|
12932 + pTunerExtra = (MXL5007T_EXTRA_MODULE *)pTuner->pExtra; |
|
12933 + |
|
12934 + |
|
12935 + // Enable demod DVBT_IIC_REPEAT. |
|
12936 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS) |
|
12937 + goto error_status_set_registers; |
|
12938 + |
|
12939 + // Set tuner RF frequency in Hz. |
|
12940 + if(pTuner->SetRfFreqHz(pTuner, RfFreqHz) != FUNCTION_SUCCESS) |
|
12941 + goto error_status_execute_function; |
|
12942 + |
|
12943 + // Determine TunerBandwidthMode according to bandwidth mode. |
|
12944 + switch(BandwidthMode) |
|
12945 + { |
|
12946 + default: |
|
12947 + case DVBT_BANDWIDTH_6MHZ: TunerBandwidthMode = MXL5007T_BANDWIDTH_6000000HZ; break; |
|
12948 + case DVBT_BANDWIDTH_7MHZ: TunerBandwidthMode = MXL5007T_BANDWIDTH_7000000HZ; break; |
|
12949 + case DVBT_BANDWIDTH_8MHZ: TunerBandwidthMode = MXL5007T_BANDWIDTH_8000000HZ; break; |
|
12950 + } |
|
12951 + |
|
12952 + // Set tuner bandwidth mode with TunerBandwidthMode. |
|
12953 + if(pTunerExtra->SetBandwidthMode(pTuner, TunerBandwidthMode) != FUNCTION_SUCCESS) |
|
12954 + goto error_status_execute_function; |
|
12955 + |
|
12956 + // Disable demod DVBT_IIC_REPEAT. |
|
12957 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS) |
|
12958 + goto error_status_set_registers; |
|
12959 + |
|
12960 + |
|
12961 + // Set demod bandwidth mode. |
|
12962 + if(pDemod->SetBandwidthMode(pDemod, BandwidthMode) != FUNCTION_SUCCESS) |
|
12963 + goto error_status_execute_function; |
|
12964 + |
|
12965 + // Reset demod particular registers. |
|
12966 + if(pDemod->ResetFunction(pDemod) != FUNCTION_SUCCESS) |
|
12967 + goto error_status_execute_function; |
|
12968 + |
|
12969 + |
|
12970 + // Reset demod by software reset. |
|
12971 + if(pDemod->SoftwareReset(pDemod) != FUNCTION_SUCCESS) |
|
12972 + goto error_status_execute_function; |
|
12973 + |
|
12974 + |
|
12975 + return FUNCTION_SUCCESS; |
|
12976 + |
|
12977 + |
|
12978 +error_status_execute_function: |
|
12979 +error_status_set_registers: |
|
12980 + return FUNCTION_ERROR; |
|
12981 +} |
|
12982 + |
|
12983 + |
|
12984 + |
|
12985 + |
|
12986 + |
|
12987 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/nim_rtl2832_mxl5007t.h |
|
12988 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
12989 +++ b/linux/drivers/media/dvb/dvb-usb/nim_rtl2832_mxl5007t.h Wed Oct 27 09:16:44 2010 +0200 |
|
12990 @@ -0,0 +1,155 @@ |
|
12991 +#ifndef __NIM_RTL2832_MXL5007T |
|
12992 +#define __NIM_RTL2832_MXL5007T |
|
12993 + |
|
12994 +/** |
|
12995 + |
|
12996 +@file |
|
12997 + |
|
12998 +@brief RTL2832 MxL5007T NIM module declaration |
|
12999 + |
|
13000 +One can manipulate RTL2832 MxL5007T NIM through RTL2832 MxL5007T NIM module. |
|
13001 +RTL2832 MxL5007T NIM module is derived from DVB-T NIM module. |
|
13002 + |
|
13003 + |
|
13004 + |
|
13005 +@par Example: |
|
13006 +@code |
|
13007 + |
|
13008 +// The example is the same as the NIM example in dvbt_nim_base.h except the listed lines. |
|
13009 + |
|
13010 + |
|
13011 + |
|
13012 +#include "nim_rtl2832_mxl5007t.h" |
|
13013 + |
|
13014 + |
|
13015 +... |
|
13016 + |
|
13017 + |
|
13018 + |
|
13019 +int main(void) |
|
13020 +{ |
|
13021 + DVBT_NIM_MODULE *pNim; |
|
13022 + DVBT_NIM_MODULE DvbtNimModuleMemory; |
|
13023 + RTL2832_EXTRA_MODULE Rtl2832ExtraModuleMemory; |
|
13024 + MXL5007T_EXTRA_MODULE Mxl5007tExtraModuleMemory; |
|
13025 + |
|
13026 + ... |
|
13027 + |
|
13028 + |
|
13029 + |
|
13030 + // Build RTL2832 MxL5007T NIM module. |
|
13031 + BuildRtl2832Mxl5007tModule( |
|
13032 + &pNim, |
|
13033 + &DvbtNimModuleMemory, |
|
13034 + |
|
13035 + 9, // Maximum I2C reading byte number is 9. |
|
13036 + 8, // Maximum I2C writing byte number is 8. |
|
13037 + CustomI2cRead, // Employ CustomI2cRead() as basic I2C reading function. |
|
13038 + CustomI2cWrite, // Employ CustomI2cWrite() as basic I2C writing function. |
|
13039 + CustomWaitMs, // Employ CustomWaitMs() as basic waiting function. |
|
13040 + |
|
13041 + &Rtl2832ExtraModuleMemory, // Employ RTL2832 extra module for RTL2832 module. |
|
13042 + 0x20, // The RTL2832 I2C device address is 0x20 in 8-bit format. |
|
13043 + CRYSTAL_FREQ_28800000HZ, // The RTL2832 crystal frequency is 28.8 MHz. |
|
13044 + RTL2832_APPLICATION_STB, // The RTL2832 application mode is STB mode. |
|
13045 + TS_INTERFACE_SERIAL, // The RTL2832 TS interface mode is serial. |
|
13046 + 50, // The RTL2832 update function reference period is 50 millisecond |
|
13047 + ON, // The RTL2832 Function 1 enabling status is on. |
|
13048 + |
|
13049 + &Mxl5007tExtraModuleMemory, // Employ Mxl5007T extra module for Mxl5007T module. |
|
13050 + 0xc0, // The MxL5007T I2C device address is 0xc0 in 8-bit format. |
|
13051 + CRYSTAL_FREQ_16000000HZ, // The MxL5007T Crystal frequency is 16.0 MHz. |
|
13052 + MXL5007T_CLK_OUT_DISABLE, // The MxL5007T clock output mode is disabled. |
|
13053 + MXL5007T_CLK_OUT_AMP_0 // The MxL5007T clock output amplitude is 0. |
|
13054 + ); |
|
13055 + |
|
13056 + |
|
13057 + |
|
13058 + // See the example for other NIM functions in dvbt_nim_base.h |
|
13059 + |
|
13060 + ... |
|
13061 + |
|
13062 + |
|
13063 + return 0; |
|
13064 +} |
|
13065 + |
|
13066 + |
|
13067 +@endcode |
|
13068 + |
|
13069 +*/ |
|
13070 + |
|
13071 + |
|
13072 +#include "demod_rtl2832.h" |
|
13073 +#include "tuner_mxl5007t.h" |
|
13074 +#include "dvbt_nim_base.h" |
|
13075 + |
|
13076 + |
|
13077 + |
|
13078 + |
|
13079 + |
|
13080 +// Definitions |
|
13081 +#define RTL2832_MXL5007T_ADDITIONAL_INIT_REG_TABLE_LEN 23 |
|
13082 + |
|
13083 +// Default |
|
13084 +#define RTL2832_MXL5007T_STANDARD_MODE_DEFAULT MXL5007T_STANDARD_DVBT |
|
13085 +#define RTL2832_MXL5007T_IF_FREQ_HZ_DEFAULT IF_FREQ_4570000HZ |
|
13086 +#define RTL2832_MXL5007T_SPECTRUM_MODE_DEFAULT SPECTRUM_NORMAL |
|
13087 +#define RTL2832_MXL5007T_QAM_IF_DIFF_OUT_LEVEL_DEFAULT 0 |
|
13088 + |
|
13089 + |
|
13090 + |
|
13091 + |
|
13092 + |
|
13093 +// Builder |
|
13094 +void |
|
13095 +BuildRtl2832Mxl5007tModule( |
|
13096 + DVBT_NIM_MODULE **ppNim, // DVB-T NIM dependence |
|
13097 + DVBT_NIM_MODULE *pDvbtNimModuleMemory, |
|
13098 + |
|
13099 + unsigned char I2cReadingByteNumMax, // Base interface dependence |
|
13100 + unsigned char I2cWritingByteNumMax, |
|
13101 + BASE_FP_I2C_READ I2cRead, |
|
13102 + BASE_FP_I2C_WRITE I2cWrite, |
|
13103 + BASE_FP_WAIT_MS WaitMs, |
|
13104 + |
|
13105 + RTL2832_EXTRA_MODULE *pRtl2832ExtraModuleMemory, // Demod dependence |
|
13106 + unsigned char DemodDeviceAddr, |
|
13107 + unsigned long DemodCrystalFreqHz, |
|
13108 + int DemodAppMode, |
|
13109 + int DemodTsInterfaceMode, |
|
13110 + unsigned long DemodUpdateFuncRefPeriodMs, |
|
13111 + int DemodIsFunc1Enabled, |
|
13112 + |
|
13113 + MXL5007T_EXTRA_MODULE *pMxl5007tExtraModuleMemory, // Tuner dependence |
|
13114 + unsigned char TunerDeviceAddr, |
|
13115 + unsigned long TunerCrystalFreqHz, |
|
13116 + int TunerClkOutMode, |
|
13117 + int TunerClkOutAmpMode |
|
13118 + ); |
|
13119 + |
|
13120 + |
|
13121 + |
|
13122 + |
|
13123 + |
|
13124 +// RTL2832 MxL5007T NIM manipulaing functions |
|
13125 +int |
|
13126 +rtl2832_mxl5007t_Initialize( |
|
13127 + DVBT_NIM_MODULE *pNim |
|
13128 + ); |
|
13129 + |
|
13130 +int |
|
13131 +rtl2832_mxl5007t_SetParameters( |
|
13132 + DVBT_NIM_MODULE *pNim, |
|
13133 + unsigned long RfFreqHz, |
|
13134 + int BandwidthMode |
|
13135 + ); |
|
13136 + |
|
13137 + |
|
13138 + |
|
13139 + |
|
13140 + |
|
13141 + |
|
13142 + |
|
13143 +#endif |
|
13144 + |
|
13145 + |
|
13146 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/nim_rtl2832_tua9001.c |
|
13147 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
13148 +++ b/linux/drivers/media/dvb/dvb-usb/nim_rtl2832_tua9001.c Wed Oct 27 09:16:44 2010 +0200 |
|
13149 @@ -0,0 +1,386 @@ |
|
13150 +/** |
|
13151 + |
|
13152 +@file |
|
13153 + |
|
13154 +@brief RTL2832 TUA9001 NIM module definition |
|
13155 + |
|
13156 +One can manipulate RTL2832 TUA9001 NIM through RTL2832 TUA9001 NIM module. |
|
13157 +RTL2832 TUA9001 NIM module is derived from DVB-T NIM module. |
|
13158 + |
|
13159 +*/ |
|
13160 + |
|
13161 + |
|
13162 +#include "nim_rtl2832_tua9001.h" |
|
13163 + |
|
13164 + |
|
13165 + |
|
13166 + |
|
13167 + |
|
13168 +/** |
|
13169 + |
|
13170 +@brief RTL2832 TUA9001 NIM module builder |
|
13171 + |
|
13172 +Use BuildRtl2832Tua9001Module() to build RTL2832 TUA9001 NIM module, set all module function pointers with the |
|
13173 +corresponding functions, and initialize module private variables. |
|
13174 + |
|
13175 + |
|
13176 +@param [in] ppNim Pointer to RTL2832 TUA9001 NIM module pointer |
|
13177 +@param [in] pDvbtNimModuleMemory Pointer to an allocated DVB-T NIM module memory |
|
13178 +@param [in] I2cReadingByteNumMax Maximum I2C reading byte number for basic I2C reading function |
|
13179 +@param [in] I2cWritingByteNumMax Maximum I2C writing byte number for basic I2C writing function |
|
13180 +@param [in] I2cRead Basic I2C reading function pointer |
|
13181 +@param [in] I2cWrite Basic I2C writing function pointer |
|
13182 +@param [in] WaitMs Basic waiting function pointer |
|
13183 +@param [in] pRtl2832ExtraModuleMemory Pointer to an allocated RTL2832 extra module memory |
|
13184 +@param [in] DemodDeviceAddr RTL2832 I2C device address |
|
13185 +@param [in] DemodCrystalFreqHz RTL2832 crystal frequency in Hz |
|
13186 +@param [in] DemodAppMode RTL2832 application mode for setting |
|
13187 +@param [in] DemodTsInterfaceMode RTL2832 TS interface mode for setting |
|
13188 +@param [in] pTua9001ExtraModuleMemory Pointer to an allocated TUA9001 extra module memory |
|
13189 +@param [in] TunerDeviceAddr TUA9001 I2C device address |
|
13190 +@param [in] TunerAgcMode TUA9001 AGC mode |
|
13191 + |
|
13192 + |
|
13193 +@note |
|
13194 + -# One should call BuildRtl2832Tua9001Module() to build RTL2832 TUA9001 NIM module before using it. |
|
13195 + |
|
13196 +*/ |
|
13197 +void |
|
13198 +BuildRtl2832Tua9001Module( |
|
13199 + DVBT_NIM_MODULE **ppNim, // DVB-T NIM dependence |
|
13200 + DVBT_NIM_MODULE *pDvbtNimModuleMemory, |
|
13201 + |
|
13202 + unsigned char I2cReadingByteNumMax, // Base interface dependence |
|
13203 + unsigned char I2cWritingByteNumMax, |
|
13204 + BASE_FP_I2C_READ I2cRead, |
|
13205 + BASE_FP_I2C_WRITE I2cWrite, |
|
13206 + BASE_FP_WAIT_MS WaitMs, |
|
13207 + |
|
13208 + RTL2832_EXTRA_MODULE *pRtl2832ExtraModuleMemory, // Demod dependence |
|
13209 + unsigned char DemodDeviceAddr, |
|
13210 + unsigned long DemodCrystalFreqHz, |
|
13211 + int DemodAppMode, |
|
13212 + int DemodTsInterfaceMode, |
|
13213 + unsigned long DemodUpdateFuncRefPeriodMs, |
|
13214 + int DemodIsFunc1Enabled, |
|
13215 + |
|
13216 + TUA9001_EXTRA_MODULE *pTua9001ExtraModuleMemory, // Tuner dependence |
|
13217 + unsigned char TunerDeviceAddr |
|
13218 + ) |
|
13219 +{ |
|
13220 + DVBT_NIM_MODULE *pNim; |
|
13221 + |
|
13222 + |
|
13223 + |
|
13224 + // Set NIM module pointer with NIM module memory. |
|
13225 + *ppNim = pDvbtNimModuleMemory; |
|
13226 + |
|
13227 + // Get NIM module. |
|
13228 + pNim = *ppNim; |
|
13229 + |
|
13230 + // Set I2C bridge module pointer with I2C bridge module memory. |
|
13231 + pNim->pI2cBridge = &pNim->I2cBridgeModuleMemory; |
|
13232 + |
|
13233 + // Set NIM extra module pointer. |
|
13234 + pNim->pExtra = INVALID_POINTER_VALUE; |
|
13235 + |
|
13236 + |
|
13237 + // Set NIM type. |
|
13238 + pNim->NimType = DVBT_NIM_RTL2832_TUA9001; |
|
13239 + |
|
13240 + |
|
13241 + // Build base interface module. |
|
13242 + BuildBaseInterface( |
|
13243 + &pNim->pBaseInterface, |
|
13244 + &pNim->BaseInterfaceModuleMemory, |
|
13245 + I2cReadingByteNumMax, |
|
13246 + I2cWritingByteNumMax, |
|
13247 + I2cRead, |
|
13248 + I2cWrite, |
|
13249 + WaitMs |
|
13250 + ); |
|
13251 + |
|
13252 + // Build RTL2832 demod module. |
|
13253 + BuildRtl2832Module( |
|
13254 + &pNim->pDemod, |
|
13255 + &pNim->DvbtDemodModuleMemory, |
|
13256 + pRtl2832ExtraModuleMemory, |
|
13257 + &pNim->BaseInterfaceModuleMemory, |
|
13258 + &pNim->I2cBridgeModuleMemory, |
|
13259 + DemodDeviceAddr, |
|
13260 + DemodCrystalFreqHz, |
|
13261 + DemodAppMode, |
|
13262 + DemodUpdateFuncRefPeriodMs, |
|
13263 + DemodIsFunc1Enabled |
|
13264 + ); |
|
13265 + |
|
13266 + // Build TUA9001 tuner module. |
|
13267 + BuildTua9001Module( |
|
13268 + &pNim->pTuner, |
|
13269 + &pNim->TunerModuleMemory, |
|
13270 + pTua9001ExtraModuleMemory, |
|
13271 + &pNim->BaseInterfaceModuleMemory, |
|
13272 + &pNim->I2cBridgeModuleMemory, |
|
13273 + TunerDeviceAddr |
|
13274 + ); |
|
13275 + |
|
13276 + |
|
13277 + // Set NIM module variables. |
|
13278 + pNim->DemodTsInterfaceMode = DemodTsInterfaceMode; |
|
13279 + |
|
13280 + |
|
13281 + // Set NIM module function pointers with default functions. |
|
13282 + pNim->GetNimType = dvbt_nim_default_GetNimType; |
|
13283 + pNim->GetParameters = dvbt_nim_default_GetParameters; |
|
13284 + pNim->IsSignalPresent = dvbt_nim_default_IsSignalPresent; |
|
13285 + pNim->IsSignalLocked = dvbt_nim_default_IsSignalLocked; |
|
13286 + pNim->GetSignalStrength = dvbt_nim_default_GetSignalStrength; |
|
13287 + pNim->GetSignalQuality = dvbt_nim_default_GetSignalQuality; |
|
13288 + pNim->GetBer = dvbt_nim_default_GetBer; |
|
13289 + pNim->GetSnrDb = dvbt_nim_default_GetSnrDb; |
|
13290 + pNim->GetTrOffsetPpm = dvbt_nim_default_GetTrOffsetPpm; |
|
13291 + pNim->GetCrOffsetHz = dvbt_nim_default_GetCrOffsetHz; |
|
13292 + pNim->GetTpsInfo = dvbt_nim_default_GetTpsInfo; |
|
13293 + pNim->UpdateFunction = dvbt_nim_default_UpdateFunction; |
|
13294 + |
|
13295 + // Set NIM module function pointers with particular functions. |
|
13296 + pNim->Initialize = rtl2832_tua9001_Initialize; |
|
13297 + pNim->SetParameters = rtl2832_tua9001_SetParameters; |
|
13298 + |
|
13299 + |
|
13300 + return; |
|
13301 +} |
|
13302 + |
|
13303 + |
|
13304 + |
|
13305 + |
|
13306 + |
|
13307 +/** |
|
13308 + |
|
13309 +@see DVBT_NIM_FP_INITIALIZE |
|
13310 + |
|
13311 +*/ |
|
13312 +int |
|
13313 +rtl2832_tua9001_Initialize( |
|
13314 + DVBT_NIM_MODULE *pNim |
|
13315 + ) |
|
13316 +{ |
|
13317 + typedef struct |
|
13318 + { |
|
13319 + int RegBitName; |
|
13320 + unsigned long Value; |
|
13321 + } |
|
13322 + REG_VALUE_ENTRY; |
|
13323 + |
|
13324 + |
|
13325 + static const REG_VALUE_ENTRY AdditionalInitRegValueTable[RTL2832_TUA9001_ADDITIONAL_INIT_REG_TABLE_LEN] = |
|
13326 + { |
|
13327 + // RegBitName, Value |
|
13328 + {DVBT_DAGC_TRG_VAL, 0x39 }, |
|
13329 + {DVBT_AGC_TARG_VAL_0, 0x0 }, |
|
13330 + {DVBT_AGC_TARG_VAL_8_1, 0x5a }, |
|
13331 + {DVBT_AAGC_LOOP_GAIN, 0x16 }, |
|
13332 + {DVBT_LOOP_GAIN2_3_0, 0x6 }, |
|
13333 + {DVBT_LOOP_GAIN2_4, 0x1 }, |
|
13334 + {DVBT_LOOP_GAIN3, 0x16 }, |
|
13335 + {DVBT_VTOP1, 0x35 }, |
|
13336 + {DVBT_VTOP2, 0x21 }, |
|
13337 + {DVBT_VTOP3, 0x21 }, |
|
13338 + {DVBT_KRF1, 0x0 }, |
|
13339 + {DVBT_KRF2, 0x40 }, |
|
13340 + {DVBT_KRF3, 0x10 }, |
|
13341 + {DVBT_KRF4, 0x10 }, |
|
13342 + {DVBT_IF_AGC_MIN, 0x80 }, |
|
13343 + {DVBT_IF_AGC_MAX, 0x7f }, |
|
13344 + {DVBT_RF_AGC_MIN, 0x9c }, |
|
13345 + {DVBT_RF_AGC_MAX, 0x7f }, |
|
13346 + {DVBT_POLAR_RF_AGC, 0x0 }, |
|
13347 + {DVBT_POLAR_IF_AGC, 0x0 }, |
|
13348 + {DVBT_AD7_SETTING, 0xe9f4 }, |
|
13349 + {DVBT_OPT_ADC_IQ, 0x1 }, |
|
13350 + {DVBT_AD_AVI, 0x0 }, |
|
13351 + {DVBT_AD_AVQ, 0x0 }, |
|
13352 + }; |
|
13353 + |
|
13354 + |
|
13355 + TUNER_MODULE *pTuner; |
|
13356 + DVBT_DEMOD_MODULE *pDemod; |
|
13357 + |
|
13358 + int i; |
|
13359 + |
|
13360 + int RegBitName; |
|
13361 + unsigned long Value; |
|
13362 + |
|
13363 + |
|
13364 + |
|
13365 + // Get tuner module and demod module. |
|
13366 + pTuner = pNim->pTuner; |
|
13367 + pDemod = pNim->pDemod; |
|
13368 + |
|
13369 + |
|
13370 + // Enable demod DVBT_IIC_REPEAT. |
|
13371 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS) |
|
13372 + goto error_status_set_registers; |
|
13373 + |
|
13374 + // Initialize tuner. |
|
13375 + if(pTuner->Initialize(pTuner) != FUNCTION_SUCCESS) |
|
13376 + goto error_status_execute_function; |
|
13377 + |
|
13378 + // Disable demod DVBT_IIC_REPEAT. |
|
13379 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS) |
|
13380 + goto error_status_set_registers; |
|
13381 + |
|
13382 + |
|
13383 + // Initialize demod. |
|
13384 + if(pDemod->Initialize(pDemod) != FUNCTION_SUCCESS) |
|
13385 + goto error_status_execute_function; |
|
13386 + |
|
13387 + // Set demod IF frequency with 0 Hz. |
|
13388 + if(pDemod->SetIfFreqHz(pDemod, IF_FREQ_0HZ) != FUNCTION_SUCCESS) |
|
13389 + goto error_status_execute_function; |
|
13390 + |
|
13391 + // Set demod spectrum mode with SPECTRUM_NORMAL. |
|
13392 + if(pDemod->SetSpectrumMode(pDemod, SPECTRUM_NORMAL) != FUNCTION_SUCCESS) |
|
13393 + goto error_status_execute_function; |
|
13394 + |
|
13395 + |
|
13396 + // Set demod registers. |
|
13397 + for(i = 0; i < RTL2832_TUA9001_ADDITIONAL_INIT_REG_TABLE_LEN; i++) |
|
13398 + { |
|
13399 + // Get register bit name and its value. |
|
13400 + RegBitName = AdditionalInitRegValueTable[i].RegBitName; |
|
13401 + Value = AdditionalInitRegValueTable[i].Value; |
|
13402 + |
|
13403 + // Set demod registers |
|
13404 + if(pDemod->SetRegBitsWithPage(pDemod, RegBitName, Value) != FUNCTION_SUCCESS) |
|
13405 + goto error_status_set_registers; |
|
13406 + } |
|
13407 + |
|
13408 + |
|
13409 + // Set TS interface according to TS interface mode. |
|
13410 + switch(pNim->DemodTsInterfaceMode) |
|
13411 + { |
|
13412 + case TS_INTERFACE_PARALLEL: |
|
13413 + |
|
13414 + // Set demod TS interface with parallel mode. |
|
13415 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SERIAL, 0) != FUNCTION_SUCCESS) |
|
13416 + goto error_status_set_registers; |
|
13417 + |
|
13418 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH0, 9) != FUNCTION_SUCCESS) |
|
13419 + goto error_status_set_registers; |
|
13420 + |
|
13421 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH1, 9) != FUNCTION_SUCCESS) |
|
13422 + goto error_status_set_registers; |
|
13423 + |
|
13424 + break; |
|
13425 + |
|
13426 + |
|
13427 + default: |
|
13428 + case TS_INTERFACE_SERIAL: |
|
13429 + |
|
13430 + // Set demod TS interface with serial mode. |
|
13431 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_SERIAL, 1) != FUNCTION_SUCCESS) |
|
13432 + goto error_status_set_registers; |
|
13433 + |
|
13434 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH0, 2) != FUNCTION_SUCCESS) |
|
13435 + goto error_status_set_registers; |
|
13436 + |
|
13437 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_CDIV_PH1, 2) != FUNCTION_SUCCESS) |
|
13438 + goto error_status_set_registers; |
|
13439 + |
|
13440 + break; |
|
13441 + } |
|
13442 + |
|
13443 + |
|
13444 + return FUNCTION_SUCCESS; |
|
13445 + |
|
13446 + |
|
13447 +error_status_execute_function: |
|
13448 +error_status_set_registers: |
|
13449 + return FUNCTION_ERROR; |
|
13450 +} |
|
13451 + |
|
13452 + |
|
13453 + |
|
13454 + |
|
13455 + |
|
13456 +/** |
|
13457 + |
|
13458 +@see DVBT_NIM_FP_SET_PARAMETERS |
|
13459 + |
|
13460 +*/ |
|
13461 +int |
|
13462 +rtl2832_tua9001_SetParameters( |
|
13463 + DVBT_NIM_MODULE *pNim, |
|
13464 + unsigned long RfFreqHz, |
|
13465 + int BandwidthMode |
|
13466 + ) |
|
13467 +{ |
|
13468 + TUNER_MODULE *pTuner; |
|
13469 + DVBT_DEMOD_MODULE *pDemod; |
|
13470 + |
|
13471 + TUA9001_EXTRA_MODULE *pTunerExtra; |
|
13472 + int TunerBandwidthMode; |
|
13473 + |
|
13474 + |
|
13475 + |
|
13476 + // Get tuner module and demod module. |
|
13477 + pTuner = pNim->pTuner; |
|
13478 + pDemod = pNim->pDemod; |
|
13479 + |
|
13480 + // Get tuner extra module. |
|
13481 + pTunerExtra = (TUA9001_EXTRA_MODULE *)pTuner->pExtra; |
|
13482 + |
|
13483 + |
|
13484 + // Enable demod DVBT_IIC_REPEAT. |
|
13485 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x1) != FUNCTION_SUCCESS) |
|
13486 + goto error_status_set_registers; |
|
13487 + |
|
13488 + // Set tuner RF frequency in Hz. |
|
13489 + if(pTuner->SetRfFreqHz(pTuner, RfFreqHz) != FUNCTION_SUCCESS) |
|
13490 + goto error_status_execute_function; |
|
13491 + |
|
13492 + // Determine TunerBandwidthMode according to bandwidth mode. |
|
13493 + switch(BandwidthMode) |
|
13494 + { |
|
13495 + default: |
|
13496 + case DVBT_BANDWIDTH_6MHZ: TunerBandwidthMode = TUA9001_BANDWIDTH_6MHZ; break; |
|
13497 + case DVBT_BANDWIDTH_7MHZ: TunerBandwidthMode = TUA9001_BANDWIDTH_7MHZ; break; |
|
13498 + case DVBT_BANDWIDTH_8MHZ: TunerBandwidthMode = TUA9001_BANDWIDTH_8MHZ; break; |
|
13499 + } |
|
13500 + |
|
13501 + // Set tuner bandwidth mode with TunerBandwidthMode. |
|
13502 + if(pTunerExtra->SetBandwidthMode(pTuner, TunerBandwidthMode) != FUNCTION_SUCCESS) |
|
13503 + goto error_status_execute_function; |
|
13504 + |
|
13505 + // Disable demod DVBT_IIC_REPEAT. |
|
13506 + if(pDemod->SetRegBitsWithPage(pDemod, DVBT_IIC_REPEAT, 0x0) != FUNCTION_SUCCESS) |
|
13507 + goto error_status_set_registers; |
|
13508 + |
|
13509 + |
|
13510 + // Set demod bandwidth mode. |
|
13511 + if(pDemod->SetBandwidthMode(pDemod, BandwidthMode) != FUNCTION_SUCCESS) |
|
13512 + goto error_status_execute_function; |
|
13513 + |
|
13514 + // Reset demod particular registers. |
|
13515 + if(pDemod->ResetFunction(pDemod) != FUNCTION_SUCCESS) |
|
13516 + goto error_status_execute_function; |
|
13517 + |
|
13518 + |
|
13519 + // Reset demod by software reset. |
|
13520 + if(pDemod->SoftwareReset(pDemod) != FUNCTION_SUCCESS) |
|
13521 + goto error_status_execute_function; |
|
13522 + |
|
13523 + |
|
13524 + return FUNCTION_SUCCESS; |
|
13525 + |
|
13526 + |
|
13527 +error_status_execute_function: |
|
13528 +error_status_set_registers: |
|
13529 + return FUNCTION_ERROR; |
|
13530 +} |
|
13531 + |
|
13532 + |
|
13533 + |
|
13534 + |
|
13535 + |
|
13536 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/nim_rtl2832_tua9001.h |
|
13537 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
13538 +++ b/linux/drivers/media/dvb/dvb-usb/nim_rtl2832_tua9001.h Wed Oct 27 09:16:44 2010 +0200 |
|
13539 @@ -0,0 +1,142 @@ |
|
13540 +#ifndef __NIM_RTL2832_TUA9001 |
|
13541 +#define __NIM_RTL2832_TUA9001 |
|
13542 + |
|
13543 +/** |
|
13544 + |
|
13545 +@file |
|
13546 + |
|
13547 +@brief RTL2832 TUA9001 NIM module declaration |
|
13548 + |
|
13549 +One can manipulate RTL2832 TUA9001 NIM through RTL2832 TUA9001 NIM module. |
|
13550 +RTL2832 TUA9001 NIM module is derived from DVB-T NIM module. |
|
13551 + |
|
13552 + |
|
13553 + |
|
13554 +@par Example: |
|
13555 +@code |
|
13556 + |
|
13557 +// The example is the same as the NIM example in dvbt_nim_base.h except the listed lines. |
|
13558 + |
|
13559 + |
|
13560 + |
|
13561 +#include "nim_rtl2832_tua9001.h" |
|
13562 + |
|
13563 + |
|
13564 +... |
|
13565 + |
|
13566 + |
|
13567 + |
|
13568 +int main(void) |
|
13569 +{ |
|
13570 + DVBT_NIM_MODULE *pNim; |
|
13571 + DVBT_NIM_MODULE DvbtNimModuleMemory; |
|
13572 + RTL2832_EXTRA_MODULE Rtl2832ExtraModuleMemory; |
|
13573 + TUA9001_EXTRA_MODULE Tua9001ExtraModuleMemory; |
|
13574 + |
|
13575 + ... |
|
13576 + |
|
13577 + |
|
13578 + |
|
13579 + // Build RTL2832 TUA9001 NIM module. |
|
13580 + BuildRtl2832Tua9001Module( |
|
13581 + &pNim, |
|
13582 + &DvbtNimModuleMemory, |
|
13583 + |
|
13584 + 9, // Maximum I2C reading byte number is 9. |
|
13585 + 8, // Maximum I2C writing byte number is 8. |
|
13586 + CustomI2cRead, // Employ CustomI2cRead() as basic I2C reading function. |
|
13587 + CustomI2cWrite, // Employ CustomI2cWrite() as basic I2C writing function. |
|
13588 + CustomWaitMs, // Employ CustomWaitMs() as basic waiting function. |
|
13589 + |
|
13590 + &Rtl2832ExtraModuleMemory, // Employ RTL2832 extra module for RTL2832 module. |
|
13591 + 0x20, // The RTL2832 I2C device address is 0x20 in 8-bit format. |
|
13592 + CRYSTAL_FREQ_28800000HZ, // The RTL2832 crystal frequency is 28.8 MHz. |
|
13593 + RTL2832_APPLICATION_STB, // The RTL2832 application mode is STB mode. |
|
13594 + 50, // The RTL2832 update function reference period is 50 millisecond |
|
13595 + ON, // The RTL2832 Function 1 enabling status is on. |
|
13596 + |
|
13597 + &Tua9001ExtraModuleMemory, // Employ TUA9001 extra module for TUA9001 module. |
|
13598 + 0xac, // The TUA9001 I2C device address is 0xac in 8-bit format. |
|
13599 + ); |
|
13600 + |
|
13601 + |
|
13602 + |
|
13603 + // See the example for other NIM functions in dvbt_nim_base.h |
|
13604 + |
|
13605 + ... |
|
13606 + |
|
13607 + |
|
13608 + return 0; |
|
13609 +} |
|
13610 + |
|
13611 + |
|
13612 +@endcode |
|
13613 + |
|
13614 +*/ |
|
13615 + |
|
13616 + |
|
13617 +#include "demod_rtl2832.h" |
|
13618 +#include "tuner_tua9001.h" |
|
13619 +#include "dvbt_nim_base.h" |
|
13620 + |
|
13621 + |
|
13622 + |
|
13623 + |
|
13624 + |
|
13625 +// Definitions |
|
13626 +#define RTL2832_TUA9001_ADDITIONAL_INIT_REG_TABLE_LEN 24 |
|
13627 + |
|
13628 + |
|
13629 + |
|
13630 + |
|
13631 + |
|
13632 +// Builder |
|
13633 +void |
|
13634 +BuildRtl2832Tua9001Module( |
|
13635 + DVBT_NIM_MODULE **ppNim, // DVB-T NIM dependence |
|
13636 + DVBT_NIM_MODULE *pDvbtNimModuleMemory, |
|
13637 + |
|
13638 + unsigned char I2cReadingByteNumMax, // Base interface dependence |
|
13639 + unsigned char I2cWritingByteNumMax, |
|
13640 + BASE_FP_I2C_READ I2cRead, |
|
13641 + BASE_FP_I2C_WRITE I2cWrite, |
|
13642 + BASE_FP_WAIT_MS WaitMs, |
|
13643 + |
|
13644 + RTL2832_EXTRA_MODULE *pRtl2832ExtraModuleMemory, // Demod dependence |
|
13645 + unsigned char DemodDeviceAddr, |
|
13646 + unsigned long DemodCrystalFreqHz, |
|
13647 + int DemodAppMode, |
|
13648 + int DemodTsInterfaceMode, |
|
13649 + unsigned long UpdateFuncRefPeriodMs, |
|
13650 + int IsFunc1Enabled, |
|
13651 + |
|
13652 + TUA9001_EXTRA_MODULE *pTua9001ExtraModuleMemory, // Tuner dependence |
|
13653 + unsigned char TunerDeviceAddr |
|
13654 + ); |
|
13655 + |
|
13656 + |
|
13657 + |
|
13658 + |
|
13659 + |
|
13660 +// RTL2832 TUA9001 NIM manipulaing functions |
|
13661 +int |
|
13662 +rtl2832_tua9001_Initialize( |
|
13663 + DVBT_NIM_MODULE *pNim |
|
13664 + ); |
|
13665 + |
|
13666 +int |
|
13667 +rtl2832_tua9001_SetParameters( |
|
13668 + DVBT_NIM_MODULE *pNim, |
|
13669 + unsigned long RfFreqHz, |
|
13670 + int BandwidthMode |
|
13671 + ); |
|
13672 + |
|
13673 + |
|
13674 + |
|
13675 + |
|
13676 + |
|
13677 + |
|
13678 + |
|
13679 +#endif |
|
13680 + |
|
13681 + |
|
13682 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/readme.txt |
|
13683 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
13684 +++ b/linux/drivers/media/dvb/dvb-usb/readme.txt Wed Oct 27 09:16:44 2010 +0200 |
|
13685 @@ -0,0 +1,40 @@ |
|
13686 +Driver Installation in Linux |
|
13687 + |
|
13688 +1. Download "v4l-dvb-(version)" source code from http://linuxtv.org/. |
|
13689 + |
|
13690 +2. Copy the folder 'rtl2832u_linux_driver' and "v4l-dvb-(version)" source code to the desktop. |
|
13691 + |
|
13692 +3. Click 'Applications' -> 'Accessories' -> 'Terminal' to enter the console mode. |
|
13693 + |
|
13694 +4. Type 'cd /root/Desktop/rtl2832u_linux_driver' to enter the folder. |
|
13695 + |
|
13696 +5. In the folder 'rtl2832u_linux_driver', type the following command to compile & install. |
|
13697 + |
|
13698 + a. Type 'cp -f *.* /root/Desktop/v4l-dvb-(version)/linux/drivers/media/dvb/dvb-usb' to copy all files into v4l-dvb-(version) code. |
|
13699 + |
|
13700 + b. add the following lines to Makefile in v4l-dvb-(version)/linux/drivers/media/dvb/dvb-usb. |
|
13701 +dvb-usb-rtl2832u-objs = demod_rtl2832.o dvbt_demod_base.o dvbt_nim_base.o foundation.o math_mpi.o nim_rtl2832_mxl5007t.o nim_rtl2832_fc2580.o nim_rtl2832_mt2266.o rtl2832u.o rtl2832u_fe.o rtl2832u_io.o tuner_mxl5007t.o tuner_fc2580.o tuner_mt2266.o tuner_tua9001.o nim_rtl2832_tua9001.o |
|
13702 +obj-$(CONFIG_DVB_USB_RTL2832U) += dvb-usb-rtl2832u.o |
|
13703 + |
|
13704 + c. add the following lines to Kconfig in v4l-dvb-(version)/linux/drivers/media/dvb/dvb-usb. |
|
13705 +config DVB_USB_RTL2832U |
|
13706 + tristate "Realtek RTL2832U DVB-T USB2.0 support" |
|
13707 + depends on DVB_USB |
|
13708 + help |
|
13709 + Realtek RTL2832U DVB-T driver. |
|
13710 + |
|
13711 + d. Type 'make clean' |
|
13712 + d. Type 'make' |
|
13713 + f. Type 'make install' |
|
13714 + |
|
13715 +6. Plug in our DVB-T USB device; |
|
13716 + |
|
13717 +7. Type 'lsmod | grep dvb', and it will show |
|
13718 + dvb_usb_rtl2831u |
|
13719 + dvb_usb |
|
13720 + dvb_core |
|
13721 + i2c_core |
|
13722 + |
|
13723 + Your driver has been installed successfully. |
|
13724 + |
|
13725 +8. Install the applications --'Xine' and 'linuxtv-dvb-apps'. |
|
13726 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/rtl2832u.c |
|
13727 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
13728 +++ b/linux/drivers/media/dvb/dvb-usb/rtl2832u.c Wed Oct 27 09:16:44 2010 +0200 |
|
13729 @@ -0,0 +1,287 @@ |
|
13730 + |
|
13731 +#include <linux/module.h> |
|
13732 +#include <linux/version.h> |
|
13733 + |
|
13734 +#include "rtl2832u.h" |
|
13735 +#include "rtl2832u_io.h" |
|
13736 + |
|
13737 +int dvb_usb_rtl2832u_debug; |
|
13738 +module_param_named(debug,dvb_usb_rtl2832u_debug, int, 0644); |
|
13739 +MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2 (or-able))." DVB_USB_DEBUG_STATUS); |
|
13740 + |
|
13741 +//DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
|
13742 + |
|
13743 +#define USB_EPA_CTL 0x0148 |
|
13744 + |
|
13745 + |
|
13746 +static int rtl2832u_streaming_ctrl(struct dvb_usb_adapter *adap , int onoff) |
|
13747 +{ |
|
13748 + u8 data[2]; |
|
13749 + //3 to avoid scanning channels loss |
|
13750 + if(onoff) |
|
13751 + { |
|
13752 + data[0] = data[1] = 0; |
|
13753 + if ( write_usb_sys_char_bytes( adap->dev , RTD2832U_USB , USB_EPA_CTL , data , 2) ) goto error; |
|
13754 + } |
|
13755 + else |
|
13756 + { |
|
13757 + data[0] = 0x10; //3stall epa, set bit 4 to 1 |
|
13758 + data[1] = 0x02; //3reset epa, set bit 9 to 1 |
|
13759 + if ( write_usb_sys_char_bytes( adap->dev , RTD2832U_USB , USB_EPA_CTL , data , 2) ) goto error; |
|
13760 + } |
|
13761 + |
|
13762 + return 0; |
|
13763 +error: |
|
13764 + return -1; |
|
13765 +} |
|
13766 + |
|
13767 + |
|
13768 +static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap) |
|
13769 +{ |
|
13770 + adap->fe = rtl2832u_fe_attach(adap->dev); |
|
13771 + return 0; |
|
13772 +} |
|
13773 + |
|
13774 + |
|
13775 +static void rtl2832u_usb_disconnect(struct usb_interface *intf) |
|
13776 +{ |
|
13777 + try_module_get(THIS_MODULE); |
|
13778 + dvb_usb_device_exit(intf); |
|
13779 +} |
|
13780 + |
|
13781 + |
|
13782 +static struct dvb_usb_device_properties rtl2832u_1st_properties; |
|
13783 +static struct dvb_usb_device_properties rtl2832u_2nd_properties; |
|
13784 +static struct dvb_usb_device_properties rtl2832u_3th_properties; |
|
13785 + |
|
13786 + |
|
13787 +static int rtl2832u_usb_probe(struct usb_interface *intf, |
|
13788 + const struct usb_device_id *id) |
|
13789 +{ |
|
13790 + if ( ( 0== dvb_usb_device_init(intf,&rtl2832u_1st_properties,THIS_MODULE,NULL) )|| |
|
13791 + ( 0== dvb_usb_device_init(intf,&rtl2832u_2nd_properties,THIS_MODULE,NULL) ) || |
|
13792 + ( 0== dvb_usb_device_init(intf,&rtl2832u_3th_properties,THIS_MODULE,NULL) )) |
|
13793 + return 0; |
|
13794 + |
|
13795 + return -ENODEV; |
|
13796 +} |
|
13797 + |
|
13798 +static struct usb_device_id rtl2832u_usb_table [] = { |
|
13799 + { USB_DEVICE(USB_VID_REALTEK, USB_PID_RTD2832U_WARM) }, |
|
13800 + { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_USB_WARM) }, |
|
13801 + { USB_DEVICE(USB_VID_KWORLD_1ST, USB_PID_KWORLD_WARM_6) }, |
|
13802 + { USB_DEVICE(USB_VID_DEXATEK, USB_PID_DEXATEK_USB_WARM) }, |
|
13803 + { USB_DEVICE(USB_VID_DEXATEK, USB_PID_DEXATEK_MINIUSB_WARM) }, |
|
13804 + { USB_DEVICE(USB_VID_DEXATEK, USB_PID_DEXATEK_5217_WARM) }, |
|
13805 + |
|
13806 + { USB_DEVICE(USB_VID_REALTEK, USB_PID_RTD2832U_2ND_WARM) }, |
|
13807 + { USB_DEVICE(USB_VID_GOLDENBRIDGE, USB_PID_GOLDENBRIDGE_WARM) }, |
|
13808 + { USB_DEVICE(USB_VID_YUAN, USB_PID_YUAN_WARM) }, |
|
13809 + { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_MINI_WARM) }, |
|
13810 + { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_GPS_WARM) }, |
|
13811 + { USB_DEVICE(USB_VID_KWORLD_1ST, USB_PID_KWORLD_WARM_7) }, |
|
13812 + |
|
13813 + { USB_DEVICE(USB_VID_KWORLD_1ST, USB_PID_KWORLD_WARM_3) }, |
|
13814 + { USB_DEVICE(USB_VID_KWORLD_1ST, USB_PID_KWORLD_WARM_8) }, |
|
13815 + { USB_DEVICE(USB_VID_GTEK, USB_PID_GTEK_WARM) }, |
|
13816 + { 0 }, |
|
13817 +}; |
|
13818 + |
|
13819 + |
|
13820 +MODULE_DEVICE_TABLE(usb, rtl2832u_usb_table); |
|
13821 + |
|
13822 +static struct dvb_usb_device_properties rtl2832u_1st_properties = { |
|
13823 + |
|
13824 + .num_adapters = 1, |
|
13825 + .adapter = |
|
13826 + { |
|
13827 + { |
|
13828 + .streaming_ctrl = rtl2832u_streaming_ctrl, |
|
13829 + .frontend_attach = rtl2832u_frontend_attach, |
|
13830 + //parameter for the MPEG2-data transfer |
|
13831 + .stream = |
|
13832 + { |
|
13833 + .type = USB_BULK, |
|
13834 + .count = RTD2831_URB_NUMBER, |
|
13835 + .endpoint = 0x01, //data pipe |
|
13836 + .u = |
|
13837 + { |
|
13838 + .bulk = |
|
13839 + { |
|
13840 + .buffersize = RTD2831_URB_SIZE, |
|
13841 + } |
|
13842 + } |
|
13843 + }, |
|
13844 + } |
|
13845 + }, |
|
13846 + |
|
13847 + .num_device_descs = 6, |
|
13848 + .devices = { |
|
13849 + { .name = "RTL2832U DVB-T USB DEVICE", |
|
13850 + .cold_ids = { NULL, NULL }, |
|
13851 + .warm_ids = { &rtl2832u_usb_table[0], NULL }, |
|
13852 + }, |
|
13853 + { .name = "DVB-T USB Dongle", |
|
13854 + .cold_ids = { NULL, NULL }, |
|
13855 + .warm_ids = { &rtl2832u_usb_table[1], NULL }, |
|
13856 + }, |
|
13857 + { .name = "USB DVB-T Device", |
|
13858 + .cold_ids = { NULL, NULL }, |
|
13859 + .warm_ids = { &rtl2832u_usb_table[2], NULL }, |
|
13860 + }, |
|
13861 + { .name = "DK DVBT DONGLE", |
|
13862 + .cold_ids = { NULL, NULL }, |
|
13863 + .warm_ids = { &rtl2832u_usb_table[3], NULL }, |
|
13864 + }, |
|
13865 + { .name = "DK mini DVBT DONGLE", |
|
13866 + .cold_ids = { NULL, NULL }, |
|
13867 + .warm_ids = { &rtl2832u_usb_table[4], NULL }, |
|
13868 + }, |
|
13869 + { .name = "DK 5217 DVBT DONGLE", |
|
13870 + .cold_ids = { NULL, NULL }, |
|
13871 + .warm_ids = { &rtl2832u_usb_table[5], NULL }, |
|
13872 + }, |
|
13873 + { NULL }, |
|
13874 + } |
|
13875 +}; |
|
13876 + |
|
13877 + |
|
13878 +static struct dvb_usb_device_properties rtl2832u_2nd_properties = { |
|
13879 + |
|
13880 + .num_adapters = 1, |
|
13881 + .adapter = |
|
13882 + { |
|
13883 + { |
|
13884 + .streaming_ctrl = rtl2832u_streaming_ctrl, |
|
13885 + .frontend_attach = rtl2832u_frontend_attach, |
|
13886 + //parameter for the MPEG2-data transfer |
|
13887 + .stream = |
|
13888 + { |
|
13889 + .type = USB_BULK, |
|
13890 + .count = RTD2831_URB_NUMBER, |
|
13891 + .endpoint = 0x01, //data pipe |
|
13892 + .u = |
|
13893 + { |
|
13894 + .bulk = |
|
13895 + { |
|
13896 + .buffersize = RTD2831_URB_SIZE, |
|
13897 + } |
|
13898 + } |
|
13899 + }, |
|
13900 + } |
|
13901 + }, |
|
13902 + |
|
13903 + .num_device_descs = 6, |
|
13904 + .devices = { |
|
13905 + { .name = "RTL2832U DVB-T USB DEVICE", |
|
13906 + .cold_ids = { NULL, NULL }, |
|
13907 + .warm_ids = { &rtl2832u_usb_table[6], NULL }, |
|
13908 + }, |
|
13909 + { .name = "RTL2832U DVB-T USB DEVICE", |
|
13910 + .cold_ids = { NULL, NULL }, |
|
13911 + .warm_ids = { &rtl2832u_usb_table[7], NULL }, |
|
13912 + }, |
|
13913 + { .name = "Digital TV Tuner Card", |
|
13914 + .cold_ids = { NULL, NULL }, |
|
13915 + .warm_ids = { &rtl2832u_usb_table[8], NULL }, |
|
13916 + }, |
|
13917 + { .name = "DVB-T FTA USB Half Minicard", |
|
13918 + .cold_ids = { NULL, NULL }, |
|
13919 + .warm_ids = { &rtl2832u_usb_table[9], NULL }, |
|
13920 + }, |
|
13921 + { .name = "DVB-T + GPS Minicard", |
|
13922 + .cold_ids = { NULL, NULL }, |
|
13923 + .warm_ids = { &rtl2832u_usb_table[10], NULL }, |
|
13924 + }, |
|
13925 + { .name = "UB450-T", |
|
13926 + .cold_ids = { NULL, NULL }, |
|
13927 + .warm_ids = { &rtl2832u_usb_table[11], NULL }, |
|
13928 + }, |
|
13929 + { NULL }, |
|
13930 + } |
|
13931 +}; |
|
13932 + |
|
13933 + |
|
13934 + |
|
13935 +static struct dvb_usb_device_properties rtl2832u_3th_properties = { |
|
13936 + |
|
13937 + .num_adapters = 1, |
|
13938 + .adapter = |
|
13939 + { |
|
13940 + { |
|
13941 + .streaming_ctrl = rtl2832u_streaming_ctrl, |
|
13942 + .frontend_attach = rtl2832u_frontend_attach, |
|
13943 + //parameter for the MPEG2-data transfer |
|
13944 + .stream = |
|
13945 + { |
|
13946 + .type = USB_BULK, |
|
13947 + .count = RTD2831_URB_NUMBER, |
|
13948 + .endpoint = 0x01, //data pipe |
|
13949 + .u = |
|
13950 + { |
|
13951 + .bulk = |
|
13952 + { |
|
13953 + .buffersize = RTD2831_URB_SIZE, |
|
13954 + } |
|
13955 + } |
|
13956 + }, |
|
13957 + } |
|
13958 + }, |
|
13959 + |
|
13960 + .num_device_descs = 3, |
|
13961 + .devices = { |
|
13962 + { .name = "USB DVB-T Device", |
|
13963 + .cold_ids = { NULL, NULL }, |
|
13964 + .warm_ids = { &rtl2832u_usb_table[12], NULL }, |
|
13965 + }, |
|
13966 + { .name = "USB DVB-T Device", |
|
13967 + .cold_ids = { NULL, NULL }, |
|
13968 + .warm_ids = { &rtl2832u_usb_table[13], NULL }, |
|
13969 + }, |
|
13970 + { .name = "RT DTV 2832U", |
|
13971 + .cold_ids = { NULL, NULL }, |
|
13972 + .warm_ids = { &rtl2832u_usb_table[14], NULL }, |
|
13973 + }, |
|
13974 + { NULL }, |
|
13975 + } |
|
13976 +}; |
|
13977 + |
|
13978 + |
|
13979 + |
|
13980 + |
|
13981 +static struct usb_driver rtl2832u_usb_driver = { |
|
13982 + .name = "dvb_usb_rtl2832u", |
|
13983 + .probe = rtl2832u_usb_probe, |
|
13984 + .disconnect = rtl2832u_usb_disconnect, |
|
13985 + .id_table = rtl2832u_usb_table, |
|
13986 +}; |
|
13987 + |
|
13988 + |
|
13989 +static int __init rtl2832u_usb_module_init(void) |
|
13990 +{ |
|
13991 + int result; |
|
13992 + if ((result = usb_register(&rtl2832u_usb_driver))) { |
|
13993 + err("usb_register failed. (%d)",result); |
|
13994 + return result; |
|
13995 + } |
|
13996 + |
|
13997 + return 0; |
|
13998 +} |
|
13999 + |
|
14000 +static void __exit rtl2832u_usb_module_exit(void) |
|
14001 +{ |
|
14002 + usb_deregister(&rtl2832u_usb_driver); |
|
14003 +} |
|
14004 + |
|
14005 + |
|
14006 + |
|
14007 +module_init(rtl2832u_usb_module_init); |
|
14008 +module_exit(rtl2832u_usb_module_exit); |
|
14009 + |
|
14010 + |
|
14011 + |
|
14012 +MODULE_AUTHOR("Realtek"); |
|
14013 +MODULE_DESCRIPTION("Driver for the RTL2832U DVB-T USB2.0 device"); |
|
14014 +MODULE_VERSION("1.1"); |
|
14015 +MODULE_LICENSE("GPL"); |
|
14016 + |
|
14017 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/rtl2832u.h |
|
14018 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
14019 +++ b/linux/drivers/media/dvb/dvb-usb/rtl2832u.h Wed Oct 27 09:16:44 2010 +0200 |
|
14020 @@ -0,0 +1,56 @@ |
|
14021 + |
|
14022 +#ifndef _RTL2832U_H_ |
|
14023 +#define _RTL2832U_H_ |
|
14024 + |
|
14025 + |
|
14026 + |
|
14027 +#include "dvb-usb.h" |
|
14028 + |
|
14029 +#define USB_VID_REALTEK 0x0BDA |
|
14030 +#define USB_PID_RTD2832U_WARM 0x2832 |
|
14031 +#define USB_PID_RTD2832U_2ND_WARM 0x2838 |
|
14032 + |
|
14033 + |
|
14034 +#define USB_VID_GOLDENBRIDGE 0x1680 |
|
14035 +#define USB_PID_GOLDENBRIDGE_WARM 0xA332 |
|
14036 + |
|
14037 +#define USB_VID_YUAN 0x1164 |
|
14038 +#define USB_PID_YUAN_WARM 0x6601 |
|
14039 + |
|
14040 +#define USB_VID_AZUREWAVE 0x13D3 |
|
14041 +#define USB_PID_AZUREWAVE_MINI_WARM 0x3234 |
|
14042 +#define USB_PID_AZUREWAVE_USB_WARM 0x3274 |
|
14043 +#define USB_PID_AZUREWAVE_GPS_WARM 0x3282 |
|
14044 + |
|
14045 +#define USB_VID_KWORLD_1ST 0x1B80 |
|
14046 +#define USB_PID_KWORLD_WARM_6 0xD396 |
|
14047 +#define USB_PID_KWORLD_WARM_3 0xD393 |
|
14048 +#define USB_PID_KWORLD_WARM_7 0xD397 |
|
14049 +#define USB_PID_KWORLD_WARM_8 0xD398 |
|
14050 + |
|
14051 + |
|
14052 +#define USB_VID_DEXATEK 0x1D19 |
|
14053 +#define USB_PID_DEXATEK_USB_WARM 0x1101 |
|
14054 +#define USB_PID_DEXATEK_MINIUSB_WARM 0x1102 |
|
14055 +#define USB_PID_DEXATEK_5217_WARM 0x1103 |
|
14056 + |
|
14057 + |
|
14058 +#define USB_VID_GTEK 0x1F4D |
|
14059 +#define USB_PID_GTEK_WARM 0x0837 |
|
14060 + |
|
14061 + |
|
14062 + |
|
14063 + |
|
14064 + |
|
14065 + |
|
14066 +#define RTD2831_URB_SIZE 4096 |
|
14067 +#define RTD2831_URB_NUMBER 10 |
|
14068 + |
|
14069 + |
|
14070 + |
|
14071 +extern struct dvb_frontend * rtl2832u_fe_attach(struct dvb_usb_device *d); |
|
14072 + |
|
14073 +#endif |
|
14074 + |
|
14075 + |
|
14076 + |
|
14077 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/rtl2832u_fe.c |
|
14078 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
14079 +++ b/linux/drivers/media/dvb/dvb-usb/rtl2832u_fe.c Wed Oct 27 09:16:44 2010 +0200 |
|
14080 @@ -0,0 +1,1588 @@ |
|
14081 + |
|
14082 +#include "rtl2832u_fe.h" |
|
14083 +#include "rtl2832u_io.h" |
|
14084 +#include "rtl2832u.h" |
|
14085 + |
|
14086 + |
|
14087 +#define UPDATE_PROCEDURE_PERIOD 500 //500ms |
|
14088 + |
|
14089 + |
|
14090 + |
|
14091 + |
|
14092 +static struct rtl2832_reg_addr rtl2832_reg_map[]= { |
|
14093 + /* RTD2831_RMAP_INDEX_USB_CTRL_BIT5*/ { RTD2832U_USB, USB_CTRL, 5, 5 }, |
|
14094 + /* RTD2831_RMAP_INDEX_USB_STAT*/ { RTD2832U_USB, USB_STAT, 0, 7 }, |
|
14095 + /* RTD2831_RMAP_INDEX_USB_EPA_CTL*/ { RTD2832U_USB, USB_EPA_CTL, 0, 31 }, |
|
14096 + /* RTD2831_RMAP_INDEX_USB_SYSCTL*/ { RTD2832U_USB, USB_SYSCTL, 0, 31 }, |
|
14097 + /* RTD2831_RMAP_INDEX_USB_EPA_CFG*/ { RTD2832U_USB, USB_EPA_CFG, 0, 31 }, |
|
14098 + /* RTD2831_RMAP_INDEX_USB_EPA_MAXPKT*/ { RTD2832U_USB, USB_EPA_MAXPKT, 0, 31}, |
|
14099 + /* RTD2831_RMAP_INDEX_USB_EPA_FIFO_CFG*/ { RTD2832U_USB, USB_EPA_FIFO_CFG, 0, 31}, |
|
14100 + |
|
14101 + /* RTD2831_RMAP_INDEX_SYS_DEMOD_CTL*/ { RTD2832U_SYS, DEMOD_CTL, 0, 7 }, |
|
14102 + /* RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL*/ { RTD2832U_SYS, GPIO_OUTPUT_VAL, 0, 7 }, |
|
14103 + /* RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_EN_BIT3*/{ RTD2832U_SYS, GPIO_OUTPUT_EN, 3, 3 }, |
|
14104 + /* RTD2831_RMAP_INDEX_SYS_GPIO_DIR_BIT3*/ { RTD2832U_SYS, GPIO_DIR, 3, 3 }, |
|
14105 + /* RTD2831_RMAP_INDEX_SYS_GPIO_CFG0_BIT67*/ { RTD2832U_SYS, GPIO_CFG0, 6, 7 }, |
|
14106 + /* RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1*/ { RTD2832U_SYS, DEMOD_CTL1, 0, 7 }, |
|
14107 + /* RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_EN_BIT1*/{ RTD2832U_SYS, GPIO_OUTPUT_EN, 1, 1 }, |
|
14108 + /* RTD2831_RMAP_INDEX_SYS_GPIO_DIR_BIT1*/ { RTD2832U_SYS, GPIO_DIR, 1, 1 }, |
|
14109 + /* RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_EN_BIT6*/{ RTD2832U_SYS, GPIO_OUTPUT_EN, 6, 6 }, |
|
14110 + /* RTD2831_RMAP_INDEX_SYS_GPIO_DIR_BIT6*/ { RTD2832U_SYS, GPIO_DIR, 6, 6 }, |
|
14111 + |
|
14112 + |
|
14113 + |
|
14114 +#if 0 |
|
14115 + /* RTD2831_RMAP_INDEX_SYS_GPD*/ { RTD2832U_SYS, GPD, 0, 7 }, |
|
14116 + /* RTD2831_RMAP_INDEX_SYS_GPOE*/ { RTD2832U_SYS, GPOE, 0, 7 }, |
|
14117 + /* RTD2831_RMAP_INDEX_SYS_GPO*/ { RTD2832U_SYS, GPO, 0, 7 }, |
|
14118 + /* RTD2831_RMAP_INDEX_SYS_SYS_0*/ { RTD2832U_SYS, SYS_0, 0, 7 }, |
|
14119 +#endif |
|
14120 + |
|
14121 +}; |
|
14122 + |
|
14123 + |
|
14124 + |
|
14125 + |
|
14126 +static void |
|
14127 +custom_wait_ms( |
|
14128 + BASE_INTERFACE_MODULE* pBaseInterface, |
|
14129 + unsigned long WaitTimeMs) |
|
14130 +{ |
|
14131 + platform_wait(WaitTimeMs); |
|
14132 + return; |
|
14133 +} |
|
14134 + |
|
14135 + |
|
14136 +static int |
|
14137 +custom_i2c_read( |
|
14138 + BASE_INTERFACE_MODULE* pBaseInterface, |
|
14139 + unsigned char DeviceAddr, |
|
14140 + unsigned char* pReadingBytes, |
|
14141 + unsigned char ByteNum |
|
14142 + ) |
|
14143 +{ |
|
14144 + struct dvb_usb_device *d; |
|
14145 + |
|
14146 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); |
|
14147 + if ( read_rtl2832_stdi2c( d, DeviceAddr , pReadingBytes , ByteNum ) ) goto error; |
|
14148 + |
|
14149 + return 0; |
|
14150 +error: |
|
14151 + return 1; |
|
14152 +} |
|
14153 + |
|
14154 + |
|
14155 + |
|
14156 +static int |
|
14157 +custom_i2c_write( |
|
14158 + BASE_INTERFACE_MODULE* pBaseInterface, |
|
14159 + unsigned char DeviceAddr, |
|
14160 + const unsigned char* pWritingBytes, |
|
14161 + unsigned char ByteNum) |
|
14162 +{ |
|
14163 + struct dvb_usb_device *d; |
|
14164 + |
|
14165 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); |
|
14166 + if ( write_rtl2832_stdi2c( d, DeviceAddr , (unsigned char*)pWritingBytes , ByteNum ) ) goto error; |
|
14167 + |
|
14168 + return 0; |
|
14169 +error: |
|
14170 + return 1; |
|
14171 +} |
|
14172 + |
|
14173 + |
|
14174 + |
|
14175 +static int |
|
14176 +read_usb_sys_register( |
|
14177 + struct rtl2832_state* p_state, |
|
14178 + rtl2832_reg_map_index reg_map_index, |
|
14179 + int* p_val) |
|
14180 +{ |
|
14181 + RegType reg_type= rtl2832_reg_map[reg_map_index].reg_type; |
|
14182 + unsigned short reg_addr= rtl2832_reg_map[reg_map_index].reg_addr; |
|
14183 + int bit_low= rtl2832_reg_map[reg_map_index].bit_low; |
|
14184 + int bit_high= rtl2832_reg_map[reg_map_index].bit_high; |
|
14185 + |
|
14186 + int n_byte_read=(bit_high>> 3)+ 1; |
|
14187 + |
|
14188 + *p_val= 0; |
|
14189 + if (read_usb_sys_int_bytes(p_state->d, reg_type, reg_addr, n_byte_read, p_val)) goto error; |
|
14190 + |
|
14191 + *p_val= ((*p_val>> bit_low) & rtl2832_reg_mask[bit_high- bit_low]); |
|
14192 + |
|
14193 + return 0; |
|
14194 + |
|
14195 +error: |
|
14196 + return 1; |
|
14197 +} |
|
14198 + |
|
14199 + |
|
14200 + |
|
14201 + |
|
14202 +static int |
|
14203 +write_usb_sys_register( |
|
14204 + struct rtl2832_state* p_state, |
|
14205 + rtl2832_reg_map_index reg_map_index, |
|
14206 + int val_write) |
|
14207 +{ |
|
14208 + RegType reg_type= rtl2832_reg_map[reg_map_index].reg_type; |
|
14209 + unsigned short reg_addr= rtl2832_reg_map[reg_map_index].reg_addr; |
|
14210 + int bit_low= rtl2832_reg_map[reg_map_index].bit_low; |
|
14211 + int bit_high= rtl2832_reg_map[reg_map_index].bit_high; |
|
14212 + |
|
14213 + int n_byte_write= (bit_high>> 3)+ 1; |
|
14214 + int val_read= 0; |
|
14215 + int new_val_write; |
|
14216 + |
|
14217 + if (read_usb_sys_int_bytes(p_state->d, reg_type, reg_addr, n_byte_write, &val_read)) goto error; |
|
14218 + |
|
14219 + new_val_write= (val_read & (~(rtl2832_reg_mask[bit_high- bit_low]<< bit_low))) | (val_write<< bit_low); |
|
14220 + |
|
14221 + if (write_usb_sys_int_bytes(p_state->d, reg_type, reg_addr, n_byte_write, new_val_write)) goto error; |
|
14222 + return 0; |
|
14223 + |
|
14224 +error: |
|
14225 + return 1; |
|
14226 +} |
|
14227 + |
|
14228 + |
|
14229 + |
|
14230 +static int |
|
14231 +set_tuner_power( |
|
14232 + struct rtl2832_state* p_state, |
|
14233 + unsigned char b_gpio4, |
|
14234 + unsigned char onoff) |
|
14235 +{ |
|
14236 + |
|
14237 + int data; |
|
14238 + |
|
14239 + deb_info(" +%s \n", __FUNCTION__); |
|
14240 + |
|
14241 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL, &data) ) goto error; |
|
14242 + |
|
14243 + if(b_gpio4) |
|
14244 + { |
|
14245 + if(onoff) data &= ~(BIT4); //set bit4 to 0 |
|
14246 + else data |= BIT4; //set bit4 to 1 |
|
14247 + |
|
14248 + } |
|
14249 + else |
|
14250 + { |
|
14251 + if(onoff) data &= ~(BIT3); //set bit3 to 0 |
|
14252 + else data |= BIT3; //set bit3 to 1 |
|
14253 + } |
|
14254 + |
|
14255 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL,data) ) goto error; |
|
14256 + |
|
14257 + deb_info(" -%s \n", __FUNCTION__); |
|
14258 + |
|
14259 + return 0; |
|
14260 +error: |
|
14261 + return 1; |
|
14262 +} |
|
14263 + |
|
14264 + |
|
14265 + |
|
14266 +static int |
|
14267 +set_demod_power( |
|
14268 + struct rtl2832_state* p_state, |
|
14269 + unsigned char onoff) |
|
14270 +{ |
|
14271 + |
|
14272 + int data; |
|
14273 + |
|
14274 + deb_info(" +%s \n", __FUNCTION__); |
|
14275 + |
|
14276 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL, &data) ) goto error; |
|
14277 + if(onoff) data &= ~(BIT0); //set bit0 to 0 |
|
14278 + else data |= BIT0; //set bit0 to 1 |
|
14279 + data &= ~(BIT0); //3 Demod Power always ON => hw issue. |
|
14280 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL,data) ) goto error; |
|
14281 + |
|
14282 + deb_info(" -%s \n", __FUNCTION__); |
|
14283 + return 0; |
|
14284 +error: |
|
14285 + return 1; |
|
14286 +} |
|
14287 + |
|
14288 + |
|
14289 + |
|
14290 +//3//////// Set GPIO3 "OUT" => Turn ON/OFF Tuner Power |
|
14291 +//3//////// Set GPIO3 "IN" => Button Wake UP (USB IF) , NO implement in rtl2832u linux driver |
|
14292 + |
|
14293 +static int |
|
14294 +gpio3_out_setting( |
|
14295 + struct rtl2832_state* p_state) |
|
14296 +{ |
|
14297 + int data; |
|
14298 + |
|
14299 + deb_info(" +%s \n", __FUNCTION__); |
|
14300 + |
|
14301 + // GPIO3_PAD Pull-HIGH, BIT76 |
|
14302 + data = 2; |
|
14303 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_CFG0_BIT67,data) ) goto error; |
|
14304 + |
|
14305 + // GPO_GPIO3 = 1, GPIO3 output value = 1 |
|
14306 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL, &data) ) goto error; |
|
14307 + data |= BIT3; //set bit3 to 1 |
|
14308 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL,data) ) goto error; |
|
14309 + |
|
14310 + // GPD_GPIO3=0, GPIO3 output direction |
|
14311 + data = 0; |
|
14312 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_DIR_BIT3,data) ) goto error; |
|
14313 + |
|
14314 + // GPOE_GPIO3=1, GPIO3 output enable |
|
14315 + data = 1; |
|
14316 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_EN_BIT3,data) ) goto error; |
|
14317 + |
|
14318 + //BTN_WAKEUP_DIS = 1 |
|
14319 + data = 1; |
|
14320 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_CTRL_BIT5,data) ) goto error; |
|
14321 + |
|
14322 + deb_info(" -%s \n", __FUNCTION__); |
|
14323 + |
|
14324 + return 0; |
|
14325 +error: |
|
14326 + return 1; |
|
14327 +} |
|
14328 + |
|
14329 + |
|
14330 + |
|
14331 + |
|
14332 + |
|
14333 + |
|
14334 +static int |
|
14335 +usb_epa_fifo_reset( |
|
14336 + struct rtl2832_state* p_state) |
|
14337 +{ |
|
14338 + |
|
14339 + int data; |
|
14340 + |
|
14341 + deb_info(" +%s \n", __FUNCTION__); |
|
14342 + |
|
14343 + //3 reset epa fifo: |
|
14344 + //3[9] Reset EPA FIFO |
|
14345 + //3 [5] FIFO Flush,Write 1 to flush the oldest TS packet (a 188 bytes block) |
|
14346 + |
|
14347 + data = 0x0210; |
|
14348 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_CTL,data) ) goto error; |
|
14349 + |
|
14350 + data = 0xffff; |
|
14351 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_CTL,&data) ) goto error; |
|
14352 + |
|
14353 + if( (data & 0xffff) != 0x0210) |
|
14354 + { |
|
14355 + deb_info("Write error RTD2831_RMAP_INDEX_USB_EPA_CTL = 0x%x\n",data); |
|
14356 + goto error; |
|
14357 + } |
|
14358 + |
|
14359 + data=0x0000; |
|
14360 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_CTL,data) ) goto error; |
|
14361 + |
|
14362 + data = 0xffff; |
|
14363 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_CTL,&data) ) goto error; |
|
14364 + |
|
14365 + if( ( data & 0xffff) != 0x0000) |
|
14366 + { |
|
14367 + deb_info("Write error RTD2831_RMAP_INDEX_USB_EPA_CTL = 0x%x\n",data); |
|
14368 + goto error; |
|
14369 + } |
|
14370 + |
|
14371 + deb_info(" -%s \n", __FUNCTION__); |
|
14372 + |
|
14373 + return 0; |
|
14374 + |
|
14375 +error: |
|
14376 + return 1; |
|
14377 + |
|
14378 +} |
|
14379 + |
|
14380 + |
|
14381 + |
|
14382 +static int |
|
14383 +usb_init_bulk_setting( |
|
14384 + struct rtl2832_state* p_state) |
|
14385 +{ |
|
14386 + |
|
14387 + int data; |
|
14388 + |
|
14389 + deb_info(" +%s \n", __FUNCTION__); |
|
14390 + |
|
14391 + //3 1.FULL packer mode(for bulk) |
|
14392 + //3 2.DMA enable. |
|
14393 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_SYSCTL, &data) ) goto error; |
|
14394 + |
|
14395 + data &=0xffffff00; |
|
14396 + data |= 0x09; |
|
14397 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_SYSCTL, data) ) goto error; |
|
14398 + |
|
14399 + data=0; |
|
14400 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_SYSCTL, &data) ) goto error; |
|
14401 + |
|
14402 + if((data&0xff)!=0x09) |
|
14403 + { |
|
14404 + deb_info("Open bulk FULL packet mode error!!\n"); |
|
14405 + goto error; |
|
14406 + } |
|
14407 + |
|
14408 + //3check epa config, |
|
14409 + //3[9-8]:00, 1 transaction per microframe |
|
14410 + //3[7]:1, epa enable |
|
14411 + //3[6-5]:10, bulk mode |
|
14412 + //3[4]:1, device to host |
|
14413 + //3[3:0]:0001, endpoint number |
|
14414 + data = 0; |
|
14415 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_CFG, &data) ) goto error; |
|
14416 + if((data&0x0300)!=0x0000 || (data&0xff)!=0xd1) |
|
14417 + { |
|
14418 + deb_info("Open bulk EPA config error! data=0x%x \n" , data); |
|
14419 + goto error; |
|
14420 + } |
|
14421 + |
|
14422 + //3 EPA maxsize packet |
|
14423 + //3 512:highspeedbulk, 64:fullspeedbulk. |
|
14424 + //3 940:highspeediso, 940:fullspeediso. |
|
14425 + |
|
14426 + //3 get info :HIGH_SPEED or FULL_SPEED |
|
14427 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_STAT, &data) ) goto error; |
|
14428 + if(data&0x01) |
|
14429 + { |
|
14430 + data = 0x00000200; |
|
14431 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_MAXPKT, data) ) goto error; |
|
14432 + |
|
14433 + data=0; |
|
14434 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_MAXPKT, &data) ) goto error; |
|
14435 + |
|
14436 + if((data&0xffff)!=0x0200) |
|
14437 + { |
|
14438 + deb_info("Open bulk EPA max packet size error!\n"); |
|
14439 + goto error; |
|
14440 + } |
|
14441 + |
|
14442 + deb_info("HIGH SPEED\n"); |
|
14443 + } |
|
14444 + else |
|
14445 + { |
|
14446 + data = 0x00000040; |
|
14447 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_MAXPKT, data) ) goto error; |
|
14448 + |
|
14449 + data=0; |
|
14450 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_MAXPKT, &data) ) goto error; |
|
14451 + |
|
14452 + if((data&0xffff)!=0x0200) |
|
14453 + { |
|
14454 + deb_info("Open bulk EPA max packet size error!\n"); |
|
14455 + goto error; |
|
14456 + } |
|
14457 + |
|
14458 + deb_info("FULL SPEED\n"); |
|
14459 + } |
|
14460 + |
|
14461 + deb_info(" -%s \n", __FUNCTION__); |
|
14462 + |
|
14463 + return 0; |
|
14464 + |
|
14465 +error: |
|
14466 + return 1; |
|
14467 +} |
|
14468 + |
|
14469 + |
|
14470 +static int |
|
14471 +usb_init_setting( |
|
14472 + struct rtl2832_state* p_state) |
|
14473 +{ |
|
14474 + |
|
14475 + int data; |
|
14476 + |
|
14477 + deb_info(" +%s \n", __FUNCTION__); |
|
14478 + |
|
14479 + if ( usb_init_bulk_setting(p_state) ) goto error; |
|
14480 + |
|
14481 + //3 change fifo length of EPA |
|
14482 + data = 0x00000014; |
|
14483 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_FIFO_CFG, data) ) goto error; |
|
14484 + data = 0xcccccccc; |
|
14485 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_USB_EPA_FIFO_CFG, &data) ) goto error; |
|
14486 + if( (data & 0xff) != 0x14) |
|
14487 + { |
|
14488 + deb_info("Write error RTD2831_RMAP_INDEX_USB_EPA_FIFO_CFG =0x%x\n",data); |
|
14489 + goto error; |
|
14490 + } |
|
14491 + |
|
14492 + if ( usb_epa_fifo_reset(p_state) ) goto error; |
|
14493 + |
|
14494 + deb_info(" -%s \n", __FUNCTION__); |
|
14495 + |
|
14496 + return 0; |
|
14497 + |
|
14498 +error: |
|
14499 + return 1; |
|
14500 +} |
|
14501 + |
|
14502 + |
|
14503 + |
|
14504 +static int |
|
14505 +suspend_latch_setting( |
|
14506 + struct rtl2832_state* p_state, |
|
14507 + unsigned char resume) |
|
14508 +{ |
|
14509 + |
|
14510 + int data; |
|
14511 + deb_info(" +%s \n", __FUNCTION__); |
|
14512 + |
|
14513 + if (resume) |
|
14514 + { |
|
14515 + //3 Suspend_latch_en = 0 => Set BIT4 = 0 |
|
14516 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1, &data) ) goto error; |
|
14517 + data &= (~BIT4); //set bit4 to 0 |
|
14518 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1,data) ) goto error; |
|
14519 + } |
|
14520 + else |
|
14521 + { |
|
14522 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1, &data) ) goto error; |
|
14523 + data |= BIT4; //set bit4 to 1 |
|
14524 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1,data) ) goto error; |
|
14525 + } |
|
14526 + |
|
14527 + deb_info(" -%s \n", __FUNCTION__); |
|
14528 + |
|
14529 + return 0; |
|
14530 +error: |
|
14531 + return 1; |
|
14532 + |
|
14533 +} |
|
14534 + |
|
14535 + |
|
14536 + |
|
14537 + |
|
14538 + |
|
14539 +//3////// DEMOD_CTL1 => IR Setting , IR wakeup from suspend mode |
|
14540 +//3////// if resume =1, resume |
|
14541 +//3////// if resume = 0, suspend |
|
14542 + |
|
14543 + |
|
14544 +static int |
|
14545 +demod_ctl1_setting( |
|
14546 + struct rtl2832_state* p_state, |
|
14547 + unsigned char resume) |
|
14548 +{ |
|
14549 + |
|
14550 + int data; |
|
14551 + |
|
14552 + deb_info(" +%s \n", __FUNCTION__); |
|
14553 + |
|
14554 + if(resume) |
|
14555 + { |
|
14556 + // IR_suspend |
|
14557 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1, &data) ) goto error; |
|
14558 + data &= (~BIT2); //set bit2 to 0 |
|
14559 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1,data) ) goto error; |
|
14560 + |
|
14561 + //Clk_400k |
|
14562 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1, &data) ) goto error; |
|
14563 + data &= (~BIT3); //set bit3 to 0 |
|
14564 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1,data) ) goto error; |
|
14565 + } |
|
14566 + else |
|
14567 + { |
|
14568 + //Clk_400k |
|
14569 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1, &data) ) goto error; |
|
14570 + data |= BIT3; //set bit3 to 1 |
|
14571 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1,data) ) goto error; |
|
14572 + |
|
14573 + // IR_suspend |
|
14574 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1, &data) ) goto error; |
|
14575 + data |= BIT2; //set bit2 to 1 |
|
14576 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1,data) ) goto error; |
|
14577 + } |
|
14578 + |
|
14579 + deb_info(" -%s \n", __FUNCTION__); |
|
14580 + |
|
14581 + return 0; |
|
14582 +error: |
|
14583 + return 1; |
|
14584 + |
|
14585 +} |
|
14586 + |
|
14587 + |
|
14588 + |
|
14589 + |
|
14590 +static int |
|
14591 +demod_ctl_setting( |
|
14592 + struct rtl2832_state* p_state, |
|
14593 + unsigned char resume) |
|
14594 +{ |
|
14595 + |
|
14596 + int data; |
|
14597 + unsigned char tmp; |
|
14598 + |
|
14599 + deb_info(" +%s \n", __FUNCTION__); |
|
14600 + |
|
14601 + if(resume) |
|
14602 + { |
|
14603 + // PLL setting |
|
14604 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL, &data) ) goto error; |
|
14605 + data |= BIT7; //set bit7 to 1 |
|
14606 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL,data) ) goto error; |
|
14607 + |
|
14608 + |
|
14609 + //2 + Begin LOCK |
|
14610 + // Demod H/W Reset |
|
14611 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL, &data) ) goto error; |
|
14612 + data &= (~BIT5); //set bit5 to 0 |
|
14613 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL,data) ) goto error; |
|
14614 + |
|
14615 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL, &data) ) goto error; |
|
14616 + data |= BIT5; //set bit5 to 1 |
|
14617 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL,data) ) goto error; |
|
14618 + |
|
14619 + //3 reset page chache to 0 |
|
14620 + if ( read_rtl2832_demod_register(p_state->d, RTL2832_DEMOD_ADDR, 0, 1, &tmp, 1 ) ) goto error; |
|
14621 + //2 -End LOCK |
|
14622 + |
|
14623 + // delay 5ms |
|
14624 + platform_wait(5); |
|
14625 + |
|
14626 + // ADC_Q setting |
|
14627 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL, &data) ) goto error; |
|
14628 + data |= BIT3; //set bit3 to 1 |
|
14629 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL,data) ) goto error; |
|
14630 + |
|
14631 + // ADC_I setting |
|
14632 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL, &data) ) goto error; |
|
14633 + data |= BIT6; //set bit3 to 1 |
|
14634 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL,data) ) goto error; |
|
14635 + } |
|
14636 + else |
|
14637 + { |
|
14638 + |
|
14639 + // ADC_I setting |
|
14640 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL, &data) ) goto error; |
|
14641 + data &= (~BIT6); //set bit3 to 0 |
|
14642 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL,data) ) goto error; |
|
14643 + |
|
14644 + // ADC_Q setting |
|
14645 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL, &data) ) goto error; |
|
14646 + data &= (~BIT3); //set bit3 to 0 |
|
14647 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL,data) ) goto error; |
|
14648 + |
|
14649 + // PLL setting |
|
14650 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL, &data) ) goto error; |
|
14651 + data &= (~BIT7); //set bit7 to 0 |
|
14652 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_DEMOD_CTL,data) ) goto error; |
|
14653 + |
|
14654 + } |
|
14655 + |
|
14656 + deb_info(" -%s \n", __FUNCTION__); |
|
14657 + |
|
14658 + return 0; |
|
14659 +error: |
|
14660 + return 1; |
|
14661 + |
|
14662 +} |
|
14663 + |
|
14664 + |
|
14665 +static int |
|
14666 +read_tuner_id_register( |
|
14667 + struct rtl2832_state* p_state, |
|
14668 + unsigned char tuner_addr, |
|
14669 + unsigned char tuner_offset, |
|
14670 + unsigned char* id_data, |
|
14671 + unsigned char length) |
|
14672 +{ |
|
14673 + unsigned char i2c_repeater; |
|
14674 + struct dvb_usb_device* d = p_state->d; |
|
14675 + |
|
14676 + //2 + Begin LOCK |
|
14677 + if(read_rtl2832_demod_register(d, RTL2832_DEMOD_ADDR, 1, 1, &i2c_repeater, 1 )) goto error; |
|
14678 + i2c_repeater |= BIT3; |
|
14679 + if(write_rtl2832_demod_register(d, RTL2832_DEMOD_ADDR, 1, 1, &i2c_repeater, 1 )) goto error; |
|
14680 + |
|
14681 + if(read_rtl2832_tuner_register(d, tuner_addr, tuner_offset, id_data, length)) goto error; |
|
14682 + |
|
14683 + if(read_rtl2832_demod_register(d, RTL2832_DEMOD_ADDR, 1, 1, &i2c_repeater, 1 )) goto error; |
|
14684 + i2c_repeater &= (~BIT3); |
|
14685 + if(write_rtl2832_demod_register(d, RTL2832_DEMOD_ADDR, 1, 1, &i2c_repeater, 1 )) goto error; |
|
14686 + //2 - End LOCK |
|
14687 + return 0; |
|
14688 + |
|
14689 +error: |
|
14690 + return 1; |
|
14691 +} |
|
14692 + |
|
14693 + |
|
14694 + |
|
14695 +static int |
|
14696 +check_mxl5007t_chip_version( |
|
14697 + struct rtl2832_state* p_state, |
|
14698 + unsigned char *chipversion) |
|
14699 +{ |
|
14700 + |
|
14701 + unsigned char Buffer[LEN_2_BYTE]; |
|
14702 + unsigned char i2c_repeater; |
|
14703 + |
|
14704 + struct dvb_usb_device* d = p_state->d; |
|
14705 + |
|
14706 + |
|
14707 + Buffer[0] = (unsigned char)MXL5007T_I2C_READING_CONST; |
|
14708 + Buffer[1] = (unsigned char)MXL5007T_CHECK_ADDRESS; |
|
14709 + |
|
14710 + |
|
14711 + if(read_rtl2832_demod_register(d, RTL2832_DEMOD_ADDR, 1, 1, &i2c_repeater, 1 )) goto error; |
|
14712 + i2c_repeater |= BIT3; |
|
14713 + if(write_rtl2832_demod_register(d, RTL2832_DEMOD_ADDR, 1, 1, &i2c_repeater, 1 )) goto error; |
|
14714 + |
|
14715 + |
|
14716 + write_rtl2832_stdi2c(d, MXL5007T_BASE_ADDRESS , Buffer, LEN_2_BYTE); |
|
14717 + |
|
14718 + read_rtl2832_stdi2c(d, MXL5007T_BASE_ADDRESS, Buffer, LEN_1_BYTE); |
|
14719 + |
|
14720 + if(read_rtl2832_demod_register(d, RTL2832_DEMOD_ADDR, 1, 1, &i2c_repeater, 1 )) goto error; |
|
14721 + i2c_repeater &= (~BIT3); |
|
14722 + if(write_rtl2832_demod_register(d, RTL2832_DEMOD_ADDR, 1, 1, &i2c_repeater, 1 )) goto error; |
|
14723 + |
|
14724 + |
|
14725 + |
|
14726 + switch(Buffer[0]) |
|
14727 + { |
|
14728 + case MXL5007T_CHECK_VALUE: |
|
14729 + *chipversion = MxL_5007T_V4; |
|
14730 + break; |
|
14731 + default: |
|
14732 + *chipversion = MxL_UNKNOWN_ID; |
|
14733 + break; |
|
14734 + } |
|
14735 + |
|
14736 + return 0; |
|
14737 + |
|
14738 +error: |
|
14739 + |
|
14740 + return 1; |
|
14741 + |
|
14742 +} |
|
14743 + |
|
14744 + |
|
14745 + |
|
14746 + |
|
14747 + |
|
14748 + |
|
14749 +static int |
|
14750 +check_tuner_type( |
|
14751 + struct rtl2832_state *p_state) |
|
14752 +{ |
|
14753 + MT2266_EXTRA_MODULE *p_mt2266_extra; |
|
14754 + unsigned char tuner_id_data[2]; |
|
14755 + |
|
14756 + |
|
14757 + if ((!read_tuner_id_register(p_state, MT2266_TUNER_ADDR, MT2266_OFFSET, tuner_id_data, LEN_1_BYTE)) && |
|
14758 + ( tuner_id_data[0] == MT2266_CHECK_VAL )) |
|
14759 + { |
|
14760 + p_state->tuner_type = RTL2832_TUNER_TYPE_MT2266; |
|
14761 + } |
|
14762 + else |
|
14763 + { |
|
14764 + if ((!read_tuner_id_register(p_state, FC2580_TUNER_ADDR, FC2580_OFFSET, tuner_id_data, LEN_1_BYTE)) && |
|
14765 + ((tuner_id_data[0]&(~BIT7)) == FC2580_CHECK_VAL )) |
|
14766 + { |
|
14767 + p_state->tuner_type = RTL2832_TUNER_TYPE_FC2580; |
|
14768 + } |
|
14769 + else |
|
14770 + { |
|
14771 + if ((!read_tuner_id_register(p_state, TUA9001_TUNER_ADDR, TUA9001_OFFSET, tuner_id_data, LEN_2_BYTE)) && |
|
14772 + (((tuner_id_data[0]<<8)|tuner_id_data[1]) == TUA9001_CHECK_VAL )) |
|
14773 + { |
|
14774 + p_state->tuner_type = RTL2832_TUNER_TYPE_TUA9001; |
|
14775 + |
|
14776 + } |
|
14777 + else |
|
14778 + { |
|
14779 + unsigned char chip_version; |
|
14780 + if ((!check_mxl5007t_chip_version(p_state, &chip_version)) && |
|
14781 + (chip_version == MXL5007T_CHECK_VALUE) ) |
|
14782 + { |
|
14783 + p_state->tuner_type = RTL2832_TUNER_TYPE_MXL5007T; |
|
14784 + } |
|
14785 + else |
|
14786 + { |
|
14787 + |
|
14788 + p_state->tuner_type = RTL2832_TUNER_TYPE_UNKNOWN; |
|
14789 + } |
|
14790 + } |
|
14791 + } |
|
14792 + |
|
14793 + } |
|
14794 + |
|
14795 + |
|
14796 + if( p_state->tuner_type == RTL2832_TUNER_TYPE_MT2266) |
|
14797 + { |
|
14798 + //3 Build RTL2832 MT2266 NIM module. |
|
14799 + BuildRtl2832Mt2266Module( |
|
14800 + &p_state->pNim, |
|
14801 + &p_state->DvbtNimModuleMemory, |
|
14802 + &p_state->Rtl2832Mt2266ExtraModuleMemory, |
|
14803 + |
|
14804 + 9, // Maximum I2C reading byte number is 9. |
|
14805 + 8, // Maximum I2C writing byte number is 8. |
|
14806 + NULL,//custom_i2c_read, // Employ CustomI2cRead() as basic I2C reading function. |
|
14807 + NULL,//custom_i2c_write, // Employ CustomI2cWrite() as basic I2C writing function. |
|
14808 + custom_wait_ms, // Employ CustomWaitMs() as basic waiting function. |
|
14809 + |
|
14810 + &p_state->Rtl2832ExtraModuleMemory, // Employ RTL2832 extra module for RTL2832 module. |
|
14811 + RTL2832_DEMOD_ADDR, // The RTL2832 I2C device address is 0x20 in 8-bit format. |
|
14812 + CRYSTAL_FREQ_28800000HZ, // The RTL2832 crystal frequency is 28.8 MHz. |
|
14813 + RTL2832_APPLICATION_DONGLE, // The RTL2832 application mode is STB mode. |
|
14814 + TS_INTERFACE_PARALLEL, |
|
14815 + 200, // The RTL2832 update function reference period is 200 millisecond |
|
14816 + OFF, // The RTL2832 Function 1 enabling status is on. |
|
14817 + |
|
14818 + &p_state->Mt2266ExtraModuleMemory, // Employ MT2266 extra module for MT2266 module. |
|
14819 + MT2266_TUNER_ADDR // The MT2266 I2C device address is 0xc0 in 8-bit format. |
|
14820 + ); |
|
14821 + |
|
14822 + p_mt2266_extra = (MT2266_EXTRA_MODULE *)(p_state->pNim->pTuner->pExtra); |
|
14823 + |
|
14824 + if(p_mt2266_extra->OpenHandle(p_state->pNim->pTuner)) |
|
14825 + deb_info("%s : MT2266 Open Handle Failed....\n", __FUNCTION__); |
|
14826 + p_state->is_mt2266_nim_module_built = 1; |
|
14827 + |
|
14828 + deb_info("%s : MT2266 tuner on board...\n", __FUNCTION__); |
|
14829 + } |
|
14830 + else if( p_state->tuner_type == RTL2832_TUNER_TYPE_FC2580) |
|
14831 + { |
|
14832 + |
|
14833 + //3Build RTL2832 FC2580 NIM module. |
|
14834 + BuildRtl2832Fc2580Module( |
|
14835 + &p_state->pNim, |
|
14836 + &p_state->DvbtNimModuleMemory, |
|
14837 + |
|
14838 + 9, // Maximum I2C reading byte number is 9. |
|
14839 + 8, // Maximum I2C writing byte number is 8. |
|
14840 + NULL,//custom_i2c_read, // Employ CustomI2cRead() as basic I2C reading function. |
|
14841 + NULL,//custom_i2c_write, // Employ CustomI2cWrite() as basic I2C writing function. |
|
14842 + custom_wait_ms, // Employ CustomWaitMs() as basic waiting function. |
|
14843 + |
|
14844 + &p_state->Rtl2832ExtraModuleMemory, // Employ RTL2832 extra module for RTL2832 module. |
|
14845 + RTL2832_DEMOD_ADDR, // The RTL2832 I2C device address is 0x20 in 8-bit format. |
|
14846 + CRYSTAL_FREQ_28800000HZ, // The RTL2832 crystal frequency is 28.8 MHz. |
|
14847 + RTL2832_APPLICATION_DONGLE, // The RTL2832 application mode is STB mode. |
|
14848 + TS_INTERFACE_PARALLEL, |
|
14849 + 200, // The RTL2832 update function reference period is 200 millisecond |
|
14850 + OFF, // The RTL2832 Function 1 enabling status is on. |
|
14851 + |
|
14852 + &p_state->Fc2580ExtraModuleMemory, // Employ FC2580 extra module for FC2580 module. |
|
14853 + FC2580_TUNER_ADDR, // The FC2580 I2C device address is 0xac in 8-bit format. |
|
14854 + CRYSTAL_FREQ_16384000HZ, // The FC2580 crystal frequency is 16.384 MHz. |
|
14855 + FC2580_AGC_INTERNAL // The FC2580 AGC mode is external AGC mode. |
|
14856 + ); |
|
14857 + |
|
14858 + deb_info("%s : FC2580 tuner on board...\n", __FUNCTION__); |
|
14859 + } |
|
14860 + else if( p_state->tuner_type == RTL2832_TUNER_TYPE_TUA9001) |
|
14861 + { |
|
14862 + |
|
14863 + //3Build RTL2832 TUA9001 NIM module. |
|
14864 + BuildRtl2832Tua9001Module( |
|
14865 + &p_state->pNim, |
|
14866 + &p_state->DvbtNimModuleMemory, |
|
14867 + |
|
14868 + 9, // Maximum I2C reading byte number is 9. |
|
14869 + 8, // Maximum I2C writing byte number is 8. |
|
14870 + NULL,//custom_i2c_read, // Employ CustomI2cRead() as basic I2C reading function. |
|
14871 + NULL,//custom_i2c_write, // Employ CustomI2cWrite() as basic I2C writing function. |
|
14872 + custom_wait_ms, // Employ CustomWaitMs() as basic waiting function. |
|
14873 + |
|
14874 + &p_state->Rtl2832ExtraModuleMemory, // Employ RTL2832 extra module for RTL2832 module. |
|
14875 + RTL2832_DEMOD_ADDR, // The RTL2832 I2C device address is 0x20 in 8-bit format. |
|
14876 + CRYSTAL_FREQ_28800000HZ, // The RTL2832 crystal frequency is 28.8 MHz. |
|
14877 + RTL2832_APPLICATION_DONGLE, // The RTL2832 application mode is STB mode. |
|
14878 + TS_INTERFACE_PARALLEL, |
|
14879 + 200, // The RTL2832 update function reference period is 200 millisecond |
|
14880 + OFF, // The RTL2832 Function 1 enabling status is on. |
|
14881 + |
|
14882 + &p_state->TUA9001ExtraModuleMemory, // Employ TUA9001 extra module for FC2580 module. |
|
14883 + TUA9001_TUNER_ADDR // The TUA9001 I2C device address is 0xc0 in 8-bit format. |
|
14884 + ); |
|
14885 + |
|
14886 + deb_info("%s : TUA9001 tuner on board...\n", __FUNCTION__); |
|
14887 + } |
|
14888 + else if( p_state->tuner_type == RTL2832_TUNER_TYPE_MXL5007T) |
|
14889 + { |
|
14890 + |
|
14891 + //3Build RTL2832 MXL5007 NIM module. |
|
14892 + BuildRtl2832Mxl5007tModule( |
|
14893 + &p_state->pNim, |
|
14894 + &p_state->DvbtNimModuleMemory, |
|
14895 + |
|
14896 + 9, // Maximum I2C reading byte number is 9. |
|
14897 + 8, // Maximum I2C writing byte number is 8. |
|
14898 + custom_i2c_read, // Employ CustomI2cRead() as basic I2C reading function. |
|
14899 + custom_i2c_write, // Employ CustomI2cWrite() as basic I2C writing function. |
|
14900 + custom_wait_ms, // Employ CustomWaitMs() as basic waiting function. |
|
14901 + |
|
14902 + &p_state->Rtl2832ExtraModuleMemory, // Employ RTL2832 extra module for RTL2832 module. |
|
14903 + RTL2832_DEMOD_ADDR, // The RTL2832 I2C device address is 0x20 in 8-bit format. |
|
14904 + CRYSTAL_FREQ_28800000HZ, // The RTL2832 crystal frequency is 28.8 MHz. |
|
14905 + RTL2832_APPLICATION_DONGLE, // The RTL2832 application mode is STB mode. |
|
14906 + TS_INTERFACE_PARALLEL, |
|
14907 + 200, // The RTL2832 update function reference period is 200 millisecond |
|
14908 + OFF, // The RTL2832 Function 1 enabling status is on. |
|
14909 + |
|
14910 + &p_state->MXL5007TExtraModuleMemory, // Employ MxL5007T extra module for MxL5007T module. |
|
14911 + MXL5007T_BASE_ADDRESS, // The MxL5007T I2C device address is 0xc0 in 8-bit format. |
|
14912 + CRYSTAL_FREQ_16000000HZ, // The MxL5007T Crystal frequency is 16.0 MHz. |
|
14913 + MXL5007T_CLK_OUT_DISABLE, // The MxL5007T clock output mode is disabled. |
|
14914 + MXL5007T_CLK_OUT_AMP_0 // The MxL5007T clock output amplitude is 0. |
|
14915 + ); |
|
14916 + |
|
14917 + deb_info("%s : MXL5007T tuner on board...\n", __FUNCTION__); |
|
14918 + } |
|
14919 + else |
|
14920 + { |
|
14921 + deb_info("%s : Unknown tuner on board...\n", __FUNCTION__); |
|
14922 + goto error; |
|
14923 + } |
|
14924 + |
|
14925 + // Set user defined data pointer of base interface structure for custom basic functions. |
|
14926 + p_state->pNim->pBaseInterface->SetUserDefinedDataPointer(p_state->pNim->pBaseInterface, p_state->d ); |
|
14927 + |
|
14928 + |
|
14929 + return 0; |
|
14930 +error: |
|
14931 + return 1; |
|
14932 +} |
|
14933 + |
|
14934 +static int |
|
14935 +gpio1_output_enable_direction( |
|
14936 + struct rtl2832_state* p_state) |
|
14937 +{ |
|
14938 + int data; |
|
14939 + // GPD_GPIO1=0, GPIO1 output direction |
|
14940 + data = 0; |
|
14941 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_DIR_BIT1,data) ) goto error; |
|
14942 + |
|
14943 + // GPOE_GPIO1=1, GPIO1 output enable |
|
14944 + data = 1; |
|
14945 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_EN_BIT1,data) ) goto error; |
|
14946 + |
|
14947 + return 0; |
|
14948 +error: |
|
14949 + return 1; |
|
14950 +} |
|
14951 + |
|
14952 + |
|
14953 +static int |
|
14954 +gpio6_output_enable_direction( |
|
14955 + struct rtl2832_state* p_state) |
|
14956 +{ |
|
14957 + int data; |
|
14958 + // GPD_GPIO6=0, GPIO6 output direction |
|
14959 + data = 0; |
|
14960 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_DIR_BIT6,data) ) goto error; |
|
14961 + |
|
14962 + // GPOE_GPIO6=1, GPIO6 output enable |
|
14963 + data = 1; |
|
14964 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_EN_BIT6,data) ) goto error; |
|
14965 + |
|
14966 + return 0; |
|
14967 +error: |
|
14968 + return 1; |
|
14969 +} |
|
14970 + |
|
14971 + |
|
14972 + |
|
14973 + |
|
14974 +static int |
|
14975 +check_reset_parameters( |
|
14976 + struct rtl2832_state* p_state, |
|
14977 + unsigned long frequency, |
|
14978 + enum fe_bandwidth bandwidth, |
|
14979 + int* reset_needed) |
|
14980 +{ |
|
14981 + |
|
14982 + int is_lock; |
|
14983 + unsigned int diff_ms; |
|
14984 + |
|
14985 + deb_info(" +%s \n", __FUNCTION__); |
|
14986 + |
|
14987 + *reset_needed = 1; //3initialize "reset_needed" |
|
14988 + |
|
14989 + if( (p_state->current_frequency == frequency) && (p_state->current_bandwidth == bandwidth) ) |
|
14990 + { |
|
14991 + if( p_state->pNim->IsSignalLocked(p_state->pNim, &is_lock) ) goto error; |
|
14992 + diff_ms = 0; |
|
14993 + |
|
14994 + while( !(is_lock == LOCKED || diff_ms > 200) ) |
|
14995 + { |
|
14996 + platform_wait(40); |
|
14997 + diff_ms += 40; |
|
14998 + if( p_state->pNim->IsSignalLocked(p_state->pNim, &is_lock) ) goto error; |
|
14999 + } |
|
15000 + |
|
15001 + if (is_lock==YES) |
|
15002 + { |
|
15003 + *reset_needed = 0; //3 set "reset_needed" = 0 |
|
15004 + deb_info("%s : The same frequency = %d setting\n", __FUNCTION__, (int)frequency); |
|
15005 + } |
|
15006 + } |
|
15007 + |
|
15008 + deb_info(" -%s \n", __FUNCTION__); |
|
15009 + |
|
15010 + return 0; |
|
15011 + |
|
15012 +error: |
|
15013 + |
|
15014 + *reset_needed = 1; //3 set "reset_needed" = 1 |
|
15015 + return 1; |
|
15016 +} |
|
15017 + |
|
15018 + |
|
15019 +/* |
|
15020 +void |
|
15021 +rtl2832_update_functions(struct work_struct *work) |
|
15022 +{ |
|
15023 + struct rtl2832_state* p_state = container_of( work , struct rtl2832_state , update_procedure_work.work); |
|
15024 + unsigned long ber_num, ber_dem; |
|
15025 + long snr_num = 0; |
|
15026 + long snr_dem = 0; |
|
15027 + long _snr= 0; |
|
15028 + |
|
15029 + |
|
15030 + if( mutex_lock_interruptible(&p_state->i2c_repeater_mutex) ) goto mutex_error; |
|
15031 + |
|
15032 + deb_info("+%s\n", __FUNCTION__); |
|
15033 + |
|
15034 + p_state->pNim->UpdateFunction(p_state->pNim); |
|
15035 + p_state->pNim->GetBer( p_state->pNim , &ber_num , &ber_dem); |
|
15036 + p_state->pNim->GetSnrDb(p_state->pNim, &snr_num, &snr_dem) ; |
|
15037 + |
|
15038 + _snr = snr_num / snr_dem; |
|
15039 + if( _snr < 0 ) _snr = 0; |
|
15040 + |
|
15041 + deb_info("-%s : ber = %lu, snr = %lu\n", __FUNCTION__,ber_num,_snr); |
|
15042 + |
|
15043 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15044 + |
|
15045 + schedule_delayed_work(&p_state->update_procedure_work,UPDATE_PROCEDURE_PERIOD); |
|
15046 + |
|
15047 + return; |
|
15048 + |
|
15049 +mutex_error: |
|
15050 + return; |
|
15051 + |
|
15052 +} |
|
15053 + |
|
15054 +*/ |
|
15055 + |
|
15056 + |
|
15057 +static int |
|
15058 +rtl2832_init( |
|
15059 + struct dvb_frontend* fe) |
|
15060 +{ |
|
15061 + struct rtl2832_state* p_state = fe->demodulator_priv; |
|
15062 + |
|
15063 + if( mutex_lock_interruptible(&p_state->i2c_repeater_mutex) ) goto mutex_error; |
|
15064 + |
|
15065 + deb_info(" +%s\n", __FUNCTION__); |
|
15066 + |
|
15067 + //usb_reset_device(p_state->d->udev); |
|
15068 + |
|
15069 + if( usb_init_setting(p_state) ) goto error; |
|
15070 + |
|
15071 + if( gpio3_out_setting(p_state) ) goto error; //3Set GPIO3 OUT |
|
15072 + |
|
15073 + if( demod_ctl1_setting(p_state , 1) ) goto error; //3 DEMOD_CTL1, resume = 1 |
|
15074 + |
|
15075 + if( set_demod_power(p_state , 1) ) goto error; //3 turn ON demod power |
|
15076 + |
|
15077 + if( suspend_latch_setting(p_state , 1) ) goto error; //3 suspend_latch_en = 0, resume = 1 |
|
15078 + |
|
15079 + if( demod_ctl_setting(p_state , 1) ) goto error; //3 DEMOD_CTL, resume =1 |
|
15080 + |
|
15081 + //3 Auto detect Tuner Power Pin (GPIO3 or GPIO4) |
|
15082 + if( set_tuner_power(p_state , 0 , 1) ) goto error; //3 turn ON tuner power, 1st try GPIO3 |
|
15083 + |
|
15084 + if( check_tuner_type(p_state) ) |
|
15085 + { |
|
15086 + if(p_state->tuner_type == RTL2832_TUNER_TYPE_UNKNOWN) |
|
15087 + { |
|
15088 + if( set_tuner_power(p_state , 0 , 0) ) goto error; //3recover GPIO3 setting at 1st try |
|
15089 + if( set_tuner_power(p_state , 1 , 1) ) goto error; //3 2nd try GPIO4 |
|
15090 + if( check_tuner_type(p_state) ) goto error; |
|
15091 + |
|
15092 + p_state->pNim->pTuner->b_set_tuner_power_gpio4 = 1; //4 Tuner Power Pin : GPIO4 |
|
15093 + } |
|
15094 + else |
|
15095 + { |
|
15096 + goto error; |
|
15097 + } |
|
15098 + } |
|
15099 + else |
|
15100 + { |
|
15101 + p_state->pNim->pTuner->b_set_tuner_power_gpio4 = 0; //4 Tuner Power Pin : GPIO3 |
|
15102 + } |
|
15103 + |
|
15104 + |
|
15105 + if( p_state->tuner_type == RTL2832_TUNER_TYPE_TUA9001) |
|
15106 + { |
|
15107 + if( gpio1_output_enable_direction(p_state) ) goto error; |
|
15108 + } |
|
15109 + else if( p_state->tuner_type == RTL2832_TUNER_TYPE_MXL5007T) |
|
15110 + { |
|
15111 + //3 MXL5007T : Set GPIO6 OUTPUT_EN & OUTPUT_DIR & OUTPUT_VAL for YUAN |
|
15112 + int data; |
|
15113 + if( gpio6_output_enable_direction(p_state) ) goto error; |
|
15114 + |
|
15115 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL, &data) ) goto error; |
|
15116 + data |= BIT6; |
|
15117 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL,data) ) goto error; |
|
15118 + |
|
15119 + } |
|
15120 + |
|
15121 + |
|
15122 + //3 Nim initialize |
|
15123 + if ( p_state->pNim->Initialize(p_state->pNim) ) goto error; |
|
15124 + |
|
15125 + p_state->is_initial = 1; |
|
15126 + |
|
15127 + deb_info(" -%s \n", __FUNCTION__); |
|
15128 + |
|
15129 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15130 + |
|
15131 + //schedule_delayed_work(&(p_state->update_procedure_work), 0); //3 Initialize update function |
|
15132 + |
|
15133 + return 0; |
|
15134 + |
|
15135 +error: |
|
15136 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15137 + |
|
15138 +mutex_error: |
|
15139 + deb_info(" -%s error end\n", __FUNCTION__); |
|
15140 + |
|
15141 + return -1; |
|
15142 +} |
|
15143 + |
|
15144 + |
|
15145 +static void |
|
15146 +rtl2832_release( |
|
15147 + struct dvb_frontend* fe) |
|
15148 +{ |
|
15149 + struct rtl2832_state* p_state = fe->demodulator_priv; |
|
15150 + MT2266_EXTRA_MODULE* p_mt2266_extra; |
|
15151 + |
|
15152 + if( p_state->pNim== NULL) |
|
15153 + { |
|
15154 + deb_info(" %s pNim = NULL \n", __FUNCTION__); |
|
15155 + return; |
|
15156 + } |
|
15157 + |
|
15158 + if( p_state->is_mt2266_nim_module_built) |
|
15159 + { |
|
15160 + p_mt2266_extra = (MT2266_EXTRA_MODULE *)(p_state->pNim->pTuner->pExtra); |
|
15161 + p_mt2266_extra->CloseHandle(p_state->pNim->pTuner); |
|
15162 + p_state->is_mt2266_nim_module_built = 0; |
|
15163 + } |
|
15164 + |
|
15165 + if(p_state->is_initial) |
|
15166 + { |
|
15167 + // cancel_rearming_delayed_work( &(p_state->update_procedure_work) ); |
|
15168 + // flush_scheduled_work(); |
|
15169 + p_state->is_initial = 0; |
|
15170 + } |
|
15171 + |
|
15172 + kfree(p_state); |
|
15173 + |
|
15174 + deb_info(" %s \n", __FUNCTION__); |
|
15175 + |
|
15176 + return; |
|
15177 +} |
|
15178 + |
|
15179 + |
|
15180 + |
|
15181 +static int |
|
15182 +rtl2832_sleep( |
|
15183 + struct dvb_frontend* fe) |
|
15184 +{ |
|
15185 + struct rtl2832_state* p_state = fe->demodulator_priv; |
|
15186 + MT2266_EXTRA_MODULE* p_mt2266_extra; |
|
15187 + DVBT_DEMOD_MODULE *pDemod; |
|
15188 + DVBT_NIM_MODULE *pNim; |
|
15189 + int data; |
|
15190 + |
|
15191 +// int page_no, addr_no; |
|
15192 +// unsigned char reg_value; |
|
15193 + |
|
15194 + |
|
15195 + pNim = p_state->pNim; |
|
15196 + pDemod = pNim->pDemod; |
|
15197 + |
|
15198 + if( pNim== NULL) |
|
15199 + { |
|
15200 + deb_info(" %s pNim = NULL \n", __FUNCTION__); |
|
15201 + return -1; |
|
15202 + } |
|
15203 + |
|
15204 + if( p_state->is_mt2266_nim_module_built) |
|
15205 + { |
|
15206 + p_mt2266_extra = (MT2266_EXTRA_MODULE *)(p_state->pNim->pTuner->pExtra); |
|
15207 + p_mt2266_extra->CloseHandle(p_state->pNim->pTuner); |
|
15208 + p_state->is_mt2266_nim_module_built = 0; |
|
15209 + } |
|
15210 + |
|
15211 + if( p_state->is_initial ) |
|
15212 + { |
|
15213 + |
|
15214 + // cancel_rearming_delayed_work( &(p_state->update_procedure_work) ); |
|
15215 + // flush_scheduled_work(); |
|
15216 + p_state->is_initial = 0; |
|
15217 + } |
|
15218 + |
|
15219 + if( mutex_lock_interruptible(&p_state->i2c_repeater_mutex) ) goto mutex_error; |
|
15220 + |
|
15221 + deb_info(" +%s \n", __FUNCTION__); |
|
15222 + |
|
15223 +#if 0 |
|
15224 + //2 For debug |
|
15225 + for( page_no = 0; page_no < 3; page_no++ ) |
|
15226 + { |
|
15227 + pDemod->SetRegPage(pDemod, page_no); |
|
15228 + for( addr_no = 0; addr_no < 256; addr_no++ ) |
|
15229 + { |
|
15230 + pDemod->GetRegBytes(pDemod, addr_no, ®_value, 1); |
|
15231 + printk("0x%x, 0x%x, 0x%x\n", page_no, addr_no, reg_value); |
|
15232 + } |
|
15233 + } |
|
15234 +#endif |
|
15235 + |
|
15236 + if( p_state->tuner_type == RTL2832_TUNER_TYPE_MXL5007T) |
|
15237 + { |
|
15238 + //3 MXL5007T : Set GPIO6 OUTPUT_VAL OFF for YUAN |
|
15239 + if ( read_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL, &data) ) goto error; |
|
15240 + data &= (~BIT6); |
|
15241 + if ( write_usb_sys_register(p_state, RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL,data) ) goto error; |
|
15242 + |
|
15243 + } |
|
15244 + |
|
15245 + |
|
15246 + if( demod_ctl1_setting(p_state , 0) ) goto error; //3 DEMOD_CTL1, resume = 0 |
|
15247 + |
|
15248 + if( set_tuner_power(p_state, p_state->pNim->pTuner->b_set_tuner_power_gpio4, 0) ) goto error; //3 turn OFF tuner power |
|
15249 + |
|
15250 + if( demod_ctl_setting(p_state , 0) ) goto error; //3 DEMOD_CTL, resume =0 |
|
15251 + //2 for H/W reason |
|
15252 + //if( suspend_latch_setting(p_state , 0) ) goto error; //3 suspend_latch_en = 1, resume = 0 |
|
15253 + |
|
15254 + //if( set_demod_power(p_state , 0) ) goto error; //3 turn OFF demod power |
|
15255 + |
|
15256 + deb_info(" -%s \n", __FUNCTION__); |
|
15257 + |
|
15258 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15259 + |
|
15260 + return 0; |
|
15261 + |
|
15262 +error: |
|
15263 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15264 + |
|
15265 +mutex_error: |
|
15266 + |
|
15267 + return 1; |
|
15268 +} |
|
15269 + |
|
15270 + |
|
15271 + |
|
15272 + |
|
15273 + |
|
15274 +static int |
|
15275 +rtl2832_set_parameters( |
|
15276 + struct dvb_frontend* fe, |
|
15277 + struct dvb_frontend_parameters* param) |
|
15278 +{ |
|
15279 + struct rtl2832_state* p_state = fe->demodulator_priv; |
|
15280 + struct dvb_ofdm_parameters* p_ofdm_param= ¶m->u.ofdm; |
|
15281 + unsigned long frequency = param->frequency; |
|
15282 + int bandwidth_mode; |
|
15283 + int is_signal_present; |
|
15284 + int reset_needed; |
|
15285 + |
|
15286 + |
|
15287 + if( p_state->pNim== NULL) |
|
15288 + { |
|
15289 + deb_info(" %s pNim = NULL \n", __FUNCTION__); |
|
15290 + return -1; |
|
15291 + } |
|
15292 + |
|
15293 + if( mutex_lock_interruptible(&p_state->i2c_repeater_mutex) ) goto mutex_error; |
|
15294 + |
|
15295 + deb_info(" +%s frequency = %lu , bandwidth = %u\n", __FUNCTION__, frequency ,p_ofdm_param->bandwidth); |
|
15296 + |
|
15297 + if ( check_reset_parameters( p_state , frequency , p_ofdm_param->bandwidth, &reset_needed) ) goto error; |
|
15298 + if( reset_needed == 0 ) |
|
15299 + { |
|
15300 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15301 + return 0; |
|
15302 + } |
|
15303 + |
|
15304 + |
|
15305 + switch (p_ofdm_param->bandwidth) |
|
15306 + { |
|
15307 + case BANDWIDTH_6_MHZ: |
|
15308 + bandwidth_mode = DVBT_BANDWIDTH_6MHZ; |
|
15309 + break; |
|
15310 + |
|
15311 + case BANDWIDTH_7_MHZ: |
|
15312 + bandwidth_mode = DVBT_BANDWIDTH_7MHZ; |
|
15313 + break; |
|
15314 + |
|
15315 + case BANDWIDTH_8_MHZ: |
|
15316 + default: |
|
15317 + bandwidth_mode = DVBT_BANDWIDTH_8MHZ; |
|
15318 + break; |
|
15319 + } |
|
15320 + |
|
15321 + if ( p_state->pNim->SetParameters( p_state->pNim, frequency , bandwidth_mode ) ) goto error; |
|
15322 + |
|
15323 + |
|
15324 + if ( p_state->pNim->IsSignalPresent( p_state->pNim, &is_signal_present) ) goto error; |
|
15325 + |
|
15326 + deb_info(" %s : ****** Signal Present = %d ******\n", __FUNCTION__, is_signal_present); |
|
15327 + |
|
15328 + p_state->current_frequency = frequency; |
|
15329 + p_state->current_bandwidth = p_ofdm_param->bandwidth; |
|
15330 + |
|
15331 + deb_info(" -%s \n", __FUNCTION__); |
|
15332 + |
|
15333 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15334 + |
|
15335 + return 0; |
|
15336 + |
|
15337 +error: |
|
15338 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15339 + |
|
15340 +mutex_error: |
|
15341 + p_state->current_frequency = 0; |
|
15342 + p_state->current_bandwidth = -1; |
|
15343 + deb_info(" -%s error end\n", __FUNCTION__); |
|
15344 + |
|
15345 + return -1; |
|
15346 + |
|
15347 +} |
|
15348 + |
|
15349 + |
|
15350 + |
|
15351 +static int |
|
15352 +rtl2832_get_parameters( |
|
15353 + struct dvb_frontend* fe, |
|
15354 + struct dvb_frontend_parameters* param) |
|
15355 +{ |
|
15356 + //struct rtl2832_state* p_state = fe->demodulator_priv; |
|
15357 + return 0; |
|
15358 +} |
|
15359 + |
|
15360 + |
|
15361 +static int |
|
15362 +rtl2832_read_status( |
|
15363 + struct dvb_frontend* fe, |
|
15364 + fe_status_t* status) |
|
15365 +{ |
|
15366 + struct rtl2832_state* p_state = fe->demodulator_priv; |
|
15367 + int is_lock; |
|
15368 + unsigned long ber_num, ber_dem; |
|
15369 + long snr_num, snr_dem, snr; |
|
15370 + |
|
15371 + |
|
15372 + if( p_state->pNim== NULL) |
|
15373 + { |
|
15374 + deb_info(" %s pNim = NULL \n", __FUNCTION__); |
|
15375 + return -1; |
|
15376 + } |
|
15377 + |
|
15378 + *status = 0; //3initialize "status" |
|
15379 + |
|
15380 + if( mutex_lock_interruptible(&p_state->i2c_repeater_mutex) ) goto mutex_error; |
|
15381 + |
|
15382 + if( p_state->pNim->GetBer( p_state->pNim , &ber_num , &ber_dem) ) goto error; |
|
15383 + |
|
15384 + if (p_state->pNim->GetSnrDb(p_state->pNim, &snr_num, &snr_dem) ) goto error; |
|
15385 + |
|
15386 + if( p_state->pNim->IsSignalLocked(p_state->pNim, &is_lock) ) goto error; |
|
15387 + |
|
15388 + |
|
15389 + if( is_lock==YES ) *status|= (FE_HAS_CARRIER| FE_HAS_VITERBI| FE_HAS_LOCK| FE_HAS_SYNC| FE_HAS_SIGNAL); |
|
15390 + |
|
15391 + snr = snr_num/snr_dem; |
|
15392 + |
|
15393 + deb_info("%s :******Signal Lock=%d******\n", __FUNCTION__, is_lock); |
|
15394 + deb_info("%s : ber = 0x%x \n", __FUNCTION__, (unsigned int)ber_num); |
|
15395 + deb_info("%s : snr = 0x%x \n", __FUNCTION__, (int)snr); |
|
15396 + |
|
15397 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15398 + |
|
15399 + return 0; |
|
15400 + |
|
15401 +error: |
|
15402 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15403 + |
|
15404 +mutex_error: |
|
15405 + return -1; |
|
15406 +} |
|
15407 + |
|
15408 + |
|
15409 + |
|
15410 +static int |
|
15411 +rtl2832_read_ber( |
|
15412 + struct dvb_frontend* fe, |
|
15413 + u32* ber) |
|
15414 +{ |
|
15415 + struct rtl2832_state* p_state = fe->demodulator_priv; |
|
15416 + unsigned long ber_num, ber_dem; |
|
15417 + |
|
15418 + if( p_state->pNim== NULL) |
|
15419 + { |
|
15420 + deb_info(" %s pNim = NULL \n", __FUNCTION__); |
|
15421 + return -1; |
|
15422 + } |
|
15423 + |
|
15424 + |
|
15425 + if( mutex_lock_interruptible(&p_state->i2c_repeater_mutex) ) goto mutex_error; |
|
15426 + |
|
15427 + if( p_state->pNim->GetBer( p_state->pNim , &ber_num , &ber_dem) ) |
|
15428 + { |
|
15429 + *ber = 19616; |
|
15430 + goto error; |
|
15431 + } |
|
15432 + |
|
15433 + *ber = ber_num; |
|
15434 + |
|
15435 + deb_info(" %s : ber = 0x%x \n", __FUNCTION__, *ber); |
|
15436 + |
|
15437 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15438 + |
|
15439 + return 0; |
|
15440 + |
|
15441 +error: |
|
15442 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15443 + |
|
15444 +mutex_error: |
|
15445 + return -1; |
|
15446 +} |
|
15447 + |
|
15448 + |
|
15449 +static int |
|
15450 +rtl2832_read_signal_strength( |
|
15451 + struct dvb_frontend* fe, |
|
15452 + u16* strength) |
|
15453 +{ |
|
15454 + struct rtl2832_state* p_state = fe->demodulator_priv; |
|
15455 + unsigned long _strength; |
|
15456 + |
|
15457 + if( p_state->pNim== NULL) |
|
15458 + { |
|
15459 + deb_info(" %s pNim = NULL \n", __FUNCTION__); |
|
15460 + return -1; |
|
15461 + } |
|
15462 + |
|
15463 + if( mutex_lock_interruptible(&p_state->i2c_repeater_mutex) ) goto mutex_error; |
|
15464 + |
|
15465 + if( p_state->pNim->GetSignalStrength( p_state->pNim , &_strength) ) |
|
15466 + { |
|
15467 + *strength = 0; |
|
15468 + goto error; |
|
15469 + } |
|
15470 + |
|
15471 + *strength = (_strength<<8) | _strength; |
|
15472 + |
|
15473 + deb_info(" %s : strength = 0x%x \n", __FUNCTION__, *strength); |
|
15474 + |
|
15475 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15476 + |
|
15477 + return 0; |
|
15478 + |
|
15479 +error: |
|
15480 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15481 + |
|
15482 +mutex_error: |
|
15483 + return -1; |
|
15484 +} |
|
15485 + |
|
15486 + |
|
15487 +static int |
|
15488 +rtl2832_read_signal_quality( |
|
15489 + struct dvb_frontend* fe, |
|
15490 + u32* quality) |
|
15491 +{ |
|
15492 + struct rtl2832_state* p_state = fe->demodulator_priv; |
|
15493 + unsigned long _quality; |
|
15494 + |
|
15495 + if( p_state->pNim== NULL) |
|
15496 + { |
|
15497 + deb_info(" %s pNim = NULL \n", __FUNCTION__); |
|
15498 + return -1; |
|
15499 + } |
|
15500 + |
|
15501 + if( mutex_lock_interruptible(&p_state->i2c_repeater_mutex) ) goto mutex_error; |
|
15502 + |
|
15503 + if ( p_state->pNim->GetSignalQuality( p_state->pNim , &_quality) ) |
|
15504 + { |
|
15505 + *quality = 0; |
|
15506 + goto error; |
|
15507 + } |
|
15508 + |
|
15509 + *quality = _quality; |
|
15510 + |
|
15511 + deb_info(" %s : quality = 0x%x \n", __FUNCTION__, *quality); |
|
15512 + |
|
15513 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15514 + |
|
15515 + return 0; |
|
15516 + |
|
15517 +error: |
|
15518 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15519 + |
|
15520 +mutex_error: |
|
15521 + return -1; |
|
15522 +} |
|
15523 + |
|
15524 + |
|
15525 + |
|
15526 +static int |
|
15527 +rtl2832_read_snr( |
|
15528 + struct dvb_frontend* fe, |
|
15529 + u16* snr) |
|
15530 +{ |
|
15531 + struct rtl2832_state* p_state = fe->demodulator_priv; |
|
15532 + long snr_num = 0; |
|
15533 + long snr_dem = 0; |
|
15534 + long _snr= 0; |
|
15535 + |
|
15536 + if( p_state->pNim== NULL) |
|
15537 + { |
|
15538 + deb_info(" %s pNim = NULL \n", __FUNCTION__); |
|
15539 + return -1; |
|
15540 + } |
|
15541 + |
|
15542 + if( mutex_lock_interruptible(&p_state->i2c_repeater_mutex) ) goto mutex_error; |
|
15543 + |
|
15544 + if (p_state->pNim->GetSnrDb(p_state->pNim, &snr_num, &snr_dem) ) |
|
15545 + { |
|
15546 + *snr = 0; |
|
15547 + goto error; |
|
15548 + } |
|
15549 + |
|
15550 + _snr = snr_num / snr_dem; |
|
15551 + |
|
15552 + if( _snr < 0 ) _snr = 0; |
|
15553 + |
|
15554 + *snr = _snr; |
|
15555 + |
|
15556 + deb_info(" %s : snr = 0x%x \n", __FUNCTION__, *snr); |
|
15557 + |
|
15558 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15559 + |
|
15560 + return 0; |
|
15561 + |
|
15562 +error: |
|
15563 + mutex_unlock(&p_state->i2c_repeater_mutex); |
|
15564 + |
|
15565 +mutex_error: |
|
15566 + return -1; |
|
15567 +} |
|
15568 + |
|
15569 + |
|
15570 + |
|
15571 +static int |
|
15572 +rtl2832_get_tune_settings( |
|
15573 + struct dvb_frontend* fe, |
|
15574 + struct dvb_frontend_tune_settings* fe_tune_settings) |
|
15575 +{ |
|
15576 + deb_info(" %s : Do Nothing\n", __FUNCTION__); |
|
15577 + fe_tune_settings->min_delay_ms = 1000; |
|
15578 + return 0; |
|
15579 +} |
|
15580 + |
|
15581 + |
|
15582 +static int |
|
15583 +rtl2832_ts_bus_ctrl( |
|
15584 + struct dvb_frontend* fe, |
|
15585 + int acquire) |
|
15586 +{ |
|
15587 + deb_info(" %s : Do Nothing\n", __FUNCTION__); |
|
15588 + return 0; |
|
15589 +} |
|
15590 + |
|
15591 + |
|
15592 + |
|
15593 + |
|
15594 +static struct dvb_frontend_ops rtl2832_ops; |
|
15595 + |
|
15596 +struct dvb_frontend* rtl2832u_fe_attach(struct dvb_usb_device *d) |
|
15597 +{ |
|
15598 + |
|
15599 + struct rtl2832_state* p_state= NULL; |
|
15600 + |
|
15601 + |
|
15602 + deb_info("+%s\n", __FUNCTION__); |
|
15603 + |
|
15604 + //3 linux fe_attach necessary setting |
|
15605 + /*allocate memory for the internal state */ |
|
15606 + p_state = kzalloc(sizeof(struct rtl2832_state), GFP_KERNEL); |
|
15607 + if (p_state == NULL) goto error; |
|
15608 + memset(p_state,0,sizeof(*p_state)); |
|
15609 + |
|
15610 + p_state->is_mt2266_nim_module_built = 0; //initialize is_mt2266_nim_module_built |
|
15611 + p_state->is_initial = 0; //initialize is_initial |
|
15612 + |
|
15613 + p_state->d = d; |
|
15614 + |
|
15615 + /* setup the state */ |
|
15616 + memcpy(&p_state->frontend.ops, &rtl2832_ops, sizeof(struct dvb_frontend_ops)); |
|
15617 + memset(&p_state->fep, 0, sizeof(struct dvb_frontend_parameters)); |
|
15618 + |
|
15619 + /* create dvb_frontend */ |
|
15620 + p_state->frontend.demodulator_priv = p_state; |
|
15621 + |
|
15622 +// INIT_DELAYED_WORK( &(p_state->update_procedure_work), rtl2832_update_functions); |
|
15623 + mutex_init(&p_state->i2c_repeater_mutex); |
|
15624 + |
|
15625 + deb_info("-%s\n", __FUNCTION__); |
|
15626 + return &p_state->frontend; |
|
15627 + |
|
15628 +error: |
|
15629 + return NULL; |
|
15630 + |
|
15631 + |
|
15632 +} |
|
15633 + |
|
15634 + |
|
15635 + |
|
15636 +static struct dvb_frontend_ops rtl2832_ops = { |
|
15637 + .info = { |
|
15638 + .name = "Realtek RTL2832 DVB-T", |
|
15639 + .type = FE_OFDM, |
|
15640 + .frequency_min = 174000000, |
|
15641 + .frequency_max = 862000000, |
|
15642 + .frequency_stepsize = 166667, |
|
15643 + .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | |
|
15644 + FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | |
|
15645 + FE_CAN_FEC_AUTO | |
|
15646 + FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | |
|
15647 + FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | |
|
15648 + FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER | |
|
15649 + FE_CAN_MUTE_TS |
|
15650 + }, |
|
15651 + |
|
15652 + .init = rtl2832_init, |
|
15653 + .release = rtl2832_release, |
|
15654 + |
|
15655 + .sleep = rtl2832_sleep, |
|
15656 + |
|
15657 + .set_frontend = rtl2832_set_parameters, |
|
15658 + .get_frontend = rtl2832_get_parameters, |
|
15659 + .get_tune_settings = rtl2832_get_tune_settings, |
|
15660 + |
|
15661 + .read_status = rtl2832_read_status, |
|
15662 + .read_ber = rtl2832_read_ber, |
|
15663 + .read_signal_strength = rtl2832_read_signal_strength, |
|
15664 + .read_snr = rtl2832_read_snr, |
|
15665 + .read_ucblocks = rtl2832_read_signal_quality, |
|
15666 + .ts_bus_ctrl = rtl2832_ts_bus_ctrl, |
|
15667 +}; |
|
15668 + |
|
15669 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/rtl2832u_fe.h |
|
15670 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
15671 +++ b/linux/drivers/media/dvb/dvb-usb/rtl2832u_fe.h Wed Oct 27 09:16:44 2010 +0200 |
|
15672 @@ -0,0 +1,207 @@ |
|
15673 + |
|
15674 +#ifndef __RTL2832U_FE_H__ |
|
15675 +#define __RTL2832U_FE_H__ |
|
15676 + |
|
15677 +#include "nim_rtl2832_tua9001.h" |
|
15678 +#include "nim_rtl2832_mt2266.h" |
|
15679 +#include "nim_rtl2832_fc2580.h" |
|
15680 +#include "nim_rtl2832_mxl5007t.h" |
|
15681 +#include "rtl2832u_io.h" |
|
15682 + |
|
15683 + |
|
15684 + |
|
15685 +typedef enum{ |
|
15686 + RTL2832_TUNER_TYPE_MT2266 = 0, |
|
15687 + RTL2832_TUNER_TYPE_FC2580, |
|
15688 + RTL2832_TUNER_TYPE_TUA9001, |
|
15689 + RTL2832_TUNER_TYPE_MXL5007T, |
|
15690 + RTL2832_TUNER_TYPE_UNKNOWN, |
|
15691 +}RTL2832_TUNER_TYPE; |
|
15692 + |
|
15693 + |
|
15694 + |
|
15695 +struct rtl2832_state { |
|
15696 + struct dvb_frontend frontend; |
|
15697 + struct dvb_frontend_parameters fep; |
|
15698 + struct dvb_usb_device* d; |
|
15699 + |
|
15700 + struct mutex i2c_repeater_mutex; |
|
15701 + |
|
15702 + unsigned long current_frequency; |
|
15703 + enum fe_bandwidth current_bandwidth; |
|
15704 + |
|
15705 + RTL2832_TUNER_TYPE tuner_type; |
|
15706 + unsigned char is_mt2266_nim_module_built; //3 For close MT handle |
|
15707 + |
|
15708 + //3if init() is called, is_initial is true ->check it to see if need to flush work queue |
|
15709 + unsigned short is_initial; |
|
15710 + //struct delayed_work update_procedure_work; |
|
15711 + |
|
15712 + DVBT_NIM_MODULE* pNim; |
|
15713 + DVBT_NIM_MODULE DvbtNimModuleMemory; |
|
15714 + RTL2832_EXTRA_MODULE Rtl2832ExtraModuleMemory; |
|
15715 + MT2266_EXTRA_MODULE Mt2266ExtraModuleMemory; |
|
15716 + FC2580_EXTRA_MODULE Fc2580ExtraModuleMemory; |
|
15717 + TUA9001_EXTRA_MODULE TUA9001ExtraModuleMemory; |
|
15718 + MXL5007T_EXTRA_MODULE MXL5007TExtraModuleMemory; |
|
15719 + RTL2832_MT2266_EXTRA_MODULE Rtl2832Mt2266ExtraModuleMemory; |
|
15720 + |
|
15721 + |
|
15722 +}; |
|
15723 + |
|
15724 + |
|
15725 + |
|
15726 +#define RTL2832_DEMOD_ADDR 0x20 |
|
15727 +#define MT2266_TUNER_ADDR 0xc0 |
|
15728 +#define FC2580_TUNER_ADDR 0xac |
|
15729 +#define TUA9001_TUNER_ADDR 0xc0 |
|
15730 + |
|
15731 +#define MT2266_OFFSET 0x00 |
|
15732 +#define MT2266_CHECK_VAL 0x85 |
|
15733 + |
|
15734 +#define FC2580_OFFSET 0x01 |
|
15735 +#define FC2580_CHECK_VAL 0x56 |
|
15736 + |
|
15737 +#define TUA9001_OFFSET 0x7e |
|
15738 +#define TUA9001_CHECK_VAL 0x2328 |
|
15739 + |
|
15740 +#define MXL5007T_BASE_ADDRESS 0xc0 |
|
15741 +#define MXL5007T_CHECK_ADDRESS 0xD9 |
|
15742 +#define MXL5007T_CHECK_VALUE 0x14 |
|
15743 + |
|
15744 + |
|
15745 + |
|
15746 + |
|
15747 + |
|
15748 +struct rtl2832_reg_addr{ |
|
15749 + RegType reg_type; |
|
15750 + unsigned short reg_addr; |
|
15751 + int bit_low; |
|
15752 + int bit_high; |
|
15753 +}; |
|
15754 + |
|
15755 + |
|
15756 + |
|
15757 +typedef enum{ |
|
15758 + RTD2831_RMAP_INDEX_USB_CTRL_BIT5 =0, |
|
15759 + RTD2831_RMAP_INDEX_USB_STAT, |
|
15760 + RTD2831_RMAP_INDEX_USB_EPA_CTL, |
|
15761 + RTD2831_RMAP_INDEX_USB_SYSCTL, |
|
15762 + RTD2831_RMAP_INDEX_USB_EPA_CFG, |
|
15763 + RTD2831_RMAP_INDEX_USB_EPA_MAXPKT, |
|
15764 + RTD2831_RMAP_INDEX_USB_EPA_FIFO_CFG, |
|
15765 + |
|
15766 + RTD2831_RMAP_INDEX_SYS_DEMOD_CTL, |
|
15767 + RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_VAL, |
|
15768 + RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_EN_BIT3, |
|
15769 + RTD2831_RMAP_INDEX_SYS_GPIO_DIR_BIT3, |
|
15770 + RTD2831_RMAP_INDEX_SYS_GPIO_CFG0_BIT67, |
|
15771 + RTD2831_RMAP_INDEX_SYS_DEMOD_CTL1, |
|
15772 + RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_EN_BIT1, |
|
15773 + RTD2831_RMAP_INDEX_SYS_GPIO_DIR_BIT1, |
|
15774 + RTD2831_RMAP_INDEX_SYS_GPIO_OUTPUT_EN_BIT6, |
|
15775 + RTD2831_RMAP_INDEX_SYS_GPIO_DIR_BIT6, |
|
15776 +#if 0 |
|
15777 + RTD2831_RMAP_INDEX_SYS_GPD, |
|
15778 + RTD2831_RMAP_INDEX_SYS_GPOE, |
|
15779 + RTD2831_RMAP_INDEX_SYS_GPO, |
|
15780 + RTD2831_RMAP_INDEX_SYS_SYS_0, |
|
15781 +#endif |
|
15782 + |
|
15783 +} rtl2832_reg_map_index; |
|
15784 + |
|
15785 + |
|
15786 + |
|
15787 +#define USB_SYSCTL 0x0000 |
|
15788 +#define USB_CTRL 0x0010 |
|
15789 +#define USB_STAT 0x0014 |
|
15790 +#define USB_EPA_CTL 0x0148 |
|
15791 +#define USB_EPA_CFG 0x0144 |
|
15792 +#define USB_EPA_MAXPKT 0x0158 |
|
15793 +#define USB_EPA_FIFO_CFG 0x0160 |
|
15794 + |
|
15795 +#define DEMOD_CTL 0x0000 |
|
15796 +#define GPIO_OUTPUT_VAL 0x0001 |
|
15797 +#define GPIO_OUTPUT_EN 0x0003 |
|
15798 +#define GPIO_DIR 0x0004 |
|
15799 +#define GPIO_CFG0 0x0007 |
|
15800 +#define GPIO_CFG1 0x0008 |
|
15801 +#define DEMOD_CTL1 0x000b |
|
15802 + |
|
15803 + |
|
15804 +static int rtl2832_reg_mask[32]= { |
|
15805 + 0x00000001, |
|
15806 + 0x00000003, |
|
15807 + 0x00000007, |
|
15808 + 0x0000000f, |
|
15809 + 0x0000001f, |
|
15810 + 0x0000003f, |
|
15811 + 0x0000007f, |
|
15812 + 0x000000ff, |
|
15813 + 0x000001ff, |
|
15814 + 0x000003ff, |
|
15815 + 0x000007ff, |
|
15816 + 0x00000fff, |
|
15817 + 0x00001fff, |
|
15818 + 0x00003fff, |
|
15819 + 0x00007fff, |
|
15820 + 0x0000ffff, |
|
15821 + 0x0001ffff, |
|
15822 + 0x0003ffff, |
|
15823 + 0x0007ffff, |
|
15824 + 0x000fffff, |
|
15825 + 0x001fffff, |
|
15826 + 0x003fffff, |
|
15827 + 0x007fffff, |
|
15828 + 0x00ffffff, |
|
15829 + 0x01ffffff, |
|
15830 + 0x03ffffff, |
|
15831 + 0x07ffffff, |
|
15832 + 0x0fffffff, |
|
15833 + 0x1fffffff, |
|
15834 + 0x3fffffff, |
|
15835 + 0x7fffffff, |
|
15836 + 0xffffffff |
|
15837 +}; |
|
15838 + |
|
15839 + |
|
15840 + |
|
15841 + |
|
15842 +#define BIT0 0x00000001 |
|
15843 +#define BIT1 0x00000002 |
|
15844 +#define BIT2 0x00000004 |
|
15845 +#define BIT3 0x00000008 |
|
15846 +#define BIT4 0x00000010 |
|
15847 +#define BIT5 0x00000020 |
|
15848 +#define BIT6 0x00000040 |
|
15849 +#define BIT7 0x00000080 |
|
15850 +#define BIT8 0x00000100 |
|
15851 +#define BIT9 0x00000200 |
|
15852 +#define BIT10 0x00000400 |
|
15853 +#define BIT11 0x00000800 |
|
15854 +#define BIT12 0x00001000 |
|
15855 +#define BIT13 0x00002000 |
|
15856 +#define BIT14 0x00004000 |
|
15857 +#define BIT15 0x00008000 |
|
15858 +#define BIT16 0x00010000 |
|
15859 +#define BIT17 0x00020000 |
|
15860 +#define BIT18 0x00040000 |
|
15861 +#define BIT19 0x00080000 |
|
15862 +#define BIT20 0x00100000 |
|
15863 +#define BIT21 0x00200000 |
|
15864 +#define BIT22 0x00400000 |
|
15865 +#define BIT23 0x00800000 |
|
15866 +#define BIT24 0x01000000 |
|
15867 +#define BIT25 0x02000000 |
|
15868 +#define BIT26 0x04000000 |
|
15869 +#define BIT27 0x08000000 |
|
15870 +#define BIT28 0x10000000 |
|
15871 +#define BIT29 0x20000000 |
|
15872 +#define BIT30 0x40000000 |
|
15873 +#define BIT31 0x80000000 |
|
15874 + |
|
15875 + |
|
15876 + |
|
15877 +#endif // __RTD2830_PRIV_H__ |
|
15878 + |
|
15879 + |
|
15880 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/rtl2832u_io.c |
|
15881 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
15882 +++ b/linux/drivers/media/dvb/dvb-usb/rtl2832u_io.c Wed Oct 27 09:16:44 2010 +0200 |
|
15883 @@ -0,0 +1,635 @@ |
|
15884 + |
|
15885 + |
|
15886 +#include "rtl2832u_io.h" |
|
15887 +#include <linux/time.h> |
|
15888 + |
|
15889 +#define ERROR_TRY_MAX_NUM 4 |
|
15890 + |
|
15891 + |
|
15892 + |
|
15893 +void |
|
15894 +platform_wait( |
|
15895 + unsigned long nMinDelayTime) |
|
15896 +{ |
|
15897 + // The unit of Sleep() waiting time is millisecond. |
|
15898 + unsigned long usec; |
|
15899 + do { |
|
15900 + usec = (nMinDelayTime > 8000) ? 8000 : nMinDelayTime; |
|
15901 + msleep(usec); |
|
15902 + nMinDelayTime -= usec; |
|
15903 + } while (nMinDelayTime > 0); |
|
15904 + |
|
15905 + return; |
|
15906 + |
|
15907 +} |
|
15908 + |
|
15909 + |
|
15910 + |
|
15911 + |
|
15912 + |
|
15913 +static int |
|
15914 +read_usb_register( |
|
15915 + struct dvb_usb_device* dib, |
|
15916 + unsigned short offset, |
|
15917 + unsigned char* data, |
|
15918 + unsigned short bytelength) |
|
15919 +{ |
|
15920 + int ret = -ENOMEM; |
|
15921 + |
|
15922 + ret = usb_control_msg(dib->udev, /* pointer to device */ |
|
15923 + usb_rcvctrlpipe( dib->udev,RTL2832_CTRL_ENDPOINT), /* pipe to control endpoint */ |
|
15924 + 0, /* USB message request value */ |
|
15925 + SKEL_VENDOR_IN, /* USB message request type value */ |
|
15926 + (USB_BASE_ADDRESS<<8) + offset, /* USB message value */ |
|
15927 + 0x0100, /* USB message index value */ |
|
15928 + data, /* pointer to the receive buffer */ |
|
15929 + bytelength, /* length of the buffer */ |
|
15930 + DIBUSB_I2C_TIMEOUT); /* time to wait for the message to complete before timing out */ |
|
15931 + |
|
15932 + if (ret != bytelength) |
|
15933 + { |
|
15934 + deb_info(" %s: offset=0x%x, error code=0x%x !\n", __FUNCTION__, offset, ret); |
|
15935 + return 1; |
|
15936 + } |
|
15937 + |
|
15938 + return 0; |
|
15939 +} |
|
15940 + |
|
15941 + |
|
15942 + |
|
15943 +static int |
|
15944 +write_usb_register( |
|
15945 + struct dvb_usb_device* dib, |
|
15946 + unsigned short offset, |
|
15947 + unsigned char* data, |
|
15948 + unsigned short bytelength) |
|
15949 +{ |
|
15950 + int ret = -ENOMEM; |
|
15951 + unsigned char try_num; |
|
15952 + |
|
15953 + try_num = 0; |
|
15954 +error_write_again: |
|
15955 + try_num++; |
|
15956 + |
|
15957 + ret = usb_control_msg(dib->udev, /* pointer to device */ |
|
15958 + usb_sndctrlpipe( dib->udev,RTL2832_CTRL_ENDPOINT), /* pipe to control endpoint */ |
|
15959 + 0, /* USB message request value */ |
|
15960 + SKEL_VENDOR_OUT, /* USB message request type value */ |
|
15961 + (USB_BASE_ADDRESS<<8) + offset, /* USB message value */ |
|
15962 + 0x0110, /* USB message index value */ |
|
15963 + data, /* pointer to the receive buffer */ |
|
15964 + bytelength, /* length of the buffer */ |
|
15965 + DIBUSB_I2C_TIMEOUT); /* time to wait for the message to complete before timing out */ |
|
15966 + |
|
15967 + if (ret != bytelength) |
|
15968 + { |
|
15969 + deb_info("error try = %d, %s: offset=0x%x, error code=0x%x !\n",try_num ,__FUNCTION__, offset, ret); |
|
15970 + |
|
15971 + if( try_num > ERROR_TRY_MAX_NUM ) goto error; |
|
15972 + else goto error_write_again; |
|
15973 + } |
|
15974 + |
|
15975 + return 0; |
|
15976 +error: |
|
15977 + return 1; |
|
15978 + } |
|
15979 + |
|
15980 + |
|
15981 + |
|
15982 + |
|
15983 +static int |
|
15984 +read_sys_register( |
|
15985 + struct dvb_usb_device* dib, |
|
15986 + unsigned short offset, |
|
15987 + unsigned char* data, |
|
15988 + unsigned short bytelength) |
|
15989 +{ |
|
15990 + int ret = -ENOMEM; |
|
15991 + |
|
15992 + ret = usb_control_msg(dib->udev, /* pointer to device */ |
|
15993 + usb_rcvctrlpipe( dib->udev,RTL2832_CTRL_ENDPOINT), /* pipe to control endpoint */ |
|
15994 + 0, /* USB message request value */ |
|
15995 + SKEL_VENDOR_IN, /* USB message request type value */ |
|
15996 + (SYS_BASE_ADDRESS<<8) + offset, /* USB message value */ |
|
15997 + 0x0200, /* USB message index value */ |
|
15998 + data, /* pointer to the receive buffer */ |
|
15999 + bytelength, /* length of the buffer */ |
|
16000 + DIBUSB_I2C_TIMEOUT); /* time to wait for the message to complete before timing out */ |
|
16001 + |
|
16002 + if (ret != bytelength) |
|
16003 + { |
|
16004 + deb_info(" %s: offset=0x%x, error code=0x%x !\n", __FUNCTION__, offset, ret); |
|
16005 + return 1; |
|
16006 + } |
|
16007 + |
|
16008 + return 0; |
|
16009 + |
|
16010 + } |
|
16011 + |
|
16012 + |
|
16013 +static int |
|
16014 +write_sys_register( |
|
16015 + struct dvb_usb_device* dib, |
|
16016 + unsigned short offset, |
|
16017 + unsigned char* data, |
|
16018 + unsigned short bytelength) |
|
16019 +{ |
|
16020 + int ret = -ENOMEM; |
|
16021 + unsigned char try_num; |
|
16022 + |
|
16023 + try_num = 0; |
|
16024 +error_write_again: |
|
16025 + try_num++; |
|
16026 + |
|
16027 + ret = usb_control_msg(dib->udev, /* pointer to device */ |
|
16028 + usb_sndctrlpipe( dib->udev,RTL2832_CTRL_ENDPOINT), /* pipe to control endpoint */ |
|
16029 + 0, /* USB message request value */ |
|
16030 + SKEL_VENDOR_OUT, /* USB message request type value */ |
|
16031 + (SYS_BASE_ADDRESS<<8) + offset, /* USB message value */ |
|
16032 + 0x0210, /* USB message index value */ |
|
16033 + data, /* pointer to the receive buffer */ |
|
16034 + bytelength, /* length of the buffer */ |
|
16035 + DIBUSB_I2C_TIMEOUT); /* time to wait for the message to complete before timing out */ |
|
16036 + |
|
16037 + if (ret != bytelength) |
|
16038 + { |
|
16039 + deb_info(" error try= %d, %s: offset=0x%x, error code=0x%x !\n",try_num, __FUNCTION__, offset, ret); |
|
16040 + if( try_num > ERROR_TRY_MAX_NUM ) goto error; |
|
16041 + else goto error_write_again; |
|
16042 + } |
|
16043 + |
|
16044 + return 0; |
|
16045 +error: |
|
16046 + return 1; |
|
16047 + } |
|
16048 + |
|
16049 + |
|
16050 + |
|
16051 + |
|
16052 +int |
|
16053 +read_rtl2832_demod_register( |
|
16054 + struct dvb_usb_device*dib, |
|
16055 + unsigned char demod_device_addr, |
|
16056 + unsigned char page, |
|
16057 + unsigned char offset, |
|
16058 + unsigned char* data, |
|
16059 + unsigned short bytelength) |
|
16060 +{ |
|
16061 + int ret = -ENOMEM; |
|
16062 + int i; |
|
16063 + |
|
16064 + if( mutex_lock_interruptible(&dib->usb_mutex) ) goto error; |
|
16065 + |
|
16066 + ret = usb_control_msg(dib->udev, /* pointer to device */ |
|
16067 + usb_rcvctrlpipe( dib->udev,RTL2832_CTRL_ENDPOINT), /* pipe to control endpoint */ |
|
16068 + 0, /* USB message request value */ |
|
16069 + SKEL_VENDOR_IN, /* USB message request type value */ |
|
16070 + demod_device_addr + (offset<<8), /* USB message value */ |
|
16071 + (0x0000 + page), /* USB message index value */ |
|
16072 + data, /* pointer to the receive buffer */ |
|
16073 + bytelength, /* length of the buffer */ |
|
16074 + DIBUSB_I2C_TIMEOUT); /* time to wait for the message to complete before timing out */ |
|
16075 + |
|
16076 + mutex_unlock(&dib->usb_mutex); |
|
16077 + |
|
16078 + |
|
16079 +// deb_info("%s: ret=%d, DA=0x%x, len=%d, page=%d, offset=0x%x, data=(", __FUNCTION__, ret, demod_device_addr, bytelength,page, offset); |
|
16080 +// for(i = 0; i < bytelength; i++) |
|
16081 +// deb_info("0x%x,", data[i]); |
|
16082 +// deb_info(")\n"); |
|
16083 + |
|
16084 + if (ret != bytelength) |
|
16085 + { |
|
16086 + deb_info("error!! %s: ret=%d, DA=0x%x, len=%d, page=%d, offset=0x%x, data=(", __FUNCTION__, ret, demod_device_addr, bytelength,page, offset); |
|
16087 + for(i = 0; i < bytelength; i++) |
|
16088 + deb_info("0x%x,", data[i]); |
|
16089 + deb_info(")\n"); |
|
16090 + |
|
16091 + goto error; |
|
16092 + } |
|
16093 + |
|
16094 + return 0; |
|
16095 + |
|
16096 +error: |
|
16097 + return 1; |
|
16098 +} |
|
16099 + |
|
16100 + |
|
16101 + |
|
16102 + |
|
16103 +int |
|
16104 +write_rtl2832_demod_register( |
|
16105 + struct dvb_usb_device*dib, |
|
16106 + unsigned char demod_device_addr, |
|
16107 + unsigned char page, |
|
16108 + unsigned char offset, |
|
16109 + unsigned char *data, |
|
16110 + unsigned short bytelength) |
|
16111 +{ |
|
16112 + int ret = -ENOMEM; |
|
16113 + unsigned char i, try_num; |
|
16114 + |
|
16115 + try_num = 0; |
|
16116 +error_write_again: |
|
16117 + try_num++; |
|
16118 + |
|
16119 + if( mutex_lock_interruptible(&dib->usb_mutex) ) goto error; |
|
16120 + |
|
16121 + ret = usb_control_msg(dib->udev, /* pointer to device */ |
|
16122 + usb_sndctrlpipe( dib->udev,RTL2832_CTRL_ENDPOINT), /* pipe to control endpoint */ |
|
16123 + 0, /* USB message request value */ |
|
16124 + SKEL_VENDOR_OUT, /* USB message request type value */ |
|
16125 + demod_device_addr + (offset<<8), /* USB message value */ |
|
16126 + (0x0010 + page), /* USB message index value */ |
|
16127 + data, /* pointer to the receive buffer */ |
|
16128 + bytelength, /* length of the buffer */ |
|
16129 + DIBUSB_I2C_TIMEOUT); /* time to wait for the message to complete before timing out */ |
|
16130 + |
|
16131 + mutex_unlock(&dib->usb_mutex); |
|
16132 + |
|
16133 +// deb_info("%s: ret=%d, DA=0x%x, len=%d, page=%d, offset=0x%x, data=(", __FUNCTION__, ret, demod_device_addr, bytelength, page,offset); |
|
16134 +// for(i = 0; i < bytelength; i++) |
|
16135 +// deb_info("0x%x,", data[i]); |
|
16136 +// deb_info(")\n"); |
|
16137 + |
|
16138 + |
|
16139 + if (ret != bytelength) |
|
16140 + { |
|
16141 + deb_info("error try = %d!! %s: ret=%d, DA=0x%x, len=%d, page=%d, offset=0x%x, data=(",try_num , __FUNCTION__, ret, demod_device_addr, bytelength,page,offset); |
|
16142 + for(i = 0; i < bytelength; i++) |
|
16143 + deb_info("0x%x,", data[i]); |
|
16144 + deb_info(")\n"); |
|
16145 + |
|
16146 + if( try_num > ERROR_TRY_MAX_NUM ) goto error; |
|
16147 + else goto error_write_again; |
|
16148 + } |
|
16149 + |
|
16150 + return 0; |
|
16151 + |
|
16152 +error: |
|
16153 + return 1; |
|
16154 + } |
|
16155 + |
|
16156 + |
|
16157 + |
|
16158 + |
|
16159 + |
|
16160 + |
|
16161 +int |
|
16162 +read_rtl2832_tuner_register( |
|
16163 + struct dvb_usb_device *dib, |
|
16164 + unsigned char device_address, |
|
16165 + unsigned char offset, |
|
16166 + unsigned char *data, |
|
16167 + unsigned short bytelength) |
|
16168 +{ |
|
16169 + int ret = -ENOMEM; |
|
16170 + int i; |
|
16171 + unsigned char data_tmp[128]; |
|
16172 + |
|
16173 + |
|
16174 + if( mutex_lock_interruptible(&dib->usb_mutex) ) goto error; |
|
16175 + |
|
16176 + ret = usb_control_msg(dib->udev, /* pointer to device */ |
|
16177 + usb_rcvctrlpipe( dib->udev,RTL2832_CTRL_ENDPOINT), /* pipe to control endpoint */ |
|
16178 + 0, /* USB message request value */ |
|
16179 + SKEL_VENDOR_IN, /* USB message request type value */ |
|
16180 + device_address+(offset<<8), /* USB message value */ |
|
16181 + 0x0300, /* USB message index value */ |
|
16182 + data_tmp, /* pointer to the receive buffer */ |
|
16183 + bytelength, /* length of the buffer */ |
|
16184 + DIBUSB_I2C_TIMEOUT); /* time to wait for the message to complete before timing out */ |
|
16185 + |
|
16186 + mutex_unlock(&dib->usb_mutex); |
|
16187 + |
|
16188 +// deb_info("%s: ret=%d, DA=0x%x, len=%d, offset=0x%x, data=(", __FUNCTION__, ret, device_address, bytelength,offset); |
|
16189 +// for(i = 0; i < bytelength; i++) |
|
16190 +// deb_info("0x%x,", data_tmp[i]); |
|
16191 +// deb_info(")\n"); |
|
16192 + |
|
16193 + if (ret != bytelength) |
|
16194 + { |
|
16195 + deb_info("error!! %s: ret=%d, DA=0x%x, len=%d, offset=0x%x, data=(", __FUNCTION__, ret, device_address, bytelength,offset); |
|
16196 + for(i = 0; i < bytelength; i++) |
|
16197 + deb_info("0x%x,", data_tmp[i]); |
|
16198 + deb_info(")\n"); |
|
16199 + |
|
16200 + goto error; |
|
16201 + } |
|
16202 + |
|
16203 + memcpy(data,data_tmp,bytelength); |
|
16204 + |
|
16205 + return 0; |
|
16206 + |
|
16207 +error: |
|
16208 + return 1; |
|
16209 + |
|
16210 + |
|
16211 +} |
|
16212 + |
|
16213 +int write_rtl2832_tuner_register( |
|
16214 + struct dvb_usb_device *dib, |
|
16215 + unsigned char device_address, |
|
16216 + unsigned char offset, |
|
16217 + unsigned char *data, |
|
16218 + unsigned short bytelength) |
|
16219 +{ |
|
16220 + int ret = -ENOMEM; |
|
16221 + unsigned char i, try_num; |
|
16222 + |
|
16223 + try_num = 0; |
|
16224 +error_write_again: |
|
16225 + try_num++; |
|
16226 + |
|
16227 + if( mutex_lock_interruptible(&dib->usb_mutex) ) goto error; |
|
16228 + |
|
16229 + ret = usb_control_msg(dib->udev, /* pointer to device */ |
|
16230 + usb_sndctrlpipe( dib->udev,RTL2832_CTRL_ENDPOINT), /* pipe to control endpoint */ |
|
16231 + 0, /* USB message request value */ |
|
16232 + SKEL_VENDOR_OUT, /* USB message request type value */ |
|
16233 + device_address+(offset<<8), /* USB message value */ |
|
16234 + 0x0310, /* USB message index value */ |
|
16235 + data, /* pointer to the receive buffer */ |
|
16236 + bytelength, /* length of the buffer */ |
|
16237 + DIBUSB_I2C_TIMEOUT); /* time to wait for the message to complete before timing out */ |
|
16238 + |
|
16239 + mutex_unlock(&dib->usb_mutex); |
|
16240 + |
|
16241 +// deb_info("%s: ret=%d, DA=0x%x, len=%d, offset=0x%x, data=(", __FUNCTION__, ret, device_address, bytelength, offset); |
|
16242 +// for(i = 0; i < bytelength; i++) |
|
16243 +// deb_info("0x%x,", data[i]); |
|
16244 +// deb_info(")\n"); |
|
16245 + |
|
16246 + |
|
16247 + if (ret != bytelength) |
|
16248 + { |
|
16249 + deb_info("error try= %d!! %s: ret=%d, DA=0x%x, len=%d, offset=0x%x, data=(",try_num, __FUNCTION__, ret, device_address, bytelength, offset); |
|
16250 + for(i = 0; i < bytelength; i++) |
|
16251 + deb_info("0x%x,", data[i]); |
|
16252 + deb_info(")\n"); |
|
16253 + |
|
16254 + if( try_num > ERROR_TRY_MAX_NUM ) goto error; |
|
16255 + else goto error_write_again; |
|
16256 + } |
|
16257 + |
|
16258 + return 0; |
|
16259 + |
|
16260 +error: |
|
16261 + return 1; |
|
16262 + } |
|
16263 + |
|
16264 + |
|
16265 + |
|
16266 + |
|
16267 +int |
|
16268 +read_rtl2832_stdi2c( |
|
16269 + struct dvb_usb_device* dib, |
|
16270 + unsigned short dev_i2c_addr, |
|
16271 + unsigned char* data, |
|
16272 + unsigned short bytelength) |
|
16273 +{ |
|
16274 + int i; |
|
16275 + int ret = -ENOMEM; |
|
16276 + unsigned char try_num; |
|
16277 + unsigned char data_tmp[128]; |
|
16278 + |
|
16279 + try_num = 0; |
|
16280 +error_write_again: |
|
16281 + try_num ++; |
|
16282 + |
|
16283 + |
|
16284 + if(bytelength >= 128) |
|
16285 + { |
|
16286 + deb_info("%s error bytelength >=128 \n", __FUNCTION__); |
|
16287 + goto error; |
|
16288 + } |
|
16289 + |
|
16290 + if( mutex_lock_interruptible(&dib->usb_mutex) ) goto error; |
|
16291 + |
|
16292 + ret = usb_control_msg(dib->udev, /* pointer to device */ |
|
16293 + usb_rcvctrlpipe( dib->udev,RTL2832_CTRL_ENDPOINT), /* pipe to control endpoint */ |
|
16294 + 0, /* USB message request value */ |
|
16295 + SKEL_VENDOR_IN, /* USB message request type value */ |
|
16296 + dev_i2c_addr, /* USB message value */ |
|
16297 + 0x0600, /* USB message index value */ |
|
16298 + data_tmp, /* pointer to the receive buffer */ |
|
16299 + bytelength, /* length of the buffer */ |
|
16300 + DIBUSB_I2C_TIMEOUT); /* time to wait for the message to complete before timing out */ |
|
16301 + |
|
16302 + mutex_unlock(&dib->usb_mutex); |
|
16303 + |
|
16304 + if (ret != bytelength) |
|
16305 + { |
|
16306 + deb_info("error try= %d!! %s: ret=%d, DA=0x%x, len=%d, data=(",try_num, __FUNCTION__, ret, dev_i2c_addr, bytelength); |
|
16307 + for(i = 0; i < bytelength; i++) |
|
16308 + deb_info("0x%x,", data_tmp[i]); |
|
16309 + deb_info(")\n"); |
|
16310 + |
|
16311 + if( try_num > ERROR_TRY_MAX_NUM ) goto error; |
|
16312 + else goto error_write_again; |
|
16313 + } |
|
16314 + |
|
16315 + memcpy(data,data_tmp,bytelength); |
|
16316 + |
|
16317 + return 0; |
|
16318 +error: |
|
16319 + return 1; |
|
16320 + |
|
16321 +} |
|
16322 + |
|
16323 + |
|
16324 + |
|
16325 +int |
|
16326 +write_rtl2832_stdi2c( |
|
16327 + struct dvb_usb_device* dib, |
|
16328 + unsigned short dev_i2c_addr, |
|
16329 + unsigned char* data, |
|
16330 + unsigned short bytelength) |
|
16331 +{ |
|
16332 + int i; |
|
16333 + int ret = -ENOMEM; |
|
16334 + unsigned char try_num; |
|
16335 + |
|
16336 + try_num = 0; |
|
16337 +error_write_again: |
|
16338 + try_num ++; |
|
16339 + |
|
16340 + if( mutex_lock_interruptible(&dib->usb_mutex) ) goto error; |
|
16341 + |
|
16342 + ret = usb_control_msg(dib->udev, /* pointer to device */ |
|
16343 + usb_sndctrlpipe( dib->udev,RTL2832_CTRL_ENDPOINT), /* pipe to control endpoint */ |
|
16344 + 0, /* USB message request value */ |
|
16345 + SKEL_VENDOR_OUT, /* USB message request type value */ |
|
16346 + dev_i2c_addr, /* USB message value */ |
|
16347 + 0x0610, /* USB message index value */ |
|
16348 + data, /* pointer to the receive buffer */ |
|
16349 + bytelength, /* length of the buffer */ |
|
16350 + DIBUSB_I2C_TIMEOUT); /* time to wait for the message to complete before timing out */ |
|
16351 + |
|
16352 + mutex_unlock(&dib->usb_mutex); |
|
16353 + |
|
16354 + if (ret != bytelength) |
|
16355 + { |
|
16356 + deb_info("error try= %d!! %s: ret=%d, DA=0x%x, len=%d, data=(",try_num, __FUNCTION__, ret, dev_i2c_addr, bytelength); |
|
16357 + for(i = 0; i < bytelength; i++) |
|
16358 + deb_info("0x%x,", data[i]); |
|
16359 + deb_info(")\n"); |
|
16360 + |
|
16361 + if( try_num > ERROR_TRY_MAX_NUM ) goto error; |
|
16362 + else goto error_write_again; |
|
16363 + |
|
16364 + } |
|
16365 + |
|
16366 + return 0; |
|
16367 + |
|
16368 +error: |
|
16369 + return 1; |
|
16370 + |
|
16371 +} |
|
16372 + |
|
16373 + |
|
16374 + |
|
16375 + |
|
16376 + |
|
16377 + |
|
16378 +//3for return PUCHAR value |
|
16379 + |
|
16380 +int |
|
16381 +read_usb_sys_char_bytes( |
|
16382 + struct dvb_usb_device* dib, |
|
16383 + RegType type, |
|
16384 + unsigned short byte_addr, |
|
16385 + unsigned char* buf, |
|
16386 + unsigned short byte_num) |
|
16387 +{ |
|
16388 + int ret = 1; |
|
16389 + |
|
16390 + if( byte_num != 1 && byte_num !=2 && byte_num !=4) |
|
16391 + { |
|
16392 + deb_info("error!! %s: length = %d \n", __FUNCTION__, byte_num); |
|
16393 + return 1; |
|
16394 + } |
|
16395 + |
|
16396 + |
|
16397 + if( mutex_lock_interruptible(&dib->usb_mutex) ) return 1; |
|
16398 + |
|
16399 + if( type == RTD2832U_USB ) |
|
16400 + { |
|
16401 + ret = read_usb_register( dib , byte_addr , buf , byte_num); |
|
16402 + } |
|
16403 + else if ( type == RTD2832U_SYS ) |
|
16404 + { |
|
16405 + ret = read_sys_register( dib , byte_addr , buf , byte_num); |
|
16406 + } |
|
16407 + |
|
16408 + mutex_unlock(&dib->usb_mutex); |
|
16409 + |
|
16410 + return ret; |
|
16411 + |
|
16412 +} |
|
16413 + |
|
16414 + |
|
16415 + |
|
16416 +int |
|
16417 +write_usb_sys_char_bytes( |
|
16418 + struct dvb_usb_device* dib, |
|
16419 + RegType type, |
|
16420 + unsigned short byte_addr, |
|
16421 + unsigned char* buf, |
|
16422 + unsigned short byte_num) |
|
16423 +{ |
|
16424 + int ret = 1; |
|
16425 + |
|
16426 + if( byte_num != 1 && byte_num !=2 && byte_num !=4) |
|
16427 + { |
|
16428 + deb_info("error!! %s: length = %d \n", __FUNCTION__, byte_num); |
|
16429 + return 1; |
|
16430 + } |
|
16431 + |
|
16432 + if( mutex_lock_interruptible(&dib->usb_mutex) ) return 1; |
|
16433 + |
|
16434 + if( type == RTD2832U_USB ) |
|
16435 + { |
|
16436 + ret = write_usb_register( dib , byte_addr , buf , byte_num); |
|
16437 + } |
|
16438 + else if ( type == RTD2832U_SYS ) |
|
16439 + { |
|
16440 + ret = write_sys_register( dib , byte_addr , buf , byte_num); |
|
16441 + } |
|
16442 + |
|
16443 + mutex_unlock(&dib->usb_mutex); |
|
16444 + |
|
16445 + return ret; |
|
16446 + |
|
16447 +} |
|
16448 + |
|
16449 + |
|
16450 +//3for return INT value |
|
16451 +int |
|
16452 +read_usb_sys_int_bytes( |
|
16453 + struct dvb_usb_device* dib, |
|
16454 + RegType type, |
|
16455 + unsigned short byte_addr, |
|
16456 + unsigned short n_bytes, |
|
16457 + int* p_val) |
|
16458 +{ |
|
16459 + int i; |
|
16460 + u8 val[LEN_4_BYTE]; |
|
16461 + int nbit_shift; |
|
16462 + |
|
16463 + *p_val= 0; |
|
16464 + |
|
16465 + if (read_usb_sys_char_bytes( dib, type, byte_addr, val , n_bytes)) goto error; |
|
16466 + |
|
16467 + for (i= 0; i< n_bytes; i++) |
|
16468 + { |
|
16469 + nbit_shift = i<<3 ; |
|
16470 + *p_val = *p_val + (val[i]<<nbit_shift ); |
|
16471 + } |
|
16472 + |
|
16473 + return 0; |
|
16474 +error: |
|
16475 + return 1; |
|
16476 + |
|
16477 +} |
|
16478 + |
|
16479 + |
|
16480 + |
|
16481 +int |
|
16482 +write_usb_sys_int_bytes( |
|
16483 + struct dvb_usb_device* dib, |
|
16484 + RegType type, |
|
16485 + unsigned short byte_addr, |
|
16486 + unsigned short n_bytes, |
|
16487 + int val) |
|
16488 +{ |
|
16489 + int i; |
|
16490 + int nbit_shift; |
|
16491 + u8 u8_val[LEN_4_BYTE]; |
|
16492 + |
|
16493 + for (i= n_bytes- 1; i>= 0; i--) |
|
16494 + { |
|
16495 + nbit_shift= i << 3; |
|
16496 + u8_val[i] = (val>> nbit_shift) & 0xff; |
|
16497 + } |
|
16498 + |
|
16499 + if( write_usb_sys_char_bytes( dib , type , byte_addr, u8_val , n_bytes) ) goto error; |
|
16500 + |
|
16501 + return 0; |
|
16502 +error: |
|
16503 + return 1; |
|
16504 +} |
|
16505 + |
|
16506 + |
|
16507 + |
|
16508 + |
|
16509 + |
|
16510 + |
|
16511 + |
|
16512 + |
|
16513 + |
|
16514 + |
|
16515 + |
|
16516 + |
|
16517 + |
|
16518 + |
|
16519 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/rtl2832u_io.h |
|
16520 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
16521 +++ b/linux/drivers/media/dvb/dvb-usb/rtl2832u_io.h Wed Oct 27 09:16:44 2010 +0200 |
|
16522 @@ -0,0 +1,206 @@ |
|
16523 + |
|
16524 + |
|
16525 + |
|
16526 +#ifndef __USB_SYS_RTL2832_H__ |
|
16527 +#define __USB_SYS_RTL2832_H__ |
|
16528 + |
|
16529 +#include "dvb-usb.h" |
|
16530 + |
|
16531 +extern int dvb_usb_rtl2832u_debug; |
|
16532 +#define deb_info(args...) dprintk(dvb_usb_rtl2832u_debug,0x01,args) |
|
16533 +#define deb_xfer(args...) dprintk(dvb_usb_rtl2832u_debug,0x02,args) |
|
16534 + |
|
16535 +#define LEN_1_BYTE 1 |
|
16536 +#define LEN_2_BYTE 2 |
|
16537 +#define LEN_4_BYTE 4 |
|
16538 + |
|
16539 + |
|
16540 +#define RTL2832_CTRL_ENDPOINT 0x00 |
|
16541 +#define DIBUSB_I2C_TIMEOUT 5000 |
|
16542 + |
|
16543 +#define SKEL_VENDOR_IN (USB_DIR_IN|USB_TYPE_VENDOR) |
|
16544 +#define SKEL_VENDOR_OUT (USB_DIR_OUT|USB_TYPE_VENDOR) |
|
16545 + |
|
16546 +#define SYS_BASE_ADDRESS 0x30 //0x3000 |
|
16547 +#define USB_BASE_ADDRESS 0x20 //0x2000 |
|
16548 + |
|
16549 +typedef enum { RTD2832U_USB =1, RTD2832U_SYS=2 } RegType; |
|
16550 + |
|
16551 +//3//////////////////////// |
|
16552 +//3for return PUCHAR value |
|
16553 +//3/////////////////////// |
|
16554 + |
|
16555 +int |
|
16556 +read_usb_sys_char_bytes( |
|
16557 + struct dvb_usb_device* dib, |
|
16558 + RegType type, |
|
16559 + unsigned short byte_addr, |
|
16560 + unsigned char* buf, |
|
16561 + unsigned short byte_num); |
|
16562 + |
|
16563 + |
|
16564 + |
|
16565 +int |
|
16566 +write_usb_sys_char_bytes( |
|
16567 + struct dvb_usb_device* dib, |
|
16568 + RegType type, |
|
16569 + unsigned short byte_addr, |
|
16570 + unsigned char* buf, |
|
16571 + unsigned short byte_num); |
|
16572 + |
|
16573 + |
|
16574 + |
|
16575 +//3////////////////// |
|
16576 +//3for return INT value |
|
16577 +//3////////////////// |
|
16578 + |
|
16579 +int |
|
16580 +read_usb_sys_int_bytes( |
|
16581 + struct dvb_usb_device* dib, |
|
16582 + RegType type, |
|
16583 + unsigned short byte_addr, |
|
16584 + unsigned short n_bytes, |
|
16585 + int* p_val); |
|
16586 + |
|
16587 + |
|
16588 +int |
|
16589 +write_usb_sys_int_bytes( |
|
16590 + struct dvb_usb_device* dib, |
|
16591 + RegType type, |
|
16592 + unsigned short byte_addr, |
|
16593 + unsigned short n_bytes, |
|
16594 + int val); |
|
16595 + |
|
16596 +///////////////////////////////////// |
|
16597 + |
|
16598 +void |
|
16599 +platform_wait( |
|
16600 + unsigned long nMinDelayTime); |
|
16601 + |
|
16602 + |
|
16603 + |
|
16604 +#if 0 |
|
16605 +//3////////////////// |
|
16606 +//3for std i2c r/w |
|
16607 +//3////////////////// |
|
16608 + |
|
16609 +int |
|
16610 +read_rtl2832_stdi2c( |
|
16611 + struct dvb_usb_device* dib, |
|
16612 + unsigned short dev_i2c_addr, |
|
16613 + unsigned char* data, |
|
16614 + unsigned short bytelength); |
|
16615 + |
|
16616 +int |
|
16617 +write_rtl2832_stdi2c( |
|
16618 + struct dvb_usb_device* dib, |
|
16619 + unsigned short dev_i2c_addr, |
|
16620 + unsigned char* data, |
|
16621 + unsigned short bytelength); |
|
16622 + |
|
16623 +#endif |
|
16624 + |
|
16625 + |
|
16626 + |
|
16627 +int |
|
16628 +read_rtl2832_demod_register( |
|
16629 + struct dvb_usb_device*dib, |
|
16630 + unsigned char demod_device_addr, |
|
16631 + unsigned char page, |
|
16632 + unsigned char offset, |
|
16633 + unsigned char* data, |
|
16634 + unsigned short bytelength); |
|
16635 + |
|
16636 + |
|
16637 + |
|
16638 + |
|
16639 +int |
|
16640 +write_rtl2832_demod_register( |
|
16641 + struct dvb_usb_device*dib, |
|
16642 + unsigned char demod_device_addr, |
|
16643 + unsigned char page, |
|
16644 + unsigned char offset, |
|
16645 + unsigned char *data, |
|
16646 + unsigned short bytelength); |
|
16647 + |
|
16648 + |
|
16649 + |
|
16650 +int |
|
16651 +read_rtl2832_tuner_register( |
|
16652 + struct dvb_usb_device *dib, |
|
16653 + unsigned char device_address, |
|
16654 + unsigned char offset, |
|
16655 + unsigned char *data, |
|
16656 + unsigned short bytelength); |
|
16657 + |
|
16658 + |
|
16659 + |
|
16660 + |
|
16661 +int write_rtl2832_tuner_register( |
|
16662 + struct dvb_usb_device *dib, |
|
16663 + unsigned char device_address, |
|
16664 + unsigned char offset, |
|
16665 + unsigned char *data, |
|
16666 + unsigned short bytelength); |
|
16667 + |
|
16668 + |
|
16669 + |
|
16670 + |
|
16671 + |
|
16672 +int |
|
16673 + write_rtl2832_stdi2c( |
|
16674 + struct dvb_usb_device* dib, |
|
16675 + unsigned short dev_i2c_addr, |
|
16676 + unsigned char* data, |
|
16677 + unsigned short bytelength); |
|
16678 + |
|
16679 + |
|
16680 + |
|
16681 +int |
|
16682 + read_rtl2832_stdi2c( |
|
16683 + struct dvb_usb_device* dib, |
|
16684 + unsigned short dev_i2c_addr, |
|
16685 + unsigned char* data, |
|
16686 + unsigned short bytelength); |
|
16687 + |
|
16688 + |
|
16689 +//////////////////////////////////// |
|
16690 + |
|
16691 +#define BIT0 0x00000001 |
|
16692 +#define BIT1 0x00000002 |
|
16693 +#define BIT2 0x00000004 |
|
16694 +#define BIT3 0x00000008 |
|
16695 +#define BIT4 0x00000010 |
|
16696 +#define BIT5 0x00000020 |
|
16697 +#define BIT6 0x00000040 |
|
16698 +#define BIT7 0x00000080 |
|
16699 +#define BIT8 0x00000100 |
|
16700 +#define BIT9 0x00000200 |
|
16701 +#define BIT10 0x00000400 |
|
16702 +#define BIT11 0x00000800 |
|
16703 +#define BIT12 0x00001000 |
|
16704 +#define BIT13 0x00002000 |
|
16705 +#define BIT14 0x00004000 |
|
16706 +#define BIT15 0x00008000 |
|
16707 +#define BIT16 0x00010000 |
|
16708 +#define BIT17 0x00020000 |
|
16709 +#define BIT18 0x00040000 |
|
16710 +#define BIT19 0x00080000 |
|
16711 +#define BIT20 0x00100000 |
|
16712 +#define BIT21 0x00200000 |
|
16713 +#define BIT22 0x00400000 |
|
16714 +#define BIT23 0x00800000 |
|
16715 +#define BIT24 0x01000000 |
|
16716 +#define BIT25 0x02000000 |
|
16717 +#define BIT26 0x04000000 |
|
16718 +#define BIT27 0x08000000 |
|
16719 +#define BIT28 0x10000000 |
|
16720 +#define BIT29 0x20000000 |
|
16721 +#define BIT30 0x40000000 |
|
16722 +#define BIT31 0x80000000 |
|
16723 + |
|
16724 + |
|
16725 +#endif |
|
16726 + |
|
16727 + |
|
16728 + |
|
16729 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/tuner_base.h |
|
16730 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
16731 +++ b/linux/drivers/media/dvb/dvb-usb/tuner_base.h Wed Oct 27 09:16:44 2010 +0200 |
|
16732 @@ -0,0 +1,365 @@ |
|
16733 +#ifndef __TUNER_BASE_H |
|
16734 +#define __TUNER_BASE_H |
|
16735 + |
|
16736 +/** |
|
16737 + |
|
16738 +@file |
|
16739 + |
|
16740 +@brief Tuner base module definition |
|
16741 + |
|
16742 +Tuner base module definitions contains tuner module structure, tuner funciton pointers, and tuner definitions. |
|
16743 + |
|
16744 + |
|
16745 + |
|
16746 +@par Example: |
|
16747 +@code |
|
16748 + |
|
16749 + |
|
16750 +#include "demod_xxx.h" |
|
16751 +#include "tuner_xxx.h" |
|
16752 + |
|
16753 + |
|
16754 + |
|
16755 +int |
|
16756 +CustomI2cRead( |
|
16757 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
16758 + unsigned char DeviceAddr, |
|
16759 + unsigned char *pReadingBytes, |
|
16760 + unsigned char ByteNum |
|
16761 + ) |
|
16762 +{ |
|
16763 + ... |
|
16764 + |
|
16765 + return FUNCTION_SUCCESS; |
|
16766 + |
|
16767 +error_status: |
|
16768 + return FUNCTION_ERROR; |
|
16769 +} |
|
16770 + |
|
16771 + |
|
16772 + |
|
16773 +int |
|
16774 +CustomI2cWrite( |
|
16775 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
16776 + unsigned char DeviceAddr, |
|
16777 + const unsigned char *pWritingBytes, |
|
16778 + unsigned char ByteNum |
|
16779 + ) |
|
16780 +{ |
|
16781 + ... |
|
16782 + |
|
16783 + return FUNCTION_SUCCESS; |
|
16784 + |
|
16785 +error_status: |
|
16786 + return FUNCTION_ERROR; |
|
16787 +} |
|
16788 + |
|
16789 + |
|
16790 + |
|
16791 +void |
|
16792 +CustomWaitMs( |
|
16793 + BASE_INTERFACE_MODULE *pBaseInterface, |
|
16794 + unsigned long WaitTimeMs |
|
16795 + ) |
|
16796 +{ |
|
16797 + ... |
|
16798 +} |
|
16799 + |
|
16800 + |
|
16801 + |
|
16802 +int main(void) |
|
16803 +{ |
|
16804 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
16805 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
16806 + |
|
16807 + XXX_DEMOD_MODULE *pDemod; |
|
16808 + XXX_DEMOD_MODULE XxxDemodModuleMemory; |
|
16809 + |
|
16810 + TUNER_MODULE *pTuner; |
|
16811 + TUNER_MODULE TunerModuleMemory; |
|
16812 + |
|
16813 + I2C_BRIDGE_MODULE I2cBridgeModuleMemory; |
|
16814 + |
|
16815 + unsigned long RfFreqHz; |
|
16816 + |
|
16817 + int TunerType; |
|
16818 + unsigned char DeviceAddr; |
|
16819 + |
|
16820 + |
|
16821 + |
|
16822 + // Build base interface module. |
|
16823 + BuildBaseInterface( |
|
16824 + &pBaseInterface, |
|
16825 + &BaseInterfaceModuleMemory, |
|
16826 + 9, // Set maximum I2C reading byte number with 9. |
|
16827 + 8, // Set maximum I2C writing byte number with 8. |
|
16828 + CustomI2cRead, // Employ CustomI2cRead() as basic I2C reading function. |
|
16829 + CustomI2cWrite, // Employ CustomI2cWrite() as basic I2C writing function. |
|
16830 + CustomWaitMs // Employ CustomWaitMs() as basic waiting function. |
|
16831 + ); |
|
16832 + |
|
16833 + |
|
16834 + // Build dmeod XXX module. |
|
16835 + // Note: Demod module builder will set I2cBridgeModuleMemory for tuner I2C command forwarding. |
|
16836 + // Must execute demod builder to set I2cBridgeModuleMemory before use tuner functions. |
|
16837 + BuildDemodXxxModule( |
|
16838 + &pDemod, |
|
16839 + &XxxDemodModuleMemory, |
|
16840 + &BaseInterfaceModuleMemory, |
|
16841 + &I2cBridgeModuleMemory, |
|
16842 + ... // Other arguments by each demod module |
|
16843 + ) |
|
16844 + |
|
16845 + |
|
16846 + // Build tuner XXX module. |
|
16847 + BuildTunerXxxModule( |
|
16848 + &pTuner, |
|
16849 + &TunerModuleMemory, |
|
16850 + &BaseInterfaceModuleMemory, |
|
16851 + &I2cBridgeModuleMemory, |
|
16852 + 0xc0, // Tuner I2C device address is 0xc0 in 8-bit format. |
|
16853 + ... // Other arguments by each demod module |
|
16854 + ); |
|
16855 + |
|
16856 + |
|
16857 + |
|
16858 + |
|
16859 + |
|
16860 + // ==== Initialize tuner and set its parameters ===== |
|
16861 + |
|
16862 + // Initialize tuner. |
|
16863 + pTuner->Initialize(pTuner); |
|
16864 + |
|
16865 + |
|
16866 + // Set tuner parameters. (RF frequency) |
|
16867 + // Note: In the example, RF frequency is 474 MHz. |
|
16868 + RfFreqHz = 474000000; |
|
16869 + |
|
16870 + pTuner->SetIfFreqHz(pTuner, RfFreqHz); |
|
16871 + |
|
16872 + |
|
16873 + |
|
16874 + |
|
16875 + |
|
16876 + // ==== Get tuner information ===== |
|
16877 + |
|
16878 + // Get tuenr type. |
|
16879 + // Note: One can find tuner type in MODULE_TYPE enumeration. |
|
16880 + pTuner->GetTunerType(pTuner, &TunerType); |
|
16881 + |
|
16882 + // Get tuner I2C device address. |
|
16883 + pTuner->GetDeviceAddr(pTuner, &DeviceAddr); |
|
16884 + |
|
16885 + |
|
16886 + // Get tuner parameters. (RF frequency) |
|
16887 + pTuner->GetRfFreqHz(pTuner, &RfFreqHz); |
|
16888 + |
|
16889 + |
|
16890 + |
|
16891 + return 0; |
|
16892 +} |
|
16893 + |
|
16894 + |
|
16895 +@endcode |
|
16896 + |
|
16897 +*/ |
|
16898 + |
|
16899 + |
|
16900 +#include "foundation.h" |
|
16901 + |
|
16902 + |
|
16903 + |
|
16904 + |
|
16905 + |
|
16906 +/// tuner module pre-definition |
|
16907 +typedef struct TUNER_MODULE_TAG TUNER_MODULE; |
|
16908 + |
|
16909 + |
|
16910 + |
|
16911 + |
|
16912 + |
|
16913 +/** |
|
16914 + |
|
16915 +@brief Tuner type getting function pointer |
|
16916 + |
|
16917 +One can use TUNER_FP_GET_TUNER_TYPE() to get tuner type. |
|
16918 + |
|
16919 + |
|
16920 +@param [in] pTuner The tuner module pointer |
|
16921 +@param [out] pTunerType Pointer to an allocated memory for storing tuner type |
|
16922 + |
|
16923 + |
|
16924 +@note |
|
16925 + -# Tuner building function will set TUNER_FP_GET_TUNER_TYPE() with the corresponding function. |
|
16926 + |
|
16927 + |
|
16928 +@see TUNER_TYPE |
|
16929 + |
|
16930 +*/ |
|
16931 +typedef void |
|
16932 +(*TUNER_FP_GET_TUNER_TYPE)( |
|
16933 + TUNER_MODULE *pTuner, |
|
16934 + int *pTunerType |
|
16935 + ); |
|
16936 + |
|
16937 + |
|
16938 + |
|
16939 + |
|
16940 + |
|
16941 +/** |
|
16942 + |
|
16943 +@brief Tuner I2C device address getting function pointer |
|
16944 + |
|
16945 +One can use TUNER_FP_GET_DEVICE_ADDR() to get tuner I2C device address. |
|
16946 + |
|
16947 + |
|
16948 +@param [in] pTuner The tuner module pointer |
|
16949 +@param [out] pDeviceAddr Pointer to an allocated memory for storing tuner I2C device address |
|
16950 + |
|
16951 + |
|
16952 +@retval FUNCTION_SUCCESS Get tuner device address successfully. |
|
16953 +@retval FUNCTION_ERROR Get tuner device address unsuccessfully. |
|
16954 + |
|
16955 + |
|
16956 +@note |
|
16957 + -# Tuner building function will set TUNER_FP_GET_DEVICE_ADDR() with the corresponding function. |
|
16958 + |
|
16959 +*/ |
|
16960 +typedef void |
|
16961 +(*TUNER_FP_GET_DEVICE_ADDR)( |
|
16962 + TUNER_MODULE *pTuner, |
|
16963 + unsigned char *pDeviceAddr |
|
16964 + ); |
|
16965 + |
|
16966 + |
|
16967 + |
|
16968 + |
|
16969 + |
|
16970 +/** |
|
16971 + |
|
16972 +@brief Tuner initializing function pointer |
|
16973 + |
|
16974 +One can use TUNER_FP_INITIALIZE() to initialie tuner. |
|
16975 + |
|
16976 + |
|
16977 +@param [in] pTuner The tuner module pointer |
|
16978 + |
|
16979 + |
|
16980 +@retval FUNCTION_SUCCESS Initialize tuner successfully. |
|
16981 +@retval FUNCTION_ERROR Initialize tuner unsuccessfully. |
|
16982 + |
|
16983 + |
|
16984 +@note |
|
16985 + -# Tuner building function will set TUNER_FP_INITIALIZE() with the corresponding function. |
|
16986 + |
|
16987 +*/ |
|
16988 +typedef int |
|
16989 +(*TUNER_FP_INITIALIZE)( |
|
16990 + TUNER_MODULE *pTuner |
|
16991 + ); |
|
16992 + |
|
16993 + |
|
16994 + |
|
16995 + |
|
16996 + |
|
16997 +/** |
|
16998 + |
|
16999 +@brief Tuner RF frequency setting function pointer |
|
17000 + |
|
17001 +One can use TUNER_FP_SET_RF_FREQ_HZ() to set tuner RF frequency in Hz. |
|
17002 + |
|
17003 + |
|
17004 +@param [in] pTuner The tuner module pointer |
|
17005 +@param [in] RfFreqHz RF frequency in Hz for setting |
|
17006 + |
|
17007 + |
|
17008 +@retval FUNCTION_SUCCESS Set tuner RF frequency successfully. |
|
17009 +@retval FUNCTION_ERROR Set tuner RF frequency unsuccessfully. |
|
17010 + |
|
17011 + |
|
17012 +@note |
|
17013 + -# Tuner building function will set TUNER_FP_SET_RF_FREQ_HZ() with the corresponding function. |
|
17014 + |
|
17015 +*/ |
|
17016 +typedef int |
|
17017 +(*TUNER_FP_SET_RF_FREQ_HZ)( |
|
17018 + TUNER_MODULE *pTuner, |
|
17019 + unsigned long RfFreqHz |
|
17020 + ); |
|
17021 + |
|
17022 + |
|
17023 + |
|
17024 + |
|
17025 + |
|
17026 +/** |
|
17027 + |
|
17028 +@brief Tuner RF frequency getting function pointer |
|
17029 + |
|
17030 +One can use TUNER_FP_GET_RF_FREQ_HZ() to get tuner RF frequency in Hz. |
|
17031 + |
|
17032 + |
|
17033 +@param [in] pTuner The tuner module pointer |
|
17034 +@param [in] pRfFreqHz Pointer to an allocated memory for storing demod RF frequency in Hz |
|
17035 + |
|
17036 + |
|
17037 +@retval FUNCTION_SUCCESS Get tuner RF frequency successfully. |
|
17038 +@retval FUNCTION_ERROR Get tuner RF frequency unsuccessfully. |
|
17039 + |
|
17040 + |
|
17041 +@note |
|
17042 + -# Tuner building function will set TUNER_FP_GET_RF_FREQ_HZ() with the corresponding function. |
|
17043 + |
|
17044 +*/ |
|
17045 +typedef int |
|
17046 +(*TUNER_FP_GET_RF_FREQ_HZ)( |
|
17047 + TUNER_MODULE *pTuner, |
|
17048 + unsigned long *pRfFreqHz |
|
17049 + ); |
|
17050 + |
|
17051 + |
|
17052 + |
|
17053 + |
|
17054 + |
|
17055 +/// Tuner module structure |
|
17056 +struct TUNER_MODULE_TAG |
|
17057 +{ |
|
17058 + unsigned char b_set_tuner_power_gpio4; //3add by chialing 2008.08.19 |
|
17059 + // Private variables |
|
17060 + int TunerType; ///< Tuner type |
|
17061 + unsigned char DeviceAddr; ///< Tuner I2C device address |
|
17062 + unsigned long RfFreqHz; ///< Tuner RF frequency in Hz |
|
17063 + |
|
17064 + int IsRfFreqHzSet; ///< Tuner RF frequency in Hz (setting status) |
|
17065 + |
|
17066 + void *pExtra; ///< Tuner extra module used by driving module |
|
17067 + BASE_INTERFACE_MODULE *pBaseInterface; ///< Base interface module |
|
17068 + I2C_BRIDGE_MODULE *pI2cBridge; ///< I2C bridge module |
|
17069 + |
|
17070 + |
|
17071 + // Tuner manipulating functions |
|
17072 + TUNER_FP_GET_TUNER_TYPE GetTunerType; ///< Tuner type getting function pointer |
|
17073 + TUNER_FP_GET_DEVICE_ADDR GetDeviceAddr; ///< Tuner I2C device address getting function pointer |
|
17074 + |
|
17075 + TUNER_FP_INITIALIZE Initialize; ///< Tuner initializing function pointer |
|
17076 + TUNER_FP_SET_RF_FREQ_HZ SetRfFreqHz; ///< Tuner RF frequency setting function pointer |
|
17077 + TUNER_FP_GET_RF_FREQ_HZ GetRfFreqHz; ///< Tuner RF frequency getting function pointer |
|
17078 + |
|
17079 +}; |
|
17080 + |
|
17081 + |
|
17082 + |
|
17083 + |
|
17084 + |
|
17085 + |
|
17086 + |
|
17087 + |
|
17088 + |
|
17089 + |
|
17090 + |
|
17091 + |
|
17092 + |
|
17093 + |
|
17094 + |
|
17095 + |
|
17096 + |
|
17097 +#endif |
|
17098 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/tuner_fc2580.c |
|
17099 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
17100 +++ b/linux/drivers/media/dvb/dvb-usb/tuner_fc2580.c Wed Oct 27 09:16:44 2010 +0200 |
|
17101 @@ -0,0 +1,992 @@ |
|
17102 +/** |
|
17103 + |
|
17104 +@file |
|
17105 + |
|
17106 +@brief FC2580 tuner module definition |
|
17107 + |
|
17108 +One can manipulate FC2580 tuner through FC2580 module. |
|
17109 +FC2580 module is derived from tuner module. |
|
17110 + |
|
17111 +*/ |
|
17112 + |
|
17113 + |
|
17114 +#include "tuner_fc2580.h" |
|
17115 + |
|
17116 + |
|
17117 + |
|
17118 + |
|
17119 + |
|
17120 +/** |
|
17121 + |
|
17122 +@brief FC2580 tuner module builder |
|
17123 + |
|
17124 +Use BuildFc2580Module() to build FC2580 module, set all module function pointers with the corresponding functions, |
|
17125 +and initialize module private variables. |
|
17126 + |
|
17127 + |
|
17128 +@param [in] ppTuner Pointer to FC2580 tuner module pointer |
|
17129 +@param [in] pTunerModuleMemory Pointer to an allocated tuner module memory |
|
17130 +@param [in] pFc2580ExtraModuleMemory Pointer to an allocated FC2580 extra module memory |
|
17131 +@param [in] pBaseInterfaceModuleMemory Pointer to an allocated base interface module memory |
|
17132 +@param [in] pI2cBridgeModuleMemory Pointer to an allocated I2C bridge module memory |
|
17133 +@param [in] DeviceAddr FC2580 I2C device address |
|
17134 +@param [in] AgcMode FC2580 AGC mode |
|
17135 + |
|
17136 + |
|
17137 +@note |
|
17138 + -# One should call BuildFc2580Module() to build FC2580 module before using it. |
|
17139 + |
|
17140 +*/ |
|
17141 +void |
|
17142 +BuildFc2580Module( |
|
17143 + TUNER_MODULE **ppTuner, |
|
17144 + TUNER_MODULE *pTunerModuleMemory, |
|
17145 + FC2580_EXTRA_MODULE *pFc2580ExtraModuleMemory, |
|
17146 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
17147 + I2C_BRIDGE_MODULE *pI2cBridgeModuleMemory, |
|
17148 + unsigned char DeviceAddr, |
|
17149 + unsigned long CrystalFreqHz, |
|
17150 + int AgcMode |
|
17151 + ) |
|
17152 +{ |
|
17153 + TUNER_MODULE *pTuner; |
|
17154 + FC2580_EXTRA_MODULE *pExtra; |
|
17155 + |
|
17156 + |
|
17157 + |
|
17158 + // Set tuner module pointer. |
|
17159 + *ppTuner = pTunerModuleMemory; |
|
17160 + |
|
17161 + // Get tuner module. |
|
17162 + pTuner = *ppTuner; |
|
17163 + |
|
17164 + // Set tuner extra module pointer, base interface module pointer, and I2C bridge module pointer. |
|
17165 + pTuner->pExtra = pFc2580ExtraModuleMemory; |
|
17166 + pTuner->pBaseInterface = pBaseInterfaceModuleMemory; |
|
17167 + pTuner->pI2cBridge = pI2cBridgeModuleMemory; |
|
17168 + |
|
17169 + // Get tuner extra module. |
|
17170 + pExtra = (FC2580_EXTRA_MODULE *)pTuner->pExtra; |
|
17171 + |
|
17172 + |
|
17173 + |
|
17174 + // Set tuner type. |
|
17175 + pTuner->TunerType = TUNER_TYPE_FC2580; |
|
17176 + |
|
17177 + // Set tuner I2C device address. |
|
17178 + pTuner->DeviceAddr = DeviceAddr; |
|
17179 + |
|
17180 + |
|
17181 + // Initialize tuner parameter setting status. |
|
17182 + pTuner->IsRfFreqHzSet = NO; |
|
17183 + |
|
17184 + |
|
17185 + // Set I2C bridge tuner arguments. |
|
17186 + fc2580_SetI2cBridgeModuleTunerArg(pTuner); |
|
17187 + |
|
17188 + |
|
17189 + // Set tuner module manipulating function pointers. |
|
17190 + pTuner->GetTunerType = fc2580_GetTunerType; |
|
17191 + pTuner->GetDeviceAddr = fc2580_GetDeviceAddr; |
|
17192 + |
|
17193 + pTuner->Initialize = fc2580_Initialize; |
|
17194 + pTuner->SetRfFreqHz = fc2580_SetRfFreqHz; |
|
17195 + pTuner->GetRfFreqHz = fc2580_GetRfFreqHz; |
|
17196 + |
|
17197 + |
|
17198 + // Initialize tuner extra module variables. |
|
17199 + pExtra->CrystalFreqHz = CrystalFreqHz; |
|
17200 + pExtra->AgcMode = AgcMode; |
|
17201 + pExtra->IsBandwidthModeSet = NO; |
|
17202 + |
|
17203 + // Set tuner extra module function pointers. |
|
17204 + pExtra->SetBandwidthMode = fc2580_SetBandwidthMode; |
|
17205 + pExtra->GetBandwidthMode = fc2580_GetBandwidthMode; |
|
17206 + |
|
17207 + |
|
17208 + return; |
|
17209 +} |
|
17210 + |
|
17211 + |
|
17212 + |
|
17213 + |
|
17214 + |
|
17215 +/** |
|
17216 + |
|
17217 +@see TUNER_FP_GET_TUNER_TYPE |
|
17218 + |
|
17219 +*/ |
|
17220 +void |
|
17221 +fc2580_GetTunerType( |
|
17222 + TUNER_MODULE *pTuner, |
|
17223 + int *pTunerType |
|
17224 + ) |
|
17225 +{ |
|
17226 + // Get tuner type from tuner module. |
|
17227 + *pTunerType = pTuner->TunerType; |
|
17228 + |
|
17229 + |
|
17230 + return; |
|
17231 +} |
|
17232 + |
|
17233 + |
|
17234 + |
|
17235 + |
|
17236 + |
|
17237 +/** |
|
17238 + |
|
17239 +@see TUNER_FP_GET_DEVICE_ADDR |
|
17240 + |
|
17241 +*/ |
|
17242 +void |
|
17243 +fc2580_GetDeviceAddr( |
|
17244 + TUNER_MODULE *pTuner, |
|
17245 + unsigned char *pDeviceAddr |
|
17246 + ) |
|
17247 +{ |
|
17248 + // Get tuner I2C device address from tuner module. |
|
17249 + *pDeviceAddr = pTuner->DeviceAddr; |
|
17250 + |
|
17251 + |
|
17252 + return; |
|
17253 +} |
|
17254 + |
|
17255 + |
|
17256 + |
|
17257 + |
|
17258 + |
|
17259 +/** |
|
17260 + |
|
17261 +@see TUNER_FP_INITIALIZE |
|
17262 + |
|
17263 +*/ |
|
17264 +int |
|
17265 +fc2580_Initialize( |
|
17266 + TUNER_MODULE *pTuner |
|
17267 + ) |
|
17268 +{ |
|
17269 + FC2580_EXTRA_MODULE *pExtra; |
|
17270 + int AgcMode; |
|
17271 + unsigned int CrystalFreqKhz; |
|
17272 + |
|
17273 + |
|
17274 + |
|
17275 + // Get tuner extra module. |
|
17276 + pExtra = (FC2580_EXTRA_MODULE *)pTuner->pExtra; |
|
17277 + |
|
17278 + |
|
17279 + // Get AGC mode. |
|
17280 + AgcMode = pExtra->AgcMode; |
|
17281 + |
|
17282 + // Initialize tuner with AGC mode. |
|
17283 + // Note: CrystalFreqKhz = round(CrystalFreqHz / 1000) |
|
17284 + CrystalFreqKhz = (unsigned int)((pExtra->CrystalFreqHz + 500) / 1000); |
|
17285 + |
|
17286 + if(fc2580_set_init(pTuner, AgcMode, CrystalFreqKhz) != FCI_SUCCESS) |
|
17287 + goto error_status_initialize_tuner; |
|
17288 + |
|
17289 + |
|
17290 + return FUNCTION_SUCCESS; |
|
17291 + |
|
17292 + |
|
17293 +error_status_initialize_tuner: |
|
17294 + return FUNCTION_ERROR; |
|
17295 +} |
|
17296 + |
|
17297 + |
|
17298 + |
|
17299 + |
|
17300 + |
|
17301 +/** |
|
17302 + |
|
17303 +@see TUNER_FP_SET_RF_FREQ_HZ |
|
17304 + |
|
17305 +*/ |
|
17306 +int |
|
17307 +fc2580_SetRfFreqHz( |
|
17308 + TUNER_MODULE *pTuner, |
|
17309 + unsigned long RfFreqHz |
|
17310 + ) |
|
17311 +{ |
|
17312 + FC2580_EXTRA_MODULE *pExtra; |
|
17313 + unsigned int RfFreqKhz; |
|
17314 + unsigned int CrystalFreqKhz; |
|
17315 + |
|
17316 + |
|
17317 + |
|
17318 + // Get tuner extra module. |
|
17319 + pExtra = (FC2580_EXTRA_MODULE *)pTuner->pExtra; |
|
17320 + |
|
17321 + |
|
17322 + // Set tuner RF frequency in KHz. |
|
17323 + // Note: RfFreqKhz = round(RfFreqHz / 1000) |
|
17324 + // CrystalFreqKhz = round(CrystalFreqHz / 1000) |
|
17325 + RfFreqKhz = (unsigned int)((RfFreqHz + 500) / 1000); |
|
17326 + CrystalFreqKhz = (unsigned int)((pExtra->CrystalFreqHz + 500) / 1000); |
|
17327 + |
|
17328 + if(fc2580_set_freq(pTuner, RfFreqKhz, CrystalFreqKhz) != FCI_SUCCESS) |
|
17329 + goto error_status_set_tuner_rf_frequency; |
|
17330 + |
|
17331 + |
|
17332 + // Set tuner RF frequency parameter. |
|
17333 + pTuner->RfFreqHz = RfFreqHz; |
|
17334 + pTuner->IsRfFreqHzSet = YES; |
|
17335 + |
|
17336 + |
|
17337 + return FUNCTION_SUCCESS; |
|
17338 + |
|
17339 + |
|
17340 +error_status_set_tuner_rf_frequency: |
|
17341 + return FUNCTION_ERROR; |
|
17342 +} |
|
17343 + |
|
17344 + |
|
17345 + |
|
17346 + |
|
17347 + |
|
17348 +/** |
|
17349 + |
|
17350 +@see TUNER_FP_GET_RF_FREQ_HZ |
|
17351 + |
|
17352 +*/ |
|
17353 +int |
|
17354 +fc2580_GetRfFreqHz( |
|
17355 + TUNER_MODULE *pTuner, |
|
17356 + unsigned long *pRfFreqHz |
|
17357 + ) |
|
17358 +{ |
|
17359 + // Get tuner RF frequency in Hz from tuner module. |
|
17360 + if(pTuner->IsRfFreqHzSet != YES) |
|
17361 + goto error_status_get_tuner_rf_frequency; |
|
17362 + |
|
17363 + *pRfFreqHz = pTuner->RfFreqHz; |
|
17364 + |
|
17365 + |
|
17366 + return FUNCTION_SUCCESS; |
|
17367 + |
|
17368 + |
|
17369 +error_status_get_tuner_rf_frequency: |
|
17370 + return FUNCTION_ERROR; |
|
17371 +} |
|
17372 + |
|
17373 + |
|
17374 + |
|
17375 + |
|
17376 + |
|
17377 +/** |
|
17378 + |
|
17379 +@brief Set FC2580 tuner bandwidth mode. |
|
17380 + |
|
17381 +*/ |
|
17382 +int |
|
17383 +fc2580_SetBandwidthMode( |
|
17384 + TUNER_MODULE *pTuner, |
|
17385 + int BandwidthMode |
|
17386 + ) |
|
17387 +{ |
|
17388 + FC2580_EXTRA_MODULE *pExtra; |
|
17389 + unsigned int CrystalFreqKhz; |
|
17390 + |
|
17391 + |
|
17392 + |
|
17393 + // Get tuner extra module. |
|
17394 + pExtra = (FC2580_EXTRA_MODULE *)pTuner->pExtra; |
|
17395 + |
|
17396 + |
|
17397 + // Set tuner bandwidth mode. |
|
17398 + // Note: CrystalFreqKhz = round(CrystalFreqHz / 1000) |
|
17399 + CrystalFreqKhz = (unsigned int)((pExtra->CrystalFreqHz + 500) / 1000); |
|
17400 + |
|
17401 + if(fc2580_set_filter(pTuner, (unsigned char)BandwidthMode, CrystalFreqKhz) != FCI_SUCCESS) |
|
17402 + goto error_status_set_tuner_bandwidth_mode; |
|
17403 + |
|
17404 + |
|
17405 + // Set tuner bandwidth mode parameter. |
|
17406 + pExtra->BandwidthMode = BandwidthMode; |
|
17407 + pExtra->IsBandwidthModeSet = YES; |
|
17408 + |
|
17409 + |
|
17410 + return FUNCTION_SUCCESS; |
|
17411 + |
|
17412 + |
|
17413 +error_status_set_tuner_bandwidth_mode: |
|
17414 + return FUNCTION_ERROR; |
|
17415 +} |
|
17416 + |
|
17417 + |
|
17418 + |
|
17419 + |
|
17420 + |
|
17421 +/** |
|
17422 + |
|
17423 +@brief Get FC2580 tuner bandwidth mode. |
|
17424 + |
|
17425 +*/ |
|
17426 +int |
|
17427 +fc2580_GetBandwidthMode( |
|
17428 + TUNER_MODULE *pTuner, |
|
17429 + int *pBandwidthMode |
|
17430 + ) |
|
17431 +{ |
|
17432 + FC2580_EXTRA_MODULE *pExtra; |
|
17433 + |
|
17434 + |
|
17435 + |
|
17436 + // Get tuner extra module. |
|
17437 + pExtra = (FC2580_EXTRA_MODULE *)pTuner->pExtra; |
|
17438 + |
|
17439 + |
|
17440 + // Get tuner bandwidth mode from tuner module. |
|
17441 + if(pExtra->IsBandwidthModeSet != YES) |
|
17442 + goto error_status_get_tuner_bandwidth_mode; |
|
17443 + |
|
17444 + *pBandwidthMode = pExtra->BandwidthMode; |
|
17445 + |
|
17446 + |
|
17447 + return FUNCTION_SUCCESS; |
|
17448 + |
|
17449 + |
|
17450 +error_status_get_tuner_bandwidth_mode: |
|
17451 + return FUNCTION_ERROR; |
|
17452 +} |
|
17453 + |
|
17454 + |
|
17455 + |
|
17456 + |
|
17457 + |
|
17458 +/** |
|
17459 + |
|
17460 +@brief Set I2C bridge module tuner arguments. |
|
17461 + |
|
17462 +FC2580 builder will use fc2580_SetI2cBridgeModuleTunerArg() to set I2C bridge module tuner arguments. |
|
17463 + |
|
17464 + |
|
17465 +@param [in] pTuner The tuner module pointer |
|
17466 + |
|
17467 + |
|
17468 +@see BuildFc2580Module() |
|
17469 + |
|
17470 +*/ |
|
17471 +void |
|
17472 +fc2580_SetI2cBridgeModuleTunerArg( |
|
17473 + TUNER_MODULE *pTuner |
|
17474 + ) |
|
17475 +{ |
|
17476 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
17477 + |
|
17478 + |
|
17479 + |
|
17480 + // Get I2C bridge module. |
|
17481 + pI2cBridge = pTuner->pI2cBridge; |
|
17482 + |
|
17483 + // Set I2C bridge module tuner arguments. |
|
17484 + pI2cBridge->pTunerDeviceAddr = &pTuner->DeviceAddr; |
|
17485 + |
|
17486 + |
|
17487 + return; |
|
17488 +} |
|
17489 + |
|
17490 + |
|
17491 + |
|
17492 + |
|
17493 + |
|
17494 + |
|
17495 + |
|
17496 + |
|
17497 + |
|
17498 + |
|
17499 + |
|
17500 + |
|
17501 + |
|
17502 + |
|
17503 + |
|
17504 + |
|
17505 + |
|
17506 + |
|
17507 + |
|
17508 + |
|
17509 + |
|
17510 + |
|
17511 + |
|
17512 +// The following context is source code provided by FCI. |
|
17513 + |
|
17514 + |
|
17515 + |
|
17516 + |
|
17517 + |
|
17518 +// FCI source code - fc2580_driver_v14011_r.c |
|
17519 + |
|
17520 + |
|
17521 +/*============================================================================== |
|
17522 + FILE NAME : FC2580_driver_v1400_r.c |
|
17523 + |
|
17524 + VERSION : 1.400_r |
|
17525 + |
|
17526 + UPDATE : September 22. 2008 |
|
17527 + |
|
17528 +==============================================================================*/ |
|
17529 + |
|
17530 +/*============================================================================== |
|
17531 + |
|
17532 + Chip ID of FC2580 is 0x56 or 0xAC(including I2C write bit) |
|
17533 + |
|
17534 +==============================================================================*/ |
|
17535 + |
|
17536 +//#include "fc2580_driver_v1400_r.h" |
|
17537 + |
|
17538 +//fc2580_band_type curr_band = NO_BAND; |
|
17539 +//unsigned int freq_xtal = 16384; |
|
17540 + |
|
17541 + |
|
17542 +/*============================================================================== |
|
17543 + milisecond delay function EXTERNAL FUNCTION |
|
17544 + |
|
17545 + This function is a generic function which write a byte into fc2580's |
|
17546 + specific address. |
|
17547 + |
|
17548 + <input parameter> |
|
17549 + |
|
17550 + a |
|
17551 + length of wanted delay in milisecond unit |
|
17552 + |
|
17553 +==============================================================================*/ |
|
17554 +void wait_msec(TUNER_MODULE *pTuner, int a) |
|
17555 +{ |
|
17556 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
17557 + |
|
17558 + |
|
17559 + // Get base interface. |
|
17560 + pBaseInterface = pTuner->pBaseInterface; |
|
17561 + |
|
17562 + |
|
17563 + // Wait time in millisecond. |
|
17564 + pBaseInterface->WaitMs(pBaseInterface, (unsigned long)a); |
|
17565 + |
|
17566 + |
|
17567 + return; |
|
17568 +} |
|
17569 + |
|
17570 +/*============================================================================== |
|
17571 + |
|
17572 + fc2580 i2c write |
|
17573 + |
|
17574 + This function is a generic function which write a byte into fc2580's |
|
17575 + specific address. |
|
17576 + |
|
17577 + <input parameter> |
|
17578 + |
|
17579 + addr |
|
17580 + fc2580's memory address\ |
|
17581 + type : byte |
|
17582 + |
|
17583 + data |
|
17584 + target data |
|
17585 + type : byte |
|
17586 + |
|
17587 +==============================================================================*/ |
|
17588 +fci_result_type fc2580_i2c_write( TUNER_MODULE *pTuner, unsigned char addr, unsigned char data ) |
|
17589 +{ |
|
17590 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
17591 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
17592 + |
|
17593 + unsigned char TunerDeviceAddr; |
|
17594 + |
|
17595 + struct dvb_usb_device *d; |
|
17596 + |
|
17597 +// unsigned char WritingBytes[2]; |
|
17598 + unsigned char WritingBytes[1]; |
|
17599 + |
|
17600 + |
|
17601 + // Get I2C bridge. |
|
17602 + pI2cBridge = pTuner->pI2cBridge; |
|
17603 + pBaseInterface = pTuner->pBaseInterface; |
|
17604 + |
|
17605 + // Get tuner device address. |
|
17606 + TunerDeviceAddr = *pI2cBridge->pTunerDeviceAddr; |
|
17607 + |
|
17608 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); |
|
17609 + |
|
17610 + |
|
17611 + // Set writing bytes. |
|
17612 + // Note: The I2C format of tuner register byte setting is as follows: |
|
17613 + // start_bit + (DeviceAddr | writing_bit) + addr + data + stop_bit |
|
17614 +// WritingBytes[0] = addr; |
|
17615 +// WritingBytes[1] = data; |
|
17616 + WritingBytes[0] = data; |
|
17617 + |
|
17618 + // Set tuner register bytes with writing buffer. |
|
17619 +// if(pI2cBridge->ForwardI2cWritingCmd(pI2cBridge, WritingBytes, LEN_2_BYTE) != FUNCTION_SUCCESS) |
|
17620 +// goto error_status_set_tuner_registers; |
|
17621 + |
|
17622 + |
|
17623 + if (write_rtl2832_tuner_register(d, TunerDeviceAddr, addr, WritingBytes, LEN_1_BYTE)) goto error; |
|
17624 + |
|
17625 + |
|
17626 + return FCI_SUCCESS; |
|
17627 + |
|
17628 +error: |
|
17629 + return FCI_FAIL; |
|
17630 +}; |
|
17631 + |
|
17632 +/*============================================================================== |
|
17633 + |
|
17634 + fc2580 i2c read |
|
17635 + |
|
17636 + This function is a generic function which gets called to read data from |
|
17637 + fc2580's target memory address. |
|
17638 + |
|
17639 + <input parameter> |
|
17640 + |
|
17641 + addr |
|
17642 + fc2580's memory address |
|
17643 + type : byte |
|
17644 + |
|
17645 + |
|
17646 + <return value> |
|
17647 + data |
|
17648 + a byte of data read out of target address 'addr' |
|
17649 + type : byte |
|
17650 + |
|
17651 +==============================================================================*/ |
|
17652 +fci_result_type fc2580_i2c_read( TUNER_MODULE *pTuner, unsigned char addr, unsigned char *read_data ) |
|
17653 +{ |
|
17654 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
17655 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
17656 + |
|
17657 + unsigned char TunerDeviceAddr; |
|
17658 + |
|
17659 + struct dvb_usb_device *d; |
|
17660 + |
|
17661 + |
|
17662 + // Get I2C bridge. |
|
17663 + pI2cBridge = pTuner->pI2cBridge; |
|
17664 + pBaseInterface = pTuner->pBaseInterface; |
|
17665 + |
|
17666 + // Get tuner device address. |
|
17667 + TunerDeviceAddr = *pI2cBridge->pTunerDeviceAddr; |
|
17668 + |
|
17669 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); |
|
17670 + |
|
17671 + |
|
17672 + // Set tuner register reading address. |
|
17673 + // Note: The I2C format of tuner register reading address setting is as follows: |
|
17674 + // start_bit + (DeviceAddr | writing_bit) + addr + stop_bit |
|
17675 +// if(pI2cBridge->ForwardI2cWritingCmd(pI2cBridge, &addr, LEN_1_BYTE) != FUNCTION_SUCCESS) |
|
17676 +// goto error_status_set_tuner_register_reading_address; |
|
17677 + |
|
17678 + // Get tuner register byte. |
|
17679 + // Note: The I2C format of tuner register byte getting is as follows: |
|
17680 + // start_bit + (DeviceAddr | reading_bit) + read_data + stop_bit |
|
17681 +// if(pI2cBridge->ForwardI2cReadingCmd(pI2cBridge, read_data, LEN_1_BYTE) != FUNCTION_SUCCESS) |
|
17682 +// goto error_status_get_tuner_registers; |
|
17683 + |
|
17684 + |
|
17685 + if(read_rtl2832_tuner_register(d, TunerDeviceAddr, addr, read_data, LEN_1_BYTE)) goto error; |
|
17686 + |
|
17687 + return FCI_SUCCESS; |
|
17688 + |
|
17689 +error: |
|
17690 + return FCI_FAIL; |
|
17691 +}; |
|
17692 + |
|
17693 + |
|
17694 +/*============================================================================== |
|
17695 + fc2580 I2C Test |
|
17696 + |
|
17697 + This function is a generic function which tests I2C interface's availability |
|
17698 + |
|
17699 + by reading out it's I2C id data from reg. address '0x01'. |
|
17700 + |
|
17701 + <input parameter> |
|
17702 + |
|
17703 + None |
|
17704 + |
|
17705 + <return value> |
|
17706 + int |
|
17707 + 1 : success - communication is avilable |
|
17708 + 0 : fail - communication is unavailable |
|
17709 + |
|
17710 + |
|
17711 +==============================================================================*/ |
|
17712 +//int fc2580_i2c_test( void ) |
|
17713 +//{ |
|
17714 +// return ( fc2580_i2c_read( 0x01 ) == 0x56 )? 0x01 : 0x00; |
|
17715 +//} |
|
17716 + |
|
17717 + |
|
17718 + |
|
17719 + |
|
17720 +/*============================================================================== |
|
17721 + fc2580 initial setting |
|
17722 + |
|
17723 + This function is a generic function which gets called to initialize |
|
17724 + |
|
17725 + fc2580 in DVB-H mode or L-Band TDMB mode |
|
17726 + |
|
17727 + <input parameter> |
|
17728 + |
|
17729 + ifagc_mode |
|
17730 + type : integer |
|
17731 + 1 : Internal AGC |
|
17732 + 2 : Voltage Control Mode |
|
17733 + |
|
17734 +==============================================================================*/ |
|
17735 +fci_result_type fc2580_set_init( TUNER_MODULE *pTuner, int ifagc_mode, unsigned int freq_xtal ) |
|
17736 +{ |
|
17737 + fci_result_type result = FCI_SUCCESS; |
|
17738 + |
|
17739 + result &= fc2580_i2c_write(pTuner, 0x00, 0x00); /*** Confidential ***/ |
|
17740 + result &= fc2580_i2c_write(pTuner, 0x12, 0x86); |
|
17741 + result &= fc2580_i2c_write(pTuner, 0x14, 0x5C); |
|
17742 + result &= fc2580_i2c_write(pTuner, 0x16, 0x3C); |
|
17743 + result &= fc2580_i2c_write(pTuner, 0x1F, 0xD2); |
|
17744 + result &= fc2580_i2c_write(pTuner, 0x09, 0xD7); |
|
17745 + result &= fc2580_i2c_write(pTuner, 0x0B, 0xD5); |
|
17746 + result &= fc2580_i2c_write(pTuner, 0x0C, 0x32); |
|
17747 + result &= fc2580_i2c_write(pTuner, 0x0E, 0x43); |
|
17748 + result &= fc2580_i2c_write(pTuner, 0x21, 0x0A); |
|
17749 + result &= fc2580_i2c_write(pTuner, 0x22, 0x82); |
|
17750 + if( ifagc_mode == 1 ) |
|
17751 + { |
|
17752 + result &= fc2580_i2c_write(pTuner, 0x45, 0x10); //internal AGC |
|
17753 + result &= fc2580_i2c_write(pTuner, 0x4C, 0x00); //HOLD_AGC polarity |
|
17754 + } |
|
17755 + else if( ifagc_mode == 2 ) |
|
17756 + { |
|
17757 + result &= fc2580_i2c_write(pTuner, 0x45, 0x20); //Voltage Control Mode |
|
17758 + result &= fc2580_i2c_write(pTuner, 0x4C, 0x02); //HOLD_AGC polarity |
|
17759 + } |
|
17760 + result &= fc2580_i2c_write(pTuner, 0x3F, 0x88); |
|
17761 + result &= fc2580_i2c_write(pTuner, 0x02, 0x0E); |
|
17762 + result &= fc2580_i2c_write(pTuner, 0x58, 0x14); |
|
17763 + result &= fc2580_set_filter(pTuner, 8, freq_xtal); //BW = 7.8MHz |
|
17764 + |
|
17765 + return result; |
|
17766 +} |
|
17767 + |
|
17768 + |
|
17769 +/*============================================================================== |
|
17770 + fc2580 frequency setting |
|
17771 + |
|
17772 + This function is a generic function which gets called to change LO Frequency |
|
17773 + |
|
17774 + of fc2580 in DVB-H mode or L-Band TDMB mode |
|
17775 + |
|
17776 + <input parameter> |
|
17777 + freq_xtal: kHz |
|
17778 + |
|
17779 + f_lo |
|
17780 + Value of target LO Frequency in 'kHz' unit |
|
17781 + ex) 2.6GHz = 2600000 |
|
17782 + |
|
17783 +==============================================================================*/ |
|
17784 +fci_result_type fc2580_set_freq( TUNER_MODULE *pTuner, unsigned int f_lo, unsigned int freq_xtal ) |
|
17785 +{ |
|
17786 + unsigned int f_diff, f_diff_shifted, n_val, k_val; |
|
17787 + unsigned int f_vco, r_val, f_comp; |
|
17788 + unsigned char pre_shift_bits = 4;// number of preshift to prevent overflow in shifting f_diff to f_diff_shifted |
|
17789 + unsigned char data_0x18; |
|
17790 + unsigned char data_0x02 = (USE_EXT_CLK<<5)|0x0E; |
|
17791 + |
|
17792 + fc2580_band_type band = ( f_lo > 1000000 )? L_BAND : ( f_lo > 400000 )? UHF_BAND : VHF_BAND; |
|
17793 + |
|
17794 + fci_result_type result = FCI_SUCCESS; |
|
17795 + |
|
17796 + f_vco = ( band == UHF_BAND )? f_lo * 4 : (( band == L_BAND )? f_lo * 2 : f_lo * 12); |
|
17797 + r_val = ( f_vco >= 2*76*freq_xtal )? 1 : ( f_vco >= 76*freq_xtal )? 2 : 4; |
|
17798 + f_comp = freq_xtal/r_val; |
|
17799 + n_val = ( f_vco / 2 ) / f_comp; |
|
17800 + |
|
17801 + f_diff = f_vco - 2* f_comp * n_val; |
|
17802 + f_diff_shifted = f_diff << ( 20 - pre_shift_bits ); |
|
17803 + k_val = f_diff_shifted / ( ( 2* f_comp ) >> pre_shift_bits ); |
|
17804 + |
|
17805 + if( f_diff_shifted - k_val * ( ( 2* f_comp ) >> pre_shift_bits ) >= ( f_comp >> pre_shift_bits ) ) |
|
17806 + k_val = k_val + 1; |
|
17807 + |
|
17808 + if( f_vco >= BORDER_FREQ ) //Select VCO Band |
|
17809 + data_0x02 = data_0x02 | 0x08; //0x02[3] = 1; |
|
17810 + else |
|
17811 + data_0x02 = data_0x02 & 0xF7; //0x02[3] = 0; |
|
17812 + |
|
17813 +// if( band != curr_band ) { |
|
17814 + switch(band) |
|
17815 + { |
|
17816 + case UHF_BAND: |
|
17817 + data_0x02 = (data_0x02 & 0x3F); |
|
17818 + |
|
17819 + result &= fc2580_i2c_write(pTuner, 0x25, 0xF0); |
|
17820 + result &= fc2580_i2c_write(pTuner, 0x27, 0x77); |
|
17821 + result &= fc2580_i2c_write(pTuner, 0x28, 0x53); |
|
17822 + result &= fc2580_i2c_write(pTuner, 0x29, 0x60); |
|
17823 + result &= fc2580_i2c_write(pTuner, 0x30, 0x09); |
|
17824 + result &= fc2580_i2c_write(pTuner, 0x50, 0x8C); |
|
17825 + result &= fc2580_i2c_write(pTuner, 0x53, 0x50); |
|
17826 + |
|
17827 + if( f_lo < 538000 ) |
|
17828 + result &= fc2580_i2c_write(pTuner, 0x5F, 0x13); |
|
17829 + else |
|
17830 + result &= fc2580_i2c_write(pTuner, 0x5F, 0x15); |
|
17831 + |
|
17832 + if( f_lo < 538000 ) |
|
17833 + { |
|
17834 + result &= fc2580_i2c_write(pTuner, 0x61, 0x07); |
|
17835 + result &= fc2580_i2c_write(pTuner, 0x62, 0x06); |
|
17836 + result &= fc2580_i2c_write(pTuner, 0x67, 0x06); |
|
17837 + result &= fc2580_i2c_write(pTuner, 0x68, 0x08); |
|
17838 + result &= fc2580_i2c_write(pTuner, 0x69, 0x10); |
|
17839 + result &= fc2580_i2c_write(pTuner, 0x6A, 0x12); |
|
17840 + } |
|
17841 + else if( f_lo < 794000 ) |
|
17842 + { |
|
17843 + result &= fc2580_i2c_write(pTuner, 0x61, 0x03); |
|
17844 + result &= fc2580_i2c_write(pTuner, 0x62, 0x03); |
|
17845 + result &= fc2580_i2c_write(pTuner, 0x67, 0x03); //ACI improve |
|
17846 + result &= fc2580_i2c_write(pTuner, 0x68, 0x05); //ACI improve |
|
17847 + result &= fc2580_i2c_write(pTuner, 0x69, 0x0C); |
|
17848 + result &= fc2580_i2c_write(pTuner, 0x6A, 0x0E); |
|
17849 + } |
|
17850 + else |
|
17851 + { |
|
17852 + result &= fc2580_i2c_write(pTuner, 0x61, 0x07); |
|
17853 + result &= fc2580_i2c_write(pTuner, 0x62, 0x06); |
|
17854 + result &= fc2580_i2c_write(pTuner, 0x67, 0x07); |
|
17855 + result &= fc2580_i2c_write(pTuner, 0x68, 0x09); |
|
17856 + result &= fc2580_i2c_write(pTuner, 0x69, 0x10); |
|
17857 + result &= fc2580_i2c_write(pTuner, 0x6A, 0x12); |
|
17858 + } |
|
17859 + |
|
17860 + result &= fc2580_i2c_write(pTuner, 0x63, 0x15); |
|
17861 + |
|
17862 + result &= fc2580_i2c_write(pTuner, 0x6B, 0x0B); |
|
17863 + result &= fc2580_i2c_write(pTuner, 0x6C, 0x0C); |
|
17864 + result &= fc2580_i2c_write(pTuner, 0x6D, 0x78); |
|
17865 + result &= fc2580_i2c_write(pTuner, 0x6E, 0x32); |
|
17866 + result &= fc2580_i2c_write(pTuner, 0x6F, 0x14); |
|
17867 + result &= fc2580_set_filter(pTuner, 8, freq_xtal); //BW = 7.8MHz |
|
17868 + break; |
|
17869 + case VHF_BAND: |
|
17870 + data_0x02 = (data_0x02 & 0x3F) | 0x80; |
|
17871 + result &= fc2580_i2c_write(pTuner, 0x27, 0x77); |
|
17872 + result &= fc2580_i2c_write(pTuner, 0x28, 0x33); |
|
17873 + result &= fc2580_i2c_write(pTuner, 0x29, 0x40); |
|
17874 + result &= fc2580_i2c_write(pTuner, 0x30, 0x09); |
|
17875 + result &= fc2580_i2c_write(pTuner, 0x50, 0x8C); |
|
17876 + result &= fc2580_i2c_write(pTuner, 0x53, 0x50); |
|
17877 + result &= fc2580_i2c_write(pTuner, 0x5F, 0x0F); |
|
17878 + result &= fc2580_i2c_write(pTuner, 0x61, 0x07); |
|
17879 + result &= fc2580_i2c_write(pTuner, 0x62, 0x00); |
|
17880 + result &= fc2580_i2c_write(pTuner, 0x63, 0x15); |
|
17881 + result &= fc2580_i2c_write(pTuner, 0x67, 0x03); |
|
17882 + result &= fc2580_i2c_write(pTuner, 0x68, 0x05); |
|
17883 + result &= fc2580_i2c_write(pTuner, 0x69, 0x10); |
|
17884 + result &= fc2580_i2c_write(pTuner, 0x6A, 0x12); |
|
17885 + result &= fc2580_i2c_write(pTuner, 0x6B, 0x08); |
|
17886 + result &= fc2580_i2c_write(pTuner, 0x6C, 0x0A); |
|
17887 + result &= fc2580_i2c_write(pTuner, 0x6D, 0x78); |
|
17888 + result &= fc2580_i2c_write(pTuner, 0x6E, 0x32); |
|
17889 + result &= fc2580_i2c_write(pTuner, 0x6F, 0x54); |
|
17890 + result &= fc2580_set_filter(pTuner, 7, freq_xtal); //BW = 6.8MHz |
|
17891 + break; |
|
17892 + case L_BAND: |
|
17893 + data_0x02 = (data_0x02 & 0x3F) | 0x40; |
|
17894 + result &= fc2580_i2c_write(pTuner, 0x2B, 0x70); |
|
17895 + result &= fc2580_i2c_write(pTuner, 0x2C, 0x37); |
|
17896 + result &= fc2580_i2c_write(pTuner, 0x2D, 0xE7); |
|
17897 + result &= fc2580_i2c_write(pTuner, 0x30, 0x09); |
|
17898 + result &= fc2580_i2c_write(pTuner, 0x44, 0x20); |
|
17899 + result &= fc2580_i2c_write(pTuner, 0x50, 0x8C); |
|
17900 + result &= fc2580_i2c_write(pTuner, 0x53, 0x50); |
|
17901 + result &= fc2580_i2c_write(pTuner, 0x5F, 0x0F); |
|
17902 + result &= fc2580_i2c_write(pTuner, 0x61, 0x0F); |
|
17903 + result &= fc2580_i2c_write(pTuner, 0x62, 0x00); |
|
17904 + result &= fc2580_i2c_write(pTuner, 0x63, 0x13); |
|
17905 + result &= fc2580_i2c_write(pTuner, 0x67, 0x00); |
|
17906 + result &= fc2580_i2c_write(pTuner, 0x68, 0x02); |
|
17907 + result &= fc2580_i2c_write(pTuner, 0x69, 0x0C); |
|
17908 + result &= fc2580_i2c_write(pTuner, 0x6A, 0x0E); |
|
17909 + result &= fc2580_i2c_write(pTuner, 0x6B, 0x08); |
|
17910 + result &= fc2580_i2c_write(pTuner, 0x6C, 0x0A); |
|
17911 + result &= fc2580_i2c_write(pTuner, 0x6D, 0xA0); |
|
17912 + result &= fc2580_i2c_write(pTuner, 0x6E, 0x50); |
|
17913 + result &= fc2580_i2c_write(pTuner, 0x6F, 0x14); |
|
17914 + result &= fc2580_set_filter(pTuner, 1, freq_xtal); //BW = 1.53MHz |
|
17915 + break; |
|
17916 + default: |
|
17917 + break; |
|
17918 + } |
|
17919 +// curr_band = band; |
|
17920 +// } |
|
17921 + |
|
17922 + //A command about AGC clock's pre-divide ratio |
|
17923 + if( freq_xtal >= 28000 ) |
|
17924 + result &= fc2580_i2c_write(pTuner, 0x4B, 0x22 ); |
|
17925 + |
|
17926 + //Commands about VCO Band and PLL setting. |
|
17927 + result &= fc2580_i2c_write(pTuner, 0x02, data_0x02); |
|
17928 + data_0x18 = ( ( r_val == 1 )? 0x00 : ( ( r_val == 2 )? 0x10 : 0x20 ) ) + (unsigned char)(k_val >> 16); |
|
17929 + result &= fc2580_i2c_write(pTuner, 0x18, data_0x18); //Load 'R' value and high part of 'K' values |
|
17930 + result &= fc2580_i2c_write(pTuner, 0x1A, (unsigned char)( k_val >> 8 ) ); //Load middle part of 'K' value |
|
17931 + result &= fc2580_i2c_write(pTuner, 0x1B, (unsigned char)( k_val ) ); //Load lower part of 'K' value |
|
17932 + result &= fc2580_i2c_write(pTuner, 0x1C, (unsigned char)( n_val ) ); //Load 'N' value |
|
17933 + |
|
17934 + //A command about UHF LNA Load Cap |
|
17935 + if( band == UHF_BAND ) |
|
17936 + result &= fc2580_i2c_write(pTuner, 0x2D, ( f_lo <= (unsigned int)794000 )? 0x9F : 0x8F ); //LNA_OUT_CAP |
|
17937 + |
|
17938 + |
|
17939 + return result; |
|
17940 +} |
|
17941 + |
|
17942 + |
|
17943 +/*============================================================================== |
|
17944 + fc2580 filter BW setting |
|
17945 + |
|
17946 + This function is a generic function which gets called to change Bandwidth |
|
17947 + |
|
17948 + frequency of fc2580's channel selection filter |
|
17949 + |
|
17950 + <input parameter> |
|
17951 + freq_xtal: kHz |
|
17952 + |
|
17953 + filter_bw |
|
17954 + 1 : 1.53MHz(TDMB) |
|
17955 + 6 : 6MHz (Bandwidth 6MHz) |
|
17956 + 7 : 6.8MHz (Bandwidth 7MHz) |
|
17957 + 8 : 7.8MHz (Bandwidth 8MHz) |
|
17958 + |
|
17959 + |
|
17960 +==============================================================================*/ |
|
17961 +fci_result_type fc2580_set_filter( TUNER_MODULE *pTuner, unsigned char filter_bw, unsigned int freq_xtal ) |
|
17962 +{ |
|
17963 + unsigned char cal_mon, i; |
|
17964 + fci_result_type result = FCI_SUCCESS; |
|
17965 + |
|
17966 + if(filter_bw == 1) |
|
17967 + { |
|
17968 + result &= fc2580_i2c_write(pTuner, 0x36, 0x1C); |
|
17969 + result &= fc2580_i2c_write(pTuner, 0x37, (unsigned char)(4151*freq_xtal/1000000) ); |
|
17970 + result &= fc2580_i2c_write(pTuner, 0x39, 0x00); |
|
17971 + result &= fc2580_i2c_write(pTuner, 0x2E, 0x09); |
|
17972 + } |
|
17973 + if(filter_bw == 6) |
|
17974 + { |
|
17975 + result &= fc2580_i2c_write(pTuner, 0x36, 0x18); |
|
17976 + result &= fc2580_i2c_write(pTuner, 0x37, (unsigned char)(4400*freq_xtal/1000000) ); |
|
17977 + result &= fc2580_i2c_write(pTuner, 0x39, 0x00); |
|
17978 + result &= fc2580_i2c_write(pTuner, 0x2E, 0x09); |
|
17979 + } |
|
17980 + else if(filter_bw == 7) |
|
17981 + { |
|
17982 + result &= fc2580_i2c_write(pTuner, 0x36, 0x18); |
|
17983 + result &= fc2580_i2c_write(pTuner, 0x37, (unsigned char)(3910*freq_xtal/1000000) ); |
|
17984 + result &= fc2580_i2c_write(pTuner, 0x39, 0x80); |
|
17985 + result &= fc2580_i2c_write(pTuner, 0x2E, 0x09); |
|
17986 + } |
|
17987 + else if(filter_bw == 8) |
|
17988 + { |
|
17989 + result &= fc2580_i2c_write(pTuner, 0x36, 0x18); |
|
17990 + result &= fc2580_i2c_write(pTuner, 0x37, (unsigned char)(3300*freq_xtal/1000000) ); |
|
17991 + result &= fc2580_i2c_write(pTuner, 0x39, 0x80); |
|
17992 + result &= fc2580_i2c_write(pTuner, 0x2E, 0x09); |
|
17993 + } |
|
17994 + |
|
17995 + |
|
17996 + for(i=0; i<5; i++) |
|
17997 + { |
|
17998 + wait_msec(pTuner, 5);//wait 5ms |
|
17999 + result &= fc2580_i2c_read(pTuner, 0x2F, &cal_mon); |
|
18000 + if( (cal_mon & 0xC0) != 0xC0) |
|
18001 + { |
|
18002 + result &= fc2580_i2c_write(pTuner, 0x2E, 0x01); |
|
18003 + result &= fc2580_i2c_write(pTuner, 0x2E, 0x09); |
|
18004 + } |
|
18005 + else |
|
18006 + break; |
|
18007 + } |
|
18008 + |
|
18009 + result &= fc2580_i2c_write(pTuner, 0x2E, 0x01); |
|
18010 + |
|
18011 + return result; |
|
18012 +} |
|
18013 + |
|
18014 +/*============================================================================== |
|
18015 + fc2580 RSSI function |
|
18016 + |
|
18017 + This function is a generic function which returns fc2580's |
|
18018 + |
|
18019 + current RSSI value. |
|
18020 + |
|
18021 + <input parameter> |
|
18022 + none |
|
18023 + |
|
18024 + <return value> |
|
18025 + int |
|
18026 + rssi : estimated input power. |
|
18027 + |
|
18028 +==============================================================================*/ |
|
18029 +//int fc2580_get_rssi(void) { |
|
18030 +// |
|
18031 +// unsigned char s_lna, s_rfvga, s_cfs, s_ifvga; |
|
18032 +// int ofs_lna, ofs_rfvga, ofs_csf, ofs_ifvga, rssi; |
|
18033 +// |
|
18034 +// fc2580_i2c_read(0x71, &s_lna ); |
|
18035 +// fc2580_i2c_read(0x72, &s_rfvga ); |
|
18036 +// fc2580_i2c_read(0x73, &s_cfs ); |
|
18037 +// fc2580_i2c_read(0x74, &s_ifvga ); |
|
18038 +// |
|
18039 +// |
|
18040 +// ofs_lna = |
|
18041 +// (curr_band==UHF_BAND)? |
|
18042 +// (s_lna==0)? 0 : |
|
18043 +// (s_lna==1)? -6 : |
|
18044 +// (s_lna==2)? -17 : |
|
18045 +// (s_lna==3)? -22 : -30 : |
|
18046 +// (curr_band==VHF_BAND)? |
|
18047 +// (s_lna==0)? 0 : |
|
18048 +// (s_lna==1)? -6 : |
|
18049 +// (s_lna==2)? -19 : |
|
18050 +// (s_lna==3)? -24 : -32 : |
|
18051 +// (curr_band==L_BAND)? |
|
18052 +// (s_lna==0)? 0 : |
|
18053 +// (s_lna==1)? -6 : |
|
18054 +// (s_lna==2)? -11 : |
|
18055 +// (s_lna==3)? -16 : -34 : |
|
18056 +// 0;//NO_BAND |
|
18057 +// ofs_rfvga = -s_rfvga+((s_rfvga>=11)? 1 : 0) + ((s_rfvga>=18)? 1 : 0); |
|
18058 +// ofs_csf = -6*s_cfs; |
|
18059 +// ofs_ifvga = s_ifvga/4; |
|
18060 +// |
|
18061 +// return rssi = ofs_lna+ofs_rfvga+ofs_csf+ofs_ifvga+OFS_RSSI; |
|
18062 +// |
|
18063 +//} |
|
18064 + |
|
18065 +/*============================================================================== |
|
18066 + fc2580 Xtal frequency Setting |
|
18067 + |
|
18068 + This function is a generic function which sets |
|
18069 + |
|
18070 + the frequency of xtal. |
|
18071 + |
|
18072 + <input parameter> |
|
18073 + |
|
18074 + frequency |
|
18075 + frequency value of internal(external) Xtal(clock) in kHz unit. |
|
18076 + |
|
18077 +==============================================================================*/ |
|
18078 +//void fc2580_set_freq_xtal(unsigned int frequency) { |
|
18079 +// |
|
18080 +// freq_xtal = frequency; |
|
18081 +// |
|
18082 +//} |
|
18083 + |
|
18084 + |
|
18085 + |
|
18086 + |
|
18087 + |
|
18088 + |
|
18089 + |
|
18090 + |
|
18091 + |
|
18092 + |
|
18093 + |
|
18094 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/tuner_fc2580.h |
|
18095 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
18096 +++ b/linux/drivers/media/dvb/dvb-usb/tuner_fc2580.h Wed Oct 27 09:16:44 2010 +0200 |
|
18097 @@ -0,0 +1,519 @@ |
|
18098 +#ifndef __TUNER_FC2580_H |
|
18099 +#define __TUNER_FC2580_H |
|
18100 + |
|
18101 +/** |
|
18102 + |
|
18103 +@file |
|
18104 + |
|
18105 +@brief FC2580 tuner module declaration |
|
18106 + |
|
18107 +One can manipulate FC2580 tuner through FC2580 module. |
|
18108 +FC2580 module is derived from tuner module. |
|
18109 + |
|
18110 + |
|
18111 + |
|
18112 +@par Example: |
|
18113 +@code |
|
18114 + |
|
18115 +// The example is the same as the tuner example in tuner_base.h except the listed lines. |
|
18116 + |
|
18117 + |
|
18118 + |
|
18119 +#include "tuner_fc2580.h" |
|
18120 + |
|
18121 + |
|
18122 +... |
|
18123 + |
|
18124 + |
|
18125 + |
|
18126 +int main(void) |
|
18127 +{ |
|
18128 + TUNER_MODULE *pTuner; |
|
18129 + FC2580_EXTRA_MODULE *pTunerExtra; |
|
18130 + |
|
18131 + TUNER_MODULE TunerModuleMemory; |
|
18132 + FC2580_EXTRA_MODULE Fc2580ExtraModuleMemory; |
|
18133 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
18134 + I2C_BRIDGE_MODULE I2cBridgeModuleMemory; |
|
18135 + |
|
18136 + unsigned long BandwidthMode; |
|
18137 + |
|
18138 + |
|
18139 + ... |
|
18140 + |
|
18141 + |
|
18142 + |
|
18143 + // Build FC2580 tuner module. |
|
18144 + BuildFc2580Module( |
|
18145 + &pTuner, |
|
18146 + &TunerModuleMemory, |
|
18147 + &Fc2580ExtraModuleMemory, |
|
18148 + &BaseInterfaceModuleMemory, |
|
18149 + &I2cBridgeModuleMemory, |
|
18150 + 0xac, // I2C device address is 0xac in 8-bit format. |
|
18151 + CRYSTAL_FREQ_16384000HZ, // Crystal frequency is 16.384 MHz. |
|
18152 + FC2580_AGC_EXTERNAL // The FC2580 AGC mode is external AGC mode. |
|
18153 + ); |
|
18154 + |
|
18155 + |
|
18156 + |
|
18157 + |
|
18158 + |
|
18159 + // Get FC2580 tuner extra module. |
|
18160 + pTunerExtra = (T2266_EXTRA_MODULE *)(pTuner->pExtra); |
|
18161 + |
|
18162 + |
|
18163 + |
|
18164 + |
|
18165 + |
|
18166 + // ==== Initialize tuner and set its parameters ===== |
|
18167 + |
|
18168 + ... |
|
18169 + |
|
18170 + // Set FC2580 bandwidth. |
|
18171 + pTunerExtra->SetBandwidthMode(pTuner, FC2580_BANDWIDTH_6MHZ); |
|
18172 + |
|
18173 + |
|
18174 + |
|
18175 + |
|
18176 + |
|
18177 + // ==== Get tuner information ===== |
|
18178 + |
|
18179 + ... |
|
18180 + |
|
18181 + // Get FC2580 bandwidth. |
|
18182 + pTunerExtra->GetBandwidthMode(pTuner, &BandwidthMode); |
|
18183 + |
|
18184 + |
|
18185 + |
|
18186 + // See the example for other tuner functions in tuner_base.h |
|
18187 + |
|
18188 + |
|
18189 + return 0; |
|
18190 +} |
|
18191 + |
|
18192 + |
|
18193 +@endcode |
|
18194 + |
|
18195 +*/ |
|
18196 + |
|
18197 + |
|
18198 + |
|
18199 + |
|
18200 + |
|
18201 +#include "tuner_base.h" |
|
18202 + |
|
18203 + |
|
18204 + |
|
18205 + |
|
18206 + |
|
18207 +// The following context is source code provided by FCI. |
|
18208 + |
|
18209 + |
|
18210 + |
|
18211 + |
|
18212 + |
|
18213 +// FCI source code - fc2580_driver_v1400_r.h |
|
18214 + |
|
18215 + |
|
18216 +/*============================================================================== |
|
18217 + FILE NAME : FC2580_driver_v1400_r.h |
|
18218 + |
|
18219 + VERSION : 1.400_r |
|
18220 + |
|
18221 + UPDATE : September 22. 2008 |
|
18222 + |
|
18223 +==============================================================================*/ |
|
18224 + |
|
18225 +/*============================================================================== |
|
18226 + |
|
18227 + Chip ID of FC2580 is 0x56 or 0xAC(including I2C write bit) |
|
18228 + |
|
18229 +==============================================================================*/ |
|
18230 + |
|
18231 + |
|
18232 +#define BORDER_FREQ 2600000 //2.6GHz : The border frequency which determines whether Low VCO or High VCO is used |
|
18233 +#define USE_EXT_CLK 0 //0 : Use internal XTAL Oscillator / 1 : Use External Clock input |
|
18234 +#define OFS_RSSI 57 |
|
18235 + |
|
18236 +typedef enum { |
|
18237 + UHF_BAND, |
|
18238 + L_BAND, |
|
18239 + VHF_BAND, |
|
18240 + NO_BAND |
|
18241 +} fc2580_band_type; |
|
18242 + |
|
18243 +typedef enum { |
|
18244 + FCI_FAIL, |
|
18245 + FCI_SUCCESS |
|
18246 +} fci_result_type; |
|
18247 + |
|
18248 +/*============================================================================== |
|
18249 + i2c command write EXTERNAL FUNCTION |
|
18250 + |
|
18251 + This function is a generic function which write a byte into fc2580's |
|
18252 + specific address. |
|
18253 + |
|
18254 + <input parameter> |
|
18255 + |
|
18256 + slave_id |
|
18257 + i2c id of slave chip |
|
18258 + type : byte |
|
18259 + |
|
18260 + addr |
|
18261 + memory address of slave chip |
|
18262 + type : byte |
|
18263 + |
|
18264 + data |
|
18265 + target data |
|
18266 + type : byte |
|
18267 + |
|
18268 +==============================================================================*/ |
|
18269 +//extern fci_result_type i2c_write( unsigned char slave_id, unsigned char addr, unsigned char *data, unsigned char n ); |
|
18270 + |
|
18271 +/*============================================================================== |
|
18272 + i2c command write EXTERNAL FUNCTION |
|
18273 + |
|
18274 + This function is a generic function which gets called to read data from |
|
18275 + slave chip's target memory address. |
|
18276 + |
|
18277 + <input parameter> |
|
18278 + |
|
18279 + slave_id |
|
18280 + i2c id of slave chip |
|
18281 + type : byte |
|
18282 + |
|
18283 + addr |
|
18284 + memory address of slave chip |
|
18285 + type : byte |
|
18286 + |
|
18287 + <return value> |
|
18288 + data |
|
18289 + a byte of data read out of target address 'addr' of slave chip |
|
18290 + type : byte |
|
18291 + |
|
18292 +==============================================================================*/ |
|
18293 +//extern fci_result_type i2c_read( unsigned char slave_id, unsigned char addr, unsigned char *read_data, unsigned char n ); |
|
18294 + |
|
18295 +/*============================================================================== |
|
18296 + milisecond delay function EXTERNAL FUNCTION |
|
18297 + |
|
18298 + This function is a generic function which write a byte into fc2580's |
|
18299 + specific address. |
|
18300 + |
|
18301 + <input parameter> |
|
18302 + |
|
18303 + a |
|
18304 + length of wanted delay in milisecond unit |
|
18305 + |
|
18306 +==============================================================================*/ |
|
18307 +extern void wait_msec(TUNER_MODULE *pTuner, int a); |
|
18308 + |
|
18309 + |
|
18310 + |
|
18311 +/*============================================================================== |
|
18312 + fc2580 i2c command write |
|
18313 + |
|
18314 + This function is a generic function which write a byte into fc2580's |
|
18315 + specific address. |
|
18316 + |
|
18317 + <input parameter> |
|
18318 + |
|
18319 + addr |
|
18320 + fc2580's memory address |
|
18321 + type : byte |
|
18322 + |
|
18323 + data |
|
18324 + target data |
|
18325 + type : byte |
|
18326 + |
|
18327 +==============================================================================*/ |
|
18328 +fci_result_type fc2580_i2c_write( TUNER_MODULE *pTuner, unsigned char addr, unsigned char data ); |
|
18329 + |
|
18330 +/*============================================================================== |
|
18331 + fc2580 i2c data read |
|
18332 + |
|
18333 + This function is a generic function which gets called to read data from |
|
18334 + fc2580's target memory address. |
|
18335 + |
|
18336 + <input parameter> |
|
18337 + |
|
18338 + addr |
|
18339 + fc2580's memory address |
|
18340 + type : byte |
|
18341 + |
|
18342 + |
|
18343 + <return value> |
|
18344 + data |
|
18345 + a byte of data read out of target address 'addr' |
|
18346 + type : byte |
|
18347 + |
|
18348 +==============================================================================*/ |
|
18349 +fci_result_type fc2580_i2c_read( TUNER_MODULE *pTuner, unsigned char addr, unsigned char *read_data ); |
|
18350 + |
|
18351 +/*============================================================================== |
|
18352 + fc2580 initial setting |
|
18353 + |
|
18354 + This function is a generic function which gets called to initialize |
|
18355 + |
|
18356 + fc2580 in DVB-H mode or L-Band TDMB mode |
|
18357 + |
|
18358 + <input parameter> |
|
18359 + |
|
18360 + ifagc_mode |
|
18361 + type : integer |
|
18362 + 1 : Internal AGC |
|
18363 + 2 : Voltage Control Mode |
|
18364 + |
|
18365 +==============================================================================*/ |
|
18366 +fci_result_type fc2580_set_init( TUNER_MODULE *pTuner, int ifagc_mode, unsigned int freq_xtal ); |
|
18367 + |
|
18368 +/*============================================================================== |
|
18369 + fc2580 frequency setting |
|
18370 + |
|
18371 + This function is a generic function which gets called to change LO Frequency |
|
18372 + |
|
18373 + of fc2580 in DVB-H mode or L-Band TDMB mode |
|
18374 + |
|
18375 + <input parameter> |
|
18376 + |
|
18377 + f_lo |
|
18378 + Value of target LO Frequency in 'kHz' unit |
|
18379 + ex) 2.6GHz = 2600000 |
|
18380 + |
|
18381 +==============================================================================*/ |
|
18382 +fci_result_type fc2580_set_freq( TUNER_MODULE *pTuner, unsigned int f_lo, unsigned int freq_xtal ); |
|
18383 + |
|
18384 + |
|
18385 +/*============================================================================== |
|
18386 + fc2580 filter BW setting |
|
18387 + |
|
18388 + This function is a generic function which gets called to change Bandwidth |
|
18389 + |
|
18390 + frequency of fc2580's channel selection filter |
|
18391 + |
|
18392 + <input parameter> |
|
18393 + |
|
18394 + filter_bw |
|
18395 + 1 : 1.53MHz(TDMB) |
|
18396 + 6 : 6MHz |
|
18397 + 7 : 7MHz |
|
18398 + 8 : 7.8MHz |
|
18399 + |
|
18400 + |
|
18401 +==============================================================================*/ |
|
18402 +fci_result_type fc2580_set_filter( TUNER_MODULE *pTuner, unsigned char filter_bw, unsigned int freq_xtal ); |
|
18403 + |
|
18404 +/*============================================================================== |
|
18405 + fc2580 RSSI function |
|
18406 + |
|
18407 + This function is a generic function which returns fc2580's |
|
18408 + |
|
18409 + current RSSI value. |
|
18410 + |
|
18411 + |
|
18412 + |
|
18413 + |
|
18414 +==============================================================================*/ |
|
18415 +//int fc2580_get_rssi(void); |
|
18416 + |
|
18417 +/*============================================================================== |
|
18418 + fc2580 Xtal frequency Setting |
|
18419 + |
|
18420 + This function is a generic function which sets |
|
18421 + |
|
18422 + the frequency of xtal. |
|
18423 + |
|
18424 + <input parameter> |
|
18425 + |
|
18426 + frequency |
|
18427 + frequency value of internal(external) Xtal(clock) in kHz unit. |
|
18428 + |
|
18429 +==============================================================================*/ |
|
18430 +//void fc2580_set_freq_xtal(unsigned int frequency); |
|
18431 + |
|
18432 + |
|
18433 + |
|
18434 + |
|
18435 + |
|
18436 + |
|
18437 + |
|
18438 + |
|
18439 + |
|
18440 + |
|
18441 + |
|
18442 + |
|
18443 + |
|
18444 + |
|
18445 + |
|
18446 + |
|
18447 + |
|
18448 + |
|
18449 + |
|
18450 + |
|
18451 + |
|
18452 + |
|
18453 + |
|
18454 + |
|
18455 + |
|
18456 +// The following context is FC2580 tuner API source code |
|
18457 + |
|
18458 + |
|
18459 + |
|
18460 + |
|
18461 + |
|
18462 +// Definitions |
|
18463 + |
|
18464 +// AGC mode |
|
18465 +enum FC2580_AGC_MODE |
|
18466 +{ |
|
18467 + FC2580_AGC_INTERNAL = 1, |
|
18468 + FC2580_AGC_EXTERNAL = 2, |
|
18469 +}; |
|
18470 + |
|
18471 + |
|
18472 +// Bandwidth mode |
|
18473 +enum FC2580_BANDWIDTH_MODE |
|
18474 +{ |
|
18475 + FC2580_BANDWIDTH_1530000HZ = 1, |
|
18476 + FC2580_BANDWIDTH_6000000HZ = 6, |
|
18477 + FC2580_BANDWIDTH_7000000HZ = 7, |
|
18478 + FC2580_BANDWIDTH_8000000HZ = 8, |
|
18479 +}; |
|
18480 + |
|
18481 + |
|
18482 + |
|
18483 + |
|
18484 + |
|
18485 +// FC2580 extra module |
|
18486 +typedef struct FC2580_EXTRA_MODULE_TAG FC2580_EXTRA_MODULE; |
|
18487 + |
|
18488 + |
|
18489 + |
|
18490 + |
|
18491 + |
|
18492 +// FC2580 bandwidth mode setting function pointer |
|
18493 +typedef int |
|
18494 +(*FC2580_FP_SET_BANDWIDTH_MODE)( |
|
18495 + TUNER_MODULE *pTuner, |
|
18496 + int BandwidthMode |
|
18497 + ); |
|
18498 + |
|
18499 + |
|
18500 + |
|
18501 +// FC2580 bandwidth mode getting function pointer |
|
18502 +typedef int |
|
18503 +(*FC2580_FP_GET_BANDWIDTH_MODE)( |
|
18504 + TUNER_MODULE *pTuner, |
|
18505 + int *pBandwidthMode |
|
18506 + ); |
|
18507 + |
|
18508 + |
|
18509 + |
|
18510 + |
|
18511 + |
|
18512 +// FC2580 extra module |
|
18513 +struct FC2580_EXTRA_MODULE_TAG |
|
18514 +{ |
|
18515 + // FC2580 extra variables |
|
18516 + unsigned long CrystalFreqHz; |
|
18517 + int AgcMode; |
|
18518 + int BandwidthMode; |
|
18519 + int IsBandwidthModeSet; |
|
18520 + |
|
18521 + // FC2580 extra function pointers |
|
18522 + FC2580_FP_SET_BANDWIDTH_MODE SetBandwidthMode; |
|
18523 + FC2580_FP_GET_BANDWIDTH_MODE GetBandwidthMode; |
|
18524 +}; |
|
18525 + |
|
18526 + |
|
18527 + |
|
18528 + |
|
18529 + |
|
18530 +// Builder |
|
18531 +void |
|
18532 +BuildFc2580Module( |
|
18533 + TUNER_MODULE **ppTuner, |
|
18534 + TUNER_MODULE *pTunerModuleMemory, |
|
18535 + FC2580_EXTRA_MODULE *pFc2580ExtraModuleMemory, |
|
18536 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
18537 + I2C_BRIDGE_MODULE *pI2cBridgeModuleMemory, |
|
18538 + unsigned char DeviceAddr, |
|
18539 + unsigned long CrystalFreqHz, |
|
18540 + int AgcMode |
|
18541 + ); |
|
18542 + |
|
18543 + |
|
18544 + |
|
18545 + |
|
18546 + |
|
18547 +// Manipulaing functions |
|
18548 +void |
|
18549 +fc2580_GetTunerType( |
|
18550 + TUNER_MODULE *pTuner, |
|
18551 + int *pTunerType |
|
18552 + ); |
|
18553 + |
|
18554 +void |
|
18555 +fc2580_GetDeviceAddr( |
|
18556 + TUNER_MODULE *pTuner, |
|
18557 + unsigned char *pDeviceAddr |
|
18558 + ); |
|
18559 + |
|
18560 +int |
|
18561 +fc2580_Initialize( |
|
18562 + TUNER_MODULE *pTuner |
|
18563 + ); |
|
18564 + |
|
18565 +int |
|
18566 +fc2580_SetRfFreqHz( |
|
18567 + TUNER_MODULE *pTuner, |
|
18568 + unsigned long RfFreqHz |
|
18569 + ); |
|
18570 + |
|
18571 +int |
|
18572 +fc2580_GetRfFreqHz( |
|
18573 + TUNER_MODULE *pTuner, |
|
18574 + unsigned long *pRfFreqHz |
|
18575 + ); |
|
18576 + |
|
18577 + |
|
18578 + |
|
18579 + |
|
18580 + |
|
18581 +// Extra manipulaing functions |
|
18582 +int |
|
18583 +fc2580_SetBandwidthMode( |
|
18584 + TUNER_MODULE *pTuner, |
|
18585 + int BandwidthMode |
|
18586 + ); |
|
18587 + |
|
18588 +int |
|
18589 +fc2580_GetBandwidthMode( |
|
18590 + TUNER_MODULE *pTuner, |
|
18591 + int *pBandwidthMode |
|
18592 + ); |
|
18593 + |
|
18594 + |
|
18595 + |
|
18596 + |
|
18597 + |
|
18598 +// I2C birdge module demod argument setting |
|
18599 +void |
|
18600 +fc2580_SetI2cBridgeModuleTunerArg( |
|
18601 + TUNER_MODULE *pTuner |
|
18602 + ); |
|
18603 + |
|
18604 + |
|
18605 + |
|
18606 + |
|
18607 + |
|
18608 + |
|
18609 + |
|
18610 + |
|
18611 + |
|
18612 + |
|
18613 + |
|
18614 + |
|
18615 + |
|
18616 +#endif |
|
18617 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/tuner_mt2266.c |
|
18618 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
18619 +++ b/linux/drivers/media/dvb/dvb-usb/tuner_mt2266.c Wed Oct 27 09:16:44 2010 +0200 |
|
18620 @@ -0,0 +1,3331 @@ |
|
18621 +/** |
|
18622 + |
|
18623 +@file |
|
18624 + |
|
18625 +@brief MT2266 tuner module definition |
|
18626 + |
|
18627 +One can manipulate MT2266 tuner through MT2266 module. |
|
18628 +MT2266 module is derived from tuner module. |
|
18629 + |
|
18630 +*/ |
|
18631 + |
|
18632 + |
|
18633 +#include "tuner_mt2266.h" |
|
18634 + |
|
18635 + |
|
18636 + |
|
18637 + |
|
18638 + |
|
18639 +/** |
|
18640 + |
|
18641 +@brief MT2266 tuner module builder |
|
18642 + |
|
18643 +Use BuildMt2266Module() to build MT2266 module, set all module function pointers with the corresponding functions, |
|
18644 +and initialize module private variables. |
|
18645 + |
|
18646 + |
|
18647 +@param [in] ppTuner Pointer to MT2266 tuner module pointer |
|
18648 +@param [in] pTunerModuleMemory Pointer to an allocated tuner module memory |
|
18649 +@param [in] pMt2266ExtraModuleMemory Pointer to an allocated MT2266 extra module memory |
|
18650 +@param [in] pBaseInterfaceModuleMemory Pointer to an allocated base interface module memory |
|
18651 +@param [in] pI2cBridgeModuleMemory Pointer to an allocated I2C bridge module memory |
|
18652 +@param [in] DeviceAddr MT2266 I2C device address |
|
18653 + |
|
18654 + |
|
18655 +@note |
|
18656 + -# One should call BuildMt2266Module() to build MT2266 module before using it. |
|
18657 + |
|
18658 +*/ |
|
18659 +void |
|
18660 +BuildMt2266Module( |
|
18661 + TUNER_MODULE **ppTuner, |
|
18662 + TUNER_MODULE *pTunerModuleMemory, |
|
18663 + MT2266_EXTRA_MODULE *pMt2266ExtraModuleMemory, |
|
18664 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
18665 + I2C_BRIDGE_MODULE *pI2cBridgeModuleMemory, |
|
18666 + unsigned char DeviceAddr |
|
18667 + ) |
|
18668 +{ |
|
18669 + TUNER_MODULE *pTuner; |
|
18670 + MT2266_EXTRA_MODULE *pExtra; |
|
18671 + |
|
18672 + |
|
18673 + |
|
18674 + // Set tuner module pointer. |
|
18675 + *ppTuner = pTunerModuleMemory; |
|
18676 + |
|
18677 + // Get tuner module. |
|
18678 + pTuner = *ppTuner; |
|
18679 + |
|
18680 + // Set tuner extra module pointer, base interface module pointer, and I2C bridge module pointer. |
|
18681 + pTuner->pExtra = pMt2266ExtraModuleMemory; |
|
18682 + pTuner->pBaseInterface = pBaseInterfaceModuleMemory; |
|
18683 + pTuner->pI2cBridge = pI2cBridgeModuleMemory; |
|
18684 + |
|
18685 + // Get tuner extra module. |
|
18686 + pExtra = (MT2266_EXTRA_MODULE *)pTuner->pExtra; |
|
18687 + |
|
18688 + |
|
18689 + |
|
18690 + // Set tuner type. |
|
18691 + pTuner->TunerType = TUNER_TYPE_MT2266; |
|
18692 + |
|
18693 + // Set tuner I2C device address. |
|
18694 + pTuner->DeviceAddr = DeviceAddr; |
|
18695 + |
|
18696 + |
|
18697 + // Initialize tuner parameter setting status. |
|
18698 + pTuner->IsRfFreqHzSet = NO; |
|
18699 + |
|
18700 + |
|
18701 + // Set I2C bridge tuner arguments. |
|
18702 + mt2266_SetI2cBridgeModuleTunerArg(pTuner); |
|
18703 + |
|
18704 + |
|
18705 + // Set tuner module manipulating function pointers. |
|
18706 + pTuner->GetTunerType = mt2266_GetTunerType; |
|
18707 + pTuner->GetDeviceAddr = mt2266_GetDeviceAddr; |
|
18708 + |
|
18709 + pTuner->Initialize = mt2266_Initialize; |
|
18710 + pTuner->SetRfFreqHz = mt2266_SetRfFreqHz; |
|
18711 + pTuner->GetRfFreqHz = mt2266_GetRfFreqHz; |
|
18712 + |
|
18713 + |
|
18714 + // Initialize tuner extra module variables. |
|
18715 + pExtra->IsBandwidthHzSet = NO; |
|
18716 + |
|
18717 + // Set tuner extra module function pointers. |
|
18718 + pExtra->OpenHandle = mt2266_OpenHandle; |
|
18719 + pExtra->CloseHandle = mt2266_CloseHandle; |
|
18720 + pExtra->GetHandle = mt2266_GetHandle; |
|
18721 + pExtra->SetBandwidthHz = mt2266_SetBandwidthHz; |
|
18722 + pExtra->GetBandwidthHz = mt2266_GetBandwidthHz; |
|
18723 + |
|
18724 + |
|
18725 + return; |
|
18726 +} |
|
18727 + |
|
18728 + |
|
18729 + |
|
18730 + |
|
18731 + |
|
18732 +/** |
|
18733 + |
|
18734 +@see TUNER_FP_GET_TUNER_TYPE |
|
18735 + |
|
18736 +*/ |
|
18737 +void |
|
18738 +mt2266_GetTunerType( |
|
18739 + TUNER_MODULE *pTuner, |
|
18740 + int *pTunerType |
|
18741 + ) |
|
18742 +{ |
|
18743 + // Get tuner type from tuner module. |
|
18744 + *pTunerType = pTuner->TunerType; |
|
18745 + |
|
18746 + |
|
18747 + return; |
|
18748 +} |
|
18749 + |
|
18750 + |
|
18751 + |
|
18752 + |
|
18753 + |
|
18754 +/** |
|
18755 + |
|
18756 +@see TUNER_FP_GET_DEVICE_ADDR |
|
18757 + |
|
18758 +*/ |
|
18759 +void |
|
18760 +mt2266_GetDeviceAddr( |
|
18761 + TUNER_MODULE *pTuner, |
|
18762 + unsigned char *pDeviceAddr |
|
18763 + ) |
|
18764 +{ |
|
18765 + // Get tuner I2C device address from tuner module. |
|
18766 + *pDeviceAddr = pTuner->DeviceAddr; |
|
18767 + |
|
18768 + |
|
18769 + return; |
|
18770 +} |
|
18771 + |
|
18772 + |
|
18773 + |
|
18774 + |
|
18775 + |
|
18776 +/** |
|
18777 + |
|
18778 +@see TUNER_FP_INITIALIZE |
|
18779 + |
|
18780 +*/ |
|
18781 +int |
|
18782 +mt2266_Initialize( |
|
18783 + TUNER_MODULE *pTuner |
|
18784 + ) |
|
18785 +{ |
|
18786 + MT2266_EXTRA_MODULE *pExtra; |
|
18787 + |
|
18788 + Handle_t DeviceHandle; |
|
18789 + UData_t Status; |
|
18790 + |
|
18791 + |
|
18792 + |
|
18793 + // Get tuner extra module. |
|
18794 + pExtra = (MT2266_EXTRA_MODULE *)pTuner->pExtra; |
|
18795 + |
|
18796 + // Get tuner handle. |
|
18797 + DeviceHandle = pExtra->DeviceHandle; |
|
18798 + |
|
18799 + |
|
18800 + // Re-initialize tuner. |
|
18801 + Status = MT2266_ReInit(DeviceHandle); |
|
18802 + |
|
18803 + if(MT_IS_ERROR(Status)) |
|
18804 + goto error_status_initialize_tuner; |
|
18805 + |
|
18806 + |
|
18807 + return FUNCTION_SUCCESS; |
|
18808 + |
|
18809 + |
|
18810 +error_status_initialize_tuner: |
|
18811 + return FUNCTION_ERROR; |
|
18812 +} |
|
18813 + |
|
18814 + |
|
18815 + |
|
18816 + |
|
18817 + |
|
18818 +/** |
|
18819 + |
|
18820 +@see TUNER_FP_SET_RF_FREQ_HZ |
|
18821 + |
|
18822 +*/ |
|
18823 +int |
|
18824 +mt2266_SetRfFreqHz( |
|
18825 + TUNER_MODULE *pTuner, |
|
18826 + unsigned long RfFreqHz |
|
18827 + ) |
|
18828 +{ |
|
18829 + MT2266_EXTRA_MODULE *pExtra; |
|
18830 + |
|
18831 + Handle_t DeviceHandle; |
|
18832 + UData_t Status; |
|
18833 + |
|
18834 + |
|
18835 + |
|
18836 + // Get tuner extra module. |
|
18837 + pExtra = (MT2266_EXTRA_MODULE *)pTuner->pExtra; |
|
18838 + |
|
18839 + // Get tuner handle. |
|
18840 + DeviceHandle = pExtra->DeviceHandle; |
|
18841 + |
|
18842 + |
|
18843 + // Set tuner RF frequency in Hz. |
|
18844 + Status = MT2266_ChangeFreq(DeviceHandle, RfFreqHz); |
|
18845 + |
|
18846 + if(MT_IS_ERROR(Status)) |
|
18847 + goto error_status_set_tuner_rf_frequency; |
|
18848 + |
|
18849 + |
|
18850 + // Set tuner RF frequency parameter. |
|
18851 + pTuner->RfFreqHz = RfFreqHz; |
|
18852 + pTuner->IsRfFreqHzSet = YES; |
|
18853 + |
|
18854 + |
|
18855 + return FUNCTION_SUCCESS; |
|
18856 + |
|
18857 + |
|
18858 +error_status_set_tuner_rf_frequency: |
|
18859 + return FUNCTION_ERROR; |
|
18860 +} |
|
18861 + |
|
18862 + |
|
18863 + |
|
18864 + |
|
18865 + |
|
18866 +/** |
|
18867 + |
|
18868 +@see TUNER_FP_GET_RF_FREQ_HZ |
|
18869 + |
|
18870 +*/ |
|
18871 +int |
|
18872 +mt2266_GetRfFreqHz( |
|
18873 + TUNER_MODULE *pTuner, |
|
18874 + unsigned long *pRfFreqHz |
|
18875 + ) |
|
18876 +{ |
|
18877 + // Get tuner RF frequency in Hz from tuner module. |
|
18878 + if(pTuner->IsRfFreqHzSet != YES) |
|
18879 + goto error_status_get_tuner_rf_frequency; |
|
18880 + |
|
18881 + *pRfFreqHz = pTuner->RfFreqHz; |
|
18882 + |
|
18883 + |
|
18884 + return FUNCTION_SUCCESS; |
|
18885 + |
|
18886 + |
|
18887 +error_status_get_tuner_rf_frequency: |
|
18888 + return FUNCTION_ERROR; |
|
18889 +} |
|
18890 + |
|
18891 + |
|
18892 + |
|
18893 + |
|
18894 + |
|
18895 +/** |
|
18896 + |
|
18897 +@brief Open MT2266 tuner handle. |
|
18898 + |
|
18899 +*/ |
|
18900 +int |
|
18901 +mt2266_OpenHandle( |
|
18902 + TUNER_MODULE *pTuner |
|
18903 + ) |
|
18904 +{ |
|
18905 + MT2266_EXTRA_MODULE *pExtra; |
|
18906 + |
|
18907 + unsigned char DeviceAddr; |
|
18908 + UData_t Status; |
|
18909 + |
|
18910 + |
|
18911 + |
|
18912 + // Get tuner extra module. |
|
18913 + pExtra = (MT2266_EXTRA_MODULE *)pTuner->pExtra; |
|
18914 + |
|
18915 + // Get tuner I2C device address. |
|
18916 + pTuner->GetDeviceAddr(pTuner, &DeviceAddr); |
|
18917 + |
|
18918 + |
|
18919 + // Open MT2266 handle. |
|
18920 + // Note: 1. Must take tuner extra module DeviceHandle as handle input argument. |
|
18921 + // 2. Take pTuner as user-defined data input argument. |
|
18922 + Status = MT2266_Open(DeviceAddr, &pExtra->DeviceHandle, pTuner); |
|
18923 + |
|
18924 + if(MT_IS_ERROR(Status)) |
|
18925 + goto error_status_open_mt2266_handle; |
|
18926 + |
|
18927 + |
|
18928 + return FUNCTION_SUCCESS; |
|
18929 + |
|
18930 + |
|
18931 +error_status_open_mt2266_handle: |
|
18932 + return FUNCTION_ERROR; |
|
18933 +} |
|
18934 + |
|
18935 + |
|
18936 + |
|
18937 + |
|
18938 + |
|
18939 +/** |
|
18940 + |
|
18941 +@brief Close MT2266 tuner handle. |
|
18942 + |
|
18943 +*/ |
|
18944 +int |
|
18945 +mt2266_CloseHandle( |
|
18946 + TUNER_MODULE *pTuner |
|
18947 + ) |
|
18948 +{ |
|
18949 + MT2266_EXTRA_MODULE *pExtra; |
|
18950 + |
|
18951 + Handle_t DeviceHandle; |
|
18952 + UData_t Status; |
|
18953 + |
|
18954 + |
|
18955 + |
|
18956 + // Get tuner extra module. |
|
18957 + pExtra = (MT2266_EXTRA_MODULE *)pTuner->pExtra; |
|
18958 + |
|
18959 + // Get tuner handle. |
|
18960 + DeviceHandle = pExtra->DeviceHandle; |
|
18961 + |
|
18962 + |
|
18963 + // Close MT2266 handle. |
|
18964 + Status = MT2266_Close(DeviceHandle); |
|
18965 + |
|
18966 + if(MT_IS_ERROR(Status)) |
|
18967 + goto error_status_open_mt2266_handle; |
|
18968 + |
|
18969 + |
|
18970 + return FUNCTION_SUCCESS; |
|
18971 + |
|
18972 + |
|
18973 +error_status_open_mt2266_handle: |
|
18974 + return FUNCTION_ERROR; |
|
18975 +} |
|
18976 + |
|
18977 + |
|
18978 + |
|
18979 + |
|
18980 + |
|
18981 +/** |
|
18982 + |
|
18983 +@brief Get MT2266 tuner handle. |
|
18984 + |
|
18985 +*/ |
|
18986 +void |
|
18987 +mt2266_GetHandle( |
|
18988 + TUNER_MODULE *pTuner, |
|
18989 + void **pDeviceHandle |
|
18990 + ) |
|
18991 +{ |
|
18992 + MT2266_EXTRA_MODULE *pExtra; |
|
18993 + |
|
18994 + |
|
18995 + |
|
18996 + // Get tuner extra module. |
|
18997 + pExtra = (MT2266_EXTRA_MODULE *)pTuner->pExtra; |
|
18998 + |
|
18999 + // Get tuner handle. |
|
19000 + *pDeviceHandle = pExtra->DeviceHandle; |
|
19001 + |
|
19002 + |
|
19003 + return; |
|
19004 +} |
|
19005 + |
|
19006 + |
|
19007 + |
|
19008 + |
|
19009 + |
|
19010 +/** |
|
19011 + |
|
19012 +@brief Set MT2266 tuner bandwidth in Hz. |
|
19013 + |
|
19014 +*/ |
|
19015 +int |
|
19016 +mt2266_SetBandwidthHz( |
|
19017 + TUNER_MODULE *pTuner, |
|
19018 + unsigned long BandwidthHz |
|
19019 + ) |
|
19020 +{ |
|
19021 + MT2266_EXTRA_MODULE *pExtra; |
|
19022 + |
|
19023 + Handle_t DeviceHandle; |
|
19024 + UData_t Status; |
|
19025 + |
|
19026 + |
|
19027 + |
|
19028 + // Get tuner extra module. |
|
19029 + pExtra = (MT2266_EXTRA_MODULE *)pTuner->pExtra; |
|
19030 + |
|
19031 + // Get tuner handle. |
|
19032 + DeviceHandle = pExtra->DeviceHandle; |
|
19033 + |
|
19034 + |
|
19035 + // Set tuner bandwidth in Hz. |
|
19036 + Status = MT2266_SetParam(DeviceHandle, MT2266_OUTPUT_BW, BandwidthHz); |
|
19037 + |
|
19038 + if(MT_IS_ERROR(Status)) |
|
19039 + goto error_status_set_tuner_bandwidth; |
|
19040 + |
|
19041 + |
|
19042 + // Set tuner bandwidth parameter. |
|
19043 + pExtra->BandwidthHz = BandwidthHz; |
|
19044 + pExtra->IsBandwidthHzSet = YES; |
|
19045 + |
|
19046 + |
|
19047 + return FUNCTION_SUCCESS; |
|
19048 + |
|
19049 + |
|
19050 +error_status_set_tuner_bandwidth: |
|
19051 + return FUNCTION_ERROR; |
|
19052 +} |
|
19053 + |
|
19054 + |
|
19055 + |
|
19056 + |
|
19057 + |
|
19058 +/** |
|
19059 + |
|
19060 +@brief Get MT2266 tuner bandwidth in Hz. |
|
19061 + |
|
19062 +*/ |
|
19063 +int |
|
19064 +mt2266_GetBandwidthHz( |
|
19065 + TUNER_MODULE *pTuner, |
|
19066 + unsigned long *pBandwidthHz |
|
19067 + ) |
|
19068 +{ |
|
19069 + MT2266_EXTRA_MODULE *pExtra; |
|
19070 + |
|
19071 + |
|
19072 + |
|
19073 + // Get tuner extra module. |
|
19074 + pExtra = (MT2266_EXTRA_MODULE *)pTuner->pExtra; |
|
19075 + |
|
19076 + |
|
19077 + // Get tuner bandwidth in Hz from tuner module. |
|
19078 + if(pExtra->IsBandwidthHzSet != YES) |
|
19079 + goto error_status_get_tuner_bandwidth; |
|
19080 + |
|
19081 + *pBandwidthHz = pExtra->BandwidthHz; |
|
19082 + |
|
19083 + |
|
19084 + return FUNCTION_SUCCESS; |
|
19085 + |
|
19086 + |
|
19087 +error_status_get_tuner_bandwidth: |
|
19088 + return FUNCTION_ERROR; |
|
19089 +} |
|
19090 + |
|
19091 + |
|
19092 + |
|
19093 + |
|
19094 + |
|
19095 +/** |
|
19096 + |
|
19097 +@brief Set I2C bridge module tuner arguments. |
|
19098 + |
|
19099 +MT2266 builder will use mt2266_SetI2cBridgeModuleTunerArg() to set I2C bridge module tuner arguments. |
|
19100 + |
|
19101 + |
|
19102 +@param [in] pTuner The tuner module pointer |
|
19103 + |
|
19104 + |
|
19105 +@see BuildMt2266Module() |
|
19106 + |
|
19107 +*/ |
|
19108 +void |
|
19109 +mt2266_SetI2cBridgeModuleTunerArg( |
|
19110 + TUNER_MODULE *pTuner |
|
19111 + ) |
|
19112 +{ |
|
19113 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
19114 + |
|
19115 + |
|
19116 + |
|
19117 + // Get I2C bridge module. |
|
19118 + pI2cBridge = pTuner->pI2cBridge; |
|
19119 + |
|
19120 + // Set I2C bridge module tuner arguments. |
|
19121 + pI2cBridge->pTunerDeviceAddr = &pTuner->DeviceAddr; |
|
19122 + |
|
19123 + |
|
19124 + return; |
|
19125 +} |
|
19126 + |
|
19127 + |
|
19128 + |
|
19129 + |
|
19130 + |
|
19131 + |
|
19132 + |
|
19133 + |
|
19134 + |
|
19135 + |
|
19136 + |
|
19137 + |
|
19138 + |
|
19139 + |
|
19140 + |
|
19141 + |
|
19142 + |
|
19143 + |
|
19144 + |
|
19145 + |
|
19146 + |
|
19147 + |
|
19148 + |
|
19149 +// The following context is source code provided by Microtune. |
|
19150 + |
|
19151 + |
|
19152 + |
|
19153 + |
|
19154 + |
|
19155 +// Microtune source code - mt_userdef.c |
|
19156 + |
|
19157 + |
|
19158 +/***************************************************************************** |
|
19159 +** |
|
19160 +** Name: mt_userdef.c |
|
19161 +** |
|
19162 +** Description: User-defined MicroTuner software interface |
|
19163 +** |
|
19164 +** Functions |
|
19165 +** Requiring |
|
19166 +** Implementation: MT_WriteSub |
|
19167 +** MT_ReadSub |
|
19168 +** MT_Sleep |
|
19169 +** |
|
19170 +** References: None |
|
19171 +** |
|
19172 +** Exports: None |
|
19173 +** |
|
19174 +** CVS ID: $Id: mt_userdef.c,v 1.2 2006/10/26 16:39:18 software Exp $ |
|
19175 +** CVS Source: $Source: /export/home/cvsroot/software/tuners/MT2266/mt_userdef.c,v $ |
|
19176 +** |
|
19177 +** Revision History: |
|
19178 +** |
|
19179 +** SCR Date Author Description |
|
19180 +** ------------------------------------------------------------------------- |
|
19181 +** N/A 03-25-2004 DAD Original |
|
19182 +** |
|
19183 +*****************************************************************************/ |
|
19184 +//#include "mt_userdef.h" |
|
19185 + |
|
19186 + |
|
19187 +/***************************************************************************** |
|
19188 +** |
|
19189 +** Name: MT_WriteSub |
|
19190 +** |
|
19191 +** Description: Write values to device using a two-wire serial bus. |
|
19192 +** |
|
19193 +** Parameters: hUserData - User-specific I/O parameter that was |
|
19194 +** passed to tuner's Open function. |
|
19195 +** addr - device serial bus address (value passed |
|
19196 +** as parameter to MTxxxx_Open) |
|
19197 +** subAddress - serial bus sub-address (Register Address) |
|
19198 +** pData - pointer to the Data to be written to the |
|
19199 +** device |
|
19200 +** cnt - number of bytes/registers to be written |
|
19201 +** |
|
19202 +** Returns: status: |
|
19203 +** MT_OK - No errors |
|
19204 +** MT_COMM_ERR - Serial bus communications error |
|
19205 +** user-defined |
|
19206 +** |
|
19207 +** Notes: This is a callback function that is called from the |
|
19208 +** the tuning algorithm. You MUST provide code for this |
|
19209 +** function to write data using the tuner's 2-wire serial |
|
19210 +** bus. |
|
19211 +** |
|
19212 +** The hUserData parameter is a user-specific argument. |
|
19213 +** If additional arguments are needed for the user's |
|
19214 +** serial bus read/write functions, this argument can be |
|
19215 +** used to supply the necessary information. |
|
19216 +** The hUserData parameter is initialized in the tuner's Open |
|
19217 +** function. |
|
19218 +** |
|
19219 +** Revision History: |
|
19220 +** |
|
19221 +** SCR Date Author Description |
|
19222 +** ------------------------------------------------------------------------- |
|
19223 +** N/A 03-25-2004 DAD Original |
|
19224 +** |
|
19225 +*****************************************************************************/ |
|
19226 +UData_t MT_WriteSub(Handle_t hUserData, |
|
19227 + UData_t addr, |
|
19228 + U8Data subAddress, |
|
19229 + U8Data *pData, |
|
19230 + UData_t cnt) |
|
19231 +{ |
|
19232 +// UData_t status = MT_OK; /* Status to be returned */ |
|
19233 + /* |
|
19234 + ** ToDo: Add code here to implement a serial-bus write |
|
19235 + ** operation to the MTxxxx tuner. If successful, |
|
19236 + ** return MT_OK. |
|
19237 + */ |
|
19238 +/* return status; */ |
|
19239 + |
|
19240 + |
|
19241 + TUNER_MODULE *pTuner; |
|
19242 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
19243 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
19244 + |
|
19245 + unsigned int i, j; |
|
19246 + |
|
19247 + unsigned char RegStartAddr; |
|
19248 + unsigned char *pWritingBytes; |
|
19249 + unsigned char ByteNum; |
|
19250 + |
|
19251 + unsigned char WritingBuffer[I2C_BUFFER_LEN]; |
|
19252 + unsigned char WritingByteNum, WritingByteNumMax, WritingByteNumRem; |
|
19253 + unsigned char RegWritingAddr; |
|
19254 + unsigned char TunerDeviceAddr; |
|
19255 + |
|
19256 + struct dvb_usb_device *d; |
|
19257 + |
|
19258 + // Get tuner module, base interface, and I2C bridge. |
|
19259 + pTuner = (TUNER_MODULE *)hUserData; |
|
19260 + pBaseInterface = pTuner->pBaseInterface; |
|
19261 + pI2cBridge = pTuner->pI2cBridge; |
|
19262 + |
|
19263 + // Get tuner device address. |
|
19264 + TunerDeviceAddr = *pI2cBridge->pTunerDeviceAddr; |
|
19265 + |
|
19266 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); //add by chialing |
|
19267 + |
|
19268 + |
|
19269 + // Get regiser start address, writing bytes, and byte number. |
|
19270 + RegStartAddr = subAddress; |
|
19271 + pWritingBytes = pData; |
|
19272 + ByteNum = (unsigned char)cnt; |
|
19273 + |
|
19274 + |
|
19275 + // Calculate maximum writing byte number. |
|
19276 + WritingByteNumMax = pBaseInterface->I2cWritingByteNumMax - LEN_1_BYTE; |
|
19277 + |
|
19278 + |
|
19279 + // Set tuner register bytes with writing bytes. |
|
19280 + // Note: Set tuner register bytes considering maximum writing byte number. |
|
19281 + for(i = 0; i < ByteNum; i += WritingByteNumMax) |
|
19282 + { |
|
19283 + // Set register writing address. |
|
19284 + RegWritingAddr = RegStartAddr + i; |
|
19285 + |
|
19286 + // Calculate remainder writing byte number. |
|
19287 + WritingByteNumRem = ByteNum - i; |
|
19288 + |
|
19289 + // Determine writing byte number. |
|
19290 + WritingByteNum = (WritingByteNumRem > WritingByteNumMax) ? WritingByteNumMax : WritingByteNumRem; |
|
19291 + |
|
19292 + |
|
19293 + // Set writing buffer. |
|
19294 + // Note: The I2C format of tuner register byte setting is as follows: |
|
19295 + // start_bit + (DeviceAddr | writing_bit) + RegWritingAddr + writing_bytes (WritingByteNum bytes) + |
|
19296 + // stop_bit |
|
19297 +// WritingBuffer[0] = RegWritingAddr; |
|
19298 + |
|
19299 + for(j = 0; j < WritingByteNum; j++) |
|
19300 + WritingBuffer[j] = pWritingBytes[i + j]; |
|
19301 + |
|
19302 + |
|
19303 + |
|
19304 + // Set tuner register bytes with writing buffer. |
|
19305 +// if(pI2cBridge->ForwardI2cWritingCmd(pI2cBridge, WritingBuffer, WritingByteNum + LEN_1_BYTE) != |
|
19306 +// FUNCTION_SUCCESS) |
|
19307 +// goto error_status_set_tuner_registers; |
|
19308 + |
|
19309 + if(write_rtl2832_tuner_register( d, TunerDeviceAddr, RegWritingAddr, WritingBuffer, WritingByteNum )) goto error; |
|
19310 + |
|
19311 + |
|
19312 + } |
|
19313 + |
|
19314 + |
|
19315 + return MT_OK; |
|
19316 + |
|
19317 +error: |
|
19318 + |
|
19319 + return MT_COMM_ERR; |
|
19320 +} |
|
19321 + |
|
19322 + |
|
19323 +/***************************************************************************** |
|
19324 +** |
|
19325 +** Name: MT_ReadSub |
|
19326 +** |
|
19327 +** Description: Read values from device using a two-wire serial bus. |
|
19328 +** |
|
19329 +** Parameters: hUserData - User-specific I/O parameter that was |
|
19330 +** passed to tuner's Open function. |
|
19331 +** addr - device serial bus address (value passed |
|
19332 +** as parameter to MTxxxx_Open) |
|
19333 +** subAddress - serial bus sub-address (Register Address) |
|
19334 +** pData - pointer to the Data to be written to the |
|
19335 +** device |
|
19336 +** cnt - number of bytes/registers to be written |
|
19337 +** |
|
19338 +** Returns: status: |
|
19339 +** MT_OK - No errors |
|
19340 +** MT_COMM_ERR - Serial bus communications error |
|
19341 +** user-defined |
|
19342 +** |
|
19343 +** Notes: This is a callback function that is called from the |
|
19344 +** the tuning algorithm. You MUST provide code for this |
|
19345 +** function to read data using the tuner's 2-wire serial |
|
19346 +** bus. |
|
19347 +** |
|
19348 +** The hUserData parameter is a user-specific argument. |
|
19349 +** If additional arguments are needed for the user's |
|
19350 +** serial bus read/write functions, this argument can be |
|
19351 +** used to supply the necessary information. |
|
19352 +** The hUserData parameter is initialized in the tuner's Open |
|
19353 +** function. |
|
19354 +** |
|
19355 +** Revision History: |
|
19356 +** |
|
19357 +** SCR Date Author Description |
|
19358 +** ------------------------------------------------------------------------- |
|
19359 +** N/A 03-25-2004 DAD Original |
|
19360 +** |
|
19361 +*****************************************************************************/ |
|
19362 +UData_t MT_ReadSub(Handle_t hUserData, |
|
19363 + UData_t addr, |
|
19364 + U8Data subAddress, |
|
19365 + U8Data *pData, |
|
19366 + UData_t cnt) |
|
19367 +{ |
|
19368 + // UData_t status = MT_OK; /* Status to be returned */ |
|
19369 + |
|
19370 + /* |
|
19371 + ** ToDo: Add code here to implement a serial-bus read |
|
19372 + ** operation to the MTxxxx tuner. If successful, |
|
19373 + ** return MT_OK. |
|
19374 + */ |
|
19375 +/* return status; */ |
|
19376 + |
|
19377 + |
|
19378 + TUNER_MODULE *pTuner; |
|
19379 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
19380 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
19381 + |
|
19382 + unsigned int i; |
|
19383 + |
|
19384 + unsigned char RegStartAddr; |
|
19385 + unsigned char *pReadingBytes; |
|
19386 + unsigned char ByteNum; |
|
19387 + |
|
19388 + unsigned char ReadingByteNum, ReadingByteNumMax, ReadingByteNumRem; |
|
19389 + unsigned char RegReadingAddr; |
|
19390 + |
|
19391 + unsigned char TunerDeviceAddr; |
|
19392 + |
|
19393 + |
|
19394 + struct dvb_usb_device *d; |
|
19395 + |
|
19396 + // Get tuner module, base interface, and I2C bridge. |
|
19397 + pTuner = (TUNER_MODULE *)hUserData; |
|
19398 + pBaseInterface = pTuner->pBaseInterface; |
|
19399 + pI2cBridge = pTuner->pI2cBridge; |
|
19400 + |
|
19401 + // Get tuner device address. |
|
19402 + TunerDeviceAddr = *pI2cBridge->pTunerDeviceAddr; |
|
19403 + |
|
19404 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); |
|
19405 + |
|
19406 + |
|
19407 + // Get regiser start address, writing bytes, and byte number. |
|
19408 + RegStartAddr = subAddress; |
|
19409 + pReadingBytes = pData; |
|
19410 + ByteNum = (unsigned char)cnt; |
|
19411 + |
|
19412 + |
|
19413 + // Calculate maximum reading byte number. |
|
19414 + ReadingByteNumMax = pBaseInterface->I2cReadingByteNumMax; |
|
19415 + |
|
19416 + |
|
19417 + // Get tuner register bytes. |
|
19418 + // Note: Get tuner register bytes considering maximum reading byte number. |
|
19419 + for(i = 0; i < ByteNum; i += ReadingByteNumMax) |
|
19420 + { |
|
19421 + // Set register reading address. |
|
19422 + RegReadingAddr = RegStartAddr + i; |
|
19423 + |
|
19424 + // Calculate remainder reading byte number. |
|
19425 + ReadingByteNumRem = ByteNum - i; |
|
19426 + |
|
19427 + // Determine reading byte number. |
|
19428 + ReadingByteNum = (ReadingByteNumRem > ReadingByteNumMax) ? ReadingByteNumMax : ReadingByteNumRem; |
|
19429 + |
|
19430 + |
|
19431 + // Set tuner register reading address. |
|
19432 + // Note: The I2C format of tuner register reading address setting is as follows: |
|
19433 + // start_bit + (DeviceAddr | writing_bit) + RegReadingAddr + stop_bit |
|
19434 +// if(pI2cBridge->ForwardI2cWritingCmd(pI2cBridge, &RegReadingAddr, LEN_1_BYTE) != FUNCTION_SUCCESS) |
|
19435 +// goto error_status_set_tuner_register_reading_address; |
|
19436 + |
|
19437 + // Get tuner register bytes. |
|
19438 + // Note: The I2C format of tuner register byte getting is as follows: |
|
19439 + // start_bit + (DeviceAddr | reading_bit) + reading_bytes (ReadingByteNum bytes) + stop_bit |
|
19440 +// if(pI2cBridge->ForwardI2cReadingCmd(pI2cBridge, &pReadingBytes[i], ReadingByteNum) != FUNCTION_SUCCESS) |
|
19441 +// goto error_status_get_tuner_registers; |
|
19442 + |
|
19443 + if(read_rtl2832_tuner_register(d, TunerDeviceAddr, RegReadingAddr, &pReadingBytes[i], ReadingByteNum)) goto error; |
|
19444 + |
|
19445 + } |
|
19446 + |
|
19447 + return MT_OK; |
|
19448 + |
|
19449 +error: |
|
19450 + return MT_COMM_ERR; |
|
19451 +} |
|
19452 + |
|
19453 + |
|
19454 +/***************************************************************************** |
|
19455 +** |
|
19456 +** Name: MT_Sleep |
|
19457 +** |
|
19458 +** Description: Delay execution for "nMinDelayTime" milliseconds |
|
19459 +** |
|
19460 +** Parameters: hUserData - User-specific I/O parameter that was |
|
19461 +** passed to tuner's Open function. |
|
19462 +** nMinDelayTime - Delay time in milliseconds |
|
19463 +** |
|
19464 +** Returns: None. |
|
19465 +** |
|
19466 +** Notes: This is a callback function that is called from the |
|
19467 +** the tuning algorithm. You MUST provide code that |
|
19468 +** blocks execution for the specified period of time. |
|
19469 +** |
|
19470 +** Revision History: |
|
19471 +** |
|
19472 +** SCR Date Author Description |
|
19473 +** ------------------------------------------------------------------------- |
|
19474 +** N/A 03-25-2004 DAD Original |
|
19475 +** |
|
19476 +*****************************************************************************/ |
|
19477 +void MT_Sleep(Handle_t hUserData, |
|
19478 + UData_t nMinDelayTime) |
|
19479 +{ |
|
19480 + /* |
|
19481 + ** ToDo: Add code here to implement a OS blocking |
|
19482 + ** for a period of "nMinDelayTime" milliseconds. |
|
19483 + */ |
|
19484 + |
|
19485 + |
|
19486 + TUNER_MODULE *pTuner; |
|
19487 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
19488 + |
|
19489 + |
|
19490 + |
|
19491 + // Get tuner module, base interface. |
|
19492 + pTuner = (TUNER_MODULE *)hUserData; |
|
19493 + pBaseInterface = pTuner->pBaseInterface; |
|
19494 + |
|
19495 + |
|
19496 + // Wait nMinDelayTime milliseconds. |
|
19497 + pBaseInterface->WaitMs(pBaseInterface, nMinDelayTime); |
|
19498 + |
|
19499 + |
|
19500 + return; |
|
19501 +} |
|
19502 + |
|
19503 + |
|
19504 +#if defined(MT2060_CNT) |
|
19505 +#if MT2060_CNT > 0 |
|
19506 +/***************************************************************************** |
|
19507 +** |
|
19508 +** Name: MT_TunerGain (MT2060 only) |
|
19509 +** |
|
19510 +** Description: Measure the relative tuner gain using the demodulator |
|
19511 +** |
|
19512 +** Parameters: hUserData - User-specific I/O parameter that was |
|
19513 +** passed to tuner's Open function. |
|
19514 +** pMeas - Tuner gain (1/100 of dB scale). |
|
19515 +** ie. 1234 = 12.34 (dB) |
|
19516 +** |
|
19517 +** Returns: status: |
|
19518 +** MT_OK - No errors |
|
19519 +** user-defined errors could be set |
|
19520 +** |
|
19521 +** Notes: This is a callback function that is called from the |
|
19522 +** the 1st IF location routine. You MUST provide |
|
19523 +** code that measures the relative tuner gain in a dB |
|
19524 +** (not linear) scale. The return value is an integer |
|
19525 +** value scaled to 1/100 of a dB. |
|
19526 +** |
|
19527 +** Revision History: |
|
19528 +** |
|
19529 +** SCR Date Author Description |
|
19530 +** ------------------------------------------------------------------------- |
|
19531 +** N/A 06-16-2004 DAD Original |
|
19532 +** N/A 11-30-2004 DAD Renamed from MT_DemodInputPower. This name |
|
19533 +** better describes what this function does. |
|
19534 +** |
|
19535 +*****************************************************************************/ |
|
19536 +UData_t MT_TunerGain(Handle_t hUserData, |
|
19537 + SData_t* pMeas) |
|
19538 +{ |
|
19539 + UData_t status = MT_OK; /* Status to be returned */ |
|
19540 + |
|
19541 + /* |
|
19542 + ** ToDo: Add code here to return the gain / power level measured |
|
19543 + ** at the input to the demodulator. |
|
19544 + */ |
|
19545 + |
|
19546 + |
|
19547 + |
|
19548 + return (status); |
|
19549 +} |
|
19550 +#endif |
|
19551 +#endif |
|
19552 + |
|
19553 + |
|
19554 + |
|
19555 + |
|
19556 + |
|
19557 + |
|
19558 + |
|
19559 + |
|
19560 + |
|
19561 + |
|
19562 + |
|
19563 + |
|
19564 + |
|
19565 + |
|
19566 + |
|
19567 + |
|
19568 + |
|
19569 + |
|
19570 + |
|
19571 + |
|
19572 + |
|
19573 + |
|
19574 + |
|
19575 +// Microtune source code - mt2266.c |
|
19576 + |
|
19577 + |
|
19578 + |
|
19579 +/***************************************************************************** |
|
19580 +** |
|
19581 +** Name: mt2266.c |
|
19582 +** |
|
19583 +** Copyright 2007 Microtune, Inc. All Rights Reserved |
|
19584 +** |
|
19585 +** This source code file contains confidential information and/or trade |
|
19586 +** secrets of Microtune, Inc. or its affiliates and is subject to the |
|
19587 +** terms of your confidentiality agreement with Microtune, Inc. or one of |
|
19588 +** its affiliates, as applicable. |
|
19589 +** |
|
19590 +*****************************************************************************/ |
|
19591 + |
|
19592 +/***************************************************************************** |
|
19593 +** |
|
19594 +** Name: mt2266.c |
|
19595 +** |
|
19596 +** Description: Microtune MT2266 Tuner software interface. |
|
19597 +** Supports tuners with Part/Rev code: 0x85. |
|
19598 +** |
|
19599 +** Functions |
|
19600 +** Implemented: UData_t MT2266_Open |
|
19601 +** UData_t MT2266_Close |
|
19602 +** UData_t MT2266_ChangeFreq |
|
19603 +** UData_t MT2266_GetLocked |
|
19604 +** UData_t MT2266_GetParam |
|
19605 +** UData_t MT2266_GetReg |
|
19606 +** UData_t MT2266_GetUHFXFreqs |
|
19607 +** UData_t MT2266_GetUserData |
|
19608 +** UData_t MT2266_ReInit |
|
19609 +** UData_t MT2266_SetParam |
|
19610 +** UData_t MT2266_SetPowerModes |
|
19611 +** UData_t MT2266_SetReg |
|
19612 +** UData_t MT2266_SetUHFXFreqs |
|
19613 +** |
|
19614 +** References: AN-00010: MicroTuner Serial Interface Application Note |
|
19615 +** MicroTune, Inc. |
|
19616 +** |
|
19617 +** Exports: None |
|
19618 +** |
|
19619 +** Dependencies: MT_ReadSub(hUserData, IC_Addr, subAddress, *pData, cnt); |
|
19620 +** - Read byte(s) of data from the two-wire bus. |
|
19621 +** |
|
19622 +** MT_WriteSub(hUserData, IC_Addr, subAddress, *pData, cnt); |
|
19623 +** - Write byte(s) of data to the two-wire bus. |
|
19624 +** |
|
19625 +** MT_Sleep(hUserData, nMinDelayTime); |
|
19626 +** - Delay execution for x milliseconds |
|
19627 +** |
|
19628 +** CVS ID: $Id: mt2266.c,v 1.5 2007/10/02 18:43:17 software Exp $ |
|
19629 +** CVS Source: $Source: /export/home/cvsroot/software/tuners/MT2266/mt2266.c,v $ |
|
19630 +** |
|
19631 +** Revision History: |
|
19632 +** |
|
19633 +** SCR Date Author Description |
|
19634 +** ------------------------------------------------------------------------- |
|
19635 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
19636 +** N/A 06-08-2006 JWS Ver 1.01: Corrected problem with tuner ID check |
|
19637 +** N/A 11-01-2006 RSK Ver 1.02: Adding multiple-filter support |
|
19638 +** as well as Get/Set functions. |
|
19639 +** N/A 11-29-2006 DAD Ver 1.03: Parenthesis clarification for gcc |
|
19640 +** N/A 12-20-2006 RSK Ver 1.04: Adding fLO_FractionalTerm() usage. |
|
19641 +** 118 05-09-2007 RSK Ver 1.05: Adding Standard MTxxxx_Tune() API. |
|
19642 +** |
|
19643 +*****************************************************************************/ |
|
19644 +//#include "mt2266.h" |
|
19645 +//#include <stdlib.h> /* for NULL */ |
|
19646 +#define MT_NULL 0 |
|
19647 + |
|
19648 +/* Version of this module */ |
|
19649 +#define VERSION 10005 /* Version 01.05 */ |
|
19650 + |
|
19651 + |
|
19652 +#ifndef MT2266_CNT |
|
19653 +#error You must define MT2266_CNT in the "mt_userdef.h" file |
|
19654 +#endif |
|
19655 + |
|
19656 +/* |
|
19657 +** Normally, the "reg" array in the tuner structure is used as a cache |
|
19658 +** containing the current value of the tuner registers. If the user's |
|
19659 +** application MUST change tuner registers without using the MT2266_SetReg |
|
19660 +** routine provided, he may compile this code with the __NO_CACHE__ |
|
19661 +** variable defined. |
|
19662 +** The PREFETCH macro will insert code code to re-read tuner registers if |
|
19663 +** __NO_CACHE__ is defined. If it is not defined (normal) then PREFETCH |
|
19664 +** does nothing. |
|
19665 +*/ |
|
19666 + |
|
19667 +#if defined(__NO_CACHE__) |
|
19668 +#define PREFETCH(var, cnt) \ |
|
19669 + if (MT_NO_ERROR(status)) \ |
|
19670 + status |= MT_ReadSub(pInfo->hUserData, pInfo->address, (var), &pInfo->reg[(var)], (cnt)); |
|
19671 +#else |
|
19672 +#define PREFETCH(var, cnt) |
|
19673 +#endif |
|
19674 + |
|
19675 + |
|
19676 + |
|
19677 +/* |
|
19678 +** Two-wire serial bus subaddresses of the tuner registers. |
|
19679 +** Also known as the tuner's register addresses. |
|
19680 +*/ |
|
19681 +enum MT2266_Register_Offsets |
|
19682 +{ |
|
19683 + MT2266_PART_REV = 0, /* 0x00 */ |
|
19684 + MT2266_LO_CTRL_1, /* 0x01 */ |
|
19685 + MT2266_LO_CTRL_2, /* 0x02 */ |
|
19686 + MT2266_LO_CTRL_3, /* 0x03 */ |
|
19687 + MT2266_SMART_ANT, /* 0x04 */ |
|
19688 + MT2266_BAND_CTRL, /* 0x05 */ |
|
19689 + MT2266_CLEARTUNE, /* 0x06 */ |
|
19690 + MT2266_IGAIN, /* 0x07 */ |
|
19691 + MT2266_BBFILT_1, /* 0x08 */ |
|
19692 + MT2266_BBFILT_2, /* 0x09 */ |
|
19693 + MT2266_BBFILT_3, /* 0x0A */ |
|
19694 + MT2266_BBFILT_4, /* 0x0B */ |
|
19695 + MT2266_BBFILT_5, /* 0x0C */ |
|
19696 + MT2266_BBFILT_6, /* 0x0D */ |
|
19697 + MT2266_BBFILT_7, /* 0x0E */ |
|
19698 + MT2266_BBFILT_8, /* 0x0F */ |
|
19699 + MT2266_RCC_CTRL, /* 0x10 */ |
|
19700 + MT2266_RSVD_11, /* 0x11 */ |
|
19701 + MT2266_STATUS_1, /* 0x12 */ |
|
19702 + MT2266_STATUS_2, /* 0x13 */ |
|
19703 + MT2266_STATUS_3, /* 0x14 */ |
|
19704 + MT2266_STATUS_4, /* 0x15 */ |
|
19705 + MT2266_STATUS_5, /* 0x16 */ |
|
19706 + MT2266_SRO_CTRL, /* 0x17 */ |
|
19707 + MT2266_RSVD_18, /* 0x18 */ |
|
19708 + MT2266_RSVD_19, /* 0x19 */ |
|
19709 + MT2266_RSVD_1A, /* 0x1A */ |
|
19710 + MT2266_RSVD_1B, /* 0x1B */ |
|
19711 + MT2266_ENABLES, /* 0x1C */ |
|
19712 + MT2266_RSVD_1D, /* 0x1D */ |
|
19713 + MT2266_RSVD_1E, /* 0x1E */ |
|
19714 + MT2266_RSVD_1F, /* 0x1F */ |
|
19715 + MT2266_GPO, /* 0x20 */ |
|
19716 + MT2266_RSVD_21, /* 0x21 */ |
|
19717 + MT2266_RSVD_22, /* 0x22 */ |
|
19718 + MT2266_RSVD_23, /* 0x23 */ |
|
19719 + MT2266_RSVD_24, /* 0x24 */ |
|
19720 + MT2266_RSVD_25, /* 0x25 */ |
|
19721 + MT2266_RSVD_26, /* 0x26 */ |
|
19722 + MT2266_RSVD_27, /* 0x27 */ |
|
19723 + MT2266_RSVD_28, /* 0x28 */ |
|
19724 + MT2266_RSVD_29, /* 0x29 */ |
|
19725 + MT2266_RSVD_2A, /* 0x2A */ |
|
19726 + MT2266_RSVD_2B, /* 0x2B */ |
|
19727 + MT2266_RSVD_2C, /* 0x2C */ |
|
19728 + MT2266_RSVD_2D, /* 0x2D */ |
|
19729 + MT2266_RSVD_2E, /* 0x2E */ |
|
19730 + MT2266_RSVD_2F, /* 0x2F */ |
|
19731 + MT2266_RSVD_30, /* 0x30 */ |
|
19732 + MT2266_RSVD_31, /* 0x31 */ |
|
19733 + MT2266_RSVD_32, /* 0x32 */ |
|
19734 + MT2266_RSVD_33, /* 0x33 */ |
|
19735 + MT2266_RSVD_34, /* 0x34 */ |
|
19736 + MT2266_RSVD_35, /* 0x35 */ |
|
19737 + MT2266_RSVD_36, /* 0x36 */ |
|
19738 + MT2266_RSVD_37, /* 0x37 */ |
|
19739 + MT2266_RSVD_38, /* 0x38 */ |
|
19740 + MT2266_RSVD_39, /* 0x39 */ |
|
19741 + MT2266_RSVD_3A, /* 0x3A */ |
|
19742 + MT2266_RSVD_3B, /* 0x3B */ |
|
19743 + MT2266_RSVD_3C, /* 0x3C */ |
|
19744 + END_REGS |
|
19745 +}; |
|
19746 + |
|
19747 +/* |
|
19748 +** DefaultsEntry points to an array of U8Data used to initialize |
|
19749 +** various registers (the first byte is the starting subaddress) |
|
19750 +** and a count of the bytes (including subaddress) in the array. |
|
19751 +** |
|
19752 +** DefaultsList is an array of DefaultsEntry elements terminated |
|
19753 +** by an entry with a NULL pointer for the data array. |
|
19754 +*/ |
|
19755 +typedef struct MT2266_DefaultsEntryTag |
|
19756 +{ |
|
19757 + U8Data *data; |
|
19758 + UData_t cnt; |
|
19759 +} MT2266_DefaultsEntry; |
|
19760 + |
|
19761 +typedef MT2266_DefaultsEntry MT2266_DefaultsList[]; |
|
19762 + |
|
19763 +#define DEF_LIST_ENTRY(a) {a, sizeof(a)/sizeof(U8Data) - 1} |
|
19764 +#define END_DEF_LIST {0,0} |
|
19765 + |
|
19766 +/* |
|
19767 +** Constants used by the tuning algorithm |
|
19768 +*/ |
|
19769 + /* REF_FREQ is now the actual crystal frequency */ |
|
19770 +#define REF_FREQ (30000000UL) /* Reference oscillator Frequency (in Hz) */ |
|
19771 +#define TUNE_STEP_SIZE (50UL) /* Tune in steps of 50 kHz */ |
|
19772 +#define MIN_UHF_FREQ (350000000UL) /* Minimum UHF frequency (in Hz) */ |
|
19773 +#define MAX_UHF_FREQ (900000000UL) /* Maximum UHF frequency (in Hz) */ |
|
19774 +#define MIN_VHF_FREQ (174000000UL) /* Minimum VHF frequency (in Hz) */ |
|
19775 +#define MAX_VHF_FREQ (230000000UL) /* Maximum VHF frequency (in Hz) */ |
|
19776 +#define OUTPUT_BW (8000000UL) /* Output channel bandwidth (in Hz) */ |
|
19777 +#define UHF_DEFAULT_FREQ (600000000UL) /* Default UHF input frequency (in Hz) */ |
|
19778 + |
|
19779 + |
|
19780 +/* |
|
19781 +** The number of Tuner Registers |
|
19782 +*/ |
|
19783 +static const UData_t Num_Registers = END_REGS; |
|
19784 + |
|
19785 +/* |
|
19786 +** Crossover Frequency sets for 2 filters, without and with attenuation. |
|
19787 +*/ |
|
19788 +typedef struct |
|
19789 +{ |
|
19790 + MT2266_XFreq_Set xfreq[ MT2266_NUMBER_OF_XFREQ_SETS ]; |
|
19791 + |
|
19792 +} MT2266_XFreqs_t; |
|
19793 + |
|
19794 + |
|
19795 +MT2266_XFreqs_t MT2266_default_XFreqs = |
|
19796 +{ |
|
19797 + /* xfreq */ |
|
19798 + { |
|
19799 + /* uhf0 */ |
|
19800 + { /* < 0 MHz: 15+1 */ |
|
19801 + 0UL, /* 0 .. 0 MHz: 15 */ |
|
19802 + 0UL, /* 0 .. 443 MHz: 14 */ |
|
19803 + 443000 / TUNE_STEP_SIZE, /* 443 .. 470 MHz: 13 */ |
|
19804 + 470000 / TUNE_STEP_SIZE, /* 470 .. 496 MHz: 12 */ |
|
19805 + 496000 / TUNE_STEP_SIZE, /* 496 .. 525 MHz: 11 */ |
|
19806 + 525000 / TUNE_STEP_SIZE, /* 525 .. 552 MHz: 10 */ |
|
19807 + 552000 / TUNE_STEP_SIZE, /* 552 .. 580 MHz: 9 */ |
|
19808 + 580000 / TUNE_STEP_SIZE, /* 580 .. 657 MHz: 8 */ |
|
19809 + 657000 / TUNE_STEP_SIZE, /* 657 .. 682 MHz: 7 */ |
|
19810 + 682000 / TUNE_STEP_SIZE, /* 682 .. 710 MHz: 6 */ |
|
19811 + 710000 / TUNE_STEP_SIZE, /* 710 .. 735 MHz: 5 */ |
|
19812 + 735000 / TUNE_STEP_SIZE, /* 735 .. 763 MHz: 4 */ |
|
19813 + 763000 / TUNE_STEP_SIZE, /* 763 .. 802 MHz: 3 */ |
|
19814 + 802000 / TUNE_STEP_SIZE, /* 802 .. 840 MHz: 2 */ |
|
19815 + 840000 / TUNE_STEP_SIZE, /* 840 .. 877 MHz: 1 */ |
|
19816 + 877000 / TUNE_STEP_SIZE /* 877+ MHz: 0 */ |
|
19817 + }, |
|
19818 + |
|
19819 + /* uhf1 */ |
|
19820 + { /* < 443 MHz: 15+1 */ |
|
19821 + 443000 / TUNE_STEP_SIZE, /* 443 .. 470 MHz: 15 */ |
|
19822 + 470000 / TUNE_STEP_SIZE, /* 470 .. 496 MHz: 14 */ |
|
19823 + 496000 / TUNE_STEP_SIZE, /* 496 .. 525 MHz: 13 */ |
|
19824 + 525000 / TUNE_STEP_SIZE, /* 525 .. 552 MHz: 12 */ |
|
19825 + 552000 / TUNE_STEP_SIZE, /* 552 .. 580 MHz: 11 */ |
|
19826 + 580000 / TUNE_STEP_SIZE, /* 580 .. 605 MHz: 10 */ |
|
19827 + 605000 / TUNE_STEP_SIZE, /* 605 .. 632 MHz: 9 */ |
|
19828 + 632000 / TUNE_STEP_SIZE, /* 632 .. 657 MHz: 8 */ |
|
19829 + 657000 / TUNE_STEP_SIZE, /* 657 .. 682 MHz: 7 */ |
|
19830 + 682000 / TUNE_STEP_SIZE, /* 682 .. 710 MHz: 6 */ |
|
19831 + 710000 / TUNE_STEP_SIZE, /* 710 .. 735 MHz: 5 */ |
|
19832 + 735000 / TUNE_STEP_SIZE, /* 735 .. 763 MHz: 4 */ |
|
19833 + 763000 / TUNE_STEP_SIZE, /* 763 .. 802 MHz: 3 */ |
|
19834 + 802000 / TUNE_STEP_SIZE, /* 802 .. 840 MHz: 2 */ |
|
19835 + 840000 / TUNE_STEP_SIZE, /* 840 .. 877 MHz: 1 */ |
|
19836 + 877000 / TUNE_STEP_SIZE /* 877+ MHz: 0 */ |
|
19837 + }, |
|
19838 + |
|
19839 + /* uhf0_a */ |
|
19840 + { /* < 0 MHz: 15+1 */ |
|
19841 + 0UL, /* 0 .. 0 MHz: 15 */ |
|
19842 + 0UL, /* 0 .. 442 MHz: 14 */ |
|
19843 + 442000 / TUNE_STEP_SIZE, /* 442 .. 472 MHz: 13 */ |
|
19844 + 472000 / TUNE_STEP_SIZE, /* 472 .. 505 MHz: 12 */ |
|
19845 + 505000 / TUNE_STEP_SIZE, /* 505 .. 535 MHz: 11 */ |
|
19846 + 535000 / TUNE_STEP_SIZE, /* 535 .. 560 MHz: 10 */ |
|
19847 + 560000 / TUNE_STEP_SIZE, /* 560 .. 593 MHz: 9 */ |
|
19848 + 593000 / TUNE_STEP_SIZE, /* 593 .. 673 MHz: 8 */ |
|
19849 + 673000 / TUNE_STEP_SIZE, /* 673 .. 700 MHz: 7 */ |
|
19850 + 700000 / TUNE_STEP_SIZE, /* 700 .. 727 MHz: 6 */ |
|
19851 + 727000 / TUNE_STEP_SIZE, /* 727 .. 752 MHz: 5 */ |
|
19852 + 752000 / TUNE_STEP_SIZE, /* 752 .. 783 MHz: 4 */ |
|
19853 + 783000 / TUNE_STEP_SIZE, /* 783 .. 825 MHz: 3 */ |
|
19854 + 825000 / TUNE_STEP_SIZE, /* 825 .. 865 MHz: 2 */ |
|
19855 + 865000 / TUNE_STEP_SIZE, /* 865 .. 905 MHz: 1 */ |
|
19856 + 905000 / TUNE_STEP_SIZE /* 905+ MHz: 0 */ |
|
19857 + }, |
|
19858 + |
|
19859 + /* uhf1_a */ |
|
19860 + { /* < 442 MHz: 15+1 */ |
|
19861 + 442000 / TUNE_STEP_SIZE, /* 442 .. 472 MHz: 15 */ |
|
19862 + 472000 / TUNE_STEP_SIZE, /* 472 .. 505 MHz: 14 */ |
|
19863 + 505000 / TUNE_STEP_SIZE, /* 505 .. 535 MHz: 13 */ |
|
19864 + 535000 / TUNE_STEP_SIZE, /* 535 .. 560 MHz: 12 */ |
|
19865 + 560000 / TUNE_STEP_SIZE, /* 560 .. 593 MHz: 11 */ |
|
19866 + 593000 / TUNE_STEP_SIZE, /* 593 .. 620 MHz: 10 */ |
|
19867 + 620000 / TUNE_STEP_SIZE, /* 620 .. 647 MHz: 9 */ |
|
19868 + 647000 / TUNE_STEP_SIZE, /* 647 .. 673 MHz: 8 */ |
|
19869 + 673000 / TUNE_STEP_SIZE, /* 673 .. 700 MHz: 7 */ |
|
19870 + 700000 / TUNE_STEP_SIZE, /* 700 .. 727 MHz: 6 */ |
|
19871 + 727000 / TUNE_STEP_SIZE, /* 727 .. 752 MHz: 5 */ |
|
19872 + 752000 / TUNE_STEP_SIZE, /* 752 .. 783 MHz: 4 */ |
|
19873 + 783000 / TUNE_STEP_SIZE, /* 783 .. 825 MHz: 3 */ |
|
19874 + 825000 / TUNE_STEP_SIZE, /* 825 .. 865 MHz: 2 */ |
|
19875 + 865000 / TUNE_STEP_SIZE, /* 865 .. 905 MHz: 1 */ |
|
19876 + 905000 / TUNE_STEP_SIZE /* 905+ MHz: 0 */ |
|
19877 + } |
|
19878 + } |
|
19879 +}; |
|
19880 + |
|
19881 +typedef struct |
|
19882 +{ |
|
19883 + Handle_t handle; |
|
19884 + Handle_t hUserData; |
|
19885 + UData_t address; |
|
19886 + UData_t version; |
|
19887 + UData_t tuner_id; |
|
19888 + UData_t f_Ref; |
|
19889 + UData_t f_Step; |
|
19890 + UData_t f_in; |
|
19891 + UData_t f_LO; |
|
19892 + UData_t f_bw; |
|
19893 + UData_t band; |
|
19894 + UData_t num_regs; |
|
19895 + U8Data RC2_Value; |
|
19896 + U8Data RC2_Nominal; |
|
19897 + U8Data reg[END_REGS]; |
|
19898 + |
|
19899 + MT2266_XFreqs_t xfreqs; |
|
19900 + |
|
19901 +} MT2266_Info_t; |
|
19902 + |
|
19903 +static UData_t nMaxTuners = MT2266_CNT; |
|
19904 +static MT2266_Info_t MT2266_Info[MT2266_CNT]; |
|
19905 +static MT2266_Info_t *Avail[MT2266_CNT]; |
|
19906 +static UData_t nOpenTuners = 0; |
|
19907 + |
|
19908 +/* |
|
19909 +** Constants used to write a minimal set of registers when changing bands. |
|
19910 +** If the user wants a total reset, they should call MT2266_Open() again. |
|
19911 +** Skip 01, 02, 03, 04 (get overwritten anyways) |
|
19912 +** Write 05 |
|
19913 +** Skip 06 - 18 |
|
19914 +** Write 19 (diff for L-Band) |
|
19915 +** Skip 1A 1B 1C |
|
19916 +** Write 1D - 2B |
|
19917 +** Skip 2C - 3C |
|
19918 +*/ |
|
19919 + |
|
19920 +static U8Data MT2266_VHF_defaults1[] = |
|
19921 +{ |
|
19922 + 0x05, /* address 0xC0, reg 0x05 */ |
|
19923 + 0x04, /* Reg 0x05 LBANDen = 1 (that's right)*/ |
|
19924 +}; |
|
19925 +static U8Data MT2266_VHF_defaults2[] = |
|
19926 +{ |
|
19927 + 0x19, /* address 0xC0, reg 0x19 */ |
|
19928 + 0x61, /* Reg 0x19 CAPto = 3*/ |
|
19929 +}; |
|
19930 +static U8Data MT2266_VHF_defaults3[] = |
|
19931 +{ |
|
19932 + 0x1D, /* address 0xC0, reg 0x1D */ |
|
19933 + 0xFE, /* reg 0x1D */ |
|
19934 + 0x00, /* reg 0x1E */ |
|
19935 + 0x00, /* reg 0x1F */ |
|
19936 + 0xB4, /* Reg 0x20 GPO = 1*/ |
|
19937 + 0x03, /* Reg 0x21 LBIASen = 1, UBIASen = 1*/ |
|
19938 + 0xA5, /* Reg 0x22 */ |
|
19939 + 0xA5, /* Reg 0x23 */ |
|
19940 + 0xA5, /* Reg 0x24 */ |
|
19941 + 0xA5, /* Reg 0x25 */ |
|
19942 + 0x82, /* Reg 0x26 CASCM = b0001 (bits reversed)*/ |
|
19943 + 0xAA, /* Reg 0x27 */ |
|
19944 + 0xF1, /* Reg 0x28 */ |
|
19945 + 0x17, /* Reg 0x29 */ |
|
19946 + 0x80, /* Reg 0x2A MIXbiasen = 1*/ |
|
19947 + 0x1F, /* Reg 0x2B */ |
|
19948 +}; |
|
19949 + |
|
19950 +static MT2266_DefaultsList MT2266_VHF_defaults = { |
|
19951 + DEF_LIST_ENTRY(MT2266_VHF_defaults1), |
|
19952 + DEF_LIST_ENTRY(MT2266_VHF_defaults2), |
|
19953 + DEF_LIST_ENTRY(MT2266_VHF_defaults3), |
|
19954 + END_DEF_LIST |
|
19955 +}; |
|
19956 + |
|
19957 +static U8Data MT2266_UHF_defaults1[] = |
|
19958 +{ |
|
19959 + 0x05, /* address 0xC0, reg 0x05 */ |
|
19960 + 0x52, /* Reg 0x05 */ |
|
19961 +}; |
|
19962 +static U8Data MT2266_UHF_defaults2[] = |
|
19963 +{ |
|
19964 + 0x19, /* address 0xC0, reg 0x19 */ |
|
19965 + 0x61, /* Reg 0x19 CAPto = 3*/ |
|
19966 +}; |
|
19967 +static U8Data MT2266_UHF_defaults3[] = |
|
19968 +{ |
|
19969 + 0x1D, /* address 0xC0, reg 0x1D */ |
|
19970 + 0xDC, /* Reg 0x1D */ |
|
19971 + 0x00, /* Reg 0x1E */ |
|
19972 + 0x0A, /* Reg 0x1F */ |
|
19973 + 0xD4, /* Reg 0x20 GPO = 1*/ |
|
19974 + 0x03, /* Reg 0x21 LBIASen = 1, UBIASen = 1*/ |
|
19975 + 0x64, /* Reg 0x22 */ |
|
19976 + 0x64, /* Reg 0x23 */ |
|
19977 + 0x64, /* Reg 0x24 */ |
|
19978 + 0x64, /* Reg 0x25 */ |
|
19979 + 0x22, /* Reg 0x26 CASCM = b0100 (bits reversed)*/ |
|
19980 + 0xAA, /* Reg 0x27 */ |
|
19981 + 0xF2, /* Reg 0x28 */ |
|
19982 + 0x1E, /* Reg 0x29 */ |
|
19983 + 0x80, /* Reg 0x2A MIXbiasen = 1*/ |
|
19984 + 0x14, /* Reg 0x2B */ |
|
19985 +}; |
|
19986 + |
|
19987 +static MT2266_DefaultsList MT2266_UHF_defaults = { |
|
19988 + DEF_LIST_ENTRY(MT2266_UHF_defaults1), |
|
19989 + DEF_LIST_ENTRY(MT2266_UHF_defaults2), |
|
19990 + DEF_LIST_ENTRY(MT2266_UHF_defaults3), |
|
19991 + END_DEF_LIST |
|
19992 +}; |
|
19993 + |
|
19994 + |
|
19995 +static UData_t UncheckedSet(MT2266_Info_t* pInfo, |
|
19996 + U8Data reg, |
|
19997 + U8Data val); |
|
19998 + |
|
19999 +static UData_t UncheckedGet(MT2266_Info_t* pInfo, |
|
20000 + U8Data reg, |
|
20001 + U8Data* val); |
|
20002 + |
|
20003 + |
|
20004 +/****************************************************************************** |
|
20005 +** |
|
20006 +** Name: MT2266_Open |
|
20007 +** |
|
20008 +** Description: Initialize the tuner's register values. |
|
20009 +** |
|
20010 +** Parameters: MT2266_Addr - Serial bus address of the tuner. |
|
20011 +** hMT2266 - Tuner handle passed back. |
|
20012 +** hUserData - User-defined data, if needed for the |
|
20013 +** MT_ReadSub() & MT_WriteSub functions. |
|
20014 +** |
|
20015 +** Returns: status: |
|
20016 +** MT_OK - No errors |
|
20017 +** MT_TUNER_ID_ERR - Tuner Part/Rev code mismatch |
|
20018 +** MT_TUNER_INIT_ERR - Tuner initialization failed |
|
20019 +** MT_COMM_ERR - Serial bus communications error |
|
20020 +** MT_ARG_NULL - Null pointer argument passed |
|
20021 +** MT_TUNER_CNT_ERR - Too many tuners open |
|
20022 +** |
|
20023 +** Dependencies: MT_ReadSub - Read byte(s) of data from the two-wire bus |
|
20024 +** MT_WriteSub - Write byte(s) of data to the two-wire bus |
|
20025 +** |
|
20026 +** Revision History: |
|
20027 +** |
|
20028 +** SCR Date Author Description |
|
20029 +** ------------------------------------------------------------------------- |
|
20030 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
20031 +** N/A 11-01-2006 RSK Ver 1.02: Initialize Crossover Tables to Default |
|
20032 +** |
|
20033 +******************************************************************************/ |
|
20034 +UData_t MT2266_Open(UData_t MT2266_Addr, |
|
20035 + Handle_t* hMT2266, |
|
20036 + Handle_t hUserData) |
|
20037 +{ |
|
20038 + UData_t status = MT_OK; /* Status to be returned. */ |
|
20039 + SData_t i, j; |
|
20040 + MT2266_Info_t* pInfo = MT_NULL; |
|
20041 + |
|
20042 + /* Check the argument before using */ |
|
20043 + if (hMT2266 == MT_NULL) |
|
20044 + return MT_ARG_NULL; |
|
20045 + *hMT2266 = MT_NULL; |
|
20046 + |
|
20047 + /* |
|
20048 + ** If this is our first tuner, initialize the address fields and |
|
20049 + ** the list of available control blocks. |
|
20050 + */ |
|
20051 + if (nOpenTuners == 0) |
|
20052 + { |
|
20053 + for (i=MT2266_CNT-1; i>=0; i--) |
|
20054 + { |
|
20055 + MT2266_Info[i].handle = MT_NULL; |
|
20056 + MT2266_Info[i].address = MAX_UDATA; |
|
20057 + MT2266_Info[i].hUserData = MT_NULL; |
|
20058 + |
|
20059 + /* Reset the UHF Crossover Frequency tables on open/init. */ |
|
20060 + for (j=0; j< MT2266_NUM_XFREQS; j++ ) |
|
20061 + { |
|
20062 + MT2266_Info[i].xfreqs.xfreq[MT2266_UHF0][j] = MT2266_default_XFreqs.xfreq[MT2266_UHF0][j]; |
|
20063 + MT2266_Info[i].xfreqs.xfreq[MT2266_UHF1][j] = MT2266_default_XFreqs.xfreq[MT2266_UHF1][j]; |
|
20064 + MT2266_Info[i].xfreqs.xfreq[MT2266_UHF0_ATTEN][j] = MT2266_default_XFreqs.xfreq[MT2266_UHF0_ATTEN][j]; |
|
20065 + MT2266_Info[i].xfreqs.xfreq[MT2266_UHF1_ATTEN][j] = MT2266_default_XFreqs.xfreq[MT2266_UHF1_ATTEN][j]; |
|
20066 + } |
|
20067 + |
|
20068 + Avail[i] = &MT2266_Info[i]; |
|
20069 + } |
|
20070 + } |
|
20071 + |
|
20072 + /* |
|
20073 + ** Look for an existing MT2266_State_t entry with this address. |
|
20074 + */ |
|
20075 + for (i=MT2266_CNT-1; i>=0; i--) |
|
20076 + { |
|
20077 + /* |
|
20078 + ** If an open'ed handle provided, we'll re-initialize that structure. |
|
20079 + ** |
|
20080 + ** We recognize an open tuner because the address and hUserData are |
|
20081 + ** the same as one that has already been opened |
|
20082 + */ |
|
20083 + if ((MT2266_Info[i].address == MT2266_Addr) && |
|
20084 + (MT2266_Info[i].hUserData == hUserData)) |
|
20085 + { |
|
20086 + pInfo = &MT2266_Info[i]; |
|
20087 + break; |
|
20088 + } |
|
20089 + } |
|
20090 + |
|
20091 + /* If not found, choose an empty spot. */ |
|
20092 + if (pInfo == MT_NULL) |
|
20093 + { |
|
20094 + /* Check to see that we're not over-allocating. */ |
|
20095 + if (nOpenTuners == MT2266_CNT) |
|
20096 + return MT_TUNER_CNT_ERR; |
|
20097 + |
|
20098 + /* Use the next available block from the list */ |
|
20099 + pInfo = Avail[nOpenTuners]; |
|
20100 + nOpenTuners++; |
|
20101 + } |
|
20102 + |
|
20103 + pInfo->handle = (Handle_t) pInfo; |
|
20104 + pInfo->hUserData = hUserData; |
|
20105 + pInfo->address = MT2266_Addr; |
|
20106 + |
|
20107 +// status |= MT2266_ReInit((Handle_t) pInfo); |
|
20108 + |
|
20109 + if (MT_IS_ERROR(status)) |
|
20110 + MT2266_Close((Handle_t) pInfo); |
|
20111 + else |
|
20112 + *hMT2266 = pInfo->handle; |
|
20113 + |
|
20114 + return (status); |
|
20115 +} |
|
20116 + |
|
20117 + |
|
20118 +static UData_t IsValidHandle(MT2266_Info_t* handle) |
|
20119 +{ |
|
20120 + return ((handle != MT_NULL) && (handle->handle == handle)) ? 1 : 0; |
|
20121 +} |
|
20122 + |
|
20123 + |
|
20124 +/****************************************************************************** |
|
20125 +** |
|
20126 +** Name: MT2266_Close |
|
20127 +** |
|
20128 +** Description: Release the handle to the tuner. |
|
20129 +** |
|
20130 +** Parameters: hMT2266 - Handle to the MT2266 tuner |
|
20131 +** |
|
20132 +** Returns: status: |
|
20133 +** MT_OK - No errors |
|
20134 +** MT_INV_HANDLE - Invalid tuner handle |
|
20135 +** |
|
20136 +** Dependencies: mt_errordef.h - definition of error codes |
|
20137 +** |
|
20138 +** Revision History: |
|
20139 +** |
|
20140 +** SCR Date Author Description |
|
20141 +** ------------------------------------------------------------------------- |
|
20142 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
20143 +** |
|
20144 +******************************************************************************/ |
|
20145 +UData_t MT2266_Close(Handle_t hMT2266) |
|
20146 +{ |
|
20147 + MT2266_Info_t* pInfo = (MT2266_Info_t*) hMT2266; |
|
20148 + |
|
20149 + if (!IsValidHandle(pInfo)) |
|
20150 + return MT_INV_HANDLE; |
|
20151 + |
|
20152 + /* Remove the tuner from our list of tuners */ |
|
20153 + pInfo->handle = MT_NULL; |
|
20154 + pInfo->address = MAX_UDATA; |
|
20155 + pInfo->hUserData = MT_NULL; |
|
20156 + nOpenTuners--; |
|
20157 + Avail[nOpenTuners] = pInfo; /* Return control block to available list */ |
|
20158 + |
|
20159 + return MT_OK; |
|
20160 +} |
|
20161 + |
|
20162 + |
|
20163 +/****************************************************************************** |
|
20164 +** |
|
20165 +** Name: Run_BB_RC_Cal2 |
|
20166 +** |
|
20167 +** Description: Run Base Band RC Calibration (Method 2) |
|
20168 +** MT2266 B0 only, others return MT_OK |
|
20169 +** |
|
20170 +** Parameters: hMT2266 - Handle to the MT2266 tuner |
|
20171 +** |
|
20172 +** Returns: status: |
|
20173 +** MT_OK - No errors |
|
20174 +** MT_COMM_ERR - Serial bus communications error |
|
20175 +** MT_INV_HANDLE - Invalid tuner handle |
|
20176 +** |
|
20177 +** Dependencies: mt_errordef.h - definition of error codes |
|
20178 +** |
|
20179 +** Revision History: |
|
20180 +** |
|
20181 +** SCR Date Author Description |
|
20182 +** ------------------------------------------------------------------------- |
|
20183 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
20184 +** |
|
20185 +******************************************************************************/ |
|
20186 +static UData_t Run_BB_RC_Cal2(Handle_t h) |
|
20187 +{ |
|
20188 + UData_t status = MT_OK; /* Status to be returned */ |
|
20189 + U8Data tmp_rcc; |
|
20190 + U8Data dumy; |
|
20191 + |
|
20192 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
20193 + |
|
20194 + /* Verify that the handle passed points to a valid tuner */ |
|
20195 + if (IsValidHandle(pInfo) == 0) |
|
20196 + status |= MT_INV_HANDLE; |
|
20197 + |
|
20198 + /* |
|
20199 + ** Set the crystal frequency in the calibration register |
|
20200 + ** and enable RC calibration #2 |
|
20201 + */ |
|
20202 + PREFETCH(MT2266_RCC_CTRL, 1); /* Fetch register(s) if __NO_CACHE__ defined */ |
|
20203 + tmp_rcc = pInfo->reg[MT2266_RCC_CTRL]; |
|
20204 + if (pInfo->f_Ref < (36000000 /*/ TUNE_STEP_SIZE*/)) |
|
20205 + tmp_rcc = (tmp_rcc & 0xDF) | 0x10; |
|
20206 + else |
|
20207 + tmp_rcc |= 0x30; |
|
20208 + status |= UncheckedSet(pInfo, MT2266_RCC_CTRL, tmp_rcc); |
|
20209 + |
|
20210 + /* Read RC Calibration value */ |
|
20211 + status |= UncheckedGet(pInfo, MT2266_STATUS_4, &dumy); |
|
20212 + |
|
20213 + /* Disable RC Cal 2 */ |
|
20214 + status |= UncheckedSet(pInfo, MT2266_RCC_CTRL, pInfo->reg[MT2266_RCC_CTRL] & 0xEF); |
|
20215 + |
|
20216 + /* Store RC Cal 2 value */ |
|
20217 + pInfo->RC2_Value = pInfo->reg[MT2266_STATUS_4]; |
|
20218 + |
|
20219 + if (pInfo->f_Ref < (36000000 /*/ TUNE_STEP_SIZE*/)) |
|
20220 + pInfo->RC2_Nominal = (U8Data) ((pInfo->f_Ref + 77570) / 155139); |
|
20221 + else |
|
20222 + pInfo->RC2_Nominal = (U8Data) ((pInfo->f_Ref + 93077) / 186154); |
|
20223 + |
|
20224 + return (status); |
|
20225 +} |
|
20226 + |
|
20227 + |
|
20228 +/****************************************************************************** |
|
20229 +** |
|
20230 +** Name: Set_BBFilt |
|
20231 +** |
|
20232 +** Description: Set Base Band Filter bandwidth |
|
20233 +** Based on SRO frequency & BB RC Calibration |
|
20234 +** User stores channel bw as 5-8 MHz. This routine |
|
20235 +** calculates a 3 dB corner bw based on 1/2 the bandwidth |
|
20236 +** and a bandwidth related constant. |
|
20237 +** |
|
20238 +** Parameters: hMT2266 - Handle to the MT2266 tuner |
|
20239 +** |
|
20240 +** Returns: status: |
|
20241 +** MT_OK - No errors |
|
20242 +** MT_COMM_ERR - Serial bus communications error |
|
20243 +** MT_INV_HANDLE - Invalid tuner handle |
|
20244 +** |
|
20245 +** Dependencies: mt_errordef.h - definition of error codes |
|
20246 +** |
|
20247 +** Revision History: |
|
20248 +** |
|
20249 +** SCR Date Author Description |
|
20250 +** ------------------------------------------------------------------------- |
|
20251 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
20252 +** |
|
20253 +******************************************************************************/ |
|
20254 +static UData_t Set_BBFilt(Handle_t h) |
|
20255 +{ |
|
20256 + UData_t f_3dB_bw; |
|
20257 + U8Data BBFilt = 0; |
|
20258 + U8Data Sel = 0; |
|
20259 + SData_t TmpFilt; |
|
20260 + SData_t i; |
|
20261 + UData_t status = MT_OK; /* Status to be returned */ |
|
20262 + |
|
20263 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
20264 + |
|
20265 + /* Verify that the handle passed points to a valid tuner */ |
|
20266 + if (IsValidHandle(pInfo) == 0) |
|
20267 + status |= MT_INV_HANDLE; |
|
20268 + |
|
20269 + /* Check RC2_Value value */ |
|
20270 + if(pInfo->RC2_Value == 0) |
|
20271 + return MT_UNKNOWN; |
|
20272 + |
|
20273 + /* |
|
20274 + ** Convert the channel bandwidth into a 3 dB bw by dividing it by 2 |
|
20275 + ** and subtracting 300, 250, 200, or 0 kHz based on 8, 7, 6, 5 MHz |
|
20276 + ** channel bandwidth. |
|
20277 + */ |
|
20278 + f_3dB_bw = (pInfo->f_bw / 2); /* bw -> bw/2 */ |
|
20279 + if (pInfo->f_bw > 7500000) |
|
20280 + { |
|
20281 + /* >3.75 MHz corner */ |
|
20282 + f_3dB_bw -= 300000; |
|
20283 + Sel = 0x00; |
|
20284 + TmpFilt = ((429916107 / pInfo->RC2_Value) * pInfo->RC2_Nominal) / f_3dB_bw - 81; |
|
20285 + } |
|
20286 + else if (pInfo->f_bw > 6500000) |
|
20287 + { |
|
20288 + /* >3.25 MHz .. 3.75 MHz corner */ |
|
20289 + f_3dB_bw -= 250000; |
|
20290 + Sel = 0x00; |
|
20291 + TmpFilt = ((429916107 / pInfo->RC2_Value) * pInfo->RC2_Nominal) / f_3dB_bw - 81; |
|
20292 + } |
|
20293 + else if (pInfo->f_bw > 5500000) |
|
20294 + { |
|
20295 + /* >2.75 MHz .. 3.25 MHz corner */ |
|
20296 + f_3dB_bw -= 200000; |
|
20297 + Sel = 0x80; |
|
20298 + TmpFilt = ((429916107 / pInfo->RC2_Value) * pInfo->RC2_Nominal) / f_3dB_bw - 113; |
|
20299 + } |
|
20300 + else |
|
20301 + { |
|
20302 + /* <= 2.75 MHz corner */ |
|
20303 + Sel = 0xC0; |
|
20304 + TmpFilt = ((429916107 / pInfo->RC2_Value) * pInfo->RC2_Nominal) / f_3dB_bw - 129; |
|
20305 + } |
|
20306 + |
|
20307 + if (TmpFilt > 63) |
|
20308 + TmpFilt = 63; |
|
20309 + else if (TmpFilt < 0) |
|
20310 + TmpFilt = 0; |
|
20311 + BBFilt = ((U8Data) TmpFilt) | Sel; |
|
20312 + |
|
20313 + for ( i = MT2266_BBFILT_1; i <= MT2266_BBFILT_8; i++ ) |
|
20314 + pInfo->reg[i] = BBFilt; |
|
20315 + |
|
20316 + if (MT_NO_ERROR(status)) |
|
20317 + status |= MT_WriteSub(pInfo->hUserData, |
|
20318 + pInfo->address, |
|
20319 + MT2266_BBFILT_1, |
|
20320 + &pInfo->reg[MT2266_BBFILT_1], |
|
20321 + 8); |
|
20322 + |
|
20323 + return (status); |
|
20324 +} |
|
20325 + |
|
20326 + |
|
20327 +/**************************************************************************** |
|
20328 +** |
|
20329 +** Name: MT2266_GetLocked |
|
20330 +** |
|
20331 +** Description: Checks to see if the PLL is locked. |
|
20332 +** |
|
20333 +** Parameters: h - Open handle to the tuner (from MT2266_Open). |
|
20334 +** |
|
20335 +** Returns: status: |
|
20336 +** MT_OK - No errors |
|
20337 +** MT_DNC_UNLOCK - Downconverter PLL unlocked |
|
20338 +** MT_COMM_ERR - Serial bus communications error |
|
20339 +** MT_INV_HANDLE - Invalid tuner handle |
|
20340 +** |
|
20341 +** Dependencies: MT_ReadSub - Read byte(s) of data from the serial bus |
|
20342 +** MT_Sleep - Delay execution for x milliseconds |
|
20343 +** |
|
20344 +** Revision History: |
|
20345 +** |
|
20346 +** SCR Date Author Description |
|
20347 +** ------------------------------------------------------------------------- |
|
20348 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
20349 +** |
|
20350 +****************************************************************************/ |
|
20351 +UData_t MT2266_GetLocked(Handle_t h) |
|
20352 +{ |
|
20353 + const UData_t nMaxWait = 200; /* wait a maximum of 200 msec */ |
|
20354 + const UData_t nPollRate = 2; /* poll status bits every 2 ms */ |
|
20355 + const UData_t nMaxLoops = nMaxWait / nPollRate; |
|
20356 + UData_t status = MT_OK; /* Status to be returned */ |
|
20357 + UData_t nDelays = 0; |
|
20358 + U8Data statreg; |
|
20359 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
20360 + |
|
20361 + if (IsValidHandle(pInfo) == 0) |
|
20362 + return MT_INV_HANDLE; |
|
20363 + |
|
20364 + do |
|
20365 + { |
|
20366 + status |= UncheckedGet(pInfo, MT2266_STATUS_1, &statreg); |
|
20367 + |
|
20368 + if ((MT_IS_ERROR(status)) || ((statreg & 0x40) == 0x40)) |
|
20369 + return (status); |
|
20370 + |
|
20371 + MT_Sleep(pInfo->hUserData, nPollRate); /* Wait between retries */ |
|
20372 + } |
|
20373 + while (++nDelays < nMaxLoops); |
|
20374 + |
|
20375 + if ((statreg & 0x40) != 0x40) |
|
20376 + status |= MT_DNC_UNLOCK; |
|
20377 + |
|
20378 + return (status); |
|
20379 +} |
|
20380 + |
|
20381 + |
|
20382 +/**************************************************************************** |
|
20383 +** |
|
20384 +** Name: MT2266_GetParam |
|
20385 +** |
|
20386 +** Description: Gets a tuning algorithm parameter. |
|
20387 +** |
|
20388 +** This function provides access to the internals of the |
|
20389 +** tuning algorithm - mostly for testing purposes. |
|
20390 +** |
|
20391 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
20392 +** param - Tuning algorithm parameter |
|
20393 +** (see enum MT2266_Param) |
|
20394 +** pValue - ptr to returned value |
|
20395 +** |
|
20396 +** param Description |
|
20397 +** ---------------------- -------------------------------- |
|
20398 +** MT2266_IC_ADDR Serial Bus address of this tuner |
|
20399 +** MT2266_MAX_OPEN Max number of MT2266's that can be open |
|
20400 +** MT2266_NUM_OPEN Number of MT2266's currently open |
|
20401 +** MT2266_NUM_REGS Number of tuner registers |
|
20402 +** MT2266_SRO_FREQ crystal frequency |
|
20403 +** MT2266_STEPSIZE minimum tuning step size |
|
20404 +** MT2266_INPUT_FREQ input center frequency |
|
20405 +** MT2266_LO_FREQ LO Frequency |
|
20406 +** MT2266_OUTPUT_BW Output channel bandwidth |
|
20407 +** MT2266_RC2_VALUE Base band filter cal RC code (method 2) |
|
20408 +** MT2266_RC2_NOMINAL Base band filter nominal cal RC code |
|
20409 +** MT2266_RF_ADC RF attenuator A/D readback |
|
20410 +** MT2266_RF_ATTN RF attenuation (0-255) |
|
20411 +** MT2266_RF_EXT External control of RF atten |
|
20412 +** MT2266_LNA_GAIN LNA gain setting (0-15) |
|
20413 +** MT2266_BB_ADC BB attenuator A/D readback |
|
20414 +** MT2266_BB_ATTN Baseband attenuation (0-255) |
|
20415 +** MT2266_BB_EXT External control of BB atten |
|
20416 +** |
|
20417 +** Usage: status |= MT2266_GetParam(hMT2266, |
|
20418 +** MT2266_OUTPUT_BW, |
|
20419 +** &f_bw); |
|
20420 +** |
|
20421 +** Returns: status: |
|
20422 +** MT_OK - No errors |
|
20423 +** MT_INV_HANDLE - Invalid tuner handle |
|
20424 +** MT_ARG_NULL - Null pointer argument passed |
|
20425 +** MT_ARG_RANGE - Invalid parameter requested |
|
20426 +** |
|
20427 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
20428 +** |
|
20429 +** See Also: MT2266_SetParam, MT2266_Open |
|
20430 +** |
|
20431 +** Revision History: |
|
20432 +** |
|
20433 +** SCR Date Author Description |
|
20434 +** ------------------------------------------------------------------------- |
|
20435 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
20436 +** |
|
20437 +****************************************************************************/ |
|
20438 +UData_t MT2266_GetParam(Handle_t h, |
|
20439 + MT2266_Param param, |
|
20440 + UData_t* pValue) |
|
20441 +{ |
|
20442 + UData_t status = MT_OK; /* Status to be returned */ |
|
20443 + U8Data tmp; |
|
20444 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
20445 + |
|
20446 + if (pValue == MT_NULL) |
|
20447 + status |= MT_ARG_NULL; |
|
20448 + |
|
20449 + /* Verify that the handle passed points to a valid tuner */ |
|
20450 + if (IsValidHandle(pInfo) == 0) |
|
20451 + status |= MT_INV_HANDLE; |
|
20452 + |
|
20453 + if (MT_NO_ERROR(status)) |
|
20454 + { |
|
20455 + switch (param) |
|
20456 + { |
|
20457 + /* Serial Bus address of this tuner */ |
|
20458 + case MT2266_IC_ADDR: |
|
20459 + *pValue = pInfo->address; |
|
20460 + break; |
|
20461 + |
|
20462 + /* Max # of MT2266's allowed to be open */ |
|
20463 + case MT2266_MAX_OPEN: |
|
20464 + *pValue = nMaxTuners; |
|
20465 + break; |
|
20466 + |
|
20467 + /* # of MT2266's open */ |
|
20468 + case MT2266_NUM_OPEN: |
|
20469 + *pValue = nOpenTuners; |
|
20470 + break; |
|
20471 + |
|
20472 + /* Number of tuner registers */ |
|
20473 + case MT2266_NUM_REGS: |
|
20474 + *pValue = Num_Registers; |
|
20475 + break; |
|
20476 + |
|
20477 + /* crystal frequency */ |
|
20478 + case MT2266_SRO_FREQ: |
|
20479 + *pValue = pInfo->f_Ref; |
|
20480 + break; |
|
20481 + |
|
20482 + /* minimum tuning step size */ |
|
20483 + case MT2266_STEPSIZE: |
|
20484 + *pValue = pInfo->f_Step; |
|
20485 + break; |
|
20486 + |
|
20487 + /* input center frequency */ |
|
20488 + case MT2266_INPUT_FREQ: |
|
20489 + *pValue = pInfo->f_in; |
|
20490 + break; |
|
20491 + |
|
20492 + /* LO Frequency */ |
|
20493 + case MT2266_LO_FREQ: |
|
20494 + *pValue = pInfo->f_LO; |
|
20495 + break; |
|
20496 + |
|
20497 + /* Output Channel Bandwidth */ |
|
20498 + case MT2266_OUTPUT_BW: |
|
20499 + *pValue = pInfo->f_bw; |
|
20500 + break; |
|
20501 + |
|
20502 + /* Base band filter cal RC code */ |
|
20503 + case MT2266_RC2_VALUE: |
|
20504 + *pValue = (UData_t) pInfo->RC2_Value; |
|
20505 + break; |
|
20506 + |
|
20507 + /* Base band filter nominal cal RC code */ |
|
20508 + case MT2266_RC2_NOMINAL: |
|
20509 + *pValue = (UData_t) pInfo->RC2_Nominal; |
|
20510 + break; |
|
20511 + |
|
20512 + /* RF attenuator A/D readback */ |
|
20513 + case MT2266_RF_ADC: |
|
20514 + status |= UncheckedGet(pInfo, MT2266_STATUS_2, &tmp); |
|
20515 + if (MT_NO_ERROR(status)) |
|
20516 + *pValue = (UData_t) tmp; |
|
20517 + break; |
|
20518 + |
|
20519 + /* BB attenuator A/D readback */ |
|
20520 + case MT2266_BB_ADC: |
|
20521 + status |= UncheckedGet(pInfo, MT2266_STATUS_3, &tmp); |
|
20522 + if (MT_NO_ERROR(status)) |
|
20523 + *pValue = (UData_t) tmp; |
|
20524 + break; |
|
20525 + |
|
20526 + /* RF attenuator setting */ |
|
20527 + case MT2266_RF_ATTN: |
|
20528 + PREFETCH(MT2266_RSVD_1F, 1); /* Fetch register(s) if __NO_CACHE__ defined */ |
|
20529 + if (MT_NO_ERROR(status)) |
|
20530 + *pValue = pInfo->reg[MT2266_RSVD_1F]; |
|
20531 + break; |
|
20532 + |
|
20533 + /* BB attenuator setting */ |
|
20534 + case MT2266_BB_ATTN: |
|
20535 + PREFETCH(MT2266_RSVD_2C, 3); /* Fetch register(s) if __NO_CACHE__ defined */ |
|
20536 + *pValue = pInfo->reg[MT2266_RSVD_2C] |
|
20537 + + pInfo->reg[MT2266_RSVD_2D] |
|
20538 + + pInfo->reg[MT2266_RSVD_2E] - 3; |
|
20539 + break; |
|
20540 + |
|
20541 + /* RF external / internal atten control */ |
|
20542 + case MT2266_RF_EXT: |
|
20543 + PREFETCH(MT2266_GPO, 1); /* Fetch register(s) if __NO_CACHE__ defined */ |
|
20544 + *pValue = ((pInfo->reg[MT2266_GPO] & 0x40) != 0x00); |
|
20545 + break; |
|
20546 + |
|
20547 + /* BB external / internal atten control */ |
|
20548 + case MT2266_BB_EXT: |
|
20549 + PREFETCH(MT2266_RSVD_33, 1); /* Fetch register(s) if __NO_CACHE__ defined */ |
|
20550 + *pValue = ((pInfo->reg[MT2266_RSVD_33] & 0x10) != 0x00); |
|
20551 + break; |
|
20552 + |
|
20553 + /* LNA gain setting (0-15) */ |
|
20554 + case MT2266_LNA_GAIN: |
|
20555 + PREFETCH(MT2266_IGAIN, 1); /* Fetch register(s) if __NO_CACHE__ defined */ |
|
20556 + *pValue = ((pInfo->reg[MT2266_IGAIN] & 0x3C) >> 2); |
|
20557 + break; |
|
20558 + |
|
20559 + case MT2266_EOP: |
|
20560 + default: |
|
20561 + status |= MT_ARG_RANGE; |
|
20562 + } |
|
20563 + } |
|
20564 + return (status); |
|
20565 +} |
|
20566 + |
|
20567 + |
|
20568 +/**************************************************************************** |
|
20569 +** LOCAL FUNCTION - DO NOT USE OUTSIDE OF mt2266.c |
|
20570 +** |
|
20571 +** Name: UncheckedGet |
|
20572 +** |
|
20573 +** Description: Gets an MT2266 register with minimal checking |
|
20574 +** |
|
20575 +** NOTE: This is a local function that performs the same |
|
20576 +** steps as the MT2266_GetReg function that is available |
|
20577 +** in the external API. It does not do any of the standard |
|
20578 +** error checking that the API function provides and should |
|
20579 +** not be called from outside this file. |
|
20580 +** |
|
20581 +** Parameters: *pInfo - Tuner control structure |
|
20582 +** reg - MT2266 register/subaddress location |
|
20583 +** *val - MT2266 register/subaddress value |
|
20584 +** |
|
20585 +** Returns: status: |
|
20586 +** MT_OK - No errors |
|
20587 +** MT_COMM_ERR - Serial bus communications error |
|
20588 +** MT_INV_HANDLE - Invalid tuner handle |
|
20589 +** MT_ARG_NULL - Null pointer argument passed |
|
20590 +** MT_ARG_RANGE - Argument out of range |
|
20591 +** |
|
20592 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
20593 +** |
|
20594 +** Use this function if you need to read a register from |
|
20595 +** the MT2266. |
|
20596 +** |
|
20597 +** Revision History: |
|
20598 +** |
|
20599 +** SCR Date Author Description |
|
20600 +** ------------------------------------------------------------------------- |
|
20601 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
20602 +** |
|
20603 +****************************************************************************/ |
|
20604 +static UData_t UncheckedGet(MT2266_Info_t* pInfo, |
|
20605 + U8Data reg, |
|
20606 + U8Data* val) |
|
20607 +{ |
|
20608 + UData_t status; /* Status to be returned */ |
|
20609 + |
|
20610 +#if defined(_DEBUG) |
|
20611 + status = MT_OK; |
|
20612 + /* Verify that the handle passed points to a valid tuner */ |
|
20613 + if (IsValidHandle(pInfo) == 0) |
|
20614 + status |= MT_INV_HANDLE; |
|
20615 + |
|
20616 + if (val == MT_NULL) |
|
20617 + status |= MT_ARG_NULL; |
|
20618 + |
|
20619 + if (reg >= END_REGS) |
|
20620 + status |= MT_ARG_RANGE; |
|
20621 + |
|
20622 + if (MT_IS_ERROR(status)) |
|
20623 + return(status); |
|
20624 +#endif |
|
20625 + |
|
20626 + status = MT_ReadSub(pInfo->hUserData, pInfo->address, reg, &pInfo->reg[reg], 1); |
|
20627 + |
|
20628 + if (MT_NO_ERROR(status)) |
|
20629 + *val = pInfo->reg[reg]; |
|
20630 + |
|
20631 + return (status); |
|
20632 +} |
|
20633 + |
|
20634 + |
|
20635 +/**************************************************************************** |
|
20636 +** |
|
20637 +** Name: MT2266_GetReg |
|
20638 +** |
|
20639 +** Description: Gets an MT2266 register. |
|
20640 +** |
|
20641 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
20642 +** reg - MT2266 register/subaddress location |
|
20643 +** *val - MT2266 register/subaddress value |
|
20644 +** |
|
20645 +** Returns: status: |
|
20646 +** MT_OK - No errors |
|
20647 +** MT_COMM_ERR - Serial bus communications error |
|
20648 +** MT_INV_HANDLE - Invalid tuner handle |
|
20649 +** MT_ARG_NULL - Null pointer argument passed |
|
20650 +** MT_ARG_RANGE - Argument out of range |
|
20651 +** |
|
20652 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
20653 +** |
|
20654 +** Use this function if you need to read a register from |
|
20655 +** the MT2266. |
|
20656 +** |
|
20657 +** Revision History: |
|
20658 +** |
|
20659 +** SCR Date Author Description |
|
20660 +** ------------------------------------------------------------------------- |
|
20661 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
20662 +** |
|
20663 +****************************************************************************/ |
|
20664 +UData_t MT2266_GetReg(Handle_t h, |
|
20665 + U8Data reg, |
|
20666 + U8Data* val) |
|
20667 +{ |
|
20668 + UData_t status = MT_OK; /* Status to be returned */ |
|
20669 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
20670 + |
|
20671 + /* Verify that the handle passed points to a valid tuner */ |
|
20672 + if (IsValidHandle(pInfo) == 0) |
|
20673 + status |= MT_INV_HANDLE; |
|
20674 + |
|
20675 + if (val == MT_NULL) |
|
20676 + status |= MT_ARG_NULL; |
|
20677 + |
|
20678 + if (reg >= END_REGS) |
|
20679 + status |= MT_ARG_RANGE; |
|
20680 + |
|
20681 + if (MT_NO_ERROR(status)) |
|
20682 + status |= UncheckedGet(pInfo, reg, val); |
|
20683 + |
|
20684 + return (status); |
|
20685 +} |
|
20686 + |
|
20687 + |
|
20688 +/**************************************************************************** |
|
20689 +** |
|
20690 +** Name: MT2266_GetUHFXFreqs |
|
20691 +** |
|
20692 +** Description: Retrieves the specified set of UHF Crossover Frequencies |
|
20693 +** |
|
20694 +** Parameters: h - Open handle to the tuner (from MT2266_Open). |
|
20695 +** |
|
20696 +** Usage: MT2266_Freq_Set tmpFreqs; |
|
20697 +** status = MT2266_GetUHFXFreqs(hMT2266, |
|
20698 +** MT2266_UHF1_WITH_ATTENUATION, |
|
20699 +** tmpFreqs ); |
|
20700 +** if (status & MT_ARG_RANGE) |
|
20701 +** // error, Invalid UHF Crossover Frequency Set requested. |
|
20702 +** else |
|
20703 +** for( int i = 0; i < MT2266_NUM_XFREQS; i++ ) |
|
20704 +** . . . |
|
20705 +** |
|
20706 +** |
|
20707 +** Returns: status: |
|
20708 +** MT_OK - No errors |
|
20709 +** MT_ARG_RANGE - freq_type is out of range. |
|
20710 +** MT_INV_HANDLE - Invalid tuner handle |
|
20711 +** |
|
20712 +** Dependencies: freqs_buffer *must* be defined of type MT2266_Freq_Set |
|
20713 +** to assure sufficient space allocation! |
|
20714 +** |
|
20715 +** USERS MUST CALL MT2266_Open() FIRST! |
|
20716 +** |
|
20717 +** See Also: MT2266_SetUHFXFreqs |
|
20718 +** |
|
20719 +** Revision History: |
|
20720 +** |
|
20721 +** SCR Date Author Description |
|
20722 +** ------------------------------------------------------------------------- |
|
20723 +** N/A 10-26-2006 RSK Original. |
|
20724 +** |
|
20725 +****************************************************************************/ |
|
20726 +UData_t MT2266_GetUHFXFreqs(Handle_t h, |
|
20727 + MT2266_UHFXFreq_Type freq_type, |
|
20728 + MT2266_XFreq_Set freqs_buffer) |
|
20729 +{ |
|
20730 + UData_t status = MT_OK; /* Status to be returned */ |
|
20731 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
20732 + |
|
20733 + /* Verify that the handle passed points to a valid tuner */ |
|
20734 + if (IsValidHandle(pInfo) == 0) |
|
20735 + status = MT_INV_HANDLE; |
|
20736 + |
|
20737 + if (freq_type >= MT2266_NUMBER_OF_XFREQ_SETS) |
|
20738 + status |= MT_ARG_RANGE; |
|
20739 + |
|
20740 + if (MT_NO_ERROR(status)) |
|
20741 + { |
|
20742 + int i; |
|
20743 + |
|
20744 + for( i = 0; i < MT2266_NUM_XFREQS; i++ ) |
|
20745 + { |
|
20746 + freqs_buffer[i] = pInfo->xfreqs.xfreq[ freq_type ][i] * TUNE_STEP_SIZE / 1000; |
|
20747 + } |
|
20748 + } |
|
20749 + |
|
20750 + return (status); |
|
20751 +} |
|
20752 + |
|
20753 + |
|
20754 +/**************************************************************************** |
|
20755 +** |
|
20756 +** Name: MT2266_GetUserData |
|
20757 +** |
|
20758 +** Description: Gets the user-defined data item. |
|
20759 +** |
|
20760 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
20761 +** |
|
20762 +** Returns: status: |
|
20763 +** MT_OK - No errors |
|
20764 +** MT_INV_HANDLE - Invalid tuner handle |
|
20765 +** MT_ARG_NULL - Null pointer argument passed |
|
20766 +** |
|
20767 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
20768 +** |
|
20769 +** The hUserData parameter is a user-specific argument |
|
20770 +** that is stored internally with the other tuner- |
|
20771 +** specific information. |
|
20772 +** |
|
20773 +** For example, if additional arguments are needed |
|
20774 +** for the user to identify the device communicating |
|
20775 +** with the tuner, this argument can be used to supply |
|
20776 +** the necessary information. |
|
20777 +** |
|
20778 +** The hUserData parameter is initialized in the tuner's |
|
20779 +** Open function to NULL. |
|
20780 +** |
|
20781 +** See Also: MT2266_SetUserData, MT2266_Open |
|
20782 +** |
|
20783 +** Revision History: |
|
20784 +** |
|
20785 +** SCR Date Author Description |
|
20786 +** ------------------------------------------------------------------------- |
|
20787 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
20788 +** |
|
20789 +****************************************************************************/ |
|
20790 +UData_t MT2266_GetUserData(Handle_t h, |
|
20791 + Handle_t* hUserData) |
|
20792 +{ |
|
20793 + UData_t status = MT_OK; /* Status to be returned */ |
|
20794 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
20795 + |
|
20796 + /* Verify that the handle passed points to a valid tuner */ |
|
20797 + if (IsValidHandle(pInfo) == 0) |
|
20798 + status = MT_INV_HANDLE; |
|
20799 + |
|
20800 + if (hUserData == MT_NULL) |
|
20801 + status |= MT_ARG_NULL; |
|
20802 + |
|
20803 + if (MT_NO_ERROR(status)) |
|
20804 + *hUserData = pInfo->hUserData; |
|
20805 + |
|
20806 + return (status); |
|
20807 +} |
|
20808 + |
|
20809 + |
|
20810 +/****************************************************************************** |
|
20811 +** |
|
20812 +** Name: MT2266_ReInit |
|
20813 +** |
|
20814 +** Description: Initialize the tuner's register values. |
|
20815 +** |
|
20816 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
20817 +** |
|
20818 +** Returns: status: |
|
20819 +** MT_OK - No errors |
|
20820 +** MT_TUNER_ID_ERR - Tuner Part/Rev code mismatch |
|
20821 +** MT_TUNER_INIT_ERR - Tuner initialization failed |
|
20822 +** MT_INV_HANDLE - Invalid tuner handle |
|
20823 +** MT_COMM_ERR - Serial bus communications error |
|
20824 +** |
|
20825 +** Dependencies: MT_ReadSub - Read byte(s) of data from the two-wire bus |
|
20826 +** MT_WriteSub - Write byte(s) of data to the two-wire bus |
|
20827 +** |
|
20828 +** Revision History: |
|
20829 +** |
|
20830 +** SCR Date Author Description |
|
20831 +** ------------------------------------------------------------------------- |
|
20832 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
20833 +** N/A 06-08-2006 JWS Ver 1.01: Corrected problem with tuner ID check |
|
20834 +** N/A 11-01-2006 RSK Ver 1.02: Initialize XFreq Tables to Default |
|
20835 +** N/A 11-29-2006 DAD Ver 1.03: Parenthesis clarification |
|
20836 +** |
|
20837 +******************************************************************************/ |
|
20838 +UData_t MT2266_ReInit(Handle_t h) |
|
20839 +{ |
|
20840 + int j; |
|
20841 + |
|
20842 + U8Data MT2266_Init_Defaults1[] = |
|
20843 + { |
|
20844 + 0x01, /* Start w/register 0x01 */ |
|
20845 + 0x00, /* Reg 0x01 */ |
|
20846 + 0x00, /* Reg 0x02 */ |
|
20847 + 0x28, /* Reg 0x03 */ |
|
20848 + 0x00, /* Reg 0x04 */ |
|
20849 + 0x52, /* Reg 0x05 */ |
|
20850 + 0x99, /* Reg 0x06 */ |
|
20851 + 0x3F, /* Reg 0x07 */ |
|
20852 + }; |
|
20853 + |
|
20854 + U8Data MT2266_Init_Defaults2[] = |
|
20855 + { |
|
20856 + 0x17, /* Start w/register 0x17 */ |
|
20857 + 0x6D, /* Reg 0x17 */ |
|
20858 + 0x71, /* Reg 0x18 */ |
|
20859 + 0x61, /* Reg 0x19 */ |
|
20860 + 0xC0, /* Reg 0x1A */ |
|
20861 + 0xBF, /* Reg 0x1B */ |
|
20862 + 0xFF, /* Reg 0x1C */ |
|
20863 + 0xDC, /* Reg 0x1D */ |
|
20864 + 0x00, /* Reg 0x1E */ |
|
20865 + 0x0A, /* Reg 0x1F */ |
|
20866 + 0xD4, /* Reg 0x20 */ |
|
20867 + 0x03, /* Reg 0x21 */ |
|
20868 + 0x64, /* Reg 0x22 */ |
|
20869 + 0x64, /* Reg 0x23 */ |
|
20870 + 0x64, /* Reg 0x24 */ |
|
20871 + 0x64, /* Reg 0x25 */ |
|
20872 + 0x22, /* Reg 0x26 */ |
|
20873 + 0xAA, /* Reg 0x27 */ |
|
20874 + 0xF2, /* Reg 0x28 */ |
|
20875 + 0x1E, /* Reg 0x29 */ |
|
20876 + 0x80, /* Reg 0x2A */ |
|
20877 + 0x14, /* Reg 0x2B */ |
|
20878 + 0x01, /* Reg 0x2C */ |
|
20879 + 0x01, /* Reg 0x2D */ |
|
20880 + 0x01, /* Reg 0x2E */ |
|
20881 + 0x01, /* Reg 0x2F */ |
|
20882 + 0x01, /* Reg 0x30 */ |
|
20883 + 0x01, /* Reg 0x31 */ |
|
20884 + 0x7F, /* Reg 0x32 */ |
|
20885 + 0x5E, /* Reg 0x33 */ |
|
20886 + 0x3F, /* Reg 0x34 */ |
|
20887 + 0xFF, /* Reg 0x35 */ |
|
20888 + 0xFF, /* Reg 0x36 */ |
|
20889 + 0xFF, /* Reg 0x37 */ |
|
20890 + 0x00, /* Reg 0x38 */ |
|
20891 + 0x77, /* Reg 0x39 */ |
|
20892 + 0x0F, /* Reg 0x3A */ |
|
20893 + 0x2D, /* Reg 0x3B */ |
|
20894 + }; |
|
20895 + |
|
20896 + UData_t status = MT_OK; /* Status to be returned */ |
|
20897 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
20898 + U8Data BBVref; |
|
20899 + U8Data tmpreg = 0; |
|
20900 + U8Data statusreg = 0; |
|
20901 + |
|
20902 + /* Verify that the handle passed points to a valid tuner */ |
|
20903 + if (IsValidHandle(pInfo) == 0) |
|
20904 + status |= MT_INV_HANDLE; |
|
20905 + |
|
20906 + /* Read the Part/Rev code from the tuner */ |
|
20907 + if (MT_NO_ERROR(status)) |
|
20908 + status |= UncheckedGet(pInfo, MT2266_PART_REV, &tmpreg); |
|
20909 + if (MT_NO_ERROR(status) && (tmpreg != 0x85)) // MT226? B0 |
|
20910 + status |= MT_TUNER_ID_ERR; |
|
20911 + else |
|
20912 + { |
|
20913 + /* |
|
20914 + ** Read the status register 5 |
|
20915 + */ |
|
20916 + tmpreg = pInfo->reg[MT2266_RSVD_11] |= 0x03; |
|
20917 + if (MT_NO_ERROR(status)) |
|
20918 + status |= UncheckedSet(pInfo, MT2266_RSVD_11, tmpreg); |
|
20919 + tmpreg &= ~(0x02); |
|
20920 + if (MT_NO_ERROR(status)) |
|
20921 + status |= UncheckedSet(pInfo, MT2266_RSVD_11, tmpreg); |
|
20922 + |
|
20923 + /* Get and store the status 5 register value */ |
|
20924 + if (MT_NO_ERROR(status)) |
|
20925 + status |= UncheckedGet(pInfo, MT2266_STATUS_5, &statusreg); |
|
20926 + |
|
20927 + /* MT2266 */ |
|
20928 + if (MT_IS_ERROR(status) || ((statusreg & 0x30) != 0x30)) |
|
20929 + status |= MT_TUNER_ID_ERR; /* Wrong tuner Part/Rev code */ |
|
20930 + } |
|
20931 + |
|
20932 + if (MT_NO_ERROR(status)) |
|
20933 + { |
|
20934 + /* Initialize the tuner state. Hold off on f_in and f_LO */ |
|
20935 + pInfo->version = VERSION; |
|
20936 + pInfo->tuner_id = pInfo->reg[MT2266_PART_REV]; |
|
20937 + pInfo->f_Ref = REF_FREQ; |
|
20938 + pInfo->f_Step = TUNE_STEP_SIZE * 1000; /* kHz -> Hz */ |
|
20939 + pInfo->f_in = UHF_DEFAULT_FREQ; |
|
20940 + pInfo->f_LO = UHF_DEFAULT_FREQ; |
|
20941 + pInfo->f_bw = OUTPUT_BW; |
|
20942 + pInfo->band = MT2266_UHF_BAND; |
|
20943 + pInfo->num_regs = END_REGS; |
|
20944 + |
|
20945 + /* Reset the UHF Crossover Frequency tables on open/init. */ |
|
20946 + for (j=0; j< MT2266_NUM_XFREQS; j++ ) |
|
20947 + { |
|
20948 + pInfo->xfreqs.xfreq[MT2266_UHF0][j] = MT2266_default_XFreqs.xfreq[MT2266_UHF0][j]; |
|
20949 + pInfo->xfreqs.xfreq[MT2266_UHF1][j] = MT2266_default_XFreqs.xfreq[MT2266_UHF1][j]; |
|
20950 + pInfo->xfreqs.xfreq[MT2266_UHF0_ATTEN][j] = MT2266_default_XFreqs.xfreq[MT2266_UHF0_ATTEN][j]; |
|
20951 + pInfo->xfreqs.xfreq[MT2266_UHF1_ATTEN][j] = MT2266_default_XFreqs.xfreq[MT2266_UHF1_ATTEN][j]; |
|
20952 + } |
|
20953 + |
|
20954 + /* Write the default values to the tuner registers. Default mode is UHF */ |
|
20955 + status |= MT_WriteSub(pInfo->hUserData, |
|
20956 + pInfo->address, |
|
20957 + MT2266_Init_Defaults1[0], |
|
20958 + &MT2266_Init_Defaults1[1], |
|
20959 + sizeof(MT2266_Init_Defaults1)/sizeof(U8Data)-1); |
|
20960 + status |= MT_WriteSub(pInfo->hUserData, |
|
20961 + pInfo->address, |
|
20962 + MT2266_Init_Defaults2[0], |
|
20963 + &MT2266_Init_Defaults2[1], |
|
20964 + sizeof(MT2266_Init_Defaults2)/sizeof(U8Data)-1); |
|
20965 + } |
|
20966 + |
|
20967 + /* Read back all the registers from the tuner */ |
|
20968 + if (MT_NO_ERROR(status)) |
|
20969 + { |
|
20970 + status |= MT_ReadSub(pInfo->hUserData, pInfo->address, 0, &pInfo->reg[0], END_REGS); |
|
20971 + } |
|
20972 + |
|
20973 + /* |
|
20974 + ** Set reg[0x33] based on statusreg |
|
20975 + */ |
|
20976 + if (MT_NO_ERROR(status)) |
|
20977 + { |
|
20978 + BBVref = (((statusreg >> 6) + 2) & 0x03); |
|
20979 + tmpreg = (pInfo->reg[MT2266_RSVD_33] & ~(0x60)) | (BBVref << 5); |
|
20980 + status |= UncheckedSet(pInfo, MT2266_RSVD_33, tmpreg); |
|
20981 + } |
|
20982 + |
|
20983 + /* Run the baseband filter calibration */ |
|
20984 + if (MT_NO_ERROR(status)) |
|
20985 + status |= Run_BB_RC_Cal2(h); |
|
20986 + |
|
20987 + /* Set the baseband filter bandwidth to the default */ |
|
20988 + if (MT_NO_ERROR(status)) |
|
20989 + status |= Set_BBFilt(h); |
|
20990 + |
|
20991 + return (status); |
|
20992 +} |
|
20993 + |
|
20994 + |
|
20995 +/**************************************************************************** |
|
20996 +** |
|
20997 +** Name: MT2266_SetParam |
|
20998 +** |
|
20999 +** Description: Sets a tuning algorithm parameter. |
|
21000 +** |
|
21001 +** This function provides access to the internals of the |
|
21002 +** tuning algorithm. You can override many of the tuning |
|
21003 +** algorithm defaults using this function. |
|
21004 +** |
|
21005 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
21006 +** param - Tuning algorithm parameter |
|
21007 +** (see enum MT2266_Param) |
|
21008 +** nValue - value to be set |
|
21009 +** |
|
21010 +** param Description |
|
21011 +** ---------------------- -------------------------------- |
|
21012 +** MT2266_SRO_FREQ crystal frequency |
|
21013 +** MT2266_STEPSIZE minimum tuning step size |
|
21014 +** MT2266_INPUT_FREQ Center of input channel |
|
21015 +** MT2266_OUTPUT_BW Output channel bandwidth |
|
21016 +** MT2266_RF_ATTN RF attenuation (0-255) |
|
21017 +** MT2266_RF_EXT External control of RF atten |
|
21018 +** MT2266_LNA_GAIN LNA gain setting (0-15) |
|
21019 +** MT2266_LNA_GAIN_DECR Decrement LNA Gain (arg=min) |
|
21020 +** MT2266_LNA_GAIN_INCR Increment LNA Gain (arg=max) |
|
21021 +** MT2266_BB_ATTN Baseband attenuation (0-255) |
|
21022 +** MT2266_BB_EXT External control of BB atten |
|
21023 +** MT2266_UHF_MAXSENS Set for UHF max sensitivity mode |
|
21024 +** MT2266_UHF_NORMAL Set for UHF normal mode |
|
21025 +** |
|
21026 +** Usage: status |= MT2266_SetParam(hMT2266, |
|
21027 +** MT2266_STEPSIZE, |
|
21028 +** 50000); |
|
21029 +** |
|
21030 +** Returns: status: |
|
21031 +** MT_OK - No errors |
|
21032 +** MT_INV_HANDLE - Invalid tuner handle |
|
21033 +** MT_ARG_RANGE - Invalid parameter requested |
|
21034 +** or set value out of range |
|
21035 +** or non-writable parameter |
|
21036 +** |
|
21037 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
21038 +** |
|
21039 +** See Also: MT2266_GetParam, MT2266_Open |
|
21040 +** |
|
21041 +** Revision History: |
|
21042 +** |
|
21043 +** SCR Date Author Description |
|
21044 +** ------------------------------------------------------------------------- |
|
21045 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
21046 +** N/A 11-29-2006 DAD Ver 1.03: Parenthesis clarification for gcc |
|
21047 +** |
|
21048 +****************************************************************************/ |
|
21049 +UData_t MT2266_SetParam(Handle_t h, |
|
21050 + MT2266_Param param, |
|
21051 + UData_t nValue) |
|
21052 +{ |
|
21053 + UData_t status = MT_OK; /* Status to be returned */ |
|
21054 + U8Data tmpreg; |
|
21055 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
21056 + |
|
21057 + /* Verify that the handle passed points to a valid tuner */ |
|
21058 + if (IsValidHandle(pInfo) == 0) |
|
21059 + status |= MT_INV_HANDLE; |
|
21060 + |
|
21061 + if (MT_NO_ERROR(status)) |
|
21062 + { |
|
21063 + switch (param) |
|
21064 + { |
|
21065 + /* crystal frequency */ |
|
21066 + case MT2266_SRO_FREQ: |
|
21067 + pInfo->f_Ref = nValue; |
|
21068 + if (pInfo->f_Ref < 22000000) |
|
21069 + { |
|
21070 + /* Turn off f_SRO divide by 2 */ |
|
21071 + status |= UncheckedSet(pInfo, |
|
21072 + MT2266_SRO_CTRL, |
|
21073 + (U8Data) (pInfo->reg[MT2266_SRO_CTRL] &= 0xFE)); |
|
21074 + } |
|
21075 + else |
|
21076 + { |
|
21077 + /* Turn on f_SRO divide by 2 */ |
|
21078 + status |= UncheckedSet(pInfo, |
|
21079 + MT2266_SRO_CTRL, |
|
21080 + (U8Data) (pInfo->reg[MT2266_SRO_CTRL] |= 0x01)); |
|
21081 + } |
|
21082 + status |= Run_BB_RC_Cal2(h); |
|
21083 + if (MT_NO_ERROR(status)) |
|
21084 + status |= Set_BBFilt(h); |
|
21085 + break; |
|
21086 + |
|
21087 + /* minimum tuning step size */ |
|
21088 + case MT2266_STEPSIZE: |
|
21089 + pInfo->f_Step = nValue; |
|
21090 + break; |
|
21091 + |
|
21092 + /* Width of output channel */ |
|
21093 + case MT2266_OUTPUT_BW: |
|
21094 + pInfo->f_bw = nValue; |
|
21095 + status |= Set_BBFilt(h); |
|
21096 + break; |
|
21097 + |
|
21098 + /* BB attenuation (0-255) */ |
|
21099 + case MT2266_BB_ATTN: |
|
21100 + if (nValue > 255) |
|
21101 + status |= MT_ARG_RANGE; |
|
21102 + else |
|
21103 + { |
|
21104 + UData_t BBA_Stage1; |
|
21105 + UData_t BBA_Stage2; |
|
21106 + UData_t BBA_Stage3; |
|
21107 + |
|
21108 + BBA_Stage3 = (nValue > 102) ? 103 : nValue + 1; |
|
21109 + BBA_Stage2 = (nValue > 175) ? 75 : nValue + 2 - BBA_Stage3; |
|
21110 + BBA_Stage1 = (nValue > 176) ? nValue - 175 : 1; |
|
21111 + pInfo->reg[MT2266_RSVD_2C] = (U8Data) BBA_Stage1; |
|
21112 + pInfo->reg[MT2266_RSVD_2D] = (U8Data) BBA_Stage2; |
|
21113 + pInfo->reg[MT2266_RSVD_2E] = (U8Data) BBA_Stage3; |
|
21114 + pInfo->reg[MT2266_RSVD_2F] = (U8Data) BBA_Stage1; |
|
21115 + pInfo->reg[MT2266_RSVD_30] = (U8Data) BBA_Stage2; |
|
21116 + pInfo->reg[MT2266_RSVD_31] = (U8Data) BBA_Stage3; |
|
21117 + status |= MT_WriteSub(pInfo->hUserData, |
|
21118 + pInfo->address, |
|
21119 + MT2266_RSVD_2C, |
|
21120 + &pInfo->reg[MT2266_RSVD_2C], |
|
21121 + 6); |
|
21122 + } |
|
21123 + break; |
|
21124 + |
|
21125 + /* RF attenuation (0-255) */ |
|
21126 + case MT2266_RF_ATTN: |
|
21127 + if (nValue > 255) |
|
21128 + status |= MT_ARG_RANGE; |
|
21129 + else |
|
21130 + status |= UncheckedSet(pInfo, MT2266_RSVD_1F, (U8Data) nValue); |
|
21131 + break; |
|
21132 + |
|
21133 + /* RF external / internal atten control */ |
|
21134 + case MT2266_RF_EXT: |
|
21135 + if (nValue == 0) |
|
21136 + tmpreg = pInfo->reg[MT2266_GPO] &= ~0x40; |
|
21137 + else |
|
21138 + tmpreg = pInfo->reg[MT2266_GPO] |= 0x40; |
|
21139 + status |= UncheckedSet(pInfo, MT2266_GPO, tmpreg); |
|
21140 + break; |
|
21141 + |
|
21142 + /* LNA gain setting (0-15) */ |
|
21143 + case MT2266_LNA_GAIN: |
|
21144 + if (nValue > 15) |
|
21145 + status |= MT_ARG_RANGE; |
|
21146 + else |
|
21147 + { |
|
21148 + tmpreg = (pInfo->reg[MT2266_IGAIN] & 0xC3) | ((U8Data)nValue << 2); |
|
21149 + status |= UncheckedSet(pInfo, MT2266_IGAIN, tmpreg); |
|
21150 + } |
|
21151 + break; |
|
21152 + |
|
21153 + /* Decrement LNA Gain setting, argument is min LNA Gain setting */ |
|
21154 + case MT2266_LNA_GAIN_DECR: |
|
21155 + if (nValue > 15) |
|
21156 + status |= MT_ARG_RANGE; |
|
21157 + else |
|
21158 + { |
|
21159 + PREFETCH(MT2266_IGAIN, 1); |
|
21160 + if (MT_NO_ERROR(status) && ((U8Data) ((pInfo->reg[MT2266_IGAIN] & 0x3C) >> 2) > (U8Data) nValue)) |
|
21161 + status |= UncheckedSet(pInfo, MT2266_IGAIN, pInfo->reg[MT2266_IGAIN] - 0x04); |
|
21162 + } |
|
21163 + break; |
|
21164 + |
|
21165 + /* Increment LNA Gain setting, argument is max LNA Gain setting */ |
|
21166 + case MT2266_LNA_GAIN_INCR: |
|
21167 + if (nValue > 15) |
|
21168 + status |= MT_ARG_RANGE; |
|
21169 + else |
|
21170 + { |
|
21171 + PREFETCH(MT2266_IGAIN, 1); |
|
21172 + if (MT_NO_ERROR(status) && ((U8Data) ((pInfo->reg[MT2266_IGAIN] & 0x3C) >> 2) < (U8Data) nValue)) |
|
21173 + status |= UncheckedSet(pInfo, MT2266_IGAIN, pInfo->reg[MT2266_IGAIN] + 0x04); |
|
21174 + } |
|
21175 + break; |
|
21176 + |
|
21177 + /* BB external / internal atten control */ |
|
21178 + case MT2266_BB_EXT: |
|
21179 + if (nValue == 0) |
|
21180 + tmpreg = pInfo->reg[MT2266_RSVD_33] &= ~0x08; |
|
21181 + else |
|
21182 + tmpreg = pInfo->reg[MT2266_RSVD_33] |= 0x08; |
|
21183 + status |= UncheckedSet(pInfo, MT2266_RSVD_33, tmpreg); |
|
21184 + break; |
|
21185 + |
|
21186 + /* Set for UHF max sensitivity mode */ |
|
21187 + case MT2266_UHF_MAXSENS: |
|
21188 + PREFETCH(MT2266_BAND_CTRL, 1); |
|
21189 + if (MT_NO_ERROR(status) && ((pInfo->reg[MT2266_BAND_CTRL] & 0x30) == 0x10)) |
|
21190 + status |= UncheckedSet(pInfo, MT2266_BAND_CTRL, pInfo->reg[MT2266_BAND_CTRL] ^ 0x30); |
|
21191 + break; |
|
21192 + |
|
21193 + /* Set for UHF normal mode */ |
|
21194 + case MT2266_UHF_NORMAL: |
|
21195 + if (MT_NO_ERROR(status) && ((pInfo->reg[MT2266_BAND_CTRL] & 0x30) == 0x20)) |
|
21196 + status |= UncheckedSet(pInfo, MT2266_BAND_CTRL, pInfo->reg[MT2266_BAND_CTRL] ^ 0x30); |
|
21197 + break; |
|
21198 + |
|
21199 + /* These parameters are read-only */ |
|
21200 + case MT2266_IC_ADDR: |
|
21201 + case MT2266_MAX_OPEN: |
|
21202 + case MT2266_NUM_OPEN: |
|
21203 + case MT2266_NUM_REGS: |
|
21204 + case MT2266_INPUT_FREQ: |
|
21205 + case MT2266_LO_FREQ: |
|
21206 + case MT2266_RC2_VALUE: |
|
21207 + case MT2266_RF_ADC: |
|
21208 + case MT2266_BB_ADC: |
|
21209 + case MT2266_EOP: |
|
21210 + default: |
|
21211 + status |= MT_ARG_RANGE; |
|
21212 + } |
|
21213 + } |
|
21214 + return (status); |
|
21215 +} |
|
21216 + |
|
21217 + |
|
21218 +/**************************************************************************** |
|
21219 +** |
|
21220 +** Name: MT2266_SetPowerModes |
|
21221 +** |
|
21222 +** Description: Sets the bits in the MT2266_ENABLES register and the |
|
21223 +** SROsd bit in the MT2266_SROADC_CTRL register. |
|
21224 +** |
|
21225 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
21226 +** flags - Bit mask of flags to indicate enabled |
|
21227 +** bits. |
|
21228 +** |
|
21229 +** Usage: status = MT2266_SetPowerModes(hMT2266, flags); |
|
21230 +** |
|
21231 +** Returns: status: |
|
21232 +** MT_OK - No errors |
|
21233 +** MT_INV_HANDLE - Invalid tuner handle |
|
21234 +** |
|
21235 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
21236 +** |
|
21237 +** The bits in the MT2266_ENABLES register and the |
|
21238 +** SROsd bit are set according to the supplied flags. |
|
21239 +** |
|
21240 +** The pre-defined flags are as follows: |
|
21241 +** MT2266_SROen |
|
21242 +** MT2266_LOen |
|
21243 +** MT2266_ADCen |
|
21244 +** MT2266_PDen |
|
21245 +** MT2266_DCOCen |
|
21246 +** MT2266_BBen |
|
21247 +** MT2266_MIXen |
|
21248 +** MT2266_LNAen |
|
21249 +** MT2266_ALL_ENABLES |
|
21250 +** MT2266_NO_ENABLES |
|
21251 +** MT2266_SROsd |
|
21252 +** MT2266_SRO_NOT_sd |
|
21253 +** |
|
21254 +** ONLY the enable bits (or SROsd bit) specified in the |
|
21255 +** flags parameter will be set. Any flag which is not |
|
21256 +** included, will cause that bit to be disabled. |
|
21257 +** |
|
21258 +** The ALL_ENABLES, NO_ENABLES, and SRO_NOT_sd constants |
|
21259 +** are for convenience. The NO_ENABLES and SRO_NOT_sd |
|
21260 +** do not actually have to be included, but are provided |
|
21261 +** for clarity. |
|
21262 +** |
|
21263 +** See Also: MT2266_Open |
|
21264 +** |
|
21265 +** Revision History: |
|
21266 +** |
|
21267 +** SCR Date Author Description |
|
21268 +** ------------------------------------------------------------------------- |
|
21269 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
21270 +** |
|
21271 +****************************************************************************/ |
|
21272 +UData_t MT2266_SetPowerModes(Handle_t h, |
|
21273 + UData_t flags) |
|
21274 +{ |
|
21275 + UData_t status = MT_OK; /* Status to be returned */ |
|
21276 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
21277 + U8Data tmpreg; |
|
21278 + |
|
21279 + /* Verify that the handle passed points to a valid tuner */ |
|
21280 + if (IsValidHandle(pInfo) == 0) |
|
21281 + status |= MT_INV_HANDLE; |
|
21282 + |
|
21283 + PREFETCH(MT2266_SRO_CTRL, 1); /* Fetch register(s) if __NO_CACHE__ defined */ |
|
21284 + if (MT_NO_ERROR(status)) |
|
21285 + { |
|
21286 + if (flags & MT2266_SROsd) |
|
21287 + tmpreg = pInfo->reg[MT2266_SRO_CTRL] |= 0x10; /* set the SROsd bit */ |
|
21288 + else |
|
21289 + tmpreg = pInfo->reg[MT2266_SRO_CTRL] &= 0xEF; /* clear the SROsd bit */ |
|
21290 + status |= UncheckedSet(pInfo, MT2266_SRO_CTRL, tmpreg); |
|
21291 + } |
|
21292 + |
|
21293 + PREFETCH(MT2266_ENABLES, 1); /* Fetch register(s) if __NO_CACHE__ defined */ |
|
21294 + |
|
21295 + if (MT_NO_ERROR(status)) |
|
21296 + { |
|
21297 + status |= UncheckedSet(pInfo, MT2266_ENABLES, (U8Data)(flags & 0xff)); |
|
21298 + } |
|
21299 + |
|
21300 + return status; |
|
21301 +} |
|
21302 + |
|
21303 + |
|
21304 +/**************************************************************************** |
|
21305 +** LOCAL FUNCTION - DO NOT USE OUTSIDE OF mt2266.c |
|
21306 +** |
|
21307 +** Name: UncheckedSet |
|
21308 +** |
|
21309 +** Description: Sets an MT2266 register. |
|
21310 +** |
|
21311 +** NOTE: This is a local function that performs the same |
|
21312 +** steps as the MT2266_SetReg function that is available |
|
21313 +** in the external API. It does not do any of the standard |
|
21314 +** error checking that the API function provides and should |
|
21315 +** not be called from outside this file. |
|
21316 +** |
|
21317 +** Parameters: *pInfo - Tuner control structure |
|
21318 +** reg - MT2266 register/subaddress location |
|
21319 +** val - MT2266 register/subaddress value |
|
21320 +** |
|
21321 +** Returns: status: |
|
21322 +** MT_OK - No errors |
|
21323 +** MT_COMM_ERR - Serial bus communications error |
|
21324 +** MT_INV_HANDLE - Invalid tuner handle |
|
21325 +** MT_ARG_RANGE - Argument out of range |
|
21326 +** |
|
21327 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
21328 +** |
|
21329 +** Sets a register value without any preliminary checking for |
|
21330 +** valid handles or register numbers. |
|
21331 +** |
|
21332 +** Revision History: |
|
21333 +** |
|
21334 +** SCR Date Author Description |
|
21335 +** ------------------------------------------------------------------------- |
|
21336 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
21337 +** |
|
21338 +****************************************************************************/ |
|
21339 +static UData_t UncheckedSet(MT2266_Info_t* pInfo, |
|
21340 + U8Data reg, |
|
21341 + U8Data val) |
|
21342 +{ |
|
21343 + UData_t status; /* Status to be returned */ |
|
21344 + |
|
21345 +#if defined(_DEBUG) |
|
21346 + status = MT_OK; |
|
21347 + /* Verify that the handle passed points to a valid tuner */ |
|
21348 + if (IsValidHandle(pInfo) == 0) |
|
21349 + status |= MT_INV_HANDLE; |
|
21350 + |
|
21351 + if (reg >= END_REGS) |
|
21352 + status |= MT_ARG_RANGE; |
|
21353 + |
|
21354 + if (MT_IS_ERROR(status)) |
|
21355 + return (status); |
|
21356 +#endif |
|
21357 + |
|
21358 + status = MT_WriteSub(pInfo->hUserData, pInfo->address, reg, &val, 1); |
|
21359 + |
|
21360 + if (MT_NO_ERROR(status)) |
|
21361 + pInfo->reg[reg] = val; |
|
21362 + |
|
21363 + return (status); |
|
21364 +} |
|
21365 + |
|
21366 + |
|
21367 +/**************************************************************************** |
|
21368 +** |
|
21369 +** Name: MT2266_SetReg |
|
21370 +** |
|
21371 +** Description: Sets an MT2266 register. |
|
21372 +** |
|
21373 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
21374 +** reg - MT2266 register/subaddress location |
|
21375 +** val - MT2266 register/subaddress value |
|
21376 +** |
|
21377 +** Returns: status: |
|
21378 +** MT_OK - No errors |
|
21379 +** MT_COMM_ERR - Serial bus communications error |
|
21380 +** MT_INV_HANDLE - Invalid tuner handle |
|
21381 +** MT_ARG_RANGE - Argument out of range |
|
21382 +** |
|
21383 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
21384 +** |
|
21385 +** Use this function if you need to override a default |
|
21386 +** register value |
|
21387 +** |
|
21388 +** Revision History: |
|
21389 +** |
|
21390 +** SCR Date Author Description |
|
21391 +** ------------------------------------------------------------------------- |
|
21392 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
21393 +** |
|
21394 +****************************************************************************/ |
|
21395 +UData_t MT2266_SetReg(Handle_t h, |
|
21396 + U8Data reg, |
|
21397 + U8Data val) |
|
21398 +{ |
|
21399 + UData_t status = MT_OK; /* Status to be returned */ |
|
21400 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
21401 + |
|
21402 + /* Verify that the handle passed points to a valid tuner */ |
|
21403 + if (IsValidHandle(pInfo) == 0) |
|
21404 + status |= MT_INV_HANDLE; |
|
21405 + |
|
21406 + if (reg >= END_REGS) |
|
21407 + status |= MT_ARG_RANGE; |
|
21408 + |
|
21409 + if (MT_NO_ERROR(status)) |
|
21410 + status |= UncheckedSet(pInfo, reg, val); |
|
21411 + |
|
21412 + return (status); |
|
21413 +} |
|
21414 + |
|
21415 + |
|
21416 +/**************************************************************************** |
|
21417 +** |
|
21418 +** Name: MT2266_SetUHFXFreqs |
|
21419 +** |
|
21420 +** Description: Assigns the specified set of UHF Crossover Frequencies |
|
21421 +** |
|
21422 +** Parameters: h - Open handle to the tuner (from MT2266_Open). |
|
21423 +** |
|
21424 +** Usage: MT2266_Freq_Set tmpFreqs; |
|
21425 +** status = MT2266_GetUHFXFreqs(hMT2266, |
|
21426 +** MT2266_UHF1_WITH_ATTENUATION, |
|
21427 +** tmpFreqs ); |
|
21428 +** ... |
|
21429 +** tmpFreqs[i] = <desired value> |
|
21430 +** ... |
|
21431 +** status = MT2266_SetUHFXFreqs(hMT2266, |
|
21432 +** MT2266_UHF1_WITH_ATTENUATION, |
|
21433 +** tmpFreqs ); |
|
21434 +** |
|
21435 +** if (status & MT_ARG_RANGE) |
|
21436 +** // error, Invalid UHF Crossover Frequency Set requested. |
|
21437 +** else |
|
21438 +** for( int i = 0; i < MT2266_NUM_XFREQS; i++ ) |
|
21439 +** . . . |
|
21440 +** |
|
21441 +** Returns: status: |
|
21442 +** MT_OK - No errors |
|
21443 +** MT_ARG_RANGE - freq_type is out of range. |
|
21444 +** MT_INV_HANDLE - Invalid tuner handle |
|
21445 +** |
|
21446 +** Dependencies: freqs_buffer *must* be defined of type MT2266_Freq_Set |
|
21447 +** to assure sufficient space allocation! |
|
21448 +** |
|
21449 +** USERS MUST CALL MT2266_Open() FIRST! |
|
21450 +** |
|
21451 +** See Also: MT2266_SetUHFXFreqs |
|
21452 +** |
|
21453 +** Revision History: |
|
21454 +** |
|
21455 +** SCR Date Author Description |
|
21456 +** ------------------------------------------------------------------------- |
|
21457 +** N/A 10-26-2006 RSK Original. |
|
21458 +** |
|
21459 +****************************************************************************/ |
|
21460 +UData_t MT2266_SetUHFXFreqs(Handle_t h, |
|
21461 + MT2266_UHFXFreq_Type freq_type, |
|
21462 + MT2266_XFreq_Set freqs_buffer) |
|
21463 +{ |
|
21464 + UData_t status = MT_OK; /* Status to be returned */ |
|
21465 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
21466 + |
|
21467 + /* Verify that the handle passed points to a valid tuner */ |
|
21468 + if (IsValidHandle(pInfo) == 0) |
|
21469 + status = MT_INV_HANDLE; |
|
21470 + |
|
21471 + if (freq_type >= MT2266_NUMBER_OF_XFREQ_SETS) |
|
21472 + status |= MT_ARG_RANGE; |
|
21473 + |
|
21474 + if (MT_NO_ERROR(status)) |
|
21475 + { |
|
21476 + int i; |
|
21477 + |
|
21478 + for( i = 0; i < MT2266_NUM_XFREQS; i++ ) |
|
21479 + { |
|
21480 + pInfo->xfreqs.xfreq[ freq_type ][i] = freqs_buffer[i] * 1000 / TUNE_STEP_SIZE; |
|
21481 + } |
|
21482 + } |
|
21483 + |
|
21484 + return (status); |
|
21485 +} |
|
21486 + |
|
21487 + |
|
21488 +/**************************************************************************** |
|
21489 +** LOCAL FUNCTION |
|
21490 +** |
|
21491 +** Name: RoundToStep |
|
21492 +** |
|
21493 +** Description: Rounds the given frequency to the closes f_Step value |
|
21494 +** given the tuner ref frequency.. |
|
21495 +** |
|
21496 +** |
|
21497 +** Parameters: freq - Frequency to be rounded (in Hz). |
|
21498 +** f_Step - Step size for the frequency (in Hz). |
|
21499 +** f_Ref - SRO frequency (in Hz). |
|
21500 +** |
|
21501 +** Returns: Rounded frequency. |
|
21502 +** |
|
21503 +** Revision History: |
|
21504 +** |
|
21505 +** SCR Date Author Description |
|
21506 +** ------------------------------------------------------------------------- |
|
21507 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
21508 +** |
|
21509 +****************************************************************************/ |
|
21510 +static UData_t RoundToStep(UData_t freq, UData_t f_Step, UData_t f_ref) |
|
21511 +{ |
|
21512 + return f_ref * (freq / f_ref) |
|
21513 + + f_Step * (((freq % f_ref) + (f_Step / 2)) / f_Step); |
|
21514 +} |
|
21515 + |
|
21516 + |
|
21517 +/**************************************************************************** |
|
21518 +** |
|
21519 +** Name: fLO_FractionalTerm |
|
21520 +** |
|
21521 +** Description: Calculates the portion contributed by FracN / denom. |
|
21522 +** |
|
21523 +** This function preserves maximum precision without |
|
21524 +** risk of overflow. It accurately calculates |
|
21525 +** f_ref * num / denom to within 1 HZ with fixed math. |
|
21526 +** |
|
21527 +** Parameters: num - Fractional portion of the multiplier |
|
21528 +** denom - denominator portion of the ratio |
|
21529 +** This routine successfully handles denom values |
|
21530 +** up to and including 2^18. |
|
21531 +** f_Ref - SRO frequency. This calculation handles |
|
21532 +** f_ref as two separate 14-bit fields. |
|
21533 +** Therefore, a maximum value of 2^28-1 |
|
21534 +** may safely be used for f_ref. This is |
|
21535 +** the genesis of the magic number "14" and the |
|
21536 +** magic mask value of 0x03FFF. |
|
21537 +** |
|
21538 +** Returns: f_ref * num / denom |
|
21539 +** |
|
21540 +** Revision History: |
|
21541 +** |
|
21542 +** SCR Date Author Description |
|
21543 +** ------------------------------------------------------------------------- |
|
21544 +** N/A 12-20-2006 RSK Ver 1.04: Adding fLO_FractionalTerm() usage. |
|
21545 +** |
|
21546 +****************************************************************************/ |
|
21547 +static UData_t fLO_FractionalTerm( UData_t f_ref, |
|
21548 + UData_t num, |
|
21549 + UData_t denom ) |
|
21550 +{ |
|
21551 + UData_t t1 = (f_ref >> 14) * num; |
|
21552 + UData_t term1 = t1 / denom; |
|
21553 + UData_t loss = t1 % denom; |
|
21554 + UData_t term2 = ( ((f_ref & 0x00003FFF) * num + (loss<<14)) + (denom/2) ) / denom; |
|
21555 + return ((term1 << 14) + term2); |
|
21556 +} |
|
21557 + |
|
21558 + |
|
21559 +/**************************************************************************** |
|
21560 +** LOCAL FUNCTION |
|
21561 +** |
|
21562 +** Name: CalcLOMult |
|
21563 +** |
|
21564 +** Description: Calculates Integer divider value and the numerator |
|
21565 +** value for LO's FracN PLL. |
|
21566 +** |
|
21567 +** This function assumes that the f_LO and f_Ref are |
|
21568 +** evenly divisible by f_LO_Step. |
|
21569 +** |
|
21570 +** Parameters: Div - OUTPUT: Whole number portion of the multiplier |
|
21571 +** FracN - OUTPUT: Fractional portion of the multiplier |
|
21572 +** f_LO - desired LO frequency. |
|
21573 +** denom - LO FracN denominator value |
|
21574 +** f_Ref - SRO frequency. |
|
21575 +** |
|
21576 +** Returns: Recalculated LO frequency. |
|
21577 +** |
|
21578 +** Revision History: |
|
21579 +** |
|
21580 +** SCR Date Author Description |
|
21581 +** ------------------------------------------------------------------------- |
|
21582 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
21583 +** N/A 12-20-2006 RSK Ver 1.04: Adding fLO_FractionalTerm() usage. |
|
21584 +** |
|
21585 +****************************************************************************/ |
|
21586 +static UData_t CalcLOMult(UData_t *Div, |
|
21587 + UData_t *FracN, |
|
21588 + UData_t f_LO, |
|
21589 + UData_t denom, |
|
21590 + UData_t f_Ref) |
|
21591 +{ |
|
21592 + UData_t a, b, i; |
|
21593 + const SData_t TwoNShift = 13; // bits to shift to obtain 2^n qty |
|
21594 + const SData_t RoundShift = 18; // bits to shift before rounding |
|
21595 + |
|
21596 + /* Calculate the whole number portion of the divider */ |
|
21597 + *Div = f_LO / f_Ref; |
|
21598 + |
|
21599 + /* |
|
21600 + ** Calculate the FracN numerator 1 bit at a time. This keeps the |
|
21601 + ** integer values from overflowing when large values are multiplied. |
|
21602 + ** This loop calculates the fractional portion of F/20MHz accurate |
|
21603 + ** to 32 bits. The 2^n factor is represented by the placement of |
|
21604 + ** the value in the 32-bit word. Since we want as much accuracy |
|
21605 + ** as possible, we'll leave it at the top of the word. |
|
21606 + */ |
|
21607 + *FracN = 0; |
|
21608 + a = f_LO; |
|
21609 + for (i=32; i>0; --i) |
|
21610 + { |
|
21611 + b = 2*(a % f_Ref); |
|
21612 + *FracN = (*FracN * 2) + (b >= f_Ref); |
|
21613 + a = b; |
|
21614 + } |
|
21615 + |
|
21616 + /* |
|
21617 + ** If the denominator is a 2^n - 1 value (the usual case) then the |
|
21618 + ** value we really need is (F/20) * 2^n - (F/20). Shifting the |
|
21619 + ** calculated (F/20) value to the right and subtracting produces |
|
21620 + ** the desired result -- still accurate to 32 bits. |
|
21621 + */ |
|
21622 + if ((denom & 0x01) != 0) |
|
21623 + *FracN -= (*FracN >> TwoNShift); |
|
21624 + |
|
21625 + /* |
|
21626 + ** Now shift the result so that it is 1 bit bigger than we need, |
|
21627 + ** use the low-order bit to round the remaining bits, and shift |
|
21628 + ** to make the answer the desired size. |
|
21629 + */ |
|
21630 + *FracN >>= RoundShift; |
|
21631 + *FracN = (*FracN & 0x01) + (*FracN >> 1); |
|
21632 + |
|
21633 + /* Check for rollover (cannot happen with 50 kHz step size) */ |
|
21634 + if (*FracN == (denom | 1)) |
|
21635 + { |
|
21636 + *FracN = 0; |
|
21637 + ++Div; |
|
21638 + } |
|
21639 + |
|
21640 + |
|
21641 + return (f_Ref * (*Div)) + fLO_FractionalTerm( f_Ref, *FracN, denom ); |
|
21642 +} |
|
21643 + |
|
21644 + |
|
21645 +/**************************************************************************** |
|
21646 +** LOCAL FUNCTION |
|
21647 +** |
|
21648 +** Name: GetCrossover |
|
21649 +** |
|
21650 +** Description: Determines the appropriate value in the set of |
|
21651 +** crossover frequencies. |
|
21652 +** |
|
21653 +** This function assumes that the crossover frequency table |
|
21654 +** ias been properly initialized in descending order. |
|
21655 +** |
|
21656 +** Parameters: f_in - The input frequency to use. |
|
21657 +** freqs - The array of crossover frequency entries. |
|
21658 +** |
|
21659 +** Returns: Index of crossover frequency band to use. |
|
21660 +** |
|
21661 +** Revision History: |
|
21662 +** |
|
21663 +** SCR Date Author Description |
|
21664 +** ------------------------------------------------------------------------- |
|
21665 +** N/A 10-27-2006 RSK Original |
|
21666 +** |
|
21667 +****************************************************************************/ |
|
21668 +static U8Data GetCrossover( UData_t f_in, UData_t* freqs ) |
|
21669 +{ |
|
21670 + U8Data idx; |
|
21671 + U8Data retVal = 0; |
|
21672 + |
|
21673 + for (idx=0; idx< (U8Data)MT2266_NUM_XFREQS; idx++) |
|
21674 + { |
|
21675 + if ( freqs[idx] >= f_in) |
|
21676 + { |
|
21677 + retVal = (U8Data)MT2266_NUM_XFREQS - idx; |
|
21678 + break; |
|
21679 + } |
|
21680 + } |
|
21681 + |
|
21682 + return retVal; |
|
21683 +} |
|
21684 + |
|
21685 + |
|
21686 +/**************************************************************************** |
|
21687 +** |
|
21688 +** Name: MT2266_ChangeFreq |
|
21689 +** |
|
21690 +** Description: Change the tuner's tuned frequency to f_in. |
|
21691 +** |
|
21692 +** Parameters: h - Open handle to the tuner (from MT2266_Open). |
|
21693 +** f_in - RF input center frequency (in Hz). |
|
21694 +** |
|
21695 +** Returns: status: |
|
21696 +** MT_OK - No errors |
|
21697 +** MT_INV_HANDLE - Invalid tuner handle |
|
21698 +** MT_DNC_UNLOCK - Downconverter PLL unlocked |
|
21699 +** MT_COMM_ERR - Serial bus communications error |
|
21700 +** MT_FIN_RANGE - Input freq out of range |
|
21701 +** MT_DNC_RANGE - Downconverter freq out of range |
|
21702 +** |
|
21703 +** Dependencies: MUST CALL MT2266_Open BEFORE MT2266_ChangeFreq! |
|
21704 +** |
|
21705 +** MT_ReadSub - Read byte(s) of data from the two-wire-bus |
|
21706 +** MT_WriteSub - Write byte(s) of data to the two-wire-bus |
|
21707 +** MT_Sleep - Delay execution for x milliseconds |
|
21708 +** MT2266_GetLocked - Checks to see if the PLL is locked |
|
21709 +** |
|
21710 +** Revision History: |
|
21711 +** |
|
21712 +** SCR Date Author Description |
|
21713 +** ------------------------------------------------------------------------- |
|
21714 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
21715 +** N/A 11-01-2006 RSK Ver 1.02: Added usage of UFILT0 and UFILT1. |
|
21716 +** N/A 11-29-2006 DAD Ver 1.03: Parenthesis clarification |
|
21717 +** 118 05-09-2007 RSK Ver 1.05: Refactored to call _Tune() API. |
|
21718 +** |
|
21719 +****************************************************************************/ |
|
21720 +UData_t MT2266_ChangeFreq(Handle_t h, |
|
21721 + UData_t f_in) /* RF input center frequency */ |
|
21722 +{ |
|
21723 + return (MT2266_Tune(h, f_in)); |
|
21724 +} |
|
21725 + |
|
21726 + |
|
21727 +/**************************************************************************** |
|
21728 +** |
|
21729 +** Name: MT2266_Tune |
|
21730 +** |
|
21731 +** Description: Change the tuner's tuned frequency to f_in. |
|
21732 +** |
|
21733 +** Parameters: h - Open handle to the tuner (from MT2266_Open). |
|
21734 +** f_in - RF input center frequency (in Hz). |
|
21735 +** |
|
21736 +** Returns: status: |
|
21737 +** MT_OK - No errors |
|
21738 +** MT_INV_HANDLE - Invalid tuner handle |
|
21739 +** MT_DNC_UNLOCK - Downconverter PLL unlocked |
|
21740 +** MT_COMM_ERR - Serial bus communications error |
|
21741 +** MT_FIN_RANGE - Input freq out of range |
|
21742 +** MT_DNC_RANGE - Downconverter freq out of range |
|
21743 +** |
|
21744 +** Dependencies: MUST CALL MT2266_Open BEFORE MT2266_Tune! |
|
21745 +** |
|
21746 +** MT_ReadSub - Read byte(s) of data from the two-wire-bus |
|
21747 +** MT_WriteSub - Write byte(s) of data to the two-wire-bus |
|
21748 +** MT_Sleep - Delay execution for x milliseconds |
|
21749 +** MT2266_GetLocked - Checks to see if the PLL is locked |
|
21750 +** |
|
21751 +** Revision History: |
|
21752 +** |
|
21753 +** SCR Date Author Description |
|
21754 +** ------------------------------------------------------------------------- |
|
21755 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
21756 +** N/A 11-01-2006 RSK Ver 1.02: Added usage of UFILT0 and UFILT1. |
|
21757 +** N/A 11-29-2006 DAD Ver 1.03: Parenthesis clarification |
|
21758 +** 118 05-09-2007 RSK Ver 1.05: Adding Standard MTxxxx_Tune() API. |
|
21759 +** |
|
21760 +****************************************************************************/ |
|
21761 +UData_t MT2266_Tune(Handle_t h, |
|
21762 + UData_t f_in) /* RF input center frequency */ |
|
21763 +{ |
|
21764 + MT2266_Info_t* pInfo = (MT2266_Info_t*) h; |
|
21765 + |
|
21766 + UData_t status = MT_OK; /* status of operation */ |
|
21767 + UData_t LO; /* LO register value */ |
|
21768 + UData_t Num; /* Numerator for LO reg. value */ |
|
21769 + UData_t ofLO; /* last time's LO frequency */ |
|
21770 + UData_t ofin; /* last time's input frequency */ |
|
21771 + U8Data LO_Band; /* LO Mode bits */ |
|
21772 + UData_t s_fRef; /* Ref Freq scaled for LO Band */ |
|
21773 + UData_t this_band; /* Band for the requested freq */ |
|
21774 + UData_t SROx2; /* SRO times 2 */ |
|
21775 + |
|
21776 + /* Verify that the handle passed points to a valid tuner */ |
|
21777 + if (IsValidHandle(pInfo) == 0) |
|
21778 + return MT_INV_HANDLE; |
|
21779 + |
|
21780 + /* |
|
21781 + ** Save original input and LO value |
|
21782 + */ |
|
21783 + ofLO = pInfo->f_LO; |
|
21784 + ofin = pInfo->f_in; |
|
21785 + |
|
21786 + /* |
|
21787 + ** Assign in the requested input value |
|
21788 + */ |
|
21789 + pInfo->f_in = f_in; |
|
21790 + |
|
21791 + /* |
|
21792 + ** Get the SRO multiplier value |
|
21793 + */ |
|
21794 + SROx2 = (2 - (pInfo->reg[MT2266_SRO_CTRL] & 0x01)); |
|
21795 + |
|
21796 + /* Check f_Step value */ |
|
21797 + if(pInfo->f_Step == 0) |
|
21798 + return MT_UNKNOWN; |
|
21799 + |
|
21800 + /* Request an LO that is on a step size boundary */ |
|
21801 + pInfo->f_LO = RoundToStep(f_in, pInfo->f_Step, pInfo->f_Ref); |
|
21802 + |
|
21803 + if (pInfo->f_LO < MIN_VHF_FREQ) |
|
21804 + { |
|
21805 + status |= MT_FIN_RANGE | MT_ARG_RANGE | MT_DNC_RANGE; |
|
21806 + return status; /* Does not support frequencies below MIN_VHF_FREQ */ |
|
21807 + } |
|
21808 + else if (pInfo->f_LO <= MAX_VHF_FREQ) |
|
21809 + { |
|
21810 + /* VHF Band */ |
|
21811 + s_fRef = pInfo->f_Ref * SROx2 / 4; |
|
21812 + LO_Band = 0; |
|
21813 + this_band = MT2266_VHF_BAND; |
|
21814 + } |
|
21815 + else if (pInfo->f_LO < MIN_UHF_FREQ) |
|
21816 + { |
|
21817 + status |= MT_FIN_RANGE | MT_ARG_RANGE | MT_DNC_RANGE; |
|
21818 + return status; /* Does not support frequencies between MAX_VHF_FREQ & MIN_UHF_FREQ */ |
|
21819 + } |
|
21820 + else if (pInfo->f_LO <= MAX_UHF_FREQ) |
|
21821 + { |
|
21822 + /* UHF Band */ |
|
21823 + s_fRef = pInfo->f_Ref * SROx2 / 2; |
|
21824 + LO_Band = 1; |
|
21825 + this_band = MT2266_UHF_BAND; |
|
21826 + } |
|
21827 + else |
|
21828 + { |
|
21829 + status |= MT_FIN_RANGE | MT_ARG_RANGE | MT_DNC_RANGE; |
|
21830 + return status; /* Does not support frequencies above MAX_UHF_FREQ */ |
|
21831 + } |
|
21832 + |
|
21833 + /* |
|
21834 + ** Calculate the LO frequencies and the values to be placed |
|
21835 + ** in the tuning registers. |
|
21836 + */ |
|
21837 + pInfo->f_LO = CalcLOMult(&LO, &Num, pInfo->f_LO, 8191, s_fRef); |
|
21838 + |
|
21839 + /* |
|
21840 + ** If we have the same LO frequencies and we're already locked, |
|
21841 + ** then just return without writing any registers. |
|
21842 + */ |
|
21843 + if ((ofLO == pInfo->f_LO) |
|
21844 + && ((pInfo->reg[MT2266_STATUS_1] & 0x40) == 0x40)) |
|
21845 + { |
|
21846 + return (status); |
|
21847 + } |
|
21848 + |
|
21849 + /* |
|
21850 + ** Reset defaults here if we're tuning into a new band |
|
21851 + */ |
|
21852 + if (MT_NO_ERROR(status)) |
|
21853 + { |
|
21854 + if (this_band != pInfo->band) |
|
21855 + { |
|
21856 + MT2266_DefaultsEntry *defaults = MT_NULL; |
|
21857 + switch (this_band) |
|
21858 + { |
|
21859 + case MT2266_VHF_BAND: |
|
21860 + defaults = &MT2266_VHF_defaults[0]; |
|
21861 + break; |
|
21862 + case MT2266_UHF_BAND: |
|
21863 + defaults = &MT2266_UHF_defaults[0]; |
|
21864 + break; |
|
21865 + default: |
|
21866 + status |= MT_ARG_RANGE; |
|
21867 + } |
|
21868 + if ( MT_NO_ERROR(status)) |
|
21869 + { |
|
21870 + while (defaults->data && MT_NO_ERROR(status)) |
|
21871 + { |
|
21872 + status |= MT_WriteSub(pInfo->hUserData, pInfo->address, defaults->data[0], &defaults->data[1], defaults->cnt); |
|
21873 + defaults++; |
|
21874 + } |
|
21875 + /* re-read the new registers into the cached values */ |
|
21876 + status |= MT_ReadSub(pInfo->hUserData, pInfo->address, 0, &pInfo->reg[0], END_REGS); |
|
21877 + pInfo->band = this_band; |
|
21878 + } |
|
21879 + } |
|
21880 + } |
|
21881 + |
|
21882 + /* |
|
21883 + ** Place all of the calculated values into the local tuner |
|
21884 + ** register fields. |
|
21885 + */ |
|
21886 + if (MT_NO_ERROR(status)) |
|
21887 + { |
|
21888 + pInfo->reg[MT2266_LO_CTRL_1] = (U8Data)(Num >> 8); |
|
21889 + pInfo->reg[MT2266_LO_CTRL_2] = (U8Data)(Num & 0xFF); |
|
21890 + pInfo->reg[MT2266_LO_CTRL_3] = (U8Data)(LO & 0xFF); |
|
21891 + |
|
21892 + /* |
|
21893 + ** Now write out the computed register values |
|
21894 + */ |
|
21895 + status |= MT_WriteSub(pInfo->hUserData, pInfo->address, MT2266_LO_CTRL_1, &pInfo->reg[MT2266_LO_CTRL_1], 3); |
|
21896 + |
|
21897 + if (pInfo->band == MT2266_UHF_BAND) |
|
21898 + { |
|
21899 + U8Data UFilt0 = 0; /* def when f_in > all */ |
|
21900 + U8Data UFilt1 = 0; /* def when f_in > all */ |
|
21901 + UData_t* XFreq0; |
|
21902 + UData_t* XFreq1; |
|
21903 + SData_t ClearTune_Fuse; |
|
21904 + SData_t f_offset; |
|
21905 + UData_t f_in_; |
|
21906 + |
|
21907 + PREFETCH(MT2266_BAND_CTRL, 2); /* Fetch register(s) if __NO_CACHE__ defined */ |
|
21908 + PREFETCH(MT2266_STATUS_5, 1); /* Fetch register(s) if __NO_CACHE__ defined */ |
|
21909 + |
|
21910 + XFreq0 = (pInfo->reg[MT2266_BAND_CTRL] & 0x10) ? pInfo->xfreqs.xfreq[ MT2266_UHF0_ATTEN ] : pInfo->xfreqs.xfreq[ MT2266_UHF0 ]; |
|
21911 + XFreq1 = (pInfo->reg[MT2266_BAND_CTRL] & 0x10) ? pInfo->xfreqs.xfreq[ MT2266_UHF1_ATTEN ] : pInfo->xfreqs.xfreq[ MT2266_UHF1 ]; |
|
21912 + |
|
21913 + ClearTune_Fuse = pInfo->reg[MT2266_STATUS_5] & 0x07; |
|
21914 + f_offset = (10000000) * ((ClearTune_Fuse > 3) ? (ClearTune_Fuse - 8) : ClearTune_Fuse); |
|
21915 + f_in_ = (f_in - f_offset) / 1000 / TUNE_STEP_SIZE; |
|
21916 + |
|
21917 + UFilt0 = GetCrossover( f_in_, XFreq0 ); |
|
21918 + UFilt1 = GetCrossover( f_in_, XFreq1 ); |
|
21919 + |
|
21920 + /* If UFilt == 16, set UBANDen and set UFilt = 15 */ |
|
21921 + if ( (UFilt0 == 16) || (UFilt1 == 16) ) |
|
21922 + { |
|
21923 + pInfo->reg[MT2266_BAND_CTRL] |= 0x01; |
|
21924 + if( UFilt0 > 0 ) UFilt0--; |
|
21925 + if( UFilt1 > 0 ) UFilt1--; |
|
21926 + } |
|
21927 + else |
|
21928 + pInfo->reg[MT2266_BAND_CTRL] &= ~(0x01); |
|
21929 + |
|
21930 + pInfo->reg[MT2266_BAND_CTRL] = |
|
21931 + (pInfo->reg[MT2266_BAND_CTRL] & 0x3F) | (LO_Band << 6); |
|
21932 + |
|
21933 + pInfo->reg[MT2266_CLEARTUNE] = (UFilt1 << 4) | UFilt0; |
|
21934 + /* Write UBANDsel [05] & ClearTune [06] */ |
|
21935 + status |= MT_WriteSub(pInfo->hUserData, pInfo->address, MT2266_BAND_CTRL, &pInfo->reg[MT2266_BAND_CTRL], 2); |
|
21936 + } |
|
21937 + } |
|
21938 + |
|
21939 + /* |
|
21940 + ** Check for LO lock |
|
21941 + */ |
|
21942 + if (MT_NO_ERROR(status)) |
|
21943 + { |
|
21944 + status |= MT2266_GetLocked(h); |
|
21945 + } |
|
21946 + |
|
21947 + return (status); |
|
21948 +} |
|
21949 + |
|
21950 + |
|
21951 + |
|
21952 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/tuner_mt2266.h |
|
21953 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
21954 +++ b/linux/drivers/media/dvb/dvb-usb/tuner_mt2266.h Wed Oct 27 09:16:44 2010 +0200 |
|
21955 @@ -0,0 +1,1618 @@ |
|
21956 +#ifndef __TUNER_MT2266_H |
|
21957 +#define __TUNER_MT2266_H |
|
21958 + |
|
21959 +/** |
|
21960 + |
|
21961 +@file |
|
21962 + |
|
21963 +@brief MT2266 tuner module declaration |
|
21964 + |
|
21965 +One can manipulate MT2266 tuner through MT2266 module. |
|
21966 +MT2266 module is derived from tunerd module. |
|
21967 + |
|
21968 + |
|
21969 + |
|
21970 +@par Example: |
|
21971 +@code |
|
21972 + |
|
21973 +// The example is the same as the tuner example in tuner_base.h except the listed lines. |
|
21974 + |
|
21975 + |
|
21976 + |
|
21977 +#include "tuner_mt2266.h" |
|
21978 + |
|
21979 + |
|
21980 +... |
|
21981 + |
|
21982 + |
|
21983 + |
|
21984 +int main(void) |
|
21985 +{ |
|
21986 + TUNER_MODULE *pTuner; |
|
21987 + MT2266_EXTRA_MODULE *pTunerExtra; |
|
21988 + |
|
21989 + TUNER_MODULE TunerModuleMemory; |
|
21990 + MT2266_EXTRA_MODULE Mt2266ExtraModuleMemory; |
|
21991 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
21992 + I2C_BRIDGE_MODULE I2cBridgeModuleMemory; |
|
21993 + |
|
21994 + unsigned long BandwidthHz; |
|
21995 + |
|
21996 + |
|
21997 + ... |
|
21998 + |
|
21999 + |
|
22000 + |
|
22001 + // Build MT2266 tuner module. |
|
22002 + BuildMt2266Module( |
|
22003 + &pTuner, |
|
22004 + &TunerModuleMemory, |
|
22005 + &Mt2266ExtraModuleMemory, |
|
22006 + &BaseInterfaceModuleMemory, |
|
22007 + &I2cBridgeModuleMemory, |
|
22008 + 0xc0 // I2C device address is 0xc0 in 8-bit format. |
|
22009 + ); |
|
22010 + |
|
22011 + |
|
22012 + |
|
22013 + |
|
22014 + |
|
22015 + // Get MT2266 tuner extra module. |
|
22016 + pTunerExtra = (T2266_EXTRA_MODULE *)(pTuner->pExtra); |
|
22017 + |
|
22018 + // Open MT2266 handle. |
|
22019 + pTunerExtra->OpenHandle(pTuner); |
|
22020 + |
|
22021 + |
|
22022 + |
|
22023 + |
|
22024 + |
|
22025 + // ==== Initialize tuner and set its parameters ===== |
|
22026 + |
|
22027 + ... |
|
22028 + |
|
22029 + // Set MT2266 bandwidth. |
|
22030 + pTunerExtra->SetBandwidthHz(pTuner, MT2266_BANDWIDTH_6MHZ); |
|
22031 + |
|
22032 + |
|
22033 + |
|
22034 + |
|
22035 + |
|
22036 + // ==== Get tuner information ===== |
|
22037 + |
|
22038 + ... |
|
22039 + |
|
22040 + // Get MT2266 bandwidth. |
|
22041 + pTunerExtra->GetBandwidthHz(pTuner, &BandwidthHz); |
|
22042 + |
|
22043 + |
|
22044 + |
|
22045 + |
|
22046 + |
|
22047 + // Close MT2266 handle. |
|
22048 + pTunerExtra->CloseHandle(pTuner); |
|
22049 + |
|
22050 + |
|
22051 + |
|
22052 + // See the example for other tuner functions in tuner_base.h |
|
22053 + |
|
22054 + |
|
22055 + return 0; |
|
22056 +} |
|
22057 + |
|
22058 + |
|
22059 +@endcode |
|
22060 + |
|
22061 +*/ |
|
22062 + |
|
22063 + |
|
22064 + |
|
22065 + |
|
22066 + |
|
22067 +// The following context is source code provided by Microtune. |
|
22068 + |
|
22069 + |
|
22070 + |
|
22071 + |
|
22072 + |
|
22073 +// Microtune source code - mt_errordef.h |
|
22074 + |
|
22075 + |
|
22076 + |
|
22077 +/***************************************************************************** |
|
22078 +** |
|
22079 +** Name: mt_errordef.h |
|
22080 +** |
|
22081 +** Description: Definition of bits in status/error word used by various |
|
22082 +** MicroTuner control programs. |
|
22083 +** |
|
22084 +** References: None |
|
22085 +** |
|
22086 +** Exports: None |
|
22087 +** |
|
22088 +** CVS ID: $Id: mt_errordef.h,v 1.1 2006/06/22 20:18:12 software Exp $ |
|
22089 +** CVS Source: $Source: /export/home/cvsroot/software/tuners/MT2266/mt_errordef.h,v $ |
|
22090 +** |
|
22091 +** Revision History: |
|
22092 +** |
|
22093 +** SCR Date Author Description |
|
22094 +** ------------------------------------------------------------------------- |
|
22095 +** N/A 09-09-2004 JWS Original |
|
22096 +** 088 01-26-2005 DAD Added MT_TUNER_INIT_ERR. |
|
22097 +** N/A 12-09-2005 DAD Added MT_TUNER_TIMEOUT (info). |
|
22098 +** |
|
22099 +*****************************************************************************/ |
|
22100 + |
|
22101 +/* |
|
22102 +** Note to users: DO NOT EDIT THIS FILE |
|
22103 +** |
|
22104 +** If you wish to rename any of the "user defined" bits, |
|
22105 +** it should be done in the user file that includes this |
|
22106 +** source file (e.g. mt_userdef.h) |
|
22107 +** |
|
22108 +*/ |
|
22109 + |
|
22110 + |
|
22111 + |
|
22112 +/* |
|
22113 +** 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 |
|
22114 +** 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
|
22115 +** M U <- Info Codes --> <# Spurs> < User> <----- Err Codes -----> |
|
22116 +** |
|
22117 +** 31 = MT_ERROR - Master Error Flag. If set, check Err Codes for reason. |
|
22118 +** 30 = MT_USER_ERROR - User-declared error flag. |
|
22119 +** 29 = Unused |
|
22120 +** 28 = Unused |
|
22121 +** 27 = MT_DNC_RANGE |
|
22122 +** 26 = MT_UPC_RANGE |
|
22123 +** 25 = MT_FOUT_RANGE |
|
22124 +** 24 = MT_FIN_OUT_OF_RANGE |
|
22125 +** 23 = MT_SPUR_PRESENT - Unavoidable spur in output |
|
22126 +** 22 = MT_TUNER_TIMEOUT |
|
22127 +** 21 = Unused |
|
22128 +** 20 = Unused |
|
22129 +** 19 = MT_SPUR_CNT_MASK (MSB) - Count of avoided spurs |
|
22130 +** 18 = MT_SPUR_CNT_MASK |
|
22131 +** 17 = MT_SPUR_CNT_MASK |
|
22132 +** 16 = MT_SPUR_CNT_MASK |
|
22133 +** 15 = MT_SPUR_CNT_MASK (LSB) |
|
22134 +** 14 = MT_USER_DEFINED4 - User-definable bit (see MT_Userdef.h) |
|
22135 +** 13 = MT_USER_DEFINED3 - User-definable bit (see MT_Userdef.h) |
|
22136 +** 12 = MT_USER_DEFINED2 - User-definable bit (see MT_Userdef.h) |
|
22137 +** 11 = MT_USER_DEFINED1 - User-definable bit (see MT_Userdef.h) |
|
22138 +** 10 = Unused |
|
22139 +** 9 = MT_TUNER_INIT_ERR - Tuner initialization error |
|
22140 +** 8 = MT_TUNER_ID_ERR - Tuner Part Code / Rev Code mismatches expected value |
|
22141 +** 7 = MT_TUNER_CNT_ERR - Attempt to open more than MT_TUNER_CNT tuners |
|
22142 +** 6 = MT_ARG_NULL - Null pointer passed as argument |
|
22143 +** 5 = MT_ARG_RANGE - Argument value out of range |
|
22144 +** 4 = MT_INV_HANDLE - Tuner handle is invalid |
|
22145 +** 3 = MT_COMM_ERR - Serial bus communications error |
|
22146 +** 2 = MT_DNC_UNLOCK - Downconverter PLL is unlocked |
|
22147 +** 1 = MT_UPC_UNLOCK - Upconverter PLL is unlocked |
|
22148 +** 0 = MT_UNKNOWN - Unknown error |
|
22149 +*/ |
|
22150 +#define MT_ERROR (1 << 31) |
|
22151 +#define MT_USER_ERROR (1 << 30) |
|
22152 + |
|
22153 +/* Macro to be used to check for errors */ |
|
22154 +#define MT_IS_ERROR(s) (((s) >> 30) != 0) |
|
22155 +#define MT_NO_ERROR(s) (((s) >> 30) == 0) |
|
22156 + |
|
22157 + |
|
22158 +#define MT_OK (0x00000000) |
|
22159 + |
|
22160 +/* Unknown error */ |
|
22161 +#define MT_UNKNOWN (0x80000001) |
|
22162 + |
|
22163 +/* Error: Upconverter PLL is not locked */ |
|
22164 +#define MT_UPC_UNLOCK (0x80000002) |
|
22165 + |
|
22166 +/* Error: Downconverter PLL is not locked */ |
|
22167 +#define MT_DNC_UNLOCK (0x80000004) |
|
22168 + |
|
22169 +/* Error: Two-wire serial bus communications error */ |
|
22170 +#define MT_COMM_ERR (0x80000008) |
|
22171 + |
|
22172 +/* Error: Tuner handle passed to function was invalid */ |
|
22173 +#define MT_INV_HANDLE (0x80000010) |
|
22174 + |
|
22175 +/* Error: Function argument is invalid (out of range) */ |
|
22176 +#define MT_ARG_RANGE (0x80000020) |
|
22177 + |
|
22178 +/* Error: Function argument (ptr to return value) was NULL */ |
|
22179 +#define MT_ARG_NULL (0x80000040) |
|
22180 + |
|
22181 +/* Error: Attempt to open more than MT_TUNER_CNT tuners */ |
|
22182 +#define MT_TUNER_CNT_ERR (0x80000080) |
|
22183 + |
|
22184 +/* Error: Tuner Part Code / Rev Code mismatches expected value */ |
|
22185 +#define MT_TUNER_ID_ERR (0x80000100) |
|
22186 + |
|
22187 +/* Error: Tuner Initialization failure */ |
|
22188 +#define MT_TUNER_INIT_ERR (0x80000200) |
|
22189 + |
|
22190 +/* User-definable fields (see mt_userdef.h) */ |
|
22191 +#define MT_USER_DEFINED1 (0x00001000) |
|
22192 +#define MT_USER_DEFINED2 (0x00002000) |
|
22193 +#define MT_USER_DEFINED3 (0x00004000) |
|
22194 +#define MT_USER_DEFINED4 (0x00008000) |
|
22195 +#define MT_USER_MASK (0x4000f000) |
|
22196 +#define MT_USER_SHIFT (12) |
|
22197 + |
|
22198 +/* Info: Mask of bits used for # of LO-related spurs that were avoided during tuning */ |
|
22199 +#define MT_SPUR_CNT_MASK (0x001f0000) |
|
22200 +#define MT_SPUR_SHIFT (16) |
|
22201 + |
|
22202 +/* Info: Tuner timeout waiting for condition */ |
|
22203 +#define MT_TUNER_TIMEOUT (0x00400000) |
|
22204 + |
|
22205 +/* Info: Unavoidable LO-related spur may be present in the output */ |
|
22206 +#define MT_SPUR_PRESENT (0x00800000) |
|
22207 + |
|
22208 +/* Info: Tuner input frequency is out of range */ |
|
22209 +#define MT_FIN_RANGE (0x01000000) |
|
22210 + |
|
22211 +/* Info: Tuner output frequency is out of range */ |
|
22212 +#define MT_FOUT_RANGE (0x02000000) |
|
22213 + |
|
22214 +/* Info: Upconverter frequency is out of range (may be reason for MT_UPC_UNLOCK) */ |
|
22215 +#define MT_UPC_RANGE (0x04000000) |
|
22216 + |
|
22217 +/* Info: Downconverter frequency is out of range (may be reason for MT_DPC_UNLOCK) */ |
|
22218 +#define MT_DNC_RANGE (0x08000000) |
|
22219 + |
|
22220 + |
|
22221 + |
|
22222 + |
|
22223 + |
|
22224 + |
|
22225 + |
|
22226 + |
|
22227 + |
|
22228 + |
|
22229 + |
|
22230 + |
|
22231 + |
|
22232 + |
|
22233 + |
|
22234 + |
|
22235 + |
|
22236 + |
|
22237 + |
|
22238 + |
|
22239 + |
|
22240 + |
|
22241 + |
|
22242 +// Microtune source code - mt_userdef.h |
|
22243 + |
|
22244 + |
|
22245 + |
|
22246 +/***************************************************************************** |
|
22247 +** |
|
22248 +** Name: mt_userdef.h |
|
22249 +** |
|
22250 +** Description: User-defined data types needed by MicroTuner source code. |
|
22251 +** |
|
22252 +** Customers must provide the code for these functions |
|
22253 +** in the file "mt_userdef.c". |
|
22254 +** |
|
22255 +** Customers must verify that the typedef's in the |
|
22256 +** "Data Types" section are correct for their platform. |
|
22257 +** |
|
22258 +** Functions |
|
22259 +** Requiring |
|
22260 +** Implementation: MT_WriteSub |
|
22261 +** MT_ReadSub |
|
22262 +** MT_Sleep |
|
22263 +** |
|
22264 +** References: None |
|
22265 +** |
|
22266 +** Exports: None |
|
22267 +** |
|
22268 +** CVS ID: $Id: mt_userdef.h,v 1.1 2006/06/22 20:18:12 software Exp $ |
|
22269 +** CVS Source: $Source: /export/home/cvsroot/software/tuners/MT2266/mt_userdef.h,v $ |
|
22270 +** |
|
22271 +** Revision History: |
|
22272 +** |
|
22273 +** SCR Date Author Description |
|
22274 +** ------------------------------------------------------------------------- |
|
22275 +** N/A 03-25-2004 DAD Original |
|
22276 +** 082 12-06-2004 JWS Multi-tuner support - requires MTxxxx_CNT |
|
22277 +** declarations |
|
22278 +** |
|
22279 +*****************************************************************************/ |
|
22280 +#if !defined( __MT_USERDEF_H ) |
|
22281 +#define __MT_USERDEF_H |
|
22282 + |
|
22283 +//#include "mt_errordef.h" |
|
22284 + |
|
22285 +#if defined( __cplusplus ) |
|
22286 +extern "C" /* Use "C" external linkage */ |
|
22287 +{ |
|
22288 +#endif |
|
22289 + |
|
22290 +/* |
|
22291 +** Data Types |
|
22292 +*/ |
|
22293 +typedef unsigned char U8Data; /* type corresponds to 8 bits */ |
|
22294 +typedef unsigned int UData_t; /* type must be at least 32 bits */ |
|
22295 +typedef int SData_t; /* type must be at least 32 bits */ |
|
22296 +typedef void * Handle_t; /* memory pointer type */ |
|
22297 +typedef double FData_t; /* floating point data type */ |
|
22298 + |
|
22299 +#define MAX_UDATA 0xffffffff /* max value storable in UData_t */ |
|
22300 + |
|
22301 +/* |
|
22302 +** Define an MTxxxx_CNT macro for each type of tuner that will be built |
|
22303 +** into your application (e.g., MT2121, MT2060). MT_TUNER_CNT |
|
22304 +** must be set to the SUM of all of the MTxxxx_CNT macros. |
|
22305 +** |
|
22306 +** #define MT2050_CNT (1) |
|
22307 +** #define MT2060_CNT (1) |
|
22308 +** #define MT2111_CNT (1) |
|
22309 +** #define MT2121_CNT (3) |
|
22310 +*/ |
|
22311 + |
|
22312 + |
|
22313 +#if !defined( MT_TUNER_CNT ) |
|
22314 +#define MT_TUNER_CNT (0) /* total num of MicroTuner tuners */ |
|
22315 +#endif |
|
22316 + |
|
22317 +/* |
|
22318 +** Optional user-defined Error/Info Codes (examples below) |
|
22319 +** |
|
22320 +** This is the area where you can define user-specific error/info return |
|
22321 +** codes to be returned by any of the functions you are responsible for |
|
22322 +** writing such as MT_WriteSub() and MT_ReadSub. There are four bits |
|
22323 +** available in the status field for your use. When set, these |
|
22324 +** bits will be returned in the status word returned by any tuner driver |
|
22325 +** call. If you OR in the MT_ERROR bit as well, the tuner driver code |
|
22326 +** will treat the code as an error. |
|
22327 +** |
|
22328 +** The following are a few examples of errors you can provide. |
|
22329 +** |
|
22330 +** Example 1: |
|
22331 +** You might check to see the hUserData handle is correct and issue |
|
22332 +** MY_USERDATA_INVALID which would be defined like this: |
|
22333 +** |
|
22334 +** #define MY_USERDATA_INVALID (MT_USER_ERROR | MT_USER_DEFINED1) |
|
22335 +** |
|
22336 +** |
|
22337 +** Example 2: |
|
22338 +** You might be able to provide more descriptive two-wire bus errors: |
|
22339 +** |
|
22340 +** #define NO_ACK (MT_USER_ERROR | MT_USER_DEFINED1) |
|
22341 +** #define NO_NACK (MT_USER_ERROR | MT_USER_DEFINED2) |
|
22342 +** #define BUS_BUSY (MT_USER_ERROR | MT_USER_DEFINED3) |
|
22343 +** |
|
22344 +** |
|
22345 +** Example 3: |
|
22346 +** You can also provide information (non-error) feedback: |
|
22347 +** |
|
22348 +** #define MY_INFO_1 (MT_USER_DEFINED1) |
|
22349 +** |
|
22350 +** |
|
22351 +** Example 4: |
|
22352 +** You can combine the fields together to make a multi-bit field. |
|
22353 +** This one can provide the tuner number based off of the addr |
|
22354 +** passed to MT_WriteSub or MT_ReadSub. It assumes that |
|
22355 +** MT_USER_DEFINED4 through MT_USER_DEFINED1 are contiguously. If |
|
22356 +** TUNER_NUM were OR'ed into the status word on an error, you could |
|
22357 +** use this to identify which tuner had the problem (and whether it |
|
22358 +** was during a read or write operation). |
|
22359 +** |
|
22360 +** #define TUNER_NUM ((addr & 0x07) >> 1) << MT_USER_SHIFT |
|
22361 +** |
|
22362 +*/ |
|
22363 + |
|
22364 +/***************************************************************************** |
|
22365 +** |
|
22366 +** Name: MT_WriteSub |
|
22367 +** |
|
22368 +** Description: Write values to device using a two-wire serial bus. |
|
22369 +** |
|
22370 +** Parameters: hUserData - User-specific I/O parameter that was |
|
22371 +** passed to tuner's Open function. |
|
22372 +** addr - device serial bus address (value passed |
|
22373 +** as parameter to MTxxxx_Open) |
|
22374 +** subAddress - serial bus sub-address (Register Address) |
|
22375 +** pData - pointer to the Data to be written to the |
|
22376 +** device |
|
22377 +** cnt - number of bytes/registers to be written |
|
22378 +** |
|
22379 +** Returns: status: |
|
22380 +** MT_OK - No errors |
|
22381 +** MT_COMM_ERR - Serial bus communications error |
|
22382 +** user-defined |
|
22383 +** |
|
22384 +** Notes: This is a callback function that is called from the |
|
22385 +** the tuning algorithm. You MUST provide code for this |
|
22386 +** function to write data using the tuner's 2-wire serial |
|
22387 +** bus. |
|
22388 +** |
|
22389 +** The hUserData parameter is a user-specific argument. |
|
22390 +** If additional arguments are needed for the user's |
|
22391 +** serial bus read/write functions, this argument can be |
|
22392 +** used to supply the necessary information. |
|
22393 +** The hUserData parameter is initialized in the tuner's Open |
|
22394 +** function. |
|
22395 +** |
|
22396 +** Revision History: |
|
22397 +** |
|
22398 +** SCR Date Author Description |
|
22399 +** ------------------------------------------------------------------------- |
|
22400 +** N/A 03-25-2004 DAD Original |
|
22401 +** |
|
22402 +*****************************************************************************/ |
|
22403 +UData_t MT_WriteSub(Handle_t hUserData, |
|
22404 + UData_t addr, |
|
22405 + U8Data subAddress, |
|
22406 + U8Data *pData, |
|
22407 + UData_t cnt); |
|
22408 + |
|
22409 + |
|
22410 +/***************************************************************************** |
|
22411 +** |
|
22412 +** Name: MT_ReadSub |
|
22413 +** |
|
22414 +** Description: Read values from device using a two-wire serial bus. |
|
22415 +** |
|
22416 +** Parameters: hUserData - User-specific I/O parameter that was |
|
22417 +** passed to tuner's Open function. |
|
22418 +** addr - device serial bus address (value passed |
|
22419 +** as parameter to MTxxxx_Open) |
|
22420 +** subAddress - serial bus sub-address (Register Address) |
|
22421 +** pData - pointer to the Data to be written to the |
|
22422 +** device |
|
22423 +** cnt - number of bytes/registers to be written |
|
22424 +** |
|
22425 +** Returns: status: |
|
22426 +** MT_OK - No errors |
|
22427 +** MT_COMM_ERR - Serial bus communications error |
|
22428 +** user-defined |
|
22429 +** |
|
22430 +** Notes: This is a callback function that is called from the |
|
22431 +** the tuning algorithm. You MUST provide code for this |
|
22432 +** function to read data using the tuner's 2-wire serial |
|
22433 +** bus. |
|
22434 +** |
|
22435 +** The hUserData parameter is a user-specific argument. |
|
22436 +** If additional arguments are needed for the user's |
|
22437 +** serial bus read/write functions, this argument can be |
|
22438 +** used to supply the necessary information. |
|
22439 +** The hUserData parameter is initialized in the tuner's Open |
|
22440 +** function. |
|
22441 +** |
|
22442 +** Revision History: |
|
22443 +** |
|
22444 +** SCR Date Author Description |
|
22445 +** ------------------------------------------------------------------------- |
|
22446 +** N/A 03-25-2004 DAD Original |
|
22447 +** |
|
22448 +*****************************************************************************/ |
|
22449 +UData_t MT_ReadSub(Handle_t hUserData, |
|
22450 + UData_t addr, |
|
22451 + U8Data subAddress, |
|
22452 + U8Data *pData, |
|
22453 + UData_t cnt); |
|
22454 + |
|
22455 + |
|
22456 +/***************************************************************************** |
|
22457 +** |
|
22458 +** Name: MT_Sleep |
|
22459 +** |
|
22460 +** Description: Delay execution for "nMinDelayTime" milliseconds |
|
22461 +** |
|
22462 +** Parameters: hUserData - User-specific I/O parameter that was |
|
22463 +** passed to tuner's Open function. |
|
22464 +** nMinDelayTime - Delay time in milliseconds |
|
22465 +** |
|
22466 +** Returns: None. |
|
22467 +** |
|
22468 +** Notes: This is a callback function that is called from the |
|
22469 +** the tuning algorithm. You MUST provide code that |
|
22470 +** blocks execution for the specified period of time. |
|
22471 +** |
|
22472 +** Revision History: |
|
22473 +** |
|
22474 +** SCR Date Author Description |
|
22475 +** ------------------------------------------------------------------------- |
|
22476 +** N/A 03-25-2004 DAD Original |
|
22477 +** |
|
22478 +*****************************************************************************/ |
|
22479 +void MT_Sleep(Handle_t hUserData, |
|
22480 + UData_t nMinDelayTime); |
|
22481 + |
|
22482 + |
|
22483 +#if defined(MT2060_CNT) |
|
22484 +#if MT2060_CNT > 0 |
|
22485 +/***************************************************************************** |
|
22486 +** |
|
22487 +** Name: MT_TunerGain (for MT2060 only) |
|
22488 +** |
|
22489 +** Description: Measure the relative tuner gain using the demodulator |
|
22490 +** |
|
22491 +** Parameters: hUserData - User-specific I/O parameter that was |
|
22492 +** passed to tuner's Open function. |
|
22493 +** pMeas - Tuner gain (1/100 of dB scale). |
|
22494 +** ie. 1234 = 12.34 (dB) |
|
22495 +** |
|
22496 +** Returns: status: |
|
22497 +** MT_OK - No errors |
|
22498 +** user-defined errors could be set |
|
22499 +** |
|
22500 +** Notes: This is a callback function that is called from the |
|
22501 +** the 1st IF location routine. You MUST provide |
|
22502 +** code that measures the relative tuner gain in a dB |
|
22503 +** (not linear) scale. The return value is an integer |
|
22504 +** value scaled to 1/100 of a dB. |
|
22505 +** |
|
22506 +** Revision History: |
|
22507 +** |
|
22508 +** SCR Date Author Description |
|
22509 +** ------------------------------------------------------------------------- |
|
22510 +** N/A 06-16-2004 DAD Original |
|
22511 +** N/A 11-30-2004 DAD Renamed from MT_DemodInputPower. This name |
|
22512 +** better describes what this function does. |
|
22513 +** |
|
22514 +*****************************************************************************/ |
|
22515 +UData_t MT_TunerGain(Handle_t hUserData, |
|
22516 + SData_t* pMeas); |
|
22517 +#endif |
|
22518 +#endif |
|
22519 + |
|
22520 +#if defined( __cplusplus ) |
|
22521 +} |
|
22522 +#endif |
|
22523 + |
|
22524 +#endif |
|
22525 + |
|
22526 + |
|
22527 + |
|
22528 + |
|
22529 + |
|
22530 + |
|
22531 + |
|
22532 + |
|
22533 + |
|
22534 + |
|
22535 + |
|
22536 + |
|
22537 + |
|
22538 + |
|
22539 + |
|
22540 + |
|
22541 + |
|
22542 + |
|
22543 + |
|
22544 + |
|
22545 + |
|
22546 + |
|
22547 + |
|
22548 +// Microtune source code - mt2266.h |
|
22549 + |
|
22550 + |
|
22551 + |
|
22552 +/***************************************************************************** |
|
22553 +** |
|
22554 +** Name: mt2266.h |
|
22555 +** |
|
22556 +** Copyright 2007 Microtune, Inc. All Rights Reserved |
|
22557 +** |
|
22558 +** This source code file contains confidential information and/or trade |
|
22559 +** secrets of Microtune, Inc. or its affiliates and is subject to the |
|
22560 +** terms of your confidentiality agreement with Microtune, Inc. or one of |
|
22561 +** its affiliates, as applicable. |
|
22562 +** |
|
22563 +*****************************************************************************/ |
|
22564 + |
|
22565 +/***************************************************************************** |
|
22566 +** |
|
22567 +** Name: mt2266.h |
|
22568 +** |
|
22569 +** Description: Microtune MT2266 Tuner software interface. |
|
22570 +** Supports tuners with Part/Rev code: 0x85. |
|
22571 +** |
|
22572 +** Functions |
|
22573 +** Implemented: UData_t MT2266_Open |
|
22574 +** UData_t MT2266_Close |
|
22575 +** UData_t MT2266_ChangeFreq |
|
22576 +** UData_t MT2266_GetLocked |
|
22577 +** UData_t MT2266_GetParam |
|
22578 +** UData_t MT2266_GetReg |
|
22579 +** UData_t MT2266_GetUHFXFreqs |
|
22580 +** UData_t MT2266_GetUserData |
|
22581 +** UData_t MT2266_ReInit |
|
22582 +** UData_t MT2266_SetParam |
|
22583 +** UData_t MT2266_SetPowerModes |
|
22584 +** UData_t MT2266_SetReg |
|
22585 +** UData_t MT2266_SetUHFXFreqs |
|
22586 +** UData_t MT2266_Tune |
|
22587 +** |
|
22588 +** References: AN-00010: MicroTuner Serial Interface Application Note |
|
22589 +** MicroTune, Inc. |
|
22590 +** |
|
22591 +** Exports: None |
|
22592 +** |
|
22593 +** Dependencies: MT_ReadSub(hUserData, IC_Addr, subAddress, *pData, cnt); |
|
22594 +** - Read byte(s) of data from the two-wire bus. |
|
22595 +** |
|
22596 +** MT_WriteSub(hUserData, IC_Addr, subAddress, *pData, cnt); |
|
22597 +** - Write byte(s) of data to the two-wire bus. |
|
22598 +** |
|
22599 +** MT_Sleep(hUserData, nMinDelayTime); |
|
22600 +** - Delay execution for x milliseconds |
|
22601 +** |
|
22602 +** CVS ID: $Id: mt2266.h,v 1.3 2007/10/02 18:43:17 software Exp $ |
|
22603 +** CVS Source: $Source: /export/home/cvsroot/software/tuners/MT2266/mt2266.h,v $ |
|
22604 +** |
|
22605 +** Revision History: |
|
22606 +** |
|
22607 +** SCR Date Author Description |
|
22608 +** ------------------------------------------------------------------------- |
|
22609 +** N/A 05-30-2006 DAD Ver 1.0: Modified version of mt2260.c (Ver 1.01). |
|
22610 +** N/A 11-01-2006 RSK Ver 1.02: Adding Get/Set UHFXFreq access functions. |
|
22611 +** 118 05-09-2007 RSK Ver 1.05: Adding Standard MTxxxx_Tune() API. |
|
22612 +** |
|
22613 +*****************************************************************************/ |
|
22614 +#if !defined( __MT2266_H ) |
|
22615 +#define __MT2266_H |
|
22616 + |
|
22617 +//#include "mt_userdef.h" |
|
22618 + |
|
22619 +#if defined( __cplusplus ) |
|
22620 +extern "C" /* Use "C" external linkage */ |
|
22621 +{ |
|
22622 +#endif |
|
22623 + |
|
22624 +/* |
|
22625 +** Parameter for function MT2266_GetParam & MT2266_SetParam that |
|
22626 +** specifies the tuning algorithm parameter to be read/written. |
|
22627 +*/ |
|
22628 +typedef enum |
|
22629 +{ |
|
22630 + /* tuner address set by MT2266_Open() */ |
|
22631 + MT2266_IC_ADDR, |
|
22632 + |
|
22633 + /* max number of MT2266 tuners set by MT2266_CNT in mt_userdef.h */ |
|
22634 + MT2266_MAX_OPEN, |
|
22635 + |
|
22636 + /* current number of open MT2266 tuners set by MT2266_Open() */ |
|
22637 + MT2266_NUM_OPEN, |
|
22638 + |
|
22639 + /* Number of tuner registers */ |
|
22640 + MT2266_NUM_REGS, |
|
22641 + |
|
22642 + /* crystal frequency (default: 18000000 Hz) */ |
|
22643 + MT2266_SRO_FREQ, |
|
22644 + |
|
22645 + /* min tuning step size (default: 50000 Hz) */ |
|
22646 + MT2266_STEPSIZE, |
|
22647 + |
|
22648 + /* input center frequency set by MT2266_ChangeFreq() */ |
|
22649 + MT2266_INPUT_FREQ, |
|
22650 + |
|
22651 + /* LO Frequency set by MT2266_ChangeFreq() */ |
|
22652 + MT2266_LO_FREQ, |
|
22653 + |
|
22654 + /* output channel bandwidth (default: 8000000 Hz) */ |
|
22655 + MT2266_OUTPUT_BW, |
|
22656 + |
|
22657 + /* Base band filter calibration RC code (default: N/A) */ |
|
22658 + MT2266_RC2_VALUE, |
|
22659 + |
|
22660 + /* Base band filter nominal cal RC code (default: N/A) */ |
|
22661 + MT2266_RC2_NOMINAL, |
|
22662 + |
|
22663 + /* RF attenuator A/D readback (read-only) */ |
|
22664 + MT2266_RF_ADC, |
|
22665 + |
|
22666 + /* BB attenuator A/D readback (read-only) */ |
|
22667 + MT2266_BB_ADC, |
|
22668 + |
|
22669 + /* RF attenuator setting (default: varies) */ |
|
22670 + MT2266_RF_ATTN, |
|
22671 + |
|
22672 + /* BB attenuator setting (default: varies) */ |
|
22673 + MT2266_BB_ATTN, |
|
22674 + |
|
22675 + /* RF external / internal atten control (default: varies) */ |
|
22676 + MT2266_RF_EXT, |
|
22677 + |
|
22678 + /* BB external / internal atten control (default: 1) */ |
|
22679 + MT2266_BB_EXT, |
|
22680 + |
|
22681 + /* LNA gain setting (0-15) (default: varies) */ |
|
22682 + MT2266_LNA_GAIN, |
|
22683 + |
|
22684 + /* Decrement LNA Gain (where arg=min LNA Gain value) */ |
|
22685 + MT2266_LNA_GAIN_DECR, |
|
22686 + |
|
22687 + /* Increment LNA Gain (where arg=max LNA Gain value) */ |
|
22688 + MT2266_LNA_GAIN_INCR, |
|
22689 + |
|
22690 + /* Set for UHF max sensitivity mode */ |
|
22691 + MT2266_UHF_MAXSENS, |
|
22692 + |
|
22693 + /* Set for UHF normal mode */ |
|
22694 + MT2266_UHF_NORMAL, |
|
22695 + |
|
22696 + MT2266_EOP /* last entry in enumerated list */ |
|
22697 +} MT2266_Param; |
|
22698 + |
|
22699 + |
|
22700 +/* |
|
22701 +** Parameter for function MT2266_GetUHFXFreqs & MT2266_SetUHFXFreqs that |
|
22702 +** specifies the particular frequency crossover table to be read/written. |
|
22703 +*/ |
|
22704 +typedef enum |
|
22705 +{ |
|
22706 + /* Reference the UHF 0 filter, without any attenuation */ |
|
22707 + MT2266_UHF0, |
|
22708 + |
|
22709 + /* Reference the UHF 1 filter, without any attenuation */ |
|
22710 + MT2266_UHF1, |
|
22711 + |
|
22712 + /* Reference the UHF 0 filter, with attenuation */ |
|
22713 + MT2266_UHF0_ATTEN, |
|
22714 + |
|
22715 + /* Reference the UHF 1 filter, with attenuation */ |
|
22716 + MT2266_UHF1_ATTEN, |
|
22717 + |
|
22718 + MT2266_NUMBER_OF_XFREQ_SETS /* last entry in enumerated list */ |
|
22719 + |
|
22720 +} MT2266_UHFXFreq_Type; |
|
22721 + |
|
22722 + |
|
22723 +#define MT2266_NUM_XFREQS (16) |
|
22724 + |
|
22725 +typedef UData_t MT2266_XFreq_Set[ MT2266_NUM_XFREQS ]; |
|
22726 + |
|
22727 +/* |
|
22728 +** Constants for Specifying Operating Band of the Tuner |
|
22729 +*/ |
|
22730 +#define MT2266_VHF_BAND (0) |
|
22731 +#define MT2266_UHF_BAND (1) |
|
22732 +#define MT2266_L_BAND (2) |
|
22733 + |
|
22734 +/* |
|
22735 +** Constants for specifying power modes these values |
|
22736 +** are bit-mapped and can be added/OR'ed to indicate |
|
22737 +** multiple settings. Examples: |
|
22738 +** MT2266_SetPowerModes(h, MT2266_NO_ENABLES + MT22266_SROsd); |
|
22739 +** MT2266_SetPowerModes(h, MT2266_ALL_ENABLES | MT22266_SRO_NOT_sd); |
|
22740 +** MT2266_SetPowerModes(h, MT2266_NO_ENABLES + MT22266_SROsd); |
|
22741 +** MT2266_SetPowerModes(h, MT2266_SROen + MT22266_LOen + MT2266_ADCen); |
|
22742 +*/ |
|
22743 +#define MT2266_SROen (0x01) |
|
22744 +#define MT2266_LOen (0x02) |
|
22745 +#define MT2266_ADCen (0x04) |
|
22746 +#define MT2266_PDen (0x08) |
|
22747 +#define MT2266_DCOCen (0x10) |
|
22748 +#define MT2266_BBen (0x20) |
|
22749 +#define MT2266_MIXen (0x40) |
|
22750 +#define MT2266_LNAen (0x80) |
|
22751 +#define MT2266_ALL_ENABLES (0xFF) |
|
22752 +#define MT2266_NO_ENABLES (0x00) |
|
22753 +#define MT2266_SROsd (0x100) |
|
22754 +#define MT2266_SRO_NOT_sd (0x000) |
|
22755 + |
|
22756 +/* ====== Functions which are declared in mt2266.c File ======= */ |
|
22757 + |
|
22758 +/****************************************************************************** |
|
22759 +** |
|
22760 +** Name: MT2266_Open |
|
22761 +** |
|
22762 +** Description: Initialize the tuner's register values. |
|
22763 +** |
|
22764 +** Usage: status = MT2266_Open(0xC0, &hMT2266, NULL); |
|
22765 +** if (MT_IS_ERROR(status)) |
|
22766 +** // Check error codes for reason |
|
22767 +** |
|
22768 +** Parameters: MT2266_Addr - Serial bus address of the tuner. |
|
22769 +** hMT2266 - Tuner handle passed back. |
|
22770 +** hUserData - User-defined data, if needed for the |
|
22771 +** MT_ReadSub() & MT_WriteSub functions. |
|
22772 +** |
|
22773 +** Returns: status: |
|
22774 +** MT_OK - No errors |
|
22775 +** MT_TUNER_ID_ERR - Tuner Part/Rev code mismatch |
|
22776 +** MT_TUNER_INIT_ERR - Tuner initialization failed |
|
22777 +** MT_COMM_ERR - Serial bus communications error |
|
22778 +** MT_ARG_NULL - Null pointer argument passed |
|
22779 +** MT_TUNER_CNT_ERR - Too many tuners open |
|
22780 +** |
|
22781 +** Dependencies: MT_ReadSub - Read byte(s) of data from the two-wire bus |
|
22782 +** MT_WriteSub - Write byte(s) of data to the two-wire bus |
|
22783 +** |
|
22784 +** Revision History: |
|
22785 +** |
|
22786 +** SCR Date Author Description |
|
22787 +** ------------------------------------------------------------------------- |
|
22788 +** N/A 02-03-2006 DAD/JWS Original. |
|
22789 +** |
|
22790 +******************************************************************************/ |
|
22791 +UData_t MT2266_Open(UData_t MT2266_Addr, |
|
22792 + Handle_t* hMT2266, |
|
22793 + Handle_t hUserData); |
|
22794 + |
|
22795 + |
|
22796 +/****************************************************************************** |
|
22797 +** |
|
22798 +** Name: MT2266_Close |
|
22799 +** |
|
22800 +** Description: Release the handle to the tuner. |
|
22801 +** |
|
22802 +** Parameters: hMT2266 - Handle to the MT2266 tuner |
|
22803 +** |
|
22804 +** Usage: status = MT2266_Close(hMT2266); |
|
22805 +** |
|
22806 +** Returns: status: |
|
22807 +** MT_OK - No errors |
|
22808 +** MT_INV_HANDLE - Invalid tuner handle |
|
22809 +** |
|
22810 +** Dependencies: mt_errordef.h - definition of error codes |
|
22811 +** |
|
22812 +** Revision History: |
|
22813 +** |
|
22814 +** SCR Date Author Description |
|
22815 +** ------------------------------------------------------------------------- |
|
22816 +** N/A 02-03-2006 DAD/JWS Original. |
|
22817 +** |
|
22818 +******************************************************************************/ |
|
22819 +UData_t MT2266_Close(Handle_t hMT2266); |
|
22820 + |
|
22821 + |
|
22822 +/**************************************************************************** |
|
22823 +** |
|
22824 +** Name: MT2266_ChangeFreq |
|
22825 +** |
|
22826 +** Description: Change the tuner's tuned frequency to f_in. |
|
22827 +** |
|
22828 +** Parameters: h - Open handle to the tuner (from MT2266_Open). |
|
22829 +** f_in - RF input center frequency (in Hz). |
|
22830 +** |
|
22831 +** Usage: status = MT2266_ChangeFreq(hMT2266, f_in); |
|
22832 +** |
|
22833 +** Returns: status: |
|
22834 +** MT_OK - No errors |
|
22835 +** MT_INV_HANDLE - Invalid tuner handle |
|
22836 +** MT_DNC_UNLOCK - Downconverter PLL unlocked |
|
22837 +** MT_COMM_ERR - Serial bus communications error |
|
22838 +** MT_FIN_RANGE - Input freq out of range |
|
22839 +** MT_DNC_RANGE - Downconverter freq out of range |
|
22840 +** |
|
22841 +** Dependencies: MUST CALL MT2266_Open BEFORE MT2266_ChangeFreq! |
|
22842 +** |
|
22843 +** MT_ReadSub - Read byte(s) of data from the two-wire-bus |
|
22844 +** MT_WriteSub - Write byte(s) of data to the two-wire-bus |
|
22845 +** MT_Sleep - Delay execution for x milliseconds |
|
22846 +** MT2266_GetLocked - Checks to see if the PLL is locked |
|
22847 +** |
|
22848 +** Revision History: |
|
22849 +** |
|
22850 +** SCR Date Author Description |
|
22851 +** ------------------------------------------------------------------------- |
|
22852 +** N/A 02-03-2006 DAD/JWS Original. |
|
22853 +** |
|
22854 +******************************************************************************/ |
|
22855 +UData_t MT2266_ChangeFreq(Handle_t h, |
|
22856 + UData_t f_in); |
|
22857 + |
|
22858 + |
|
22859 +/**************************************************************************** |
|
22860 +** |
|
22861 +** Name: MT2266_GetLocked |
|
22862 +** |
|
22863 +** Description: Checks to see if the PLL is locked. |
|
22864 +** |
|
22865 +** Parameters: h - Open handle to the tuner (from MT2266_Open). |
|
22866 +** |
|
22867 +** Usage: status = MT2266_GetLocked(hMT2266); |
|
22868 +** if (status & MT_DNC_UNLOCK) |
|
22869 +** // error!, PLL is unlocked |
|
22870 +** |
|
22871 +** Returns: status: |
|
22872 +** MT_OK - No errors |
|
22873 +** MT_DNC_UNLOCK - Downconverter PLL unlocked |
|
22874 +** MT_COMM_ERR - Serial bus communications error |
|
22875 +** MT_INV_HANDLE - Invalid tuner handle |
|
22876 +** |
|
22877 +** Dependencies: MT_ReadSub - Read byte(s) of data from the serial bus |
|
22878 +** MT_Sleep - Delay execution for x milliseconds |
|
22879 +** |
|
22880 +** Revision History: |
|
22881 +** |
|
22882 +** SCR Date Author Description |
|
22883 +** ------------------------------------------------------------------------- |
|
22884 +** N/A 02-03-2006 DAD/JWS Original. |
|
22885 +** |
|
22886 +****************************************************************************/ |
|
22887 +UData_t MT2266_GetLocked(Handle_t h); |
|
22888 + |
|
22889 + |
|
22890 +/**************************************************************************** |
|
22891 +** |
|
22892 +** Name: MT2266_GetParam |
|
22893 +** |
|
22894 +** Description: Gets a tuning algorithm parameter. |
|
22895 +** |
|
22896 +** This function provides access to the internals of the |
|
22897 +** tuning algorithm - mostly for testing purposes. |
|
22898 +** |
|
22899 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
22900 +** param - Tuning algorithm parameter |
|
22901 +** (see enum MT2266_Param) |
|
22902 +** pValue - ptr to returned value |
|
22903 +** |
|
22904 +** param Description |
|
22905 +** ---------------------- -------------------------------- |
|
22906 +** MT2266_IC_ADDR Serial Bus address of this tuner |
|
22907 +** MT2266_MAX_OPEN Max number of MT2266's that can be open |
|
22908 +** MT2266_NUM_OPEN Number of MT2266's currently open |
|
22909 +** MT2266_NUM_REGS Number of tuner registers |
|
22910 +** MT2266_SRO_FREQ crystal frequency |
|
22911 +** MT2266_STEPSIZE minimum tuning step size |
|
22912 +** MT2266_INPUT_FREQ input center frequency |
|
22913 +** MT2266_LO_FREQ LO Frequency |
|
22914 +** MT2266_OUTPUT_BW Output channel bandwidth |
|
22915 +** MT2266_RC2_VALUE Base band filter cal RC code (method 2) |
|
22916 +** MT2266_RF_ADC RF attenuator A/D readback |
|
22917 +** MT2266_RF_ATTN RF attenuation (0-255) |
|
22918 +** MT2266_RF_EXT External control of RF atten |
|
22919 +** MT2266_LNA_GAIN LNA gain setting (0-15) |
|
22920 +** MT2266_BB_ADC BB attenuator A/D readback |
|
22921 +** MT2266_BB_ATTN Baseband attenuation (0-255) |
|
22922 +** MT2266_BB_EXT External control of BB atten |
|
22923 +** |
|
22924 +** Usage: status |= MT2266_GetParam(hMT2266, |
|
22925 +** MT2266_OUTPUT_BW, |
|
22926 +** &f_bw); |
|
22927 +** |
|
22928 +** Returns: status: |
|
22929 +** MT_OK - No errors |
|
22930 +** MT_INV_HANDLE - Invalid tuner handle |
|
22931 +** MT_ARG_NULL - Null pointer argument passed |
|
22932 +** MT_ARG_RANGE - Invalid parameter requested |
|
22933 +** |
|
22934 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
22935 +** |
|
22936 +** See Also: MT2266_SetParam, MT2266_Open |
|
22937 +** |
|
22938 +** Revision History: |
|
22939 +** |
|
22940 +** SCR Date Author Description |
|
22941 +** ------------------------------------------------------------------------- |
|
22942 +** N/A 02-03-2006 DAD/JWS Original. |
|
22943 +** |
|
22944 +****************************************************************************/ |
|
22945 +UData_t MT2266_GetParam(Handle_t h, |
|
22946 + MT2266_Param param, |
|
22947 + UData_t* pValue); |
|
22948 + |
|
22949 + |
|
22950 +/**************************************************************************** |
|
22951 +** |
|
22952 +** Name: MT2266_GetReg |
|
22953 +** |
|
22954 +** Description: Gets an MT2266 register. |
|
22955 +** |
|
22956 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
22957 +** reg - MT2266 register/subaddress location |
|
22958 +** *val - MT2266 register/subaddress value |
|
22959 +** |
|
22960 +** Returns: status: |
|
22961 +** MT_OK - No errors |
|
22962 +** MT_COMM_ERR - Serial bus communications error |
|
22963 +** MT_INV_HANDLE - Invalid tuner handle |
|
22964 +** MT_ARG_NULL - Null pointer argument passed |
|
22965 +** MT_ARG_RANGE - Argument out of range |
|
22966 +** |
|
22967 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
22968 +** |
|
22969 +** Use this function if you need to read a register from |
|
22970 +** the MT2266. |
|
22971 +** |
|
22972 +** Revision History: |
|
22973 +** |
|
22974 +** SCR Date Author Description |
|
22975 +** ------------------------------------------------------------------------- |
|
22976 +** N/A 02-03-2006 DAD/JWS Original. |
|
22977 +** |
|
22978 +****************************************************************************/ |
|
22979 +UData_t MT2266_GetReg(Handle_t h, |
|
22980 + U8Data reg, |
|
22981 + U8Data* val); |
|
22982 + |
|
22983 + |
|
22984 +/**************************************************************************** |
|
22985 +** |
|
22986 +** Name: MT2266_GetUHFXFreqs |
|
22987 +** |
|
22988 +** Description: Retrieves the specified set of UHF Crossover Frequencies |
|
22989 +** |
|
22990 +** Parameters: h - Open handle to the tuner (from MT2266_Open). |
|
22991 +** |
|
22992 +** Usage: MT2266_Freq_Set tmpFreqs; |
|
22993 +** status = MT2266_GetUHFXFreqs(hMT2266, |
|
22994 +** MT2266_UHF1_WITH_ATTENUATION, |
|
22995 +** tmpFreqs ); |
|
22996 +** if (status & MT_ARG_RANGE) |
|
22997 +** // error, Invalid UHF Crossover Frequency Set requested. |
|
22998 +** else |
|
22999 +** for( int i = 0; i < MT2266_NUM_XFREQS; i++ ) |
|
23000 +** . . . |
|
23001 +** |
|
23002 +** |
|
23003 +** Returns: status: |
|
23004 +** MT_OK - No errors |
|
23005 +** MT_ARG_RANGE - freq_type is out of range. |
|
23006 +** MT_INV_HANDLE - Invalid tuner handle |
|
23007 +** |
|
23008 +** Dependencies: freqs_buffer *must* be defined of type MT2266_Freq_Set |
|
23009 +** to assure sufficient space allocation! |
|
23010 +** |
|
23011 +** USERS MUST CALL MT2266_Open() FIRST! |
|
23012 +** |
|
23013 +** See Also: MT2266_SetUHFXFreqs |
|
23014 +** |
|
23015 +** Revision History: |
|
23016 +** |
|
23017 +** SCR Date Author Description |
|
23018 +** ------------------------------------------------------------------------- |
|
23019 +** N/A 11-01-2006 RSK Original. |
|
23020 +** |
|
23021 +****************************************************************************/ |
|
23022 +UData_t MT2266_GetUHFXFreqs(Handle_t h, |
|
23023 + MT2266_UHFXFreq_Type freq_type, |
|
23024 + MT2266_XFreq_Set freqs_buffer); |
|
23025 + |
|
23026 + |
|
23027 +/**************************************************************************** |
|
23028 +** |
|
23029 +** Name: MT2266_GetUserData |
|
23030 +** |
|
23031 +** Description: Gets the user-defined data item. |
|
23032 +** |
|
23033 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
23034 +** |
|
23035 +** Usage: status = MT2266_GetUserData(hMT2266, &hUserData); |
|
23036 +** |
|
23037 +** Returns: status: |
|
23038 +** MT_OK - No errors |
|
23039 +** MT_INV_HANDLE - Invalid tuner handle |
|
23040 +** MT_ARG_NULL - Null pointer argument passed |
|
23041 +** |
|
23042 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
23043 +** |
|
23044 +** The hUserData parameter is a user-specific argument |
|
23045 +** that is stored internally with the other tuner- |
|
23046 +** specific information. |
|
23047 +** |
|
23048 +** For example, if additional arguments are needed |
|
23049 +** for the user to identify the device communicating |
|
23050 +** with the tuner, this argument can be used to supply |
|
23051 +** the necessary information. |
|
23052 +** |
|
23053 +** The hUserData parameter is initialized in the tuner's |
|
23054 +** Open function to NULL. |
|
23055 +** |
|
23056 +** See Also: MT2266_SetUserData, MT2266_Open |
|
23057 +** |
|
23058 +** Revision History: |
|
23059 +** |
|
23060 +** SCR Date Author Description |
|
23061 +** ------------------------------------------------------------------------- |
|
23062 +** N/A 02-03-2006 DAD/JWS Original. |
|
23063 +** |
|
23064 +****************************************************************************/ |
|
23065 +UData_t MT2266_GetUserData(Handle_t h, |
|
23066 + Handle_t* hUserData); |
|
23067 + |
|
23068 + |
|
23069 +/****************************************************************************** |
|
23070 +** |
|
23071 +** Name: MT2266_ReInit |
|
23072 +** |
|
23073 +** Description: Initialize the tuner's register values. |
|
23074 +** |
|
23075 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
23076 +** |
|
23077 +** Returns: status: |
|
23078 +** MT_OK - No errors |
|
23079 +** MT_TUNER_ID_ERR - Tuner Part/Rev code mismatch |
|
23080 +** MT_TUNER_INIT_ERR - Tuner initialization failed |
|
23081 +** MT_INV_HANDLE - Invalid tuner handle |
|
23082 +** MT_COMM_ERR - Serial bus communications error |
|
23083 +** |
|
23084 +** Dependencies: MT_ReadSub - Read byte(s) of data from the two-wire bus |
|
23085 +** MT_WriteSub - Write byte(s) of data to the two-wire bus |
|
23086 +** |
|
23087 +** Revision History: |
|
23088 +** |
|
23089 +** SCR Date Author Description |
|
23090 +** ------------------------------------------------------------------------- |
|
23091 +** N/A 02-03-2006 DAD/JWS Original. |
|
23092 +** |
|
23093 +******************************************************************************/ |
|
23094 +UData_t MT2266_ReInit(Handle_t h); |
|
23095 + |
|
23096 + |
|
23097 +/**************************************************************************** |
|
23098 +** |
|
23099 +** Name: MT2266_SetParam |
|
23100 +** |
|
23101 +** Description: Sets a tuning algorithm parameter. |
|
23102 +** |
|
23103 +** This function provides access to the internals of the |
|
23104 +** tuning algorithm. You can override many of the tuning |
|
23105 +** algorithm defaults using this function. |
|
23106 +** |
|
23107 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
23108 +** param - Tuning algorithm parameter |
|
23109 +** (see enum MT2266_Param) |
|
23110 +** nValue - value to be set |
|
23111 +** |
|
23112 +** param Description |
|
23113 +** ---------------------- -------------------------------- |
|
23114 +** MT2266_SRO_FREQ crystal frequency |
|
23115 +** MT2266_STEPSIZE minimum tuning step size |
|
23116 +** MT2266_INPUT_FREQ Center of input channel |
|
23117 +** MT2266_OUTPUT_BW Output channel bandwidth |
|
23118 +** MT2266_RF_ATTN RF attenuation (0-255) |
|
23119 +** MT2266_RF_EXT External control of RF atten |
|
23120 +** MT2266_LNA_GAIN LNA gain setting (0-15) |
|
23121 +** MT2266_LNA_GAIN_DECR Decrement LNA Gain (arg=min) |
|
23122 +** MT2266_LNA_GAIN_INCR Increment LNA Gain (arg=max) |
|
23123 +** MT2266_BB_ATTN Baseband attenuation (0-255) |
|
23124 +** MT2266_BB_EXT External control of BB atten |
|
23125 +** MT2266_UHF_MAXSENS Set for UHF max sensitivity mode |
|
23126 +** MT2266_UHF_NORMAL Set for UHF normal mode |
|
23127 +** |
|
23128 +** Usage: status |= MT2266_SetParam(hMT2266, |
|
23129 +** MT2266_STEPSIZE, |
|
23130 +** 50000); |
|
23131 +** |
|
23132 +** Returns: status: |
|
23133 +** MT_OK - No errors |
|
23134 +** MT_INV_HANDLE - Invalid tuner handle |
|
23135 +** MT_ARG_NULL - Null pointer argument passed |
|
23136 +** MT_ARG_RANGE - Invalid parameter requested |
|
23137 +** or set value out of range |
|
23138 +** or non-writable parameter |
|
23139 +** |
|
23140 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
23141 +** |
|
23142 +** See Also: MT2266_GetParam, MT2266_Open |
|
23143 +** |
|
23144 +** Revision History: |
|
23145 +** |
|
23146 +** SCR Date Author Description |
|
23147 +** ------------------------------------------------------------------------- |
|
23148 +** N/A 02-03-2006 DAD/JWS Original. |
|
23149 +** |
|
23150 +****************************************************************************/ |
|
23151 +UData_t MT2266_SetParam(Handle_t h, |
|
23152 + MT2266_Param param, |
|
23153 + UData_t nValue); |
|
23154 + |
|
23155 + |
|
23156 +/**************************************************************************** |
|
23157 +** |
|
23158 +** Name: MT2266_SetPowerModes |
|
23159 +** |
|
23160 +** Description: Sets the bits in the MT2266_ENABLES register and the |
|
23161 +** SROsd bit in the MT2266_SROADC_CTRL register. |
|
23162 +** |
|
23163 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
23164 +** flags - Bit mask of flags to indicate enabled |
|
23165 +** bits. |
|
23166 +** |
|
23167 +** Usage: status = MT2266_SetPowerModes(hMT2266, flags); |
|
23168 +** |
|
23169 +** Returns: status: |
|
23170 +** MT_OK - No errors |
|
23171 +** MT_INV_HANDLE - Invalid tuner handle |
|
23172 +** |
|
23173 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
23174 +** |
|
23175 +** The bits in the MT2266_ENABLES register and the |
|
23176 +** SROsd bit are set according to the supplied flags. |
|
23177 +** |
|
23178 +** The pre-defined flags are as follows: |
|
23179 +** MT2266_SROen |
|
23180 +** MT2266_LOen |
|
23181 +** MT2266_ADCen |
|
23182 +** MT2266_PDen |
|
23183 +** MT2266_DCOCen |
|
23184 +** MT2266_BBen |
|
23185 +** MT2266_MIXen |
|
23186 +** MT2266_LNAen |
|
23187 +** MT2266_ALL_ENABLES |
|
23188 +** MT2266_NO_ENABLES |
|
23189 +** MT2266_SROsd |
|
23190 +** MT2266_SRO_NOT_sd |
|
23191 +** |
|
23192 +** ONLY the enable bits (or SROsd bit) specified in the |
|
23193 +** flags parameter will be set. Any flag which is not |
|
23194 +** included, will cause that bit to be disabled. |
|
23195 +** |
|
23196 +** The ALL_ENABLES, NO_ENABLES, and SRO_NOT_sd constants |
|
23197 +** are for convenience. The NO_ENABLES and SRO_NOT_sd |
|
23198 +** do not actually have to be included, but are provided |
|
23199 +** for clarity. |
|
23200 +** |
|
23201 +** See Also: MT2266_Open |
|
23202 +** |
|
23203 +** Revision History: |
|
23204 +** |
|
23205 +** SCR Date Author Description |
|
23206 +** ------------------------------------------------------------------------- |
|
23207 +** N/A 02-03-2006 DAD/JWS Original. |
|
23208 +** |
|
23209 +****************************************************************************/ |
|
23210 +UData_t MT2266_SetPowerModes(Handle_t h, |
|
23211 + UData_t flags); |
|
23212 + |
|
23213 + |
|
23214 +/**************************************************************************** |
|
23215 +** |
|
23216 +** Name: MT2266_SetReg |
|
23217 +** |
|
23218 +** Description: Sets an MT2266 register. |
|
23219 +** |
|
23220 +** Parameters: h - Tuner handle (returned by MT2266_Open) |
|
23221 +** reg - MT2266 register/subaddress location |
|
23222 +** val - MT2266 register/subaddress value |
|
23223 +** |
|
23224 +** Returns: status: |
|
23225 +** MT_OK - No errors |
|
23226 +** MT_COMM_ERR - Serial bus communications error |
|
23227 +** MT_INV_HANDLE - Invalid tuner handle |
|
23228 +** MT_ARG_RANGE - Argument out of range |
|
23229 +** |
|
23230 +** Dependencies: USERS MUST CALL MT2266_Open() FIRST! |
|
23231 +** |
|
23232 +** Use this function if you need to override a default |
|
23233 +** register value |
|
23234 +** |
|
23235 +** Revision History: |
|
23236 +** |
|
23237 +** SCR Date Author Description |
|
23238 +** ------------------------------------------------------------------------- |
|
23239 +** N/A 02-03-2006 DAD/JWS Original. |
|
23240 +** |
|
23241 +****************************************************************************/ |
|
23242 +UData_t MT2266_SetReg(Handle_t h, |
|
23243 + U8Data reg, |
|
23244 + U8Data val); |
|
23245 + |
|
23246 + |
|
23247 +/**************************************************************************** |
|
23248 +** |
|
23249 +** Name: MT2266_SetUHFXFreqs |
|
23250 +** |
|
23251 +** Description: Retrieves the specified set of UHF Crossover Frequencies |
|
23252 +** |
|
23253 +** Parameters: h - Open handle to the tuner (from MT2266_Open). |
|
23254 +** |
|
23255 +** Usage: MT2266_Freq_Set tmpFreqs; |
|
23256 +** status = MT2266_SetUHFXFreqs(hMT2266, |
|
23257 +** MT2266_UHF1_WITH_ATTENUATION, |
|
23258 +** tmpFreqs ); |
|
23259 +** if (status & MT_ARG_RANGE) |
|
23260 +** // error, Invalid UHF Crossover Frequency Set requested. |
|
23261 +** else |
|
23262 +** for( int i = 0; i < MT2266_NUM_XFREQS; i++ ) |
|
23263 +** . . . |
|
23264 +** |
|
23265 +** |
|
23266 +** Returns: status: |
|
23267 +** MT_OK - No errors |
|
23268 +** MT_ARG_RANGE - freq_type is out of range. |
|
23269 +** MT_INV_HANDLE - Invalid tuner handle |
|
23270 +** |
|
23271 +** Dependencies: freqs_buffer *must* be defined of type MT2266_Freq_Set |
|
23272 +** to assure sufficient space allocation! |
|
23273 +** |
|
23274 +** USERS MUST CALL MT2266_Open() FIRST! |
|
23275 +** |
|
23276 +** See Also: MT2266_SetUHFXFreqs |
|
23277 +** |
|
23278 +** Revision History: |
|
23279 +** |
|
23280 +** SCR Date Author Description |
|
23281 +** ------------------------------------------------------------------------- |
|
23282 +** N/A 11_01-2006 RSK Original. |
|
23283 +** |
|
23284 +****************************************************************************/ |
|
23285 +UData_t MT2266_SetUHFXFreqs(Handle_t h, |
|
23286 + MT2266_UHFXFreq_Type freq_type, |
|
23287 + MT2266_XFreq_Set freqs_buffer); |
|
23288 + |
|
23289 + |
|
23290 +/**************************************************************************** |
|
23291 +** |
|
23292 +** Name: MT2266_Tune |
|
23293 +** |
|
23294 +** Description: Change the tuner's tuned frequency to f_in. |
|
23295 +** |
|
23296 +** Parameters: h - Open handle to the tuner (from MT2266_Open). |
|
23297 +** f_in - RF input center frequency (in Hz). |
|
23298 +** |
|
23299 +** Usage: status = MT2266_Tune(hMT2266, f_in); |
|
23300 +** |
|
23301 +** Returns: status: |
|
23302 +** MT_OK - No errors |
|
23303 +** MT_INV_HANDLE - Invalid tuner handle |
|
23304 +** MT_DNC_UNLOCK - Downconverter PLL unlocked |
|
23305 +** MT_COMM_ERR - Serial bus communications error |
|
23306 +** MT_FIN_RANGE - Input freq out of range |
|
23307 +** MT_DNC_RANGE - Downconverter freq out of range |
|
23308 +** |
|
23309 +** Dependencies: MUST CALL MT2266_Open BEFORE MT2266_Tune! |
|
23310 +** |
|
23311 +** MT_ReadSub - Read byte(s) of data from the two-wire-bus |
|
23312 +** MT_WriteSub - Write byte(s) of data to the two-wire-bus |
|
23313 +** MT_Sleep - Delay execution for x milliseconds |
|
23314 +** MT2266_GetLocked - Checks to see if the PLL is locked |
|
23315 +** |
|
23316 +** Revision History: |
|
23317 +** |
|
23318 +** SCR Date Author Description |
|
23319 +** ------------------------------------------------------------------------- |
|
23320 +** 118 05-09-2007 RSK Original API Introduction (was ChangeFreq). |
|
23321 +** |
|
23322 +******************************************************************************/ |
|
23323 +UData_t MT2266_Tune(Handle_t h, |
|
23324 + UData_t f_in); |
|
23325 + |
|
23326 + |
|
23327 +#if defined( __cplusplus ) |
|
23328 +} |
|
23329 +#endif |
|
23330 + |
|
23331 +#endif |
|
23332 + |
|
23333 + |
|
23334 + |
|
23335 + |
|
23336 + |
|
23337 + |
|
23338 + |
|
23339 + |
|
23340 + |
|
23341 + |
|
23342 + |
|
23343 + |
|
23344 + |
|
23345 + |
|
23346 + |
|
23347 + |
|
23348 + |
|
23349 + |
|
23350 + |
|
23351 + |
|
23352 + |
|
23353 + |
|
23354 + |
|
23355 +// The following context is MT2266 tuner API source code |
|
23356 + |
|
23357 + |
|
23358 + |
|
23359 + |
|
23360 + |
|
23361 +/** |
|
23362 + |
|
23363 +@file |
|
23364 + |
|
23365 +@brief MT2266 tuner module declaration |
|
23366 + |
|
23367 +One can manipulate MT2266 tuner through MT2266 module. |
|
23368 +MT2266 module is derived from tuner module. |
|
23369 + |
|
23370 +*/ |
|
23371 + |
|
23372 + |
|
23373 +#include "tuner_base.h" |
|
23374 + |
|
23375 + |
|
23376 + |
|
23377 + |
|
23378 + |
|
23379 +// Definitions |
|
23380 + |
|
23381 +// MT2266 API option |
|
23382 +#define __NO_CACHE__ |
|
23383 +#define MT2266_CNT 4 |
|
23384 + |
|
23385 + |
|
23386 +// Bandwidth modes |
|
23387 +enum MT2266_BANDWIDTH_HZ |
|
23388 +{ |
|
23389 + MT2266_BANDWIDTH_5MHZ = 5000000, |
|
23390 + MT2266_BANDWIDTH_6MHZ = 6000000, |
|
23391 + MT2266_BANDWIDTH_7MHZ = 7000000, |
|
23392 + MT2266_BANDWIDTH_8MHZ = 8000000, |
|
23393 +}; |
|
23394 + |
|
23395 + |
|
23396 + |
|
23397 + |
|
23398 + |
|
23399 +/// MT2266 extra module alias |
|
23400 +typedef struct MT2266_EXTRA_MODULE_TAG MT2266_EXTRA_MODULE; |
|
23401 + |
|
23402 + |
|
23403 + |
|
23404 + |
|
23405 + |
|
23406 +// MT2266 handle openning function pointer |
|
23407 +typedef int |
|
23408 +(*MT2266_FP_OPEN_HANDLE)( |
|
23409 + TUNER_MODULE *pTuner |
|
23410 + ); |
|
23411 + |
|
23412 + |
|
23413 + |
|
23414 +// MT2266 handle closing function pointer |
|
23415 +typedef int |
|
23416 +(*MT2266_FP_CLOSE_HANDLE)( |
|
23417 + TUNER_MODULE *pTuner |
|
23418 + ); |
|
23419 + |
|
23420 + |
|
23421 + |
|
23422 +// MT2266 handle getting function pointer |
|
23423 +typedef void |
|
23424 +(*MT2266_FP_GET_HANDLE)( |
|
23425 + TUNER_MODULE *pTuner, |
|
23426 + void **pDeviceHandle |
|
23427 + ); |
|
23428 + |
|
23429 + |
|
23430 + |
|
23431 +// MT2266 bandwidth setting function pointer |
|
23432 +typedef int |
|
23433 +(*MT2266_FP_SET_BANDWIDTH_HZ)( |
|
23434 + TUNER_MODULE *pTuner, |
|
23435 + unsigned long BandwidthHz |
|
23436 + ); |
|
23437 + |
|
23438 + |
|
23439 + |
|
23440 +// MT2266 bandwidth getting function pointer |
|
23441 +typedef int |
|
23442 +(*MT2266_FP_GET_BANDWIDTH_HZ)( |
|
23443 + TUNER_MODULE *pTuner, |
|
23444 + unsigned long *pBandwidthHz |
|
23445 + ); |
|
23446 + |
|
23447 + |
|
23448 + |
|
23449 + |
|
23450 + |
|
23451 +// MT2266 extra module |
|
23452 +struct MT2266_EXTRA_MODULE_TAG |
|
23453 +{ |
|
23454 + // MT2266 extra variables |
|
23455 + void *DeviceHandle; |
|
23456 + unsigned long BandwidthHz; |
|
23457 + int IsBandwidthHzSet; |
|
23458 + |
|
23459 + // MT2266 extra function pointers |
|
23460 + MT2266_FP_OPEN_HANDLE OpenHandle; |
|
23461 + MT2266_FP_CLOSE_HANDLE CloseHandle; |
|
23462 + MT2266_FP_GET_HANDLE GetHandle; |
|
23463 + MT2266_FP_SET_BANDWIDTH_HZ SetBandwidthHz; |
|
23464 + MT2266_FP_GET_BANDWIDTH_HZ GetBandwidthHz; |
|
23465 +}; |
|
23466 + |
|
23467 + |
|
23468 + |
|
23469 + |
|
23470 + |
|
23471 +// Builder |
|
23472 +void |
|
23473 +BuildMt2266Module( |
|
23474 + TUNER_MODULE **ppTuner, |
|
23475 + TUNER_MODULE *pTunerModuleMemory, |
|
23476 + MT2266_EXTRA_MODULE *pMt2266ExtraModuleMemory, |
|
23477 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
23478 + I2C_BRIDGE_MODULE *pI2cBridgeModuleMemory, |
|
23479 + unsigned char DeviceAddr |
|
23480 + ); |
|
23481 + |
|
23482 + |
|
23483 + |
|
23484 + |
|
23485 + |
|
23486 +// Manipulaing functions |
|
23487 +void |
|
23488 +mt2266_GetTunerType( |
|
23489 + TUNER_MODULE *pTuner, |
|
23490 + int *pTunerType |
|
23491 + ); |
|
23492 + |
|
23493 +void |
|
23494 +mt2266_GetDeviceAddr( |
|
23495 + TUNER_MODULE *pTuner, |
|
23496 + unsigned char *pDeviceAddr |
|
23497 + ); |
|
23498 + |
|
23499 +int |
|
23500 +mt2266_Initialize( |
|
23501 + TUNER_MODULE *pTuner |
|
23502 + ); |
|
23503 + |
|
23504 +int |
|
23505 +mt2266_SetRfFreqHz( |
|
23506 + TUNER_MODULE *pTuner, |
|
23507 + unsigned long RfFreqHz |
|
23508 + ); |
|
23509 + |
|
23510 +int |
|
23511 +mt2266_GetRfFreqHz( |
|
23512 + TUNER_MODULE *pTuner, |
|
23513 + unsigned long *pRfFreqHz |
|
23514 + ); |
|
23515 + |
|
23516 + |
|
23517 + |
|
23518 + |
|
23519 + |
|
23520 +// Extra manipulaing functions |
|
23521 +int |
|
23522 +mt2266_OpenHandle( |
|
23523 + TUNER_MODULE *pTuner |
|
23524 + ); |
|
23525 + |
|
23526 +int |
|
23527 +mt2266_CloseHandle( |
|
23528 + TUNER_MODULE *pTuner |
|
23529 + ); |
|
23530 + |
|
23531 +void |
|
23532 +mt2266_GetHandle( |
|
23533 + TUNER_MODULE *pTuner, |
|
23534 + void **pDeviceHandle |
|
23535 + ); |
|
23536 + |
|
23537 +int |
|
23538 +mt2266_SetBandwidthHz( |
|
23539 + TUNER_MODULE *pTuner, |
|
23540 + unsigned long BandwidthHz |
|
23541 + ); |
|
23542 + |
|
23543 +int |
|
23544 +mt2266_GetBandwidthHz( |
|
23545 + TUNER_MODULE *pTuner, |
|
23546 + unsigned long *pBandwidthHz |
|
23547 + ); |
|
23548 + |
|
23549 + |
|
23550 + |
|
23551 + |
|
23552 + |
|
23553 +// I2C birdge module demod argument setting |
|
23554 +void |
|
23555 +mt2266_SetI2cBridgeModuleTunerArg( |
|
23556 + TUNER_MODULE *pTuner |
|
23557 + ); |
|
23558 + |
|
23559 + |
|
23560 + |
|
23561 + |
|
23562 + |
|
23563 + |
|
23564 + |
|
23565 + |
|
23566 + |
|
23567 + |
|
23568 + |
|
23569 + |
|
23570 + |
|
23571 + |
|
23572 + |
|
23573 +#endif |
|
23574 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/tuner_mxl5007t.c |
|
23575 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
23576 +++ b/linux/drivers/media/dvb/dvb-usb/tuner_mxl5007t.c Wed Oct 27 09:16:44 2010 +0200 |
|
23577 @@ -0,0 +1,1289 @@ |
|
23578 +/** |
|
23579 + |
|
23580 +@file |
|
23581 + |
|
23582 +@brief MxL5007T tuner module definition |
|
23583 + |
|
23584 +One can manipulate MxL5007T tuner through MxL5007T module. |
|
23585 +MxL5007T module is derived from tuner module. |
|
23586 + |
|
23587 +*/ |
|
23588 + |
|
23589 + |
|
23590 +#include "tuner_mxl5007t.h" |
|
23591 + |
|
23592 + |
|
23593 + |
|
23594 + |
|
23595 + |
|
23596 +/** |
|
23597 + |
|
23598 +@brief MxL5007T tuner module builder |
|
23599 + |
|
23600 +Use BuildMxl5007tModule() to build MxL5007T module, set all module function pointers with the corresponding functions, |
|
23601 +and initialize module private variables. |
|
23602 + |
|
23603 + |
|
23604 +@param [in] ppTuner Pointer to MxL5007T tuner module pointer |
|
23605 +@param [in] pTunerModuleMemory Pointer to an allocated tuner module memory |
|
23606 +@param [in] pMxl5007tExtraModuleMemory Pointer to an allocated MxL5007T extra module memory |
|
23607 +@param [in] pBaseInterfaceModuleMemory Pointer to an allocated base interface module memory |
|
23608 +@param [in] pI2cBridgeModuleMemory Pointer to an allocated I2C bridge module memory |
|
23609 +@param [in] DeviceAddr MxL5007T I2C device address |
|
23610 +@param [in] CrystalFreqHz MxL5007T crystal frequency in Hz |
|
23611 +@param [in] AgcMode MxL5007T AGC mode |
|
23612 + |
|
23613 + |
|
23614 +@note |
|
23615 + -# One should call BuildMxl5007tModule() to build MxL5007T module before using it. |
|
23616 + |
|
23617 +*/ |
|
23618 +void |
|
23619 +BuildMxl5007tModule( |
|
23620 + TUNER_MODULE **ppTuner, |
|
23621 + TUNER_MODULE *pTunerModuleMemory, |
|
23622 + MXL5007T_EXTRA_MODULE *pMxl5007tExtraModuleMemory, |
|
23623 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
23624 + I2C_BRIDGE_MODULE *pI2cBridgeModuleMemory, |
|
23625 + unsigned char DeviceAddr, |
|
23626 + unsigned long CrystalFreqHz, |
|
23627 + int StandardMode, |
|
23628 + unsigned long IfFreqHz, |
|
23629 + int SpectrumMode, |
|
23630 + int ClkOutMode, |
|
23631 + int ClkOutAmpMode, |
|
23632 + long QamIfDiffOutLevel |
|
23633 + ) |
|
23634 +{ |
|
23635 + TUNER_MODULE *pTuner; |
|
23636 + MXL5007T_EXTRA_MODULE *pExtra; |
|
23637 + MxL5007_TunerConfigS *pTunerConfigS; |
|
23638 + |
|
23639 + |
|
23640 + |
|
23641 + // Set tuner module pointer. |
|
23642 + *ppTuner = pTunerModuleMemory; |
|
23643 + |
|
23644 + // Get tuner module. |
|
23645 + pTuner = *ppTuner; |
|
23646 + |
|
23647 + // Set tuner extra module pointer, base interface module pointer, and I2C bridge module pointer. |
|
23648 + pTuner->pExtra = pMxl5007tExtraModuleMemory; |
|
23649 + pTuner->pBaseInterface = pBaseInterfaceModuleMemory; |
|
23650 + pTuner->pI2cBridge = pI2cBridgeModuleMemory; |
|
23651 + |
|
23652 + // Get tuner extra module. |
|
23653 + pExtra = (MXL5007T_EXTRA_MODULE *)pTuner->pExtra; |
|
23654 + |
|
23655 + // Set and get MaxLinear-defined MxL5007T structure pointer. |
|
23656 + pExtra->pTunerConfigS = &(pExtra->TunerConfigSMemory); |
|
23657 + pTunerConfigS = pExtra->pTunerConfigS; |
|
23658 + |
|
23659 + // Set additional definition tuner module pointer. |
|
23660 + pTunerConfigS->pTuner = pTuner; |
|
23661 + |
|
23662 + |
|
23663 + |
|
23664 + // Set tuner type. |
|
23665 + pTuner->TunerType = TUNER_TYPE_MXL5007T; |
|
23666 + |
|
23667 + // Set tuner I2C device address. |
|
23668 + pTuner->DeviceAddr = DeviceAddr; |
|
23669 + |
|
23670 + |
|
23671 + // Initialize tuner parameter setting status. |
|
23672 + pTuner->IsRfFreqHzSet = NO; |
|
23673 + |
|
23674 + |
|
23675 + // Set I2C bridge tuner arguments. |
|
23676 + mxl5007t_SetI2cBridgeModuleTunerArg(pTuner); |
|
23677 + |
|
23678 + |
|
23679 + // Set tuner module manipulating function pointers. |
|
23680 + pTuner->GetTunerType = mxl5007t_GetTunerType; |
|
23681 + pTuner->GetDeviceAddr = mxl5007t_GetDeviceAddr; |
|
23682 + |
|
23683 + pTuner->Initialize = mxl5007t_Initialize; |
|
23684 + pTuner->SetRfFreqHz = mxl5007t_SetRfFreqHz; |
|
23685 + pTuner->GetRfFreqHz = mxl5007t_GetRfFreqHz; |
|
23686 + |
|
23687 + |
|
23688 + // Initialize tuner extra module variables. |
|
23689 + pExtra->IsBandwidthModeSet = NO; |
|
23690 + |
|
23691 + |
|
23692 + // Initialize MaxLinear-defined MxL5007T structure variables. |
|
23693 + // Note: The API doesn't use I2C device address of MaxLinear-defined MxL5007T structure. |
|
23694 + switch(StandardMode) |
|
23695 + { |
|
23696 + default: |
|
23697 + case MXL5007T_STANDARD_DVBT: pTunerConfigS->Mode = MxL_MODE_DVBT; break; |
|
23698 + case MXL5007T_STANDARD_ATSC: pTunerConfigS->Mode = MxL_MODE_ATSC; break; |
|
23699 + case MXL5007T_STANDARD_QAM: pTunerConfigS->Mode = MxL_MODE_CABLE; break; |
|
23700 + case MXL5007T_STANDARD_ISDBT: pTunerConfigS->Mode = MxL_MODE_ISDBT; break; |
|
23701 + } |
|
23702 + |
|
23703 + pTunerConfigS->IF_Diff_Out_Level = (SINT32)QamIfDiffOutLevel; |
|
23704 + |
|
23705 + switch(CrystalFreqHz) |
|
23706 + { |
|
23707 + default: |
|
23708 + case CRYSTAL_FREQ_16000000HZ: pTunerConfigS->Xtal_Freq = MxL_XTAL_16_MHZ; break; |
|
23709 + case CRYSTAL_FREQ_25000000HZ: pTunerConfigS->Xtal_Freq = MxL_XTAL_25_MHZ; break; |
|
23710 + case CRYSTAL_FREQ_27000000HZ: pTunerConfigS->Xtal_Freq = MxL_XTAL_27_MHZ; break; |
|
23711 + case CRYSTAL_FREQ_28800000HZ: pTunerConfigS->Xtal_Freq = MxL_XTAL_28_8_MHZ; break; |
|
23712 + } |
|
23713 + |
|
23714 + switch(IfFreqHz) |
|
23715 + { |
|
23716 + default: |
|
23717 + case IF_FREQ_4570000HZ: pTunerConfigS->IF_Freq = MxL_IF_4_57_MHZ; break; |
|
23718 + case IF_FREQ_44000000HZ: pTunerConfigS->IF_Freq = MxL_IF_44_MHZ; break; |
|
23719 + } |
|
23720 + |
|
23721 + switch(SpectrumMode) |
|
23722 + { |
|
23723 + default: |
|
23724 + case SPECTRUM_NORMAL: pTunerConfigS->IF_Spectrum = MxL_NORMAL_IF; break; |
|
23725 + case SPECTRUM_INVERSE: pTunerConfigS->IF_Spectrum = MxL_INVERT_IF; break; |
|
23726 + } |
|
23727 + |
|
23728 + switch(ClkOutMode) |
|
23729 + { |
|
23730 + default: |
|
23731 + case MXL5007T_CLK_OUT_DISABLE: pTunerConfigS->ClkOut_Setting = MxL_CLKOUT_DISABLE; break; |
|
23732 + case MXL5007T_CLK_OUT_ENABLE: pTunerConfigS->ClkOut_Setting = MxL_CLKOUT_ENABLE; break; |
|
23733 + } |
|
23734 + |
|
23735 + switch(ClkOutAmpMode) |
|
23736 + { |
|
23737 + default: |
|
23738 + case MXL5007T_CLK_OUT_AMP_0: pTunerConfigS->ClkOut_Amp = MxL_CLKOUT_AMP_0; break; |
|
23739 + case MXL5007T_CLK_OUT_AMP_1: pTunerConfigS->ClkOut_Amp = MxL_CLKOUT_AMP_1; break; |
|
23740 + case MXL5007T_CLK_OUT_AMP_2: pTunerConfigS->ClkOut_Amp = MxL_CLKOUT_AMP_2; break; |
|
23741 + case MXL5007T_CLK_OUT_AMP_3: pTunerConfigS->ClkOut_Amp = MxL_CLKOUT_AMP_3; break; |
|
23742 + case MXL5007T_CLK_OUT_AMP_4: pTunerConfigS->ClkOut_Amp = MxL_CLKOUT_AMP_4; break; |
|
23743 + case MXL5007T_CLK_OUT_AMP_5: pTunerConfigS->ClkOut_Amp = MxL_CLKOUT_AMP_5; break; |
|
23744 + case MXL5007T_CLK_OUT_AMP_6: pTunerConfigS->ClkOut_Amp = MxL_CLKOUT_AMP_6; break; |
|
23745 + case MXL5007T_CLK_OUT_AMP_7: pTunerConfigS->ClkOut_Amp = MxL_CLKOUT_AMP_7; break; |
|
23746 + } |
|
23747 + |
|
23748 + pTunerConfigS->BW_MHz = MXL5007T_BANDWIDTH_MODE_DEFAULT; |
|
23749 + pTunerConfigS->RF_Freq_Hz = MXL5007T_RF_FREQ_HZ_DEFAULT; |
|
23750 + |
|
23751 + |
|
23752 + // Set tuner extra module function pointers. |
|
23753 + pExtra->SetBandwidthMode = mxl5007t_SetBandwidthMode; |
|
23754 + pExtra->GetBandwidthMode = mxl5007t_GetBandwidthMode; |
|
23755 + |
|
23756 + |
|
23757 + return; |
|
23758 +} |
|
23759 + |
|
23760 + |
|
23761 + |
|
23762 + |
|
23763 + |
|
23764 +/** |
|
23765 + |
|
23766 +@see TUNER_FP_GET_TUNER_TYPE |
|
23767 + |
|
23768 +*/ |
|
23769 +void |
|
23770 +mxl5007t_GetTunerType( |
|
23771 + TUNER_MODULE *pTuner, |
|
23772 + int *pTunerType |
|
23773 + ) |
|
23774 +{ |
|
23775 + // Get tuner type from tuner module. |
|
23776 + *pTunerType = pTuner->TunerType; |
|
23777 + |
|
23778 + |
|
23779 + return; |
|
23780 +} |
|
23781 + |
|
23782 + |
|
23783 + |
|
23784 + |
|
23785 + |
|
23786 +/** |
|
23787 + |
|
23788 +@see TUNER_FP_GET_DEVICE_ADDR |
|
23789 + |
|
23790 +*/ |
|
23791 +void |
|
23792 +mxl5007t_GetDeviceAddr( |
|
23793 + TUNER_MODULE *pTuner, |
|
23794 + unsigned char *pDeviceAddr |
|
23795 + ) |
|
23796 +{ |
|
23797 + // Get tuner I2C device address from tuner module. |
|
23798 + *pDeviceAddr = pTuner->DeviceAddr; |
|
23799 + |
|
23800 + |
|
23801 + return; |
|
23802 +} |
|
23803 + |
|
23804 + |
|
23805 + |
|
23806 + |
|
23807 + |
|
23808 +/** |
|
23809 + |
|
23810 +@see TUNER_FP_INITIALIZE |
|
23811 + |
|
23812 +*/ |
|
23813 +int |
|
23814 +mxl5007t_Initialize( |
|
23815 + TUNER_MODULE *pTuner |
|
23816 + ) |
|
23817 +{ |
|
23818 + MXL5007T_EXTRA_MODULE *pExtra; |
|
23819 + MxL5007_TunerConfigS *pTunerConfigS; |
|
23820 + |
|
23821 + |
|
23822 + |
|
23823 + // Get tuner extra module. |
|
23824 + pExtra = (MXL5007T_EXTRA_MODULE *)pTuner->pExtra; |
|
23825 + |
|
23826 + // Get MaxLinear-defined MxL5007T structure. |
|
23827 + pTunerConfigS = pExtra->pTunerConfigS; |
|
23828 + |
|
23829 + |
|
23830 + // Initialize tuner. |
|
23831 + if(MxL_Tuner_Init(pTunerConfigS) != MxL_OK) |
|
23832 + goto error_status_initialize_tuner; |
|
23833 + |
|
23834 + |
|
23835 + return FUNCTION_SUCCESS; |
|
23836 + |
|
23837 + |
|
23838 +error_status_initialize_tuner: |
|
23839 + return FUNCTION_ERROR; |
|
23840 +} |
|
23841 + |
|
23842 + |
|
23843 + |
|
23844 + |
|
23845 + |
|
23846 +/** |
|
23847 + |
|
23848 +@see TUNER_FP_SET_RF_FREQ_HZ |
|
23849 + |
|
23850 +*/ |
|
23851 +int |
|
23852 +mxl5007t_SetRfFreqHz( |
|
23853 + TUNER_MODULE *pTuner, |
|
23854 + unsigned long RfFreqHz |
|
23855 + ) |
|
23856 +{ |
|
23857 + MXL5007T_EXTRA_MODULE *pExtra; |
|
23858 + MxL5007_TunerConfigS *pTunerConfigS; |
|
23859 + |
|
23860 + UINT32 Mxl5007tRfFreqHz; |
|
23861 + MxL5007_BW_MHz Mxl5007tBandwidthMhz; |
|
23862 + |
|
23863 + |
|
23864 + |
|
23865 + // Get tuner extra module. |
|
23866 + pExtra = (MXL5007T_EXTRA_MODULE *)pTuner->pExtra; |
|
23867 + |
|
23868 + // Get MaxLinear-defined MxL5007T structure. |
|
23869 + pTunerConfigS = pExtra->pTunerConfigS; |
|
23870 + |
|
23871 + |
|
23872 + // Get bandwidth. |
|
23873 + Mxl5007tBandwidthMhz = pTunerConfigS->BW_MHz; |
|
23874 + |
|
23875 + // Set RF frequency. |
|
23876 + Mxl5007tRfFreqHz = (UINT32)RfFreqHz; |
|
23877 + |
|
23878 + // Set MxL5007T RF frequency and bandwidth. |
|
23879 + if(MxL_Tuner_RFTune(pTunerConfigS, Mxl5007tRfFreqHz, Mxl5007tBandwidthMhz) != MxL_OK) |
|
23880 + goto error_status_set_tuner_rf_frequency; |
|
23881 + |
|
23882 + |
|
23883 + // Set tuner RF frequency parameter. |
|
23884 + pTuner->RfFreqHz = RfFreqHz; |
|
23885 + pTuner->IsRfFreqHzSet = YES; |
|
23886 + |
|
23887 + |
|
23888 + return FUNCTION_SUCCESS; |
|
23889 + |
|
23890 + |
|
23891 +error_status_set_tuner_rf_frequency: |
|
23892 + return FUNCTION_ERROR; |
|
23893 +} |
|
23894 + |
|
23895 + |
|
23896 + |
|
23897 + |
|
23898 + |
|
23899 +/** |
|
23900 + |
|
23901 +@see TUNER_FP_GET_RF_FREQ_HZ |
|
23902 + |
|
23903 +*/ |
|
23904 +int |
|
23905 +mxl5007t_GetRfFreqHz( |
|
23906 + TUNER_MODULE *pTuner, |
|
23907 + unsigned long *pRfFreqHz |
|
23908 + ) |
|
23909 +{ |
|
23910 + // Get tuner RF frequency in Hz from tuner module. |
|
23911 + if(pTuner->IsRfFreqHzSet != YES) |
|
23912 + goto error_status_get_tuner_rf_frequency; |
|
23913 + |
|
23914 + *pRfFreqHz = pTuner->RfFreqHz; |
|
23915 + |
|
23916 + |
|
23917 + return FUNCTION_SUCCESS; |
|
23918 + |
|
23919 + |
|
23920 +error_status_get_tuner_rf_frequency: |
|
23921 + return FUNCTION_ERROR; |
|
23922 +} |
|
23923 + |
|
23924 + |
|
23925 + |
|
23926 + |
|
23927 + |
|
23928 +/** |
|
23929 + |
|
23930 +@brief Set MxL5007T tuner bandwidth mode. |
|
23931 + |
|
23932 +*/ |
|
23933 +int |
|
23934 +mxl5007t_SetBandwidthMode( |
|
23935 + TUNER_MODULE *pTuner, |
|
23936 + int BandwidthMode |
|
23937 + ) |
|
23938 +{ |
|
23939 + MXL5007T_EXTRA_MODULE *pExtra; |
|
23940 + MxL5007_TunerConfigS *pTunerConfigS; |
|
23941 + |
|
23942 + UINT32 Mxl5007tRfFreqHz; |
|
23943 + MxL5007_BW_MHz Mxl5007tBandwidthMhz; |
|
23944 + |
|
23945 + |
|
23946 + |
|
23947 + // Get tuner extra module. |
|
23948 + pExtra = (MXL5007T_EXTRA_MODULE *)pTuner->pExtra; |
|
23949 + |
|
23950 + // Get MaxLinear-defined MxL5007T structure. |
|
23951 + pTunerConfigS = pExtra->pTunerConfigS; |
|
23952 + |
|
23953 + |
|
23954 + // Get RF frequency. |
|
23955 + Mxl5007tRfFreqHz = pTunerConfigS->RF_Freq_Hz; |
|
23956 + |
|
23957 + // Set bandwidth. |
|
23958 + switch(BandwidthMode) |
|
23959 + { |
|
23960 + case MXL5007T_BANDWIDTH_6000000HZ: Mxl5007tBandwidthMhz = MxL_BW_6MHz; break; |
|
23961 + case MXL5007T_BANDWIDTH_7000000HZ: Mxl5007tBandwidthMhz = MxL_BW_7MHz; break; |
|
23962 + case MXL5007T_BANDWIDTH_8000000HZ: Mxl5007tBandwidthMhz = MxL_BW_8MHz; break; |
|
23963 + |
|
23964 + default: goto error_status_get_undefined_value; |
|
23965 + } |
|
23966 + |
|
23967 + // Set MxL5007T RF frequency and bandwidth. |
|
23968 + if(MxL_Tuner_RFTune(pTunerConfigS, Mxl5007tRfFreqHz, Mxl5007tBandwidthMhz) != MxL_OK) |
|
23969 + goto error_status_set_tuner_bandwidth; |
|
23970 + |
|
23971 + |
|
23972 + // Set tuner bandwidth parameter. |
|
23973 + pExtra->BandwidthMode = BandwidthMode; |
|
23974 + pExtra->IsBandwidthModeSet = YES; |
|
23975 + |
|
23976 + |
|
23977 + return FUNCTION_SUCCESS; |
|
23978 + |
|
23979 + |
|
23980 +error_status_set_tuner_bandwidth: |
|
23981 +error_status_get_undefined_value: |
|
23982 + return FUNCTION_ERROR; |
|
23983 +} |
|
23984 + |
|
23985 + |
|
23986 + |
|
23987 + |
|
23988 + |
|
23989 +/** |
|
23990 + |
|
23991 +@brief Get MxL5007T tuner bandwidth mode. |
|
23992 + |
|
23993 +*/ |
|
23994 +int |
|
23995 +mxl5007t_GetBandwidthMode( |
|
23996 + TUNER_MODULE *pTuner, |
|
23997 + int *pBandwidthMode |
|
23998 + ) |
|
23999 +{ |
|
24000 + MXL5007T_EXTRA_MODULE *pExtra; |
|
24001 + |
|
24002 + |
|
24003 + |
|
24004 + // Get tuner extra module. |
|
24005 + pExtra = (MXL5007T_EXTRA_MODULE *)pTuner->pExtra; |
|
24006 + |
|
24007 + |
|
24008 + // Get tuner bandwidth mode from tuner module. |
|
24009 + if(pExtra->IsBandwidthModeSet != YES) |
|
24010 + goto error_status_get_tuner_bandwidth_mode; |
|
24011 + |
|
24012 + *pBandwidthMode = pExtra->BandwidthMode; |
|
24013 + |
|
24014 + |
|
24015 + return FUNCTION_SUCCESS; |
|
24016 + |
|
24017 + |
|
24018 +error_status_get_tuner_bandwidth_mode: |
|
24019 + return FUNCTION_ERROR; |
|
24020 +} |
|
24021 + |
|
24022 + |
|
24023 + |
|
24024 + |
|
24025 + |
|
24026 +/** |
|
24027 + |
|
24028 +@brief Set I2C bridge module tuner arguments. |
|
24029 + |
|
24030 +MXL5007T builder will use mxl5007t_SetI2cBridgeModuleTunerArg() to set I2C bridge module tuner arguments. |
|
24031 + |
|
24032 + |
|
24033 +@param [in] pTuner The tuner module pointer |
|
24034 + |
|
24035 + |
|
24036 +@see BuildMxl5007tModule() |
|
24037 + |
|
24038 +*/ |
|
24039 +void |
|
24040 +mxl5007t_SetI2cBridgeModuleTunerArg( |
|
24041 + TUNER_MODULE *pTuner |
|
24042 + ) |
|
24043 +{ |
|
24044 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
24045 + |
|
24046 + |
|
24047 + |
|
24048 + // Get I2C bridge module. |
|
24049 + pI2cBridge = pTuner->pI2cBridge; |
|
24050 + |
|
24051 + // Set I2C bridge module tuner arguments. |
|
24052 + pI2cBridge->pTunerDeviceAddr = &pTuner->DeviceAddr; |
|
24053 + |
|
24054 + |
|
24055 + return; |
|
24056 +} |
|
24057 + |
|
24058 + |
|
24059 + |
|
24060 + |
|
24061 + |
|
24062 + |
|
24063 + |
|
24064 + |
|
24065 + |
|
24066 + |
|
24067 + |
|
24068 + |
|
24069 + |
|
24070 + |
|
24071 + |
|
24072 + |
|
24073 + |
|
24074 + |
|
24075 + |
|
24076 + |
|
24077 + |
|
24078 + |
|
24079 + |
|
24080 +// The following context is source code provided by MaxLinear. |
|
24081 + |
|
24082 + |
|
24083 + |
|
24084 + |
|
24085 + |
|
24086 +// MaxLinear source code - MxL_User_Define.c |
|
24087 + |
|
24088 + |
|
24089 +/* |
|
24090 + |
|
24091 + Driver APIs for MxL5007 Tuner |
|
24092 + |
|
24093 + Copyright, Maxlinear, Inc. |
|
24094 + All Rights Reserved |
|
24095 + |
|
24096 + File Name: MxL_User_Define.c |
|
24097 + |
|
24098 + */ |
|
24099 + |
|
24100 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|
24101 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|
24102 +// // |
|
24103 +// I2C Functions (implement by customer) // |
|
24104 +// // |
|
24105 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|
24106 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|
24107 + |
|
24108 +/****************************************************************************** |
|
24109 +** |
|
24110 +** Name: MxL_I2C_Write |
|
24111 +** |
|
24112 +** Description: I2C write operations |
|
24113 +** |
|
24114 +** Parameters: |
|
24115 +** DeviceAddr - MxL5007 Device address |
|
24116 +** pArray - Write data array pointer |
|
24117 +** count - total number of array |
|
24118 +** |
|
24119 +** Returns: 0 if success |
|
24120 +** |
|
24121 +** Revision History: |
|
24122 +** |
|
24123 +** SCR Date Author Description |
|
24124 +** ------------------------------------------------------------------------- |
|
24125 +** N/A 12-16-2007 khuang initial release. |
|
24126 +** |
|
24127 +******************************************************************************/ |
|
24128 +//UINT32 MxL_I2C_Write(UINT8 DeviceAddr, UINT8* pArray, UINT32 count) |
|
24129 +UINT32 MxL_I2C_Write(MxL5007_TunerConfigS* myTuner, UINT8* pArray, UINT32 count) |
|
24130 +{ |
|
24131 + TUNER_MODULE *pTuner; |
|
24132 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
24133 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
24134 + unsigned char WritingByteNumMax; |
|
24135 + |
|
24136 + unsigned long i; |
|
24137 + unsigned char Buffer[I2C_BUFFER_LEN]; |
|
24138 + int WritingIndex; |
|
24139 + |
|
24140 + unsigned char *pData; |
|
24141 + unsigned long DataLen; |
|
24142 + |
|
24143 + |
|
24144 + |
|
24145 + // Get tuner module, base interface, and I2C bridge. |
|
24146 + pTuner = myTuner->pTuner; |
|
24147 + pBaseInterface = pTuner->pBaseInterface; |
|
24148 + pI2cBridge = pTuner->pI2cBridge; |
|
24149 + |
|
24150 + // Get writing byte and byte number. |
|
24151 + pData = (unsigned char *)pArray; |
|
24152 + DataLen = (unsigned long)count; |
|
24153 + |
|
24154 + // Calculate MxL5007T maximum writing byte number. |
|
24155 + // Note: MxL5007T maximum writing byte number must be a multiple of 2. |
|
24156 + WritingByteNumMax = pBaseInterface->I2cWritingByteNumMax; |
|
24157 + WritingByteNumMax = ((WritingByteNumMax % 2) == 0) ? WritingByteNumMax : (WritingByteNumMax - 1); |
|
24158 + |
|
24159 + |
|
24160 + // Set register bytes. |
|
24161 + // Note: The 2 kind of I2C formats of MxL5007T is described as follows: |
|
24162 + // 1. start_bit + (device_addr | writing_bit) + (register_addr + writing_byte) * n + stop_bit |
|
24163 + // ... |
|
24164 + // start_bit + (device_addr | writing_bit) + (register_addr + writing_byte) * m + stop_bit |
|
24165 + // 2. start_bit + (device_addr | writing_bit) + 0xff + stop_bit |
|
24166 + for(i = 0, WritingIndex = 0; i < DataLen; i++, WritingIndex++) |
|
24167 + { |
|
24168 + // Put data into buffer. |
|
24169 + Buffer[WritingIndex] = pData[i]; |
|
24170 + |
|
24171 + // If writing buffer is full or put data into buffer completely, send the I2C writing command with buffer. |
|
24172 + if( (WritingIndex == (WritingByteNumMax - 1)) || (i == (DataLen - 1)) ) |
|
24173 + { |
|
24174 + if(pI2cBridge->ForwardI2cWritingCmd(pI2cBridge, Buffer, (WritingIndex + LEN_1_BYTE)) != FUNCTION_SUCCESS) |
|
24175 + goto error_status_set_tuner_registers; |
|
24176 + |
|
24177 + WritingIndex = -1; |
|
24178 + } |
|
24179 + } |
|
24180 + |
|
24181 + |
|
24182 + return MxL_OK; |
|
24183 + |
|
24184 + |
|
24185 +error_status_set_tuner_registers: |
|
24186 + return MxL_ERR_OTHERS; |
|
24187 +} |
|
24188 + |
|
24189 +/****************************************************************************** |
|
24190 +** |
|
24191 +** Name: MxL_I2C_Read |
|
24192 +** |
|
24193 +** Description: I2C read operations |
|
24194 +** |
|
24195 +** Parameters: |
|
24196 +** DeviceAddr - MxL5007 Device address |
|
24197 +** Addr - register address for read |
|
24198 +** *Data - data return |
|
24199 +** |
|
24200 +** Returns: 0 if success |
|
24201 +** |
|
24202 +** Revision History: |
|
24203 +** |
|
24204 +** SCR Date Author Description |
|
24205 +** ------------------------------------------------------------------------- |
|
24206 +** N/A 12-16-2007 khuang initial release. |
|
24207 +** |
|
24208 +******************************************************************************/ |
|
24209 +//UINT32 MxL_I2C_Read(UINT8 DeviceAddr, UINT8 Addr, UINT8* mData) |
|
24210 +UINT32 MxL_I2C_Read(MxL5007_TunerConfigS* myTuner, UINT8 Addr, UINT8* mData) |
|
24211 +{ |
|
24212 + TUNER_MODULE *pTuner; |
|
24213 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
24214 + |
|
24215 + unsigned char Buffer[LEN_2_BYTE]; |
|
24216 + |
|
24217 + |
|
24218 + |
|
24219 + // Get tuner module and I2C bridge. |
|
24220 + pTuner = myTuner->pTuner; |
|
24221 + pI2cBridge = pTuner->pI2cBridge; |
|
24222 + |
|
24223 + // Set tuner register reading address. |
|
24224 + // Note: The I2C format of tuner register reading address setting is as follows: |
|
24225 + // start_bit + (DeviceAddr | writing_bit) + 0xfb + RegReadingAddr + stop_bit |
|
24226 + Buffer[0] = (unsigned char)MXL5007T_I2C_READING_CONST; |
|
24227 + Buffer[1] = (unsigned char)Addr; |
|
24228 + if(pI2cBridge->ForwardI2cWritingCmd(pI2cBridge, Buffer, LEN_2_BYTE) != FUNCTION_SUCCESS) |
|
24229 + goto error_status_set_tuner_register_reading_address; |
|
24230 + |
|
24231 + // Get tuner register bytes. |
|
24232 + // Note: The I2C format of tuner register byte getting is as follows: |
|
24233 + // start_bit + (DeviceAddr | reading_bit) + reading_byte + stop_bit |
|
24234 + if(pI2cBridge->ForwardI2cReadingCmd(pI2cBridge, Buffer, LEN_1_BYTE) != FUNCTION_SUCCESS) |
|
24235 + goto error_status_get_tuner_registers; |
|
24236 + |
|
24237 + *mData = (UINT8)Buffer[0]; |
|
24238 + |
|
24239 + |
|
24240 + return MxL_OK; |
|
24241 + |
|
24242 + |
|
24243 +error_status_get_tuner_registers: |
|
24244 +error_status_set_tuner_register_reading_address: |
|
24245 + return MxL_ERR_OTHERS; |
|
24246 +} |
|
24247 + |
|
24248 +/****************************************************************************** |
|
24249 +** |
|
24250 +** Name: MxL_Delay |
|
24251 +** |
|
24252 +** Description: Delay function in milli-second |
|
24253 +** |
|
24254 +** Parameters: |
|
24255 +** mSec - milli-second to delay |
|
24256 +** |
|
24257 +** Returns: 0 |
|
24258 +** |
|
24259 +** Revision History: |
|
24260 +** |
|
24261 +** SCR Date Author Description |
|
24262 +** ------------------------------------------------------------------------- |
|
24263 +** N/A 12-16-2007 khuang initial release. |
|
24264 +** |
|
24265 +******************************************************************************/ |
|
24266 +//void MxL_Delay(UINT32 mSec) |
|
24267 +void MxL_Delay(MxL5007_TunerConfigS* myTuner, UINT32 mSec) |
|
24268 +{ |
|
24269 + TUNER_MODULE *pTuner; |
|
24270 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
24271 + |
|
24272 + |
|
24273 + |
|
24274 + // Get tuner module and base interface. |
|
24275 + pTuner = myTuner->pTuner; |
|
24276 + pBaseInterface = pTuner->pBaseInterface; |
|
24277 + |
|
24278 + // Wait in ms. |
|
24279 + pBaseInterface->WaitMs(pBaseInterface, mSec); |
|
24280 + |
|
24281 + |
|
24282 + return; |
|
24283 +} |
|
24284 + |
|
24285 + |
|
24286 + |
|
24287 + |
|
24288 + |
|
24289 + |
|
24290 + |
|
24291 + |
|
24292 + |
|
24293 + |
|
24294 + |
|
24295 + |
|
24296 + |
|
24297 + |
|
24298 + |
|
24299 + |
|
24300 + |
|
24301 + |
|
24302 + |
|
24303 + |
|
24304 + |
|
24305 + |
|
24306 + |
|
24307 +// MaxLinear source code - MxL5007.c |
|
24308 + |
|
24309 + |
|
24310 +/* |
|
24311 + MxL5007 Source Code : V4.1.3 |
|
24312 + |
|
24313 + Copyright, Maxlinear, Inc. |
|
24314 + All Rights Reserved |
|
24315 + |
|
24316 + File Name: MxL5007.c |
|
24317 + |
|
24318 + Description: The source code is for MxL5007 user to quickly integrate MxL5007 into their software. |
|
24319 + There are two functions the user can call to generate a array of I2C command that's require to |
|
24320 + program the MxL5007 tuner. The user should pass an array pointer and an integer pointer in to the |
|
24321 + function. The funciton will fill up the array with format like follow: |
|
24322 + |
|
24323 + addr1 |
|
24324 + data1 |
|
24325 + addr2 |
|
24326 + data2 |
|
24327 + ... |
|
24328 + |
|
24329 + The user can then pass this array to their I2C function to perform progromming the tuner. |
|
24330 +*/ |
|
24331 +//#include "StdAfx.h" |
|
24332 +//#include "MxL5007_Common.h" |
|
24333 +//#include "MxL5007.h" |
|
24334 + |
|
24335 + |
|
24336 + |
|
24337 +UINT32 MxL5007_Init(UINT8* pArray, // a array pointer that store the addr and data pairs for I2C write |
|
24338 + UINT32* Array_Size, // a integer pointer that store the number of element in above array |
|
24339 + UINT8 Mode, |
|
24340 + SINT32 IF_Diff_Out_Level, |
|
24341 + UINT32 Xtal_Freq_Hz, |
|
24342 + UINT32 IF_Freq_Hz, |
|
24343 + UINT8 Invert_IF, |
|
24344 + UINT8 Clk_Out_Enable, |
|
24345 + UINT8 Clk_Out_Amp |
|
24346 + ) |
|
24347 +{ |
|
24348 + |
|
24349 + UINT32 Reg_Index=0; |
|
24350 + UINT32 Array_Index=0; |
|
24351 + |
|
24352 + IRVType IRV_Init[]= |
|
24353 + { |
|
24354 + //{ Addr, Data} |
|
24355 + { 0x02, 0x06}, |
|
24356 + { 0x03, 0x48}, |
|
24357 + { 0x05, 0x04}, |
|
24358 + { 0x06, 0x10}, |
|
24359 + { 0x2E, 0x15}, //Override |
|
24360 + { 0x30, 0x10}, //Override |
|
24361 + { 0x45, 0x58}, //Override |
|
24362 + { 0x48, 0x19}, //Override |
|
24363 + { 0x52, 0x03}, //Override |
|
24364 + { 0x53, 0x44}, //Override |
|
24365 + { 0x6A, 0x4B}, //Override |
|
24366 + { 0x76, 0x00}, //Override |
|
24367 + { 0x78, 0x18}, //Override |
|
24368 + { 0x7A, 0x17}, //Override |
|
24369 + { 0x85, 0x06}, //Override |
|
24370 + { 0x01, 0x01}, //TOP_MASTER_ENABLE=1 |
|
24371 + { 0, 0} |
|
24372 + }; |
|
24373 + |
|
24374 + |
|
24375 + IRVType IRV_Init_Cable[]= |
|
24376 + { |
|
24377 + //{ Addr, Data} |
|
24378 + { 0x02, 0x06}, |
|
24379 + { 0x03, 0x48}, |
|
24380 + { 0x05, 0x04}, |
|
24381 + { 0x06, 0x10}, |
|
24382 + { 0x09, 0x3F}, |
|
24383 + { 0x0A, 0x3F}, |
|
24384 + { 0x0B, 0x3F}, |
|
24385 + { 0x2E, 0x15}, //Override |
|
24386 + { 0x30, 0x10}, //Override |
|
24387 + { 0x45, 0x58}, //Override |
|
24388 + { 0x48, 0x19}, //Override |
|
24389 + { 0x52, 0x03}, //Override |
|
24390 + { 0x53, 0x44}, //Override |
|
24391 + { 0x6A, 0x4B}, //Override |
|
24392 + { 0x76, 0x00}, //Override |
|
24393 + { 0x78, 0x18}, //Override |
|
24394 + { 0x7A, 0x17}, //Override |
|
24395 + { 0x85, 0x06}, //Override |
|
24396 + { 0x01, 0x01}, //TOP_MASTER_ENABLE=1 |
|
24397 + { 0, 0} |
|
24398 + }; |
|
24399 + //edit Init setting here |
|
24400 + |
|
24401 + PIRVType myIRV; |
|
24402 + |
|
24403 + switch(Mode) |
|
24404 + { |
|
24405 + case MxL_MODE_ISDBT: //ISDB-T Mode |
|
24406 + myIRV = IRV_Init; |
|
24407 + SetIRVBit(myIRV, 0x06, 0x1F, 0x10); |
|
24408 + break; |
|
24409 + case MxL_MODE_DVBT: //DVBT Mode |
|
24410 + myIRV = IRV_Init; |
|
24411 + SetIRVBit(myIRV, 0x06, 0x1F, 0x11); |
|
24412 + break; |
|
24413 + case MxL_MODE_ATSC: //ATSC Mode |
|
24414 + myIRV = IRV_Init; |
|
24415 + SetIRVBit(myIRV, 0x06, 0x1F, 0x12); |
|
24416 + break; |
|
24417 + case MxL_MODE_CABLE: |
|
24418 + myIRV = IRV_Init_Cable; |
|
24419 + SetIRVBit(myIRV, 0x09, 0xFF, 0xC1); |
|
24420 + SetIRVBit(myIRV, 0x0A, 0xFF, 8-IF_Diff_Out_Level); |
|
24421 + SetIRVBit(myIRV, 0x0B, 0xFF, 0x17); |
|
24422 + break; |
|
24423 + |
|
24424 + |
|
24425 + } |
|
24426 + |
|
24427 + switch(IF_Freq_Hz) |
|
24428 + { |
|
24429 + case MxL_IF_4_MHZ: |
|
24430 + SetIRVBit(myIRV, 0x02, 0x0F, 0x00); |
|
24431 + break; |
|
24432 + case MxL_IF_4_5_MHZ: //4.5MHz |
|
24433 + SetIRVBit(myIRV, 0x02, 0x0F, 0x02); |
|
24434 + break; |
|
24435 + case MxL_IF_4_57_MHZ: //4.57MHz |
|
24436 + SetIRVBit(myIRV, 0x02, 0x0F, 0x03); |
|
24437 + break; |
|
24438 + case MxL_IF_5_MHZ: |
|
24439 + SetIRVBit(myIRV, 0x02, 0x0F, 0x04); |
|
24440 + break; |
|
24441 + case MxL_IF_5_38_MHZ: //5.38MHz |
|
24442 + SetIRVBit(myIRV, 0x02, 0x0F, 0x05); |
|
24443 + break; |
|
24444 + case MxL_IF_6_MHZ: |
|
24445 + SetIRVBit(myIRV, 0x02, 0x0F, 0x06); |
|
24446 + break; |
|
24447 + case MxL_IF_6_28_MHZ: //6.28MHz |
|
24448 + SetIRVBit(myIRV, 0x02, 0x0F, 0x07); |
|
24449 + break; |
|
24450 + case MxL_IF_9_1915_MHZ: //9.1915MHz |
|
24451 + SetIRVBit(myIRV, 0x02, 0x0F, 0x08); |
|
24452 + break; |
|
24453 + case MxL_IF_35_25_MHZ: |
|
24454 + SetIRVBit(myIRV, 0x02, 0x0F, 0x09); |
|
24455 + break; |
|
24456 + case MxL_IF_36_15_MHZ: |
|
24457 + SetIRVBit(myIRV, 0x02, 0x0F, 0x0a); |
|
24458 + break; |
|
24459 + case MxL_IF_44_MHZ: |
|
24460 + SetIRVBit(myIRV, 0x02, 0x0F, 0x0B); |
|
24461 + break; |
|
24462 + } |
|
24463 + |
|
24464 + if(Invert_IF) |
|
24465 + SetIRVBit(myIRV, 0x02, 0x10, 0x10); //Invert IF |
|
24466 + else |
|
24467 + SetIRVBit(myIRV, 0x02, 0x10, 0x00); //Normal IF |
|
24468 + |
|
24469 + |
|
24470 + switch(Xtal_Freq_Hz) |
|
24471 + { |
|
24472 + case MxL_XTAL_16_MHZ: |
|
24473 + SetIRVBit(myIRV, 0x03, 0xF0, 0x00); //select xtal freq & Ref Freq |
|
24474 + SetIRVBit(myIRV, 0x05, 0x0F, 0x00); |
|
24475 + break; |
|
24476 + case MxL_XTAL_20_MHZ: |
|
24477 + SetIRVBit(myIRV, 0x03, 0xF0, 0x10); |
|
24478 + SetIRVBit(myIRV, 0x05, 0x0F, 0x01); |
|
24479 + break; |
|
24480 + case MxL_XTAL_20_25_MHZ: |
|
24481 + SetIRVBit(myIRV, 0x03, 0xF0, 0x20); |
|
24482 + SetIRVBit(myIRV, 0x05, 0x0F, 0x02); |
|
24483 + break; |
|
24484 + case MxL_XTAL_20_48_MHZ: |
|
24485 + SetIRVBit(myIRV, 0x03, 0xF0, 0x30); |
|
24486 + SetIRVBit(myIRV, 0x05, 0x0F, 0x03); |
|
24487 + break; |
|
24488 + case MxL_XTAL_24_MHZ: |
|
24489 + SetIRVBit(myIRV, 0x03, 0xF0, 0x40); |
|
24490 + SetIRVBit(myIRV, 0x05, 0x0F, 0x04); |
|
24491 + break; |
|
24492 + case MxL_XTAL_25_MHZ: |
|
24493 + SetIRVBit(myIRV, 0x03, 0xF0, 0x50); |
|
24494 + SetIRVBit(myIRV, 0x05, 0x0F, 0x05); |
|
24495 + break; |
|
24496 + case MxL_XTAL_25_14_MHZ: |
|
24497 + SetIRVBit(myIRV, 0x03, 0xF0, 0x60); |
|
24498 + SetIRVBit(myIRV, 0x05, 0x0F, 0x06); |
|
24499 + break; |
|
24500 + case MxL_XTAL_27_MHZ: |
|
24501 + SetIRVBit(myIRV, 0x03, 0xF0, 0x70); |
|
24502 + SetIRVBit(myIRV, 0x05, 0x0F, 0x07); |
|
24503 + break; |
|
24504 + case MxL_XTAL_28_8_MHZ: |
|
24505 + SetIRVBit(myIRV, 0x03, 0xF0, 0x80); |
|
24506 + SetIRVBit(myIRV, 0x05, 0x0F, 0x08); |
|
24507 + break; |
|
24508 + case MxL_XTAL_32_MHZ: |
|
24509 + SetIRVBit(myIRV, 0x03, 0xF0, 0x90); |
|
24510 + SetIRVBit(myIRV, 0x05, 0x0F, 0x09); |
|
24511 + break; |
|
24512 + case MxL_XTAL_40_MHZ: |
|
24513 + SetIRVBit(myIRV, 0x03, 0xF0, 0xA0); |
|
24514 + SetIRVBit(myIRV, 0x05, 0x0F, 0x0A); |
|
24515 + break; |
|
24516 + case MxL_XTAL_44_MHZ: |
|
24517 + SetIRVBit(myIRV, 0x03, 0xF0, 0xB0); |
|
24518 + SetIRVBit(myIRV, 0x05, 0x0F, 0x0B); |
|
24519 + break; |
|
24520 + case MxL_XTAL_48_MHZ: |
|
24521 + SetIRVBit(myIRV, 0x03, 0xF0, 0xC0); |
|
24522 + SetIRVBit(myIRV, 0x05, 0x0F, 0x0C); |
|
24523 + break; |
|
24524 + case MxL_XTAL_49_3811_MHZ: |
|
24525 + SetIRVBit(myIRV, 0x03, 0xF0, 0xD0); |
|
24526 + SetIRVBit(myIRV, 0x05, 0x0F, 0x0D); |
|
24527 + break; |
|
24528 + } |
|
24529 + |
|
24530 + if(!Clk_Out_Enable) //default is enable |
|
24531 + SetIRVBit(myIRV, 0x03, 0x08, 0x00); |
|
24532 + |
|
24533 + //Clk_Out_Amp |
|
24534 + SetIRVBit(myIRV, 0x03, 0x07, Clk_Out_Amp); |
|
24535 + |
|
24536 + //Generate one Array that Contain Data, Address |
|
24537 + while (myIRV[Reg_Index].Num || myIRV[Reg_Index].Val) |
|
24538 + { |
|
24539 + pArray[Array_Index++] = myIRV[Reg_Index].Num; |
|
24540 + pArray[Array_Index++] = myIRV[Reg_Index].Val; |
|
24541 + Reg_Index++; |
|
24542 + } |
|
24543 + |
|
24544 + *Array_Size=Array_Index; |
|
24545 + return 0; |
|
24546 +} |
|
24547 + |
|
24548 + |
|
24549 +UINT32 MxL5007_RFTune(UINT8* pArray, UINT32* Array_Size, UINT32 RF_Freq, UINT8 BWMHz) |
|
24550 +{ |
|
24551 + IRVType IRV_RFTune[]= |
|
24552 + { |
|
24553 + //{ Addr, Data} |
|
24554 + { 0x0F, 0x00}, //abort tune |
|
24555 + { 0x0C, 0x15}, |
|
24556 + { 0x0D, 0x40}, |
|
24557 + { 0x0E, 0x0E}, |
|
24558 + { 0x1F, 0x87}, //Override |
|
24559 + { 0x20, 0x1F}, //Override |
|
24560 + { 0x21, 0x87}, //Override |
|
24561 + { 0x22, 0x1F}, //Override |
|
24562 + { 0x80, 0x01}, //Freq Dependent Setting |
|
24563 + { 0x0F, 0x01}, //start tune |
|
24564 + { 0, 0} |
|
24565 + }; |
|
24566 + |
|
24567 + UINT32 dig_rf_freq=0; |
|
24568 + UINT32 temp; |
|
24569 + UINT32 Reg_Index=0; |
|
24570 + UINT32 Array_Index=0; |
|
24571 + UINT32 i; |
|
24572 + UINT32 frac_divider = 1000000; |
|
24573 + |
|
24574 + switch(BWMHz) |
|
24575 + { |
|
24576 + case MxL_BW_6MHz: //6MHz |
|
24577 + SetIRVBit(IRV_RFTune, 0x0C, 0x3F, 0x15); //set DIG_MODEINDEX, DIG_MODEINDEX_A, and DIG_MODEINDEX_CSF |
|
24578 + break; |
|
24579 + case MxL_BW_7MHz: //7MHz |
|
24580 + SetIRVBit(IRV_RFTune, 0x0C, 0x3F, 0x2A); |
|
24581 + break; |
|
24582 + case MxL_BW_8MHz: //8MHz |
|
24583 + SetIRVBit(IRV_RFTune, 0x0C, 0x3F, 0x3F); |
|
24584 + break; |
|
24585 + } |
|
24586 + |
|
24587 + |
|
24588 + //Convert RF frequency into 16 bits => 10 bit integer (MHz) + 6 bit fraction |
|
24589 + dig_rf_freq = RF_Freq / MHz; |
|
24590 + temp = RF_Freq % MHz; |
|
24591 + for(i=0; i<6; i++) |
|
24592 + { |
|
24593 + dig_rf_freq <<= 1; |
|
24594 + frac_divider /=2; |
|
24595 + if(temp > frac_divider) |
|
24596 + { |
|
24597 + temp -= frac_divider; |
|
24598 + dig_rf_freq++; |
|
24599 + } |
|
24600 + } |
|
24601 + |
|
24602 + //add to have shift center point by 7.8124 kHz |
|
24603 + if(temp > 7812) |
|
24604 + dig_rf_freq ++; |
|
24605 + |
|
24606 + SetIRVBit(IRV_RFTune, 0x0D, 0xFF, (UINT8)dig_rf_freq); |
|
24607 + SetIRVBit(IRV_RFTune, 0x0E, 0xFF, (UINT8)(dig_rf_freq>>8)); |
|
24608 + |
|
24609 + if (RF_Freq >=333*MHz) |
|
24610 + SetIRVBit(IRV_RFTune, 0x80, 0x40, 0x40); |
|
24611 + |
|
24612 + //Generate one Array that Contain Data, Address |
|
24613 + while (IRV_RFTune[Reg_Index].Num || IRV_RFTune[Reg_Index].Val) |
|
24614 + { |
|
24615 + pArray[Array_Index++] = IRV_RFTune[Reg_Index].Num; |
|
24616 + pArray[Array_Index++] = IRV_RFTune[Reg_Index].Val; |
|
24617 + Reg_Index++; |
|
24618 + } |
|
24619 + |
|
24620 + *Array_Size=Array_Index; |
|
24621 + |
|
24622 + return 0; |
|
24623 +} |
|
24624 + |
|
24625 +//local functions called by Init and RFTune |
|
24626 +UINT32 SetIRVBit(PIRVType pIRV, UINT8 Num, UINT8 Mask, UINT8 Val) |
|
24627 +{ |
|
24628 + while (pIRV->Num || pIRV->Val) |
|
24629 + { |
|
24630 + if (pIRV->Num==Num) |
|
24631 + { |
|
24632 + pIRV->Val&=~Mask; |
|
24633 + pIRV->Val|=Val; |
|
24634 + } |
|
24635 + pIRV++; |
|
24636 + |
|
24637 + } |
|
24638 + return 0; |
|
24639 +} |
|
24640 + |
|
24641 + |
|
24642 + |
|
24643 + |
|
24644 + |
|
24645 + |
|
24646 + |
|
24647 + |
|
24648 + |
|
24649 + |
|
24650 + |
|
24651 + |
|
24652 + |
|
24653 + |
|
24654 + |
|
24655 + |
|
24656 + |
|
24657 + |
|
24658 + |
|
24659 + |
|
24660 + |
|
24661 + |
|
24662 + |
|
24663 +// MaxLinear source code - MxL5007_API.h |
|
24664 + |
|
24665 + |
|
24666 +/* |
|
24667 + |
|
24668 + Driver APIs for MxL5007 Tuner |
|
24669 + |
|
24670 + Copyright, Maxlinear, Inc. |
|
24671 + All Rights Reserved |
|
24672 + |
|
24673 + File Name: MxL5007_API.c |
|
24674 + |
|
24675 + Version: 4.1.3 |
|
24676 +*/ |
|
24677 + |
|
24678 + |
|
24679 +//#include "StdAfx.h" |
|
24680 +//#include "MxL5007_API.h" |
|
24681 +//#include "MxL_User_Define.c" |
|
24682 +//#include "MxL5007.c" |
|
24683 + |
|
24684 + |
|
24685 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|
24686 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|
24687 +// // |
|
24688 +// Tuner Functions // |
|
24689 +// // |
|
24690 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|
24691 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|
24692 +MxL_ERR_MSG MxL_Set_Register(MxL5007_TunerConfigS* myTuner, UINT8 RegAddr, UINT8 RegData) |
|
24693 +{ |
|
24694 + UINT32 Status=0; |
|
24695 + UINT8 pArray[2]; |
|
24696 + pArray[0] = RegAddr; |
|
24697 + pArray[1] = RegData; |
|
24698 +// Status = MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, 2); |
|
24699 + Status = MxL_I2C_Write(myTuner, pArray, 2); |
|
24700 + if(Status) return MxL_ERR_SET_REG; |
|
24701 + |
|
24702 + return MxL_OK; |
|
24703 + |
|
24704 +} |
|
24705 + |
|
24706 +MxL_ERR_MSG MxL_Get_Register(MxL5007_TunerConfigS* myTuner, UINT8 RegAddr, UINT8 *RegData) |
|
24707 +{ |
|
24708 +// if(MxL_I2C_Read((UINT8)myTuner->I2C_Addr, RegAddr, RegData)) |
|
24709 + if(MxL_I2C_Read(myTuner, RegAddr, RegData)) |
|
24710 + return MxL_ERR_GET_REG; |
|
24711 + return MxL_OK; |
|
24712 + |
|
24713 +} |
|
24714 + |
|
24715 +MxL_ERR_MSG MxL_Soft_Reset(MxL5007_TunerConfigS* myTuner) |
|
24716 +{ |
|
24717 + UINT32 Status=0; |
|
24718 + UINT8 reg_reset; |
|
24719 + reg_reset = 0xFF; |
|
24720 +// if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, ®_reset, 1)) |
|
24721 + if(MxL_I2C_Write(myTuner, ®_reset, 1)) |
|
24722 + return MxL_ERR_OTHERS; |
|
24723 + |
|
24724 + return MxL_OK; |
|
24725 +} |
|
24726 + |
|
24727 +MxL_ERR_MSG MxL_Loop_Through_On(MxL5007_TunerConfigS* myTuner, MxL5007_LoopThru isOn) |
|
24728 +{ |
|
24729 + UINT8 pArray[2]; // a array pointer that store the addr and data pairs for I2C write |
|
24730 + |
|
24731 + pArray[0]=0x04; |
|
24732 + if(isOn) |
|
24733 + pArray[1]= 0x01; |
|
24734 + else |
|
24735 + pArray[1]= 0x0; |
|
24736 + |
|
24737 +// if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, 2)) |
|
24738 + if(MxL_I2C_Write(myTuner, pArray, 2)) |
|
24739 + return MxL_ERR_OTHERS; |
|
24740 + |
|
24741 + return MxL_OK; |
|
24742 +} |
|
24743 + |
|
24744 +MxL_ERR_MSG MxL_Stand_By(MxL5007_TunerConfigS* myTuner) |
|
24745 +{ |
|
24746 + UINT8 pArray[4]; // a array pointer that store the addr and data pairs for I2C write |
|
24747 + |
|
24748 + pArray[0] = 0x01; |
|
24749 + pArray[1] = 0x0; |
|
24750 + pArray[2] = 0x0F; |
|
24751 + pArray[3] = 0x0; |
|
24752 + |
|
24753 +// if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, 4)) |
|
24754 + if(MxL_I2C_Write(myTuner, pArray, 4)) |
|
24755 + return MxL_ERR_OTHERS; |
|
24756 + |
|
24757 + return MxL_OK; |
|
24758 +} |
|
24759 + |
|
24760 +MxL_ERR_MSG MxL_Wake_Up(MxL5007_TunerConfigS* myTuner) |
|
24761 +{ |
|
24762 + UINT8 pArray[2]; // a array pointer that store the addr and data pairs for I2C write |
|
24763 + |
|
24764 + pArray[0] = 0x01; |
|
24765 + pArray[1] = 0x01; |
|
24766 + |
|
24767 +// if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, 2)) |
|
24768 + if(MxL_I2C_Write(myTuner, pArray, 2)) |
|
24769 + return MxL_ERR_OTHERS; |
|
24770 + |
|
24771 + if(MxL_Tuner_RFTune(myTuner, myTuner->RF_Freq_Hz, myTuner->BW_MHz)) |
|
24772 + return MxL_ERR_RFTUNE; |
|
24773 + |
|
24774 + return MxL_OK; |
|
24775 +} |
|
24776 + |
|
24777 +MxL_ERR_MSG MxL_Tuner_Init(MxL5007_TunerConfigS* myTuner) |
|
24778 +{ |
|
24779 + UINT8 pArray[MAX_ARRAY_SIZE]; // a array pointer that store the addr and data pairs for I2C write |
|
24780 + UINT32 Array_Size; // a integer pointer that store the number of element in above array |
|
24781 + |
|
24782 + //Soft reset tuner |
|
24783 + if(MxL_Soft_Reset(myTuner)) |
|
24784 + return MxL_ERR_INIT; |
|
24785 + |
|
24786 + //perform initialization calculation |
|
24787 + MxL5007_Init(pArray, &Array_Size, (UINT8)myTuner->Mode, myTuner->IF_Diff_Out_Level, (UINT32)myTuner->Xtal_Freq, |
|
24788 + (UINT32)myTuner->IF_Freq, (UINT8)myTuner->IF_Spectrum, (UINT8)myTuner->ClkOut_Setting, (UINT8)myTuner->ClkOut_Amp); |
|
24789 + |
|
24790 + //perform I2C write here |
|
24791 +// if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, Array_Size)) |
|
24792 + if(MxL_I2C_Write(myTuner, pArray, Array_Size)) |
|
24793 + return MxL_ERR_INIT; |
|
24794 + |
|
24795 + return MxL_OK; |
|
24796 +} |
|
24797 + |
|
24798 + |
|
24799 +MxL_ERR_MSG MxL_Tuner_RFTune(MxL5007_TunerConfigS* myTuner, UINT32 RF_Freq_Hz, MxL5007_BW_MHz BWMHz) |
|
24800 +{ |
|
24801 + UINT32 Status=0; |
|
24802 + UINT8 pArray[MAX_ARRAY_SIZE]; // a array pointer that store the addr and data pairs for I2C write |
|
24803 + UINT32 Array_Size; // a integer pointer that store the number of element in above array |
|
24804 + |
|
24805 + //Store information into struc |
|
24806 + myTuner->RF_Freq_Hz = RF_Freq_Hz; |
|
24807 + myTuner->BW_MHz = BWMHz; |
|
24808 + |
|
24809 + //perform Channel Change calculation |
|
24810 + MxL5007_RFTune(pArray,&Array_Size,RF_Freq_Hz,BWMHz); |
|
24811 + |
|
24812 + //perform I2C write here |
|
24813 +// if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, Array_Size)) |
|
24814 + if(MxL_I2C_Write(myTuner, pArray, Array_Size)) |
|
24815 + return MxL_ERR_RFTUNE; |
|
24816 + |
|
24817 + //wait for 3ms |
|
24818 +// MxL_Delay(3); |
|
24819 + MxL_Delay(myTuner, 3); |
|
24820 + |
|
24821 + return MxL_OK; |
|
24822 +} |
|
24823 + |
|
24824 +MxL5007_ChipVersion MxL_Check_ChipVersion(MxL5007_TunerConfigS* myTuner) |
|
24825 +{ |
|
24826 + UINT8 Data; |
|
24827 +// if(MxL_I2C_Read((UINT8)myTuner->I2C_Addr, 0xD9, &Data)) |
|
24828 + if(MxL_I2C_Read(myTuner, 0xD9, &Data)) |
|
24829 + return MxL_GET_ID_FAIL; |
|
24830 + |
|
24831 + switch(Data) |
|
24832 + { |
|
24833 + case 0x14: return MxL_5007T_V4; break; |
|
24834 + default: return MxL_UNKNOWN_ID; |
|
24835 + } |
|
24836 +} |
|
24837 + |
|
24838 +MxL_ERR_MSG MxL_RFSynth_Lock_Status(MxL5007_TunerConfigS* myTuner, BOOL* isLock) |
|
24839 +{ |
|
24840 + UINT8 Data; |
|
24841 + *isLock = MxL_FALSE; |
|
24842 +// if(MxL_I2C_Read((UINT8)myTuner->I2C_Addr, 0xD8, &Data)) |
|
24843 + if(MxL_I2C_Read(myTuner, 0xD8, &Data)) |
|
24844 + return MxL_ERR_OTHERS; |
|
24845 + Data &= 0x0C; |
|
24846 + if (Data == 0x0C) |
|
24847 + *isLock = MxL_TRUE; //RF Synthesizer is Lock |
|
24848 + return MxL_OK; |
|
24849 +} |
|
24850 + |
|
24851 +MxL_ERR_MSG MxL_REFSynth_Lock_Status(MxL5007_TunerConfigS* myTuner, BOOL* isLock) |
|
24852 +{ |
|
24853 + UINT8 Data; |
|
24854 + *isLock = MxL_FALSE; |
|
24855 +// if(MxL_I2C_Read((UINT8)myTuner->I2C_Addr, 0xD8, &Data)) |
|
24856 + if(MxL_I2C_Read(myTuner, 0xD8, &Data)) |
|
24857 + return MxL_ERR_OTHERS; |
|
24858 + Data &= 0x03; |
|
24859 + if (Data == 0x03) |
|
24860 + *isLock = MxL_TRUE; //REF Synthesizer is Lock |
|
24861 + return MxL_OK; |
|
24862 +} |
|
24863 + |
|
24864 + |
|
24865 + |
|
24866 + |
|
24867 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/tuner_mxl5007t.h |
|
24868 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
24869 +++ b/linux/drivers/media/dvb/dvb-usb/tuner_mxl5007t.h Wed Oct 27 09:16:44 2010 +0200 |
|
24870 @@ -0,0 +1,834 @@ |
|
24871 +#ifndef __TUNER_MXL5007T_H |
|
24872 +#define __TUNER_MXL5007T_H |
|
24873 + |
|
24874 +/** |
|
24875 + |
|
24876 +@file |
|
24877 + |
|
24878 +@brief MxL5007T tuner module declaration |
|
24879 + |
|
24880 +One can manipulate MxL5007T tuner through MxL5007T module. |
|
24881 +MxL5007T module is derived from tuner module. |
|
24882 + |
|
24883 + |
|
24884 + |
|
24885 +@par Example: |
|
24886 +@code |
|
24887 + |
|
24888 +// The example is the same as the tuner example in tuner_base.h except the listed lines. |
|
24889 + |
|
24890 + |
|
24891 + |
|
24892 +#include "tuner_mxl5007t.h" |
|
24893 + |
|
24894 + |
|
24895 +... |
|
24896 + |
|
24897 + |
|
24898 + |
|
24899 +int main(void) |
|
24900 +{ |
|
24901 + TUNER_MODULE *pTuner; |
|
24902 + MXL5007T_EXTRA_MODULE *pTunerExtra; |
|
24903 + |
|
24904 + TUNER_MODULE TunerModuleMemory; |
|
24905 + MXL5007T_EXTRA_MODULE Mxl5007tExtraModuleMemory; |
|
24906 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
24907 + I2C_BRIDGE_MODULE I2cBridgeModuleMemory; |
|
24908 + |
|
24909 + unsigned long BandwidthMode; |
|
24910 + |
|
24911 + |
|
24912 + ... |
|
24913 + |
|
24914 + |
|
24915 + |
|
24916 + // Build MxL5007T tuner module. |
|
24917 + BuildMxl5007tModule( |
|
24918 + &pTuner, |
|
24919 + &TunerModuleMemory, |
|
24920 + &Mxl5007tExtraModuleMemory, |
|
24921 + &BaseInterfaceModuleMemory, |
|
24922 + &I2cBridgeModuleMemory, |
|
24923 + 0xc0, // I2C device address is 0xc0 in 8-bit format. |
|
24924 + CRYSTAL_FREQ_16000000HZ, // Crystal frequency is 16.0 MHz. |
|
24925 + MXL5007T_STANDARD_DVBT, // The MxL5007T standard mode is DVB-T. |
|
24926 + IF_FREQ_4570000HZ, // The MxL5007T IF frequency is 4.57 MHz. |
|
24927 + SPECTRUM_NORMAL, // The MxL5007T spectrum mode is normal. |
|
24928 + MXL5007T_CLK_OUT_DISABLE, // The MxL5007T clock output mode is disabled. |
|
24929 + MXL5007T_CLK_OUT_AMP_0, // The MxL5007T clock output amplitude is 0. |
|
24930 + 0 // The MxL5007T QAM IF differential output level is 0 for cable only. |
|
24931 + ); |
|
24932 + |
|
24933 + |
|
24934 + |
|
24935 + |
|
24936 + |
|
24937 + // Get MxL5007T tuner extra module. |
|
24938 + pTunerExtra = (T2266_EXTRA_MODULE *)(pTuner->pExtra); |
|
24939 + |
|
24940 + |
|
24941 + |
|
24942 + |
|
24943 + |
|
24944 + // ==== Initialize tuner and set its parameters ===== |
|
24945 + |
|
24946 + ... |
|
24947 + |
|
24948 + // Set MXL5007T bandwidth. |
|
24949 + pTunerExtra->SetBandwidthMode(pTuner, MXL5007T_BANDWIDTH_6MHZ); |
|
24950 + |
|
24951 + |
|
24952 + |
|
24953 + |
|
24954 + |
|
24955 + // ==== Get tuner information ===== |
|
24956 + |
|
24957 + ... |
|
24958 + |
|
24959 + // Get MXL5007T bandwidth. |
|
24960 + pTunerExtra->GetBandwidthMode(pTuner, &BandwidthMode); |
|
24961 + |
|
24962 + |
|
24963 + |
|
24964 + // See the example for other tuner functions in tuner_base.h |
|
24965 + |
|
24966 + |
|
24967 + return 0; |
|
24968 +} |
|
24969 + |
|
24970 + |
|
24971 +@endcode |
|
24972 + |
|
24973 +*/ |
|
24974 + |
|
24975 + |
|
24976 + |
|
24977 + |
|
24978 + |
|
24979 +#include "tuner_base.h" |
|
24980 + |
|
24981 + |
|
24982 + |
|
24983 + |
|
24984 + |
|
24985 +// The following context is source code provided by MaxLinear. |
|
24986 + |
|
24987 + |
|
24988 + |
|
24989 + |
|
24990 + |
|
24991 +// MaxLinear source code - MxL5007_Common.h |
|
24992 + |
|
24993 + |
|
24994 +/******************************************************************************* |
|
24995 + * |
|
24996 + * FILE NAME : MxL_Common.h |
|
24997 + * |
|
24998 + * AUTHOR : Kyle Huang |
|
24999 + * DATE CREATED : May 05, 2008 |
|
25000 + * |
|
25001 + * DESCRIPTION : |
|
25002 + * |
|
25003 + ******************************************************************************* |
|
25004 + * Copyright (c) 2006, MaxLinear, Inc. |
|
25005 + ******************************************************************************/ |
|
25006 + |
|
25007 +//#ifndef __MXL5007_COMMON_H |
|
25008 +//#define __MXL5007_COMMON_H |
|
25009 + |
|
25010 + |
|
25011 + |
|
25012 +/****************************************************************************** |
|
25013 +* User-Defined Types (Typedefs) |
|
25014 +******************************************************************************/ |
|
25015 + |
|
25016 + |
|
25017 +/**************************************************************************** |
|
25018 +* Imports and definitions for WIN32 |
|
25019 +****************************************************************************/ |
|
25020 +//#include <windows.h> |
|
25021 +typedef unsigned char UINT8; |
|
25022 +typedef unsigned short UINT16; |
|
25023 +typedef unsigned int UINT32; |
|
25024 +typedef char SINT8; |
|
25025 +typedef short SINT16; |
|
25026 +typedef int SINT32; |
|
25027 +//typedef float REAL32; |
|
25028 + |
|
25029 +// Additional definition |
|
25030 +#define BOOL int |
|
25031 +#define MxL_FALSE 0 |
|
25032 +#define MxL_TRUE 1 |
|
25033 + |
|
25034 +/****************************************************************************\ |
|
25035 +* Imports and definitions for non WIN32 platforms * |
|
25036 +\****************************************************************************/ |
|
25037 +/* |
|
25038 +typedef unsigned char UINT8; |
|
25039 +typedef unsigned short UINT16; |
|
25040 +typedef unsigned int UINT32; |
|
25041 +typedef char SINT8; |
|
25042 +typedef short SINT16; |
|
25043 +typedef int SINT32; |
|
25044 +typedef float REAL32; |
|
25045 + |
|
25046 +// create a boolean |
|
25047 +#ifndef __boolean__ |
|
25048 +#define __boolean__ |
|
25049 +typedef enum {FALSE=0,TRUE} BOOL; |
|
25050 +#endif //boolean |
|
25051 +*/ |
|
25052 + |
|
25053 + |
|
25054 +/****************************************************************************\ |
|
25055 +* Definitions for all platforms * |
|
25056 +\****************************************************************************/ |
|
25057 +#ifndef NULL |
|
25058 +#define NULL (void*)0 |
|
25059 +#endif |
|
25060 + |
|
25061 + |
|
25062 + |
|
25063 +/******************************/ |
|
25064 +/* MxL5007 Err message */ |
|
25065 +/******************************/ |
|
25066 +typedef enum{ |
|
25067 + MxL_OK = 0, |
|
25068 + MxL_ERR_INIT = 1, |
|
25069 + MxL_ERR_RFTUNE = 2, |
|
25070 + MxL_ERR_SET_REG = 3, |
|
25071 + MxL_ERR_GET_REG = 4, |
|
25072 + MxL_ERR_OTHERS = 10 |
|
25073 +}MxL_ERR_MSG; |
|
25074 + |
|
25075 +/******************************/ |
|
25076 +/* MxL5007 Chip verstion */ |
|
25077 +/******************************/ |
|
25078 +typedef enum{ |
|
25079 + MxL_UNKNOWN_ID = 0x00, |
|
25080 + MxL_5007T_V4 = 0x14, |
|
25081 + MxL_GET_ID_FAIL = 0xFF |
|
25082 +}MxL5007_ChipVersion; |
|
25083 + |
|
25084 + |
|
25085 +/****************************************************************************** |
|
25086 + CONSTANTS |
|
25087 +******************************************************************************/ |
|
25088 + |
|
25089 +#ifndef MHz |
|
25090 + #define MHz 1000000 |
|
25091 +#endif |
|
25092 + |
|
25093 +#define MAX_ARRAY_SIZE 100 |
|
25094 + |
|
25095 + |
|
25096 +// Enumeration of Mode |
|
25097 +// Enumeration of Mode |
|
25098 +typedef enum |
|
25099 +{ |
|
25100 + MxL_MODE_ISDBT = 0, |
|
25101 + MxL_MODE_DVBT = 1, |
|
25102 + MxL_MODE_ATSC = 2, |
|
25103 + MxL_MODE_CABLE = 0x10 |
|
25104 +} MxL5007_Mode ; |
|
25105 + |
|
25106 +typedef enum |
|
25107 +{ |
|
25108 + MxL_IF_4_MHZ = 4000000, |
|
25109 + MxL_IF_4_5_MHZ = 4500000, |
|
25110 + MxL_IF_4_57_MHZ = 4570000, |
|
25111 + MxL_IF_5_MHZ = 5000000, |
|
25112 + MxL_IF_5_38_MHZ = 5380000, |
|
25113 + MxL_IF_6_MHZ = 6000000, |
|
25114 + MxL_IF_6_28_MHZ = 6280000, |
|
25115 + MxL_IF_9_1915_MHZ = 9191500, |
|
25116 + MxL_IF_35_25_MHZ = 35250000, |
|
25117 + MxL_IF_36_15_MHZ = 36150000, |
|
25118 + MxL_IF_44_MHZ = 44000000 |
|
25119 +} MxL5007_IF_Freq ; |
|
25120 + |
|
25121 +typedef enum |
|
25122 +{ |
|
25123 + MxL_XTAL_16_MHZ = 16000000, |
|
25124 + MxL_XTAL_20_MHZ = 20000000, |
|
25125 + MxL_XTAL_20_25_MHZ = 20250000, |
|
25126 + MxL_XTAL_20_48_MHZ = 20480000, |
|
25127 + MxL_XTAL_24_MHZ = 24000000, |
|
25128 + MxL_XTAL_25_MHZ = 25000000, |
|
25129 + MxL_XTAL_25_14_MHZ = 25140000, |
|
25130 + MxL_XTAL_27_MHZ = 27000000, |
|
25131 + MxL_XTAL_28_8_MHZ = 28800000, |
|
25132 + MxL_XTAL_32_MHZ = 32000000, |
|
25133 + MxL_XTAL_40_MHZ = 40000000, |
|
25134 + MxL_XTAL_44_MHZ = 44000000, |
|
25135 + MxL_XTAL_48_MHZ = 48000000, |
|
25136 + MxL_XTAL_49_3811_MHZ = 49381100 |
|
25137 +} MxL5007_Xtal_Freq ; |
|
25138 + |
|
25139 +typedef enum |
|
25140 +{ |
|
25141 + MxL_BW_6MHz = 6, |
|
25142 + MxL_BW_7MHz = 7, |
|
25143 + MxL_BW_8MHz = 8 |
|
25144 +} MxL5007_BW_MHz; |
|
25145 + |
|
25146 +typedef enum |
|
25147 +{ |
|
25148 + MxL_NORMAL_IF = 0 , |
|
25149 + MxL_INVERT_IF |
|
25150 + |
|
25151 +} MxL5007_IF_Spectrum ; |
|
25152 + |
|
25153 +typedef enum |
|
25154 +{ |
|
25155 + MxL_LT_DISABLE = 0 , |
|
25156 + MxL_LT_ENABLE |
|
25157 + |
|
25158 +} MxL5007_LoopThru ; |
|
25159 + |
|
25160 +typedef enum |
|
25161 +{ |
|
25162 + MxL_CLKOUT_DISABLE = 0 , |
|
25163 + MxL_CLKOUT_ENABLE |
|
25164 + |
|
25165 +} MxL5007_ClkOut; |
|
25166 + |
|
25167 +typedef enum |
|
25168 +{ |
|
25169 + MxL_CLKOUT_AMP_0 = 0 , |
|
25170 + MxL_CLKOUT_AMP_1, |
|
25171 + MxL_CLKOUT_AMP_2, |
|
25172 + MxL_CLKOUT_AMP_3, |
|
25173 + MxL_CLKOUT_AMP_4, |
|
25174 + MxL_CLKOUT_AMP_5, |
|
25175 + MxL_CLKOUT_AMP_6, |
|
25176 + MxL_CLKOUT_AMP_7 |
|
25177 +} MxL5007_ClkOut_Amp; |
|
25178 + |
|
25179 +typedef enum |
|
25180 +{ |
|
25181 + MxL_I2C_ADDR_96 = 96 , |
|
25182 + MxL_I2C_ADDR_97 = 97 , |
|
25183 + MxL_I2C_ADDR_98 = 98 , |
|
25184 + MxL_I2C_ADDR_99 = 99 |
|
25185 +} MxL5007_I2CAddr ; |
|
25186 + |
|
25187 +// |
|
25188 +// MxL5007 TunerConfig Struct |
|
25189 +// |
|
25190 +typedef struct _MxL5007_TunerConfigS |
|
25191 +{ |
|
25192 + MxL5007_I2CAddr I2C_Addr; |
|
25193 + MxL5007_Mode Mode; |
|
25194 + SINT32 IF_Diff_Out_Level; |
|
25195 + MxL5007_Xtal_Freq Xtal_Freq; |
|
25196 + MxL5007_IF_Freq IF_Freq; |
|
25197 + MxL5007_IF_Spectrum IF_Spectrum; |
|
25198 + MxL5007_ClkOut ClkOut_Setting; |
|
25199 + MxL5007_ClkOut_Amp ClkOut_Amp; |
|
25200 + MxL5007_BW_MHz BW_MHz; |
|
25201 + UINT32 RF_Freq_Hz; |
|
25202 + |
|
25203 + // Additional definition |
|
25204 + TUNER_MODULE *pTuner; |
|
25205 + |
|
25206 +} MxL5007_TunerConfigS; |
|
25207 + |
|
25208 + |
|
25209 + |
|
25210 + |
|
25211 +//#endif /* __MXL5007_COMMON_H__*/ |
|
25212 + |
|
25213 + |
|
25214 + |
|
25215 + |
|
25216 + |
|
25217 + |
|
25218 + |
|
25219 + |
|
25220 + |
|
25221 + |
|
25222 + |
|
25223 + |
|
25224 + |
|
25225 + |
|
25226 + |
|
25227 + |
|
25228 + |
|
25229 + |
|
25230 + |
|
25231 + |
|
25232 + |
|
25233 + |
|
25234 + |
|
25235 +// MaxLinear source code - MxL5007.h |
|
25236 + |
|
25237 + |
|
25238 + |
|
25239 +/* |
|
25240 + |
|
25241 + Driver APIs for MxL5007 Tuner |
|
25242 + |
|
25243 + Copyright, Maxlinear, Inc. |
|
25244 + All Rights Reserved |
|
25245 + |
|
25246 + File Name: MxL5007.h |
|
25247 + |
|
25248 + */ |
|
25249 + |
|
25250 + |
|
25251 +//#include "MxL5007_Common.h" |
|
25252 + |
|
25253 + |
|
25254 +typedef struct |
|
25255 +{ |
|
25256 + UINT8 Num; //Register number |
|
25257 + UINT8 Val; //Register value |
|
25258 +} IRVType, *PIRVType; |
|
25259 + |
|
25260 + |
|
25261 +UINT32 MxL5007_Init(UINT8* pArray, // a array pointer that store the addr and data pairs for I2C write |
|
25262 + UINT32* Array_Size, // a integer pointer that store the number of element in above array |
|
25263 + UINT8 Mode, |
|
25264 + SINT32 IF_Diff_Out_Level, |
|
25265 + UINT32 Xtal_Freq_Hz, |
|
25266 + UINT32 IF_Freq_Hz, |
|
25267 + UINT8 Invert_IF, |
|
25268 + UINT8 Clk_Out_Enable, |
|
25269 + UINT8 Clk_Out_Amp |
|
25270 + ); |
|
25271 +UINT32 MxL5007_RFTune(UINT8* pArray, UINT32* Array_Size, |
|
25272 + UINT32 RF_Freq, // RF Frequency in Hz |
|
25273 + UINT8 BWMHz // Bandwidth in MHz |
|
25274 + ); |
|
25275 +UINT32 SetIRVBit(PIRVType pIRV, UINT8 Num, UINT8 Mask, UINT8 Val); |
|
25276 + |
|
25277 + |
|
25278 + |
|
25279 + |
|
25280 + |
|
25281 + |
|
25282 + |
|
25283 + |
|
25284 + |
|
25285 + |
|
25286 + |
|
25287 + |
|
25288 + |
|
25289 + |
|
25290 + |
|
25291 + |
|
25292 + |
|
25293 + |
|
25294 + |
|
25295 + |
|
25296 + |
|
25297 + |
|
25298 + |
|
25299 +// MaxLinear source code - MxL5007.h |
|
25300 + |
|
25301 + |
|
25302 + |
|
25303 +/* |
|
25304 + |
|
25305 + Driver APIs for MxL5007 Tuner |
|
25306 + |
|
25307 + Copyright, Maxlinear, Inc. |
|
25308 + All Rights Reserved |
|
25309 + |
|
25310 + File Name: MxL5007_API.h |
|
25311 + |
|
25312 + */ |
|
25313 +//#ifndef __MxL5007_API_H |
|
25314 +//#define __MxL5007_API_H |
|
25315 + |
|
25316 +//#include "MxL5007_Common.h" |
|
25317 + |
|
25318 +/****************************************************************************** |
|
25319 +** |
|
25320 +** Name: MxL_Set_Register |
|
25321 +** |
|
25322 +** Description: Write one register to MxL5007 |
|
25323 +** |
|
25324 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25325 +** RegAddr - Register address to be written |
|
25326 +** RegData - Data to be written |
|
25327 +** |
|
25328 +** Returns: MxL_ERR_MSG - MxL_OK if success |
|
25329 +** - MxL_ERR_SET_REG if fail |
|
25330 +** |
|
25331 +******************************************************************************/ |
|
25332 +MxL_ERR_MSG MxL_Set_Register(MxL5007_TunerConfigS* myTuner, UINT8 RegAddr, UINT8 RegData); |
|
25333 + |
|
25334 +/****************************************************************************** |
|
25335 +** |
|
25336 +** Name: MxL_Get_Register |
|
25337 +** |
|
25338 +** Description: Read one register from MxL5007 |
|
25339 +** |
|
25340 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25341 +** RegAddr - Register address to be read |
|
25342 +** RegData - Pointer to register read |
|
25343 +** |
|
25344 +** Returns: MxL_ERR_MSG - MxL_OK if success |
|
25345 +** - MxL_ERR_GET_REG if fail |
|
25346 +** |
|
25347 +******************************************************************************/ |
|
25348 +MxL_ERR_MSG MxL_Get_Register(MxL5007_TunerConfigS* myTuner, UINT8 RegAddr, UINT8 *RegData); |
|
25349 + |
|
25350 +/****************************************************************************** |
|
25351 +** |
|
25352 +** Name: MxL_Tuner_Init |
|
25353 +** |
|
25354 +** Description: MxL5007 Initialization |
|
25355 +** |
|
25356 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25357 +** |
|
25358 +** Returns: MxL_ERR_MSG - MxL_OK if success |
|
25359 +** - MxL_ERR_INIT if fail |
|
25360 +** |
|
25361 +******************************************************************************/ |
|
25362 +MxL_ERR_MSG MxL_Tuner_Init(MxL5007_TunerConfigS* ); |
|
25363 + |
|
25364 +/****************************************************************************** |
|
25365 +** |
|
25366 +** Name: MxL_Tuner_RFTune |
|
25367 +** |
|
25368 +** Description: Frequency tunning for channel |
|
25369 +** |
|
25370 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25371 +** RF_Freq_Hz - RF Frequency in Hz |
|
25372 +** BWMHz - Bandwidth 6, 7 or 8 MHz |
|
25373 +** |
|
25374 +** Returns: MxL_ERR_MSG - MxL_OK if success |
|
25375 +** - MxL_ERR_RFTUNE if fail |
|
25376 +** |
|
25377 +******************************************************************************/ |
|
25378 +MxL_ERR_MSG MxL_Tuner_RFTune(MxL5007_TunerConfigS*, UINT32 RF_Freq_Hz, MxL5007_BW_MHz BWMHz); |
|
25379 + |
|
25380 +/****************************************************************************** |
|
25381 +** |
|
25382 +** Name: MxL_Soft_Reset |
|
25383 +** |
|
25384 +** Description: Software Reset the MxL5007 Tuner |
|
25385 +** |
|
25386 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25387 +** |
|
25388 +** Returns: MxL_ERR_MSG - MxL_OK if success |
|
25389 +** - MxL_ERR_OTHERS if fail |
|
25390 +** |
|
25391 +******************************************************************************/ |
|
25392 +MxL_ERR_MSG MxL_Soft_Reset(MxL5007_TunerConfigS*); |
|
25393 + |
|
25394 +/****************************************************************************** |
|
25395 +** |
|
25396 +** Name: MxL_Loop_Through_On |
|
25397 +** |
|
25398 +** Description: Turn On/Off on-chip Loop-through |
|
25399 +** |
|
25400 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25401 +** isOn - True to turn On Loop Through |
|
25402 +** - False to turn off Loop Through |
|
25403 +** |
|
25404 +** Returns: MxL_ERR_MSG - MxL_OK if success |
|
25405 +** - MxL_ERR_OTHERS if fail |
|
25406 +** |
|
25407 +******************************************************************************/ |
|
25408 +MxL_ERR_MSG MxL_Loop_Through_On(MxL5007_TunerConfigS*, MxL5007_LoopThru); |
|
25409 + |
|
25410 +/****************************************************************************** |
|
25411 +** |
|
25412 +** Name: MxL_Standby |
|
25413 +** |
|
25414 +** Description: Enter Standby Mode |
|
25415 +** |
|
25416 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25417 +** |
|
25418 +** Returns: MxL_ERR_MSG - MxL_OK if success |
|
25419 +** - MxL_ERR_OTHERS if fail |
|
25420 +** |
|
25421 +******************************************************************************/ |
|
25422 +MxL_ERR_MSG MxL_Stand_By(MxL5007_TunerConfigS*); |
|
25423 + |
|
25424 +/****************************************************************************** |
|
25425 +** |
|
25426 +** Name: MxL_Wakeup |
|
25427 +** |
|
25428 +** Description: Wakeup from Standby Mode (Note: after wake up, please call RF_Tune again) |
|
25429 +** |
|
25430 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25431 +** |
|
25432 +** Returns: MxL_ERR_MSG - MxL_OK if success |
|
25433 +** - MxL_ERR_OTHERS if fail |
|
25434 +** |
|
25435 +******************************************************************************/ |
|
25436 +MxL_ERR_MSG MxL_Wake_Up(MxL5007_TunerConfigS*); |
|
25437 + |
|
25438 +/****************************************************************************** |
|
25439 +** |
|
25440 +** Name: MxL_Check_ChipVersion |
|
25441 +** |
|
25442 +** Description: Return the MxL5007 Chip ID |
|
25443 +** |
|
25444 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25445 +** |
|
25446 +** Returns: MxL_ChipVersion |
|
25447 +** |
|
25448 +******************************************************************************/ |
|
25449 +MxL5007_ChipVersion MxL_Check_ChipVersion(MxL5007_TunerConfigS*); |
|
25450 + |
|
25451 +/****************************************************************************** |
|
25452 +** |
|
25453 +** Name: MxL_RFSynth_Lock_Status |
|
25454 +** |
|
25455 +** Description: RF synthesizer lock status of MxL5007 |
|
25456 +** |
|
25457 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25458 +** isLock - Pointer to Lock Status |
|
25459 +** |
|
25460 +** Returns: MxL_ERR_MSG - MxL_OK if success |
|
25461 +** - MxL_ERR_OTHERS if fail |
|
25462 +** |
|
25463 +******************************************************************************/ |
|
25464 +MxL_ERR_MSG MxL_RFSynth_Lock_Status(MxL5007_TunerConfigS* , BOOL* isLock); |
|
25465 + |
|
25466 +/****************************************************************************** |
|
25467 +** |
|
25468 +** Name: MxL_REFSynth_Lock_Status |
|
25469 +** |
|
25470 +** Description: REF synthesizer lock status of MxL5007 |
|
25471 +** |
|
25472 +** Parameters: myTuner - Pointer to MxL5007_TunerConfigS |
|
25473 +** isLock - Pointer to Lock Status |
|
25474 +** |
|
25475 +** Returns: MxL_ERR_MSG - MxL_OK if success |
|
25476 +** - MxL_ERR_OTHERS if fail |
|
25477 +** |
|
25478 +******************************************************************************/ |
|
25479 +MxL_ERR_MSG MxL_REFSynth_Lock_Status(MxL5007_TunerConfigS* , BOOL* isLock); |
|
25480 + |
|
25481 +//#endif //__MxL5007_API_H |
|
25482 + |
|
25483 + |
|
25484 + |
|
25485 + |
|
25486 + |
|
25487 + |
|
25488 + |
|
25489 + |
|
25490 + |
|
25491 + |
|
25492 + |
|
25493 + |
|
25494 + |
|
25495 + |
|
25496 + |
|
25497 + |
|
25498 + |
|
25499 + |
|
25500 + |
|
25501 + |
|
25502 + |
|
25503 + |
|
25504 + |
|
25505 +// The following context is MxL5007T tuner API source code |
|
25506 + |
|
25507 + |
|
25508 + |
|
25509 + |
|
25510 + |
|
25511 +// Definitions |
|
25512 + |
|
25513 +// Standard mode |
|
25514 +enum MXL5007T_STANDARD_MODE |
|
25515 +{ |
|
25516 + MXL5007T_STANDARD_DVBT, |
|
25517 + MXL5007T_STANDARD_ATSC, |
|
25518 + MXL5007T_STANDARD_QAM, |
|
25519 + MXL5007T_STANDARD_ISDBT, |
|
25520 +}; |
|
25521 + |
|
25522 + |
|
25523 +// Clock output mode |
|
25524 +enum MXL5007T_CLK_OUT_MODE |
|
25525 +{ |
|
25526 + MXL5007T_CLK_OUT_DISABLE, |
|
25527 + MXL5007T_CLK_OUT_ENABLE, |
|
25528 +}; |
|
25529 + |
|
25530 + |
|
25531 +// Clock output amplitude mode |
|
25532 +enum MXL5007T_CLK_OUT_AMP_MODE |
|
25533 +{ |
|
25534 + MXL5007T_CLK_OUT_AMP_0, |
|
25535 + MXL5007T_CLK_OUT_AMP_1, |
|
25536 + MXL5007T_CLK_OUT_AMP_2, |
|
25537 + MXL5007T_CLK_OUT_AMP_3, |
|
25538 + MXL5007T_CLK_OUT_AMP_4, |
|
25539 + MXL5007T_CLK_OUT_AMP_5, |
|
25540 + MXL5007T_CLK_OUT_AMP_6, |
|
25541 + MXL5007T_CLK_OUT_AMP_7, |
|
25542 +}; |
|
25543 + |
|
25544 + |
|
25545 +// Bandwidth mode |
|
25546 +enum MXL5007T_BANDWIDTH_MODE |
|
25547 +{ |
|
25548 + MXL5007T_BANDWIDTH_6000000HZ, |
|
25549 + MXL5007T_BANDWIDTH_7000000HZ, |
|
25550 + MXL5007T_BANDWIDTH_8000000HZ, |
|
25551 +}; |
|
25552 + |
|
25553 + |
|
25554 + |
|
25555 +// Constant |
|
25556 +#define MXL5007T_I2C_READING_CONST 0xfb |
|
25557 + |
|
25558 +// Default value |
|
25559 +#define MXL5007T_RF_FREQ_HZ_DEFAULT 44000000; |
|
25560 +#define MXL5007T_BANDWIDTH_MODE_DEFAULT MxL_BW_6MHz; |
|
25561 + |
|
25562 + |
|
25563 + |
|
25564 + |
|
25565 + |
|
25566 +// MxL5007T extra module |
|
25567 +typedef struct MXL5007T_EXTRA_MODULE_TAG MXL5007T_EXTRA_MODULE; |
|
25568 + |
|
25569 + |
|
25570 + |
|
25571 + |
|
25572 + |
|
25573 +// MxL5007T bandwidth mode setting function pointer |
|
25574 +typedef int |
|
25575 +(*MXL5007T_FP_SET_BANDWIDTH_MODE)( |
|
25576 + TUNER_MODULE *pTuner, |
|
25577 + int BandwidthMode |
|
25578 + ); |
|
25579 + |
|
25580 + |
|
25581 + |
|
25582 +// MxL5007T bandwidth mode getting function pointer |
|
25583 +typedef int |
|
25584 +(*MXL5007T_FP_GET_BANDWIDTH_MODE)( |
|
25585 + TUNER_MODULE *pTuner, |
|
25586 + int *pBandwidthMode |
|
25587 + ); |
|
25588 + |
|
25589 + |
|
25590 + |
|
25591 + |
|
25592 + |
|
25593 +// MxL5007T extra module |
|
25594 +struct MXL5007T_EXTRA_MODULE_TAG |
|
25595 +{ |
|
25596 + // MxL5007T extra variables |
|
25597 + int BandwidthMode; |
|
25598 + int IsBandwidthModeSet; |
|
25599 + |
|
25600 + // MxL5007T MaxLinear-defined structure |
|
25601 + MxL5007_TunerConfigS *pTunerConfigS; |
|
25602 + MxL5007_TunerConfigS TunerConfigSMemory; |
|
25603 + |
|
25604 + // MxL5007T extra function pointers |
|
25605 + MXL5007T_FP_SET_BANDWIDTH_MODE SetBandwidthMode; |
|
25606 + MXL5007T_FP_GET_BANDWIDTH_MODE GetBandwidthMode; |
|
25607 +}; |
|
25608 + |
|
25609 + |
|
25610 + |
|
25611 + |
|
25612 + |
|
25613 +// Builder |
|
25614 +void |
|
25615 +BuildMxl5007tModule( |
|
25616 + TUNER_MODULE **ppTuner, |
|
25617 + TUNER_MODULE *pTunerModuleMemory, |
|
25618 + MXL5007T_EXTRA_MODULE *pMxl5007tExtraModuleMemory, |
|
25619 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
25620 + I2C_BRIDGE_MODULE *pI2cBridgeModuleMemory, |
|
25621 + unsigned char DeviceAddr, |
|
25622 + unsigned long CrystalFreqHz, |
|
25623 + int StandardMode, |
|
25624 + unsigned long IfFreqHz, |
|
25625 + int SpectrumMode, |
|
25626 + int ClkOutMode, |
|
25627 + int ClkOutAmpMode, |
|
25628 + long QamIfDiffOutLevel |
|
25629 + ); |
|
25630 + |
|
25631 + |
|
25632 + |
|
25633 + |
|
25634 + |
|
25635 +// Manipulaing functions |
|
25636 +void |
|
25637 +mxl5007t_GetTunerType( |
|
25638 + TUNER_MODULE *pTuner, |
|
25639 + int *pTunerType |
|
25640 + ); |
|
25641 + |
|
25642 +void |
|
25643 +mxl5007t_GetDeviceAddr( |
|
25644 + TUNER_MODULE *pTuner, |
|
25645 + unsigned char *pDeviceAddr |
|
25646 + ); |
|
25647 + |
|
25648 +int |
|
25649 +mxl5007t_Initialize( |
|
25650 + TUNER_MODULE *pTuner |
|
25651 + ); |
|
25652 + |
|
25653 +int |
|
25654 +mxl5007t_SetRfFreqHz( |
|
25655 + TUNER_MODULE *pTuner, |
|
25656 + unsigned long RfFreqHz |
|
25657 + ); |
|
25658 + |
|
25659 +int |
|
25660 +mxl5007t_GetRfFreqHz( |
|
25661 + TUNER_MODULE *pTuner, |
|
25662 + unsigned long *pRfFreqHz |
|
25663 + ); |
|
25664 + |
|
25665 + |
|
25666 + |
|
25667 + |
|
25668 + |
|
25669 +// Extra manipulaing functions |
|
25670 +int |
|
25671 +mxl5007t_SetBandwidthMode( |
|
25672 + TUNER_MODULE *pTuner, |
|
25673 + int BandwidthMode |
|
25674 + ); |
|
25675 + |
|
25676 +int |
|
25677 +mxl5007t_GetBandwidthMode( |
|
25678 + TUNER_MODULE *pTuner, |
|
25679 + int *pBandwidthMode |
|
25680 + ); |
|
25681 + |
|
25682 + |
|
25683 + |
|
25684 + |
|
25685 + |
|
25686 +// I2C birdge module demod argument setting |
|
25687 +void |
|
25688 +mxl5007t_SetI2cBridgeModuleTunerArg( |
|
25689 + TUNER_MODULE *pTuner |
|
25690 + ); |
|
25691 + |
|
25692 + |
|
25693 + |
|
25694 + |
|
25695 + |
|
25696 + |
|
25697 + |
|
25698 + |
|
25699 + |
|
25700 + |
|
25701 + |
|
25702 + |
|
25703 + |
|
25704 +#endif |
|
25705 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/tuner_tua9001.c |
|
25706 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
25707 +++ b/linux/drivers/media/dvb/dvb-usb/tuner_tua9001.c Wed Oct 27 09:16:44 2010 +0200 |
|
25708 @@ -0,0 +1,1252 @@ |
|
25709 +/** |
|
25710 + |
|
25711 +@file |
|
25712 + |
|
25713 +@brief TUA9001 tuner module definition |
|
25714 + |
|
25715 +One can manipulate TUA9001 tuner through TUA9001 module. |
|
25716 +TUA9001 module is derived from tuner module. |
|
25717 + |
|
25718 +*/ |
|
25719 + |
|
25720 + |
|
25721 +#include "tuner_tua9001.h" |
|
25722 + |
|
25723 + |
|
25724 + |
|
25725 + |
|
25726 + |
|
25727 +/** |
|
25728 + |
|
25729 +@brief TUA9001 tuner module builder |
|
25730 + |
|
25731 +Use BuildTua9001Module() to build TUA9001 module, set all module function pointers with the corresponding functions, |
|
25732 +and initialize module private variables. |
|
25733 + |
|
25734 + |
|
25735 +@param [in] ppTuner Pointer to TUA9001 tuner module pointer |
|
25736 +@param [in] pTunerModuleMemory Pointer to an allocated tuner module memory |
|
25737 +@param [in] pTua9001ExtraModuleMemory Pointer to an allocated TUA9001 extra module memory |
|
25738 +@param [in] pBaseInterfaceModuleMemory Pointer to an allocated base interface module memory |
|
25739 +@param [in] pI2cBridgeModuleMemory Pointer to an allocated I2C bridge module memory |
|
25740 +@param [in] DeviceAddr TUA9001 I2C device address |
|
25741 + |
|
25742 + |
|
25743 +@note |
|
25744 + -# One should call BuildTua9001Module() to build TUA9001 module before using it. |
|
25745 + |
|
25746 +*/ |
|
25747 +void |
|
25748 +BuildTua9001Module( |
|
25749 + TUNER_MODULE **ppTuner, |
|
25750 + TUNER_MODULE *pTunerModuleMemory, |
|
25751 + TUA9001_EXTRA_MODULE *pTua9001ExtraModuleMemory, |
|
25752 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
25753 + I2C_BRIDGE_MODULE *pI2cBridgeModuleMemory, |
|
25754 + unsigned char DeviceAddr |
|
25755 + ) |
|
25756 +{ |
|
25757 + TUNER_MODULE *pTuner; |
|
25758 + TUA9001_EXTRA_MODULE *pExtra; |
|
25759 + |
|
25760 + |
|
25761 + |
|
25762 + // Set tuner module pointer. |
|
25763 + *ppTuner = pTunerModuleMemory; |
|
25764 + |
|
25765 + // Get tuner module. |
|
25766 + pTuner = *ppTuner; |
|
25767 + |
|
25768 + // Set tuner extra module pointer, base interface module pointer, and I2C bridge module pointer. |
|
25769 + pTuner->pExtra = pTua9001ExtraModuleMemory; |
|
25770 + pTuner->pBaseInterface = pBaseInterfaceModuleMemory; |
|
25771 + pTuner->pI2cBridge = pI2cBridgeModuleMemory; |
|
25772 + |
|
25773 + // Get tuner extra module. |
|
25774 + pExtra = (TUA9001_EXTRA_MODULE *)pTuner->pExtra; |
|
25775 + |
|
25776 + |
|
25777 + |
|
25778 + // Set tuner type. |
|
25779 + pTuner->TunerType = TUNER_TYPE_TUA9001; |
|
25780 + |
|
25781 + // Set tuner I2C device address. |
|
25782 + pTuner->DeviceAddr = DeviceAddr; |
|
25783 + |
|
25784 + |
|
25785 + // Initialize tuner parameter setting status. |
|
25786 + pTuner->IsRfFreqHzSet = NO; |
|
25787 + |
|
25788 + // Initialize tuner module variables. |
|
25789 + // Note: Need to give both RF frequency and bandwidth for TUA9001 tuning function, |
|
25790 + // so we have to give a default RF frequncy. |
|
25791 + pTuner->RfFreqHz = TUA9001_RF_FREQ_HZ_DEFAULT; |
|
25792 + |
|
25793 + |
|
25794 + // Set I2C bridge tuner arguments. |
|
25795 + tua9001_SetI2cBridgeModuleTunerArg(pTuner); |
|
25796 + |
|
25797 + |
|
25798 + // Set tuner module manipulating function pointers. |
|
25799 + pTuner->GetTunerType = tua9001_GetTunerType; |
|
25800 + pTuner->GetDeviceAddr = tua9001_GetDeviceAddr; |
|
25801 + |
|
25802 + pTuner->Initialize = tua9001_Initialize; |
|
25803 + pTuner->SetRfFreqHz = tua9001_SetRfFreqHz; |
|
25804 + pTuner->GetRfFreqHz = tua9001_GetRfFreqHz; |
|
25805 + |
|
25806 + |
|
25807 + // Initialize tuner extra module variables. |
|
25808 + // Note: Need to give both RF frequency and bandwidth for TUA9001 tuning function, |
|
25809 + // so we have to give a default bandwidth. |
|
25810 + pExtra->BandwidthMode = TUA9001_BANDWIDTH_MODE_DEFAULT; |
|
25811 + pExtra->IsBandwidthModeSet = NO; |
|
25812 + |
|
25813 + // Set tuner extra module function pointers. |
|
25814 + pExtra->SetBandwidthMode = tua9001_SetBandwidthMode; |
|
25815 + pExtra->GetBandwidthMode = tua9001_GetBandwidthMode; |
|
25816 + pExtra->GetRegBytesWithRegAddr = tua9001_GetRegBytesWithRegAddr; |
|
25817 + pExtra->SetSysRegByte = tua9001_SetSysRegByte; |
|
25818 + pExtra->GetSysRegByte = tua9001_GetSysRegByte; |
|
25819 + |
|
25820 + |
|
25821 + return; |
|
25822 +} |
|
25823 + |
|
25824 + |
|
25825 + |
|
25826 + |
|
25827 + |
|
25828 +/** |
|
25829 + |
|
25830 +@see TUNER_FP_GET_TUNER_TYPE |
|
25831 + |
|
25832 +*/ |
|
25833 +void |
|
25834 +tua9001_GetTunerType( |
|
25835 + TUNER_MODULE *pTuner, |
|
25836 + int *pTunerType |
|
25837 + ) |
|
25838 +{ |
|
25839 + // Get tuner type from tuner module. |
|
25840 + *pTunerType = pTuner->TunerType; |
|
25841 + |
|
25842 + |
|
25843 + return; |
|
25844 +} |
|
25845 + |
|
25846 + |
|
25847 + |
|
25848 + |
|
25849 + |
|
25850 +/** |
|
25851 + |
|
25852 +@see TUNER_FP_GET_DEVICE_ADDR |
|
25853 + |
|
25854 +*/ |
|
25855 +void |
|
25856 +tua9001_GetDeviceAddr( |
|
25857 + TUNER_MODULE *pTuner, |
|
25858 + unsigned char *pDeviceAddr |
|
25859 + ) |
|
25860 +{ |
|
25861 + // Get tuner I2C device address from tuner module. |
|
25862 + *pDeviceAddr = pTuner->DeviceAddr; |
|
25863 + |
|
25864 + |
|
25865 + return; |
|
25866 +} |
|
25867 + |
|
25868 + |
|
25869 + |
|
25870 + |
|
25871 + |
|
25872 +/** |
|
25873 + |
|
25874 +@see TUNER_FP_INITIALIZE |
|
25875 + |
|
25876 +*/ |
|
25877 +int |
|
25878 +tua9001_Initialize( |
|
25879 + TUNER_MODULE *pTuner |
|
25880 + ) |
|
25881 +{ |
|
25882 + TUA9001_EXTRA_MODULE *pExtra; |
|
25883 + |
|
25884 + |
|
25885 + |
|
25886 + // Get tuner extra module. |
|
25887 + pExtra = (TUA9001_EXTRA_MODULE *)pTuner->pExtra; |
|
25888 + |
|
25889 + // Initialize TUA9001 tuner. |
|
25890 + if(initializeTua9001(pTuner) != TUNER_OK) |
|
25891 + goto error_status_initialize_tuner; |
|
25892 + |
|
25893 + |
|
25894 + return FUNCTION_SUCCESS; |
|
25895 + |
|
25896 + |
|
25897 +error_status_initialize_tuner: |
|
25898 + return FUNCTION_ERROR; |
|
25899 +} |
|
25900 + |
|
25901 + |
|
25902 + |
|
25903 + |
|
25904 + |
|
25905 +/** |
|
25906 + |
|
25907 +@see TUNER_FP_SET_RF_FREQ_HZ |
|
25908 + |
|
25909 +*/ |
|
25910 +int |
|
25911 +tua9001_SetRfFreqHz( |
|
25912 + TUNER_MODULE *pTuner, |
|
25913 + unsigned long RfFreqHz |
|
25914 + ) |
|
25915 +{ |
|
25916 + TUA9001_EXTRA_MODULE *pExtra; |
|
25917 + |
|
25918 + long RfFreqKhz; |
|
25919 + int BandwidthMode; |
|
25920 + |
|
25921 + |
|
25922 + |
|
25923 + // Get tuner extra module. |
|
25924 + pExtra = (TUA9001_EXTRA_MODULE *)pTuner->pExtra; |
|
25925 + |
|
25926 + // Get bandwidth mode. |
|
25927 + BandwidthMode = pExtra->BandwidthMode; |
|
25928 + |
|
25929 + // Calculate RF frequency in KHz. |
|
25930 + // Note: RfFreqKhz = round(RfFreqHz / 1000) |
|
25931 + RfFreqKhz = (long)((RfFreqHz + 500) / 1000); |
|
25932 + |
|
25933 + // Set TUA9001 RF frequency and bandwidth. |
|
25934 + if(tuneTua9001(pTuner, RfFreqKhz, BandwidthMode) != TUNER_OK) |
|
25935 + goto error_status_set_tuner_rf_frequency; |
|
25936 + |
|
25937 + |
|
25938 + // Set tuner RF frequency parameter. |
|
25939 + pTuner->RfFreqHz = (unsigned long)(RfFreqKhz * 1000); |
|
25940 + pTuner->IsRfFreqHzSet = YES; |
|
25941 + |
|
25942 + |
|
25943 + return FUNCTION_SUCCESS; |
|
25944 + |
|
25945 + |
|
25946 +error_status_set_tuner_rf_frequency: |
|
25947 + return FUNCTION_ERROR; |
|
25948 +} |
|
25949 + |
|
25950 + |
|
25951 + |
|
25952 + |
|
25953 + |
|
25954 +/** |
|
25955 + |
|
25956 +@see TUNER_FP_GET_RF_FREQ_HZ |
|
25957 + |
|
25958 +*/ |
|
25959 +int |
|
25960 +tua9001_GetRfFreqHz( |
|
25961 + TUNER_MODULE *pTuner, |
|
25962 + unsigned long *pRfFreqHz |
|
25963 + ) |
|
25964 +{ |
|
25965 + // Get tuner RF frequency in Hz from tuner module. |
|
25966 + if(pTuner->IsRfFreqHzSet != YES) |
|
25967 + goto error_status_get_tuner_rf_frequency; |
|
25968 + |
|
25969 + *pRfFreqHz = pTuner->RfFreqHz; |
|
25970 + |
|
25971 + |
|
25972 + return FUNCTION_SUCCESS; |
|
25973 + |
|
25974 + |
|
25975 +error_status_get_tuner_rf_frequency: |
|
25976 + return FUNCTION_ERROR; |
|
25977 +} |
|
25978 + |
|
25979 + |
|
25980 + |
|
25981 + |
|
25982 + |
|
25983 +/** |
|
25984 + |
|
25985 +@brief Set TUA9001 tuner bandwidth mode. |
|
25986 + |
|
25987 +*/ |
|
25988 +int |
|
25989 +tua9001_SetBandwidthMode( |
|
25990 + TUNER_MODULE *pTuner, |
|
25991 + int BandwidthMode |
|
25992 + ) |
|
25993 +{ |
|
25994 + TUA9001_EXTRA_MODULE *pExtra; |
|
25995 + |
|
25996 + long RfFreqKhz; |
|
25997 + |
|
25998 + |
|
25999 + |
|
26000 + // Get tuner extra module. |
|
26001 + pExtra = (TUA9001_EXTRA_MODULE *)pTuner->pExtra; |
|
26002 + |
|
26003 + // Get RF frequncy in KHz. |
|
26004 + // Note: Doesn't need to take round() of RfFreqHz, because its value unit is 1000 Hz. |
|
26005 + RfFreqKhz = (long)(pTuner->RfFreqHz / 1000); |
|
26006 + |
|
26007 + // Set TUA9001 RF frequency and bandwidth. |
|
26008 + if(tuneTua9001(pTuner, RfFreqKhz, BandwidthMode) != TUNER_OK) |
|
26009 + goto error_status_set_tuner_bandwidth; |
|
26010 + |
|
26011 + |
|
26012 + // Set tuner bandwidth parameter. |
|
26013 + pExtra->BandwidthMode = BandwidthMode; |
|
26014 + pExtra->IsBandwidthModeSet = YES; |
|
26015 + |
|
26016 + |
|
26017 + return FUNCTION_SUCCESS; |
|
26018 + |
|
26019 + |
|
26020 +error_status_set_tuner_bandwidth: |
|
26021 + return FUNCTION_ERROR; |
|
26022 +} |
|
26023 + |
|
26024 + |
|
26025 + |
|
26026 + |
|
26027 + |
|
26028 +/** |
|
26029 + |
|
26030 +@brief Get TUA9001 tuner bandwidth mode. |
|
26031 + |
|
26032 +*/ |
|
26033 +int |
|
26034 +tua9001_GetBandwidthMode( |
|
26035 + TUNER_MODULE *pTuner, |
|
26036 + int *pBandwidthMode |
|
26037 + ) |
|
26038 +{ |
|
26039 + TUA9001_EXTRA_MODULE *pExtra; |
|
26040 + |
|
26041 + |
|
26042 + |
|
26043 + // Get tuner extra module. |
|
26044 + pExtra = (TUA9001_EXTRA_MODULE *)pTuner->pExtra; |
|
26045 + |
|
26046 + |
|
26047 + // Get tuner bandwidth in Hz from tuner module. |
|
26048 + if(pExtra->IsBandwidthModeSet != YES) |
|
26049 + goto error_status_get_tuner_bandwidth; |
|
26050 + |
|
26051 + *pBandwidthMode = pExtra->BandwidthMode; |
|
26052 + |
|
26053 + |
|
26054 + return FUNCTION_SUCCESS; |
|
26055 + |
|
26056 + |
|
26057 +error_status_get_tuner_bandwidth: |
|
26058 + return FUNCTION_ERROR; |
|
26059 +} |
|
26060 + |
|
26061 + |
|
26062 + |
|
26063 + |
|
26064 +//3 +BIg Lock in Upper Func to ON/OFF repeater |
|
26065 +/** |
|
26066 + |
|
26067 +@brief Get register bytes with address. |
|
26068 + |
|
26069 +*/ |
|
26070 +int |
|
26071 +tua9001_GetRegBytesWithRegAddr( |
|
26072 + TUNER_MODULE *pTuner, |
|
26073 + unsigned char DeviceAddr, |
|
26074 + unsigned char RegAddr, |
|
26075 + unsigned char *pReadingBytes, |
|
26076 + unsigned char ByteNum |
|
26077 + ) |
|
26078 +{ |
|
26079 + // Get tuner register byte. |
|
26080 +// if(rtl2832usb_ReadWithRegAddr(DeviceAddr, RegAddr, pReadingBytes, ByteNum) != FUNCTION_SUCCESS) |
|
26081 +// goto error_status_get_tuner_registers_with_address; |
|
26082 + |
|
26083 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
26084 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
26085 + |
|
26086 + unsigned char TunerDeviceAddr; |
|
26087 + |
|
26088 + struct dvb_usb_device *d; |
|
26089 + |
|
26090 + |
|
26091 + // Get I2C bridge. |
|
26092 + pI2cBridge = pTuner->pI2cBridge; |
|
26093 + pBaseInterface = pTuner->pBaseInterface; |
|
26094 + |
|
26095 + // Get tuner device address. |
|
26096 + TunerDeviceAddr = *pI2cBridge->pTunerDeviceAddr; |
|
26097 + |
|
26098 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); |
|
26099 + |
|
26100 + if( read_rtl2832_tuner_register( d, TunerDeviceAddr, RegAddr, pReadingBytes, ByteNum ) ) |
|
26101 + goto error_status_get_tuner_registers_with_address; |
|
26102 + |
|
26103 + return FUNCTION_SUCCESS; |
|
26104 + |
|
26105 + |
|
26106 +error_status_get_tuner_registers_with_address: |
|
26107 + return FUNCTION_ERROR; |
|
26108 +} |
|
26109 + |
|
26110 +//3 -BIg Lock in Upper Func to ON/OFF repeater |
|
26111 + |
|
26112 + |
|
26113 + |
|
26114 +/** |
|
26115 + |
|
26116 +@brief Set system register byte. |
|
26117 + |
|
26118 +*/ |
|
26119 +int |
|
26120 +tua9001_SetSysRegByte( |
|
26121 + TUNER_MODULE *pTuner, |
|
26122 + unsigned short RegAddr, |
|
26123 + unsigned char WritingByte |
|
26124 + ) |
|
26125 +{ |
|
26126 + // Set demod system register byte. |
|
26127 +// if(RTK_SYS_Byte_Write(RegAddr, LEN_1_BYTE, &WritingByte) != TRUE) |
|
26128 +// goto error_status_set_system_registers; |
|
26129 + |
|
26130 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
26131 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
26132 + |
|
26133 + struct dvb_usb_device *d; |
|
26134 + |
|
26135 + // Get I2C bridge. |
|
26136 + pI2cBridge = pTuner->pI2cBridge; |
|
26137 + pBaseInterface = pTuner->pBaseInterface; |
|
26138 + |
|
26139 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); |
|
26140 + |
|
26141 + if ( write_usb_sys_char_bytes( d, RTD2832U_SYS, RegAddr, &WritingByte, LEN_1_BYTE) ) |
|
26142 + goto error_status_set_system_registers; |
|
26143 + |
|
26144 + return FUNCTION_SUCCESS; |
|
26145 + |
|
26146 + |
|
26147 +error_status_set_system_registers: |
|
26148 + return FUNCTION_ERROR; |
|
26149 +} |
|
26150 + |
|
26151 + |
|
26152 + |
|
26153 + |
|
26154 + |
|
26155 +/** |
|
26156 + |
|
26157 +@brief Get system register byte. |
|
26158 + |
|
26159 +*/ |
|
26160 +int |
|
26161 +tua9001_GetSysRegByte( |
|
26162 + TUNER_MODULE *pTuner, |
|
26163 + unsigned short RegAddr, |
|
26164 + unsigned char *pReadingByte |
|
26165 + ) |
|
26166 +{ |
|
26167 + // Get demod system register byte. |
|
26168 +// if(RTK_SYS_Byte_Read(RegAddr, LEN_1_BYTE, pReadingByte) != TRUE) |
|
26169 +// goto error_status_get_system_registers; |
|
26170 + |
|
26171 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
26172 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
26173 + |
|
26174 + struct dvb_usb_device *d; |
|
26175 + |
|
26176 + // Get I2C bridge. |
|
26177 + pI2cBridge = pTuner->pI2cBridge; |
|
26178 + pBaseInterface = pTuner->pBaseInterface; |
|
26179 + |
|
26180 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); |
|
26181 + |
|
26182 + if ( read_usb_sys_char_bytes(d, RTD2832U_SYS, RegAddr, pReadingByte, LEN_1_BYTE) ) |
|
26183 + goto error_status_get_system_registers; |
|
26184 + |
|
26185 + return FUNCTION_SUCCESS; |
|
26186 + |
|
26187 + |
|
26188 +error_status_get_system_registers: |
|
26189 + return FUNCTION_ERROR; |
|
26190 +} |
|
26191 + |
|
26192 + |
|
26193 + |
|
26194 + |
|
26195 + |
|
26196 +/** |
|
26197 + |
|
26198 +@brief Set I2C bridge module tuner arguments. |
|
26199 + |
|
26200 +TUA9001 builder will use tua9001_SetI2cBridgeModuleTunerArg() to set I2C bridge module tuner arguments. |
|
26201 + |
|
26202 + |
|
26203 +@param [in] pTuner The tuner module pointer |
|
26204 + |
|
26205 + |
|
26206 +@see BuildTua9001Module() |
|
26207 + |
|
26208 +*/ |
|
26209 +void |
|
26210 +tua9001_SetI2cBridgeModuleTunerArg( |
|
26211 + TUNER_MODULE *pTuner |
|
26212 + ) |
|
26213 +{ |
|
26214 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
26215 + |
|
26216 + |
|
26217 + |
|
26218 + // Get I2C bridge module. |
|
26219 + pI2cBridge = pTuner->pI2cBridge; |
|
26220 + |
|
26221 + // Set I2C bridge module tuner arguments. |
|
26222 + pI2cBridge->pTunerDeviceAddr = &pTuner->DeviceAddr; |
|
26223 + |
|
26224 + |
|
26225 + return; |
|
26226 +} |
|
26227 + |
|
26228 + |
|
26229 + |
|
26230 + |
|
26231 + |
|
26232 +// TUA9001 custom-implement functions |
|
26233 + |
|
26234 + |
|
26235 +int setRESETN (TUNER_MODULE *pTuner, unsigned int i_state) |
|
26236 +{ |
|
26237 + TUA9001_EXTRA_MODULE *pExtra; |
|
26238 + unsigned char Byte; |
|
26239 + |
|
26240 + |
|
26241 + // Get tuner extra module. |
|
26242 + pExtra = (TUA9001_EXTRA_MODULE *)pTuner->pExtra; |
|
26243 + |
|
26244 + // Get GPO value. |
|
26245 + if(pExtra->GetSysRegByte(pTuner, GPO_ADDR, &Byte) != FUNCTION_SUCCESS) |
|
26246 + goto error_status_get_system_registers; |
|
26247 + |
|
26248 + // Note: Hardware PCB has inverter in this pin, should give inverted value on GPIO3. |
|
26249 + if (i_state == H_LEVEL) |
|
26250 + { |
|
26251 + /* set tuner RESETN pin to "H" */ |
|
26252 + // Note: The GPIO3 output value should be '0'. |
|
26253 + if( pTuner->b_set_tuner_power_gpio4 ) Byte &= ~BIT_4_MASK; |
|
26254 + else Byte &= ~BIT_3_MASK; |
|
26255 + } |
|
26256 + else |
|
26257 + { |
|
26258 + /* set tuner RESETN pin to "L" */ |
|
26259 + // Note: The GPIO3 output value should be '1'. |
|
26260 + if( pTuner->b_set_tuner_power_gpio4 ) Byte |= BIT_4_MASK; |
|
26261 + else Byte |= BIT_3_MASK; |
|
26262 + } |
|
26263 + |
|
26264 + // Set GPO value. |
|
26265 + if(pExtra->SetSysRegByte(pTuner, GPO_ADDR, Byte) != FUNCTION_SUCCESS) |
|
26266 + goto error_status_set_system_registers; |
|
26267 + |
|
26268 + |
|
26269 + return TUNER_OK; |
|
26270 + |
|
26271 + |
|
26272 +error_status_set_system_registers: |
|
26273 +error_status_get_system_registers: |
|
26274 + return TUNER_ERR; |
|
26275 +} |
|
26276 + |
|
26277 + |
|
26278 + |
|
26279 +int setRXEN (TUNER_MODULE *pTuner, unsigned int i_state) |
|
26280 +{ |
|
26281 + TUA9001_EXTRA_MODULE *pExtra; |
|
26282 + unsigned char Byte; |
|
26283 + |
|
26284 + |
|
26285 + // Get tuner extra module. |
|
26286 + pExtra = (TUA9001_EXTRA_MODULE *)pTuner->pExtra; |
|
26287 + |
|
26288 + // Get GPO value. |
|
26289 + if(pExtra->GetSysRegByte(pTuner, GPO_ADDR, &Byte) != FUNCTION_SUCCESS) |
|
26290 + goto error_status_get_system_registers; |
|
26291 + |
|
26292 + if (i_state == H_LEVEL) |
|
26293 + { |
|
26294 + /* set tuner RXEN pin to "H" */ |
|
26295 + // Note: The GPIO1 output value should be '1'. |
|
26296 + Byte |= BIT_1_MASK; |
|
26297 + } |
|
26298 + else |
|
26299 + { |
|
26300 + /* set tuner RXEN pin to "L" */ |
|
26301 + // Note: The GPIO1 output value should be '0'. |
|
26302 + Byte &= ~BIT_1_MASK; |
|
26303 + } |
|
26304 + |
|
26305 + // Set GPO value. |
|
26306 + if(pExtra->SetSysRegByte(pTuner, GPO_ADDR, Byte) != FUNCTION_SUCCESS) |
|
26307 + goto error_status_set_system_registers; |
|
26308 + |
|
26309 + |
|
26310 + return TUNER_OK; |
|
26311 + |
|
26312 + |
|
26313 +error_status_set_system_registers: |
|
26314 +error_status_get_system_registers: |
|
26315 + return TUNER_ERR; |
|
26316 +} |
|
26317 + |
|
26318 + |
|
26319 + |
|
26320 +int setCEN (TUNER_MODULE *pTuner, unsigned int i_state) |
|
26321 +{ |
|
26322 + // Do nothing. |
|
26323 + // Note: Hardware PCB always gives 'H' to tuner CEN pin. |
|
26324 + return TUNER_OK; |
|
26325 +} |
|
26326 + |
|
26327 + |
|
26328 + |
|
26329 +int waitloop (TUNER_MODULE *pTuner, unsigned int i_looptime) |
|
26330 +{ |
|
26331 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
26332 + unsigned long WaitTimeMs; |
|
26333 + |
|
26334 + |
|
26335 + // Get base interface. |
|
26336 + pBaseInterface = pTuner->pBaseInterface; |
|
26337 + |
|
26338 + /* wait time = i_looptime * 1 uS */ |
|
26339 + // Note: 1. The unit of WaitMs() function is ms. |
|
26340 + // 2. WaitTimeMs = ceil(i_looptime / 1000) |
|
26341 + WaitTimeMs = i_looptime / 1000; |
|
26342 + |
|
26343 + if((i_looptime % 1000) > 0) |
|
26344 + WaitTimeMs += 1; |
|
26345 + |
|
26346 + pBaseInterface->WaitMs(pBaseInterface, WaitTimeMs); |
|
26347 + |
|
26348 + |
|
26349 + return TUNER_OK; |
|
26350 +} |
|
26351 + |
|
26352 + |
|
26353 + |
|
26354 +int i2cBusWrite (TUNER_MODULE *pTuner, unsigned char deviceAddress, unsigned char registerAddress, char *data, |
|
26355 + unsigned int length) |
|
26356 +{ |
|
26357 + BASE_INTERFACE_MODULE *pBaseInterface; |
|
26358 + |
|
26359 + unsigned char ByteNum; |
|
26360 + unsigned char WritingBytes[I2C_BUFFER_LEN]; |
|
26361 + unsigned int i; |
|
26362 + |
|
26363 + I2C_BRIDGE_MODULE *pI2cBridge; |
|
26364 + unsigned char TunerDeviceAddr; |
|
26365 + struct dvb_usb_device *d; |
|
26366 + |
|
26367 + // Get base interface. |
|
26368 + pBaseInterface = pTuner->pBaseInterface; |
|
26369 + |
|
26370 + // Get I2C bridge. |
|
26371 + pI2cBridge = pTuner->pI2cBridge; |
|
26372 + |
|
26373 + // Get tuner device address. |
|
26374 + TunerDeviceAddr = *pI2cBridge->pTunerDeviceAddr; |
|
26375 + |
|
26376 + pBaseInterface->GetUserDefinedDataPointer(pBaseInterface, (void **)&d); |
|
26377 + |
|
26378 + |
|
26379 + /* I2C write data format */ |
|
26380 + /* STA device_address ACK register_address ACK H_Byte-Data ACK L_Byte-Data !ACK STO */ |
|
26381 + |
|
26382 + /* STA = start condition, ACK = Acknowledge, STO = stop condition */ |
|
26383 + /* *data = pointer to data source */ |
|
26384 + /* length = number of bytes to write */ |
|
26385 + |
|
26386 + // Determine byte number. |
|
26387 + //ByteNum = length + LEN_1_BYTE; |
|
26388 + ByteNum = length; |
|
26389 + |
|
26390 + // Determine writing bytes. |
|
26391 + //WritingBytes[0] = registerAddress; |
|
26392 + |
|
26393 + for(i = 0; i < length; i++) |
|
26394 + //WritingBytes[LEN_1_BYTE + i] = data[i]; |
|
26395 + WritingBytes[i] = data[i]; |
|
26396 + |
|
26397 + // Send I2C writing command. |
|
26398 +// if(pBaseInterface->I2cWrite(pBaseInterface, deviceAddress, WritingBytes, ByteNum) != FUNCTION_SUCCESS) |
|
26399 +// goto error_status_set_tuner_registers; |
|
26400 + |
|
26401 + |
|
26402 + if( write_rtl2832_tuner_register( d, TunerDeviceAddr, registerAddress, WritingBytes, ByteNum ) ) |
|
26403 + goto error_status_set_tuner_registers; |
|
26404 + |
|
26405 + |
|
26406 + return TUNER_OK; |
|
26407 + |
|
26408 + |
|
26409 +error_status_set_tuner_registers: |
|
26410 + return TUNER_ERR; |
|
26411 +} |
|
26412 + |
|
26413 + |
|
26414 + |
|
26415 +int i2cBusRead (TUNER_MODULE *pTuner, unsigned char deviceAddress, unsigned char registerAddress, char *data, |
|
26416 + unsigned int length) |
|
26417 +{ |
|
26418 + TUA9001_EXTRA_MODULE *pExtra; |
|
26419 + |
|
26420 + |
|
26421 + // Get tuner extra module. |
|
26422 + pExtra = (TUA9001_EXTRA_MODULE *)pTuner->pExtra; |
|
26423 + |
|
26424 + |
|
26425 + /* I2C read data format */ |
|
26426 + /* STA device_address ACK register_address ACK STA H_Byte-Data ACK device_address_read ACK H_Byte-Data ACK L_Byte-Data ACKH STO */ |
|
26427 + |
|
26428 + /* STA = start condition, ACK = Acknowledge (generated by TUA9001), ACKH = Acknowledge (generated by Host), STO = stop condition */ |
|
26429 + /* *data = pointer to data destination */ |
|
26430 + /* length = number of bytes to read */ |
|
26431 + |
|
26432 + // Get tuner register bytes with address. |
|
26433 + // Note: We must use re-start I2C reading format for TUA9001 tuner register reading. |
|
26434 + if(pExtra->GetRegBytesWithRegAddr(pTuner, deviceAddress, registerAddress, data, length) != FUNCTION_SUCCESS) |
|
26435 + goto error_status_get_tuner_registers; |
|
26436 + |
|
26437 + |
|
26438 + return TUNER_OK; |
|
26439 + |
|
26440 + |
|
26441 +error_status_get_tuner_registers: |
|
26442 + return TUNER_ERR; |
|
26443 +} |
|
26444 + |
|
26445 + |
|
26446 + |
|
26447 + |
|
26448 + |
|
26449 + |
|
26450 + |
|
26451 + |
|
26452 + |
|
26453 + |
|
26454 + |
|
26455 + |
|
26456 + |
|
26457 + |
|
26458 + |
|
26459 + |
|
26460 + |
|
26461 + |
|
26462 + |
|
26463 + |
|
26464 + |
|
26465 + |
|
26466 + |
|
26467 +// The following context is source code provided by Infineon. |
|
26468 + |
|
26469 + |
|
26470 + |
|
26471 + |
|
26472 + |
|
26473 +// Infineon source code - driver_tua9001.c |
|
26474 + |
|
26475 + |
|
26476 +/* ============================================================================ |
|
26477 +** Copyright (C) 1997-2007 Infineon AG All rights reserved. |
|
26478 +** ============================================================================ |
|
26479 +** |
|
26480 +** ============================================================================ |
|
26481 +** Revision Information : |
|
26482 +** File name: driver_tua9001.c |
|
26483 +** Version: V 1.01 |
|
26484 +** Date: |
|
26485 +** |
|
26486 +** ============================================================================ |
|
26487 +** History: |
|
26488 +** |
|
26489 +** Date Author Comment |
|
26490 +** ---------------------------------------------------------------------------- |
|
26491 +** |
|
26492 +** 2007.11.06 Walter Pichler created. |
|
26493 +** 2008.04.08 Walter Pichler adaption to TUA 9001E |
|
26494 +** |
|
26495 +** ============================================================================ |
|
26496 +*/ |
|
26497 + |
|
26498 +/*============================================================================ |
|
26499 +Includes |
|
26500 +============================================================================*/ |
|
26501 + |
|
26502 +//#include "driver_tua9001.h" |
|
26503 +//#include "driver_tua9001_NeededFunctions.h" /* Note: This function have to be provided by the user */ |
|
26504 + |
|
26505 +/*============================================================================ |
|
26506 +Local compiler keeys ( usage depends on the application ) |
|
26507 +============================================================================*/ |
|
26508 + |
|
26509 +#define CRYSTAL_26_MHZ |
|
26510 +//#define CRYSTAL_19.2_MHZ |
|
26511 +//#define CRYSTAL_20.48_MHZ |
|
26512 + |
|
26513 +//#define AGC_BY_IIC |
|
26514 +//#define AGC_BY_AGC_BUS |
|
26515 +#define AGC_BY_EXT_PIN |
|
26516 + |
|
26517 + |
|
26518 +/*============================================================================ |
|
26519 +Named Constants Definitions ( usage depends on the application ) |
|
26520 +============================================================================*/ |
|
26521 + |
|
26522 +#define TUNERs_TUA9001_DEVADDR 0xC0 |
|
26523 + |
|
26524 +/* Note: The correct device address depends hardware settings. See Datasheet |
|
26525 + and User Manual for details. */ |
|
26526 + |
|
26527 +/*============================================================================ |
|
26528 +Local Named Constants Definitions |
|
26529 +============================================================================*/ |
|
26530 +#define OPERATIONAL_MODE 0x03 |
|
26531 +#define CHANNEL_BANDWITH 0x04 |
|
26532 +#define SW_CONTR_TIME_SLICING 0x05 |
|
26533 +#define BASEBAND_GAIN_CONTROL 0x06 |
|
26534 +#define MANUAL_BASEBAND_GAIN 0x0b |
|
26535 +#define REFERENCE_FREQUENCY 0x1d |
|
26536 +#define CHANNEL_WORD 0x1f |
|
26537 +#define CHANNEL_OFFSET 0x20 |
|
26538 +#define CHANNEL_FILTER_TRIMMING 0x2f |
|
26539 +#define OUTPUT_BUFFER 0x32 |
|
26540 +#define RF_AGC_CONFIG_A 0x36 |
|
26541 +#define RF_AGC_CONFIG_B 0x37 |
|
26542 +#define UHF_LNA_SELECT 0x39 |
|
26543 +#define LEVEL_DETECTOR 0x3a |
|
26544 +#define MIXER_CURRENT 0x3b |
|
26545 +#define PORT_CONTROL 0x3e |
|
26546 +#define CRYSTAL_TRIMMING 0x41 |
|
26547 +#define CHANNEL_FILTER_STATUS 0x60 |
|
26548 +#define SIG_STRENGHT_INDICATION 0x62 |
|
26549 +#define PLL_LOCK 0x69 |
|
26550 +#define RECEIVER_STATE 0x70 |
|
26551 +#define RF_INPUT 0x71 |
|
26552 +#define BASEBAND_GAIN 0x72 |
|
26553 +#define CHIP_IDENT_CODE 0x7e |
|
26554 +#define CHIP_REVISION 0x7f |
|
26555 + |
|
26556 +#define TUNERs_TUA9001_BW_8 0xcf |
|
26557 +#define TUNERs_TUA9001_BW_7 0x10 |
|
26558 +#define TUNERs_TUA9001_BW_6 0x20 |
|
26559 +#define TUNERs_TUA9001_BW_5 0x30 |
|
26560 + |
|
26561 + |
|
26562 + |
|
26563 + |
|
26564 +/*============================================================================ |
|
26565 + Types definition |
|
26566 +============================================================================*/ |
|
26567 + |
|
26568 + |
|
26569 + |
|
26570 + |
|
26571 +/*============================================================================ |
|
26572 + Public Functions |
|
26573 +============================================================================*/ |
|
26574 + |
|
26575 + |
|
26576 +/** |
|
26577 + * tuner initialisation |
|
26578 + * @retval TUNER_OK No error |
|
26579 + * @retval TUNER_ERR Error |
|
26580 +*/ |
|
26581 + |
|
26582 +int initializeTua9001 (TUNER_MODULE *pTuner) |
|
26583 +{ |
|
26584 + unsigned int counter; |
|
26585 + char i2cseq[2]; |
|
26586 + tunerReceiverState_t tunerState; |
|
26587 + unsigned char DeviceAddr; |
|
26588 + |
|
26589 + // Get tuner deviece address. |
|
26590 + pTuner->GetDeviceAddr(pTuner, &DeviceAddr); |
|
26591 + |
|
26592 + /* Note: CEN may also be hard wired in the application*/ |
|
26593 + if(setCEN (pTuner, H_LEVEL) != TUNER_OK) goto error_status; /* asserting Chip enable */ |
|
26594 + |
|
26595 + if(setRESETN (pTuner, L_LEVEL) != TUNER_OK) goto error_status; /* asserting RESET */ |
|
26596 + |
|
26597 + if(setRXEN (pTuner, L_LEVEL) != TUNER_OK) goto error_status; /* RXEN to low >> IDLE STATE */ |
|
26598 + |
|
26599 + /* Note: 20ms assumes that all external power supplies are settled. If not, add more time here */ |
|
26600 + waitloop (pTuner, 20); /* wait for 20 uS */ |
|
26601 + |
|
26602 + if(setRESETN (pTuner, H_LEVEL) != TUNER_OK) goto error_status; /* de-asserting RESET */ |
|
26603 + |
|
26604 + /* This is to wait for the Crystal Oscillator to settle .. wait until IDLE mode is reached */ |
|
26605 + counter = 6; |
|
26606 + do |
|
26607 + { |
|
26608 + counter --; |
|
26609 + waitloop (pTuner, 1000); /* wait for 1 mS */ |
|
26610 + if(getReceiverStateTua9001 (pTuner, &tunerState) != TUNER_OK) goto error_status; |
|
26611 + }while ((tunerState != IDLE) && (counter)); |
|
26612 + |
|
26613 + if (tunerState != IDLE) |
|
26614 + return TUNER_ERR; /* error >> break initialization */ |
|
26615 + |
|
26616 + /**** Overwrite default register value ****/ |
|
26617 + i2cseq[0] = 0x65; /* Waiting time before PLL cal. start */ |
|
26618 + i2cseq[1] = 0x12; |
|
26619 + if(i2cBusWrite (pTuner, DeviceAddr, 0x1e, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26620 + |
|
26621 + i2cseq[0] = 0xB8; /* VCO Varactor bias fine tuning */ |
|
26622 + i2cseq[1] = 0x88; |
|
26623 + if(i2cBusWrite (pTuner, DeviceAddr, 0x25, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26624 + |
|
26625 + i2cseq[0] = 0x54; /* LNA switching Threshold for UHF1/2 */ |
|
26626 + i2cseq[1] = 0x60; |
|
26627 + if(i2cBusWrite (pTuner, DeviceAddr, 0x39, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26628 + |
|
26629 + i2cseq[0] = 0x00; |
|
26630 + i2cseq[1] = 0xC0; |
|
26631 + if(i2cBusWrite (pTuner, DeviceAddr, 0x3b, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26632 + |
|
26633 + i2cseq[0] = 0xF0; /* LO- Path Set LDO output voltage */ |
|
26634 + i2cseq[1] = 0x00; |
|
26635 + if(i2cBusWrite (pTuner, DeviceAddr, 0x3a, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26636 + |
|
26637 + i2cseq[0] = 0x00; /* Set EXTAGC interval */ |
|
26638 + i2cseq[1] = 0x00; |
|
26639 + if(i2cBusWrite (pTuner, DeviceAddr, 0x08, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26640 + |
|
26641 + i2cseq[0] = 0x00; /* Set max. capacitive load */ |
|
26642 + i2cseq[1] = 0x30; |
|
26643 + if(i2cBusWrite (pTuner, DeviceAddr, 0x32, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26644 + |
|
26645 + |
|
26646 + /**** Set Crystal Reference Frequency an Trim value ****/ |
|
26647 +#if defined(CRYSTAL_26_MHZ) /* Frequency 26 MHz */ |
|
26648 + i2cseq[0] = 0x01; |
|
26649 + i2cseq[1] = 0xB0; |
|
26650 + if(i2cBusWrite (pTuner, DeviceAddr, 0x1d, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26651 + |
|
26652 + i2cseq[0] = 0x70; /* NDK 3225 series 26 MHz XTAL */ |
|
26653 + i2cseq[1] = 0x3a; |
|
26654 + if(i2cBusWrite (pTuner, DeviceAddr, 0x41, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26655 + i2cseq[0] = 0x1C; |
|
26656 + i2cseq[1] = 0x78; |
|
26657 + if(i2cBusWrite (pTuner, DeviceAddr, 0x40, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26658 + |
|
26659 +#elif defined(CRYSTAL_19.2_MHZ) /* Frequency 19.2 MHz */ |
|
26660 + i2cseq[0] = 0x01; |
|
26661 + i2cseq[1] = 0xA0; |
|
26662 + if(i2cBusWrite (pTuner, DeviceAddr, 0x1d, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26663 + /* Note: Insert optimised register values for 0x40 / 0x41 for used crystal */ |
|
26664 + /* contact application support for further information */ |
|
26665 +#elif defined(CRYSTAL_20.48_MHZ) /* Frequency 20,48 MHz */ |
|
26666 + i2cseq[0] = 0x01; |
|
26667 + i2cseq[1] = 0xA8; |
|
26668 + if(i2cBusWrite (pTuner, DeviceAddr, 0x1d, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26669 + /* Note: Insert optimised register values for 0x40 / 0x41 for used crystal */ |
|
26670 + /* contact application support for further information */ |
|
26671 +#endif |
|
26672 + |
|
26673 + |
|
26674 + |
|
26675 + /**** Set desired Analog Baseband AGC mode ****/ |
|
26676 +#if defined (AGC_BY_IIC) |
|
26677 + i2cseq[0] = 0x00; /* Bypass AGC controller >> IIC based AGC */ |
|
26678 + i2cseq[1] = 0x40; |
|
26679 + if(i2cBusWrite (pTuner, DeviceAddr, 0x06, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26680 +#elif defined(AGC_BY_AGC_BUS) |
|
26681 + i2cseq[0] = 0x00; /* Digital AGC bus */ |
|
26682 + i2cseq[1] = 0x00; /* 0,5 dB steps */ |
|
26683 + if(i2cBusWrite (pTuner, DeviceAddr, 0x06, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26684 +#elif defined(AGC_BY_EXT_PIN) |
|
26685 + i2cseq[0] = 0x40; /* Ext. AGC pin */ |
|
26686 + i2cseq[1] = 0x00; |
|
26687 + if(i2cBusWrite (pTuner, DeviceAddr, 0x06, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26688 +#endif |
|
26689 + |
|
26690 + |
|
26691 + /**** set desired RF AGC parameter *****/ |
|
26692 + i2cseq[0] = 0x1c; /* Set Wideband Detector Current (100 uA) */ |
|
26693 + i2cseq[1] = 0x00; |
|
26694 + if(i2cBusWrite (pTuner, DeviceAddr, 0x2c, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26695 + |
|
26696 + i2cseq[0] = 0xC0; /* Set RF AGC Threshold (-32.5dBm) */ |
|
26697 + i2cseq[1] = 0x13; |
|
26698 + if(i2cBusWrite (pTuner, DeviceAddr, 0x36, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26699 + |
|
26700 + i2cseq[0] = 0x6f; /* RF AGC Parameter */ |
|
26701 + i2cseq[1] = 0x18; |
|
26702 + if(i2cBusWrite (pTuner, DeviceAddr, 0x37, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26703 + |
|
26704 + i2cseq[0] = 0x00; /* aditional VCO settings */ |
|
26705 + i2cseq[1] = 0x08; |
|
26706 + if(i2cBusWrite (pTuner, DeviceAddr, 0x27, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26707 + |
|
26708 + i2cseq[0] = 0x00; /* aditional PLL settings */ |
|
26709 + i2cseq[1] = 0x01; |
|
26710 + if(i2cBusWrite (pTuner, DeviceAddr, 0x2a, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26711 + |
|
26712 + i2cseq[0] = 0x0a; /* VCM correction */ |
|
26713 + i2cseq[1] = 0x40; |
|
26714 + if(i2cBusWrite (pTuner, DeviceAddr, 0x34, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26715 + |
|
26716 + |
|
26717 + return TUNER_OK; |
|
26718 + |
|
26719 + |
|
26720 +error_status: |
|
26721 + return TUNER_ERR; |
|
26722 +} |
|
26723 + |
|
26724 + |
|
26725 + |
|
26726 +/** |
|
26727 + * tuner tune |
|
26728 + * @param i_freq tuning frequency |
|
26729 + * @param i_bandwidth channel bandwidth |
|
26730 + * @retval TUNER_OK No error |
|
26731 + * @retval TUNER_ERR Error |
|
26732 +*/ |
|
26733 + |
|
26734 +int tuneTua9001 (TUNER_MODULE *pTuner, long i_freq, tunerDriverBW_t i_bandwidth) |
|
26735 +{ |
|
26736 + char i2cseq[2]; |
|
26737 + unsigned int divider_factor; |
|
26738 + unsigned int ch_offset; |
|
26739 + unsigned int counter; |
|
26740 + unsigned int lo_path_settings; |
|
26741 + tunerReceiverState_t tunerState; |
|
26742 + unsigned char DeviceAddr; |
|
26743 + |
|
26744 + // Get tuner deviece address. |
|
26745 + pTuner->GetDeviceAddr(pTuner, &DeviceAddr); |
|
26746 + |
|
26747 + |
|
26748 + |
|
26749 + /* de-assert RXEN >> IDLE STATE */ |
|
26750 + if(setRXEN (pTuner, L_LEVEL) != TUNER_OK) goto error_status; |
|
26751 + |
|
26752 + |
|
26753 + /* calculate divider factor */ |
|
26754 + if (i_freq < 1000000) /* divider factor and channel offset for UHF/VHF III */ |
|
26755 + { |
|
26756 + ch_offset = 0x1C20; /* channel offset 150 MHz */ |
|
26757 + divider_factor = (unsigned int) (((i_freq - 150000) * 48) / 1000); |
|
26758 + lo_path_settings = 0xb6de; |
|
26759 + } |
|
26760 + |
|
26761 + else /* calculate divider factor for L-Band Frequencies */ |
|
26762 + { |
|
26763 + ch_offset = 0x5460; /* channel offset 450 MHz */ |
|
26764 + divider_factor = (unsigned int) (((i_freq - 450000) * 48) / 1000); |
|
26765 + lo_path_settings = 0xbede; |
|
26766 + } |
|
26767 + |
|
26768 + |
|
26769 + // Set LO Path |
|
26770 + i2cseq[0] = lo_path_settings >> 8; |
|
26771 + i2cseq[1] = lo_path_settings & 0xff; |
|
26772 + if(i2cBusWrite (pTuner, DeviceAddr, 0x2b, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26773 + |
|
26774 + // Set channel offset |
|
26775 + i2cseq [0] = ch_offset >> 8; |
|
26776 + i2cseq [1] = ch_offset & 0xff; |
|
26777 + if(i2cBusWrite (pTuner, DeviceAddr, 0x20, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26778 + |
|
26779 + // Set Frequency |
|
26780 + i2cseq [0] = divider_factor >> 8; |
|
26781 + i2cseq [1] = divider_factor & 0xff; |
|
26782 + if(i2cBusWrite (pTuner, DeviceAddr, 0x1f, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26783 + |
|
26784 + // Set bandwidth |
|
26785 + if(i2cBusRead (pTuner, DeviceAddr, 0x04, i2cseq, 2) != TUNER_OK) goto error_status; /* get current register value */ |
|
26786 + i2cseq [0] &= TUNERs_TUA9001_BW_8; |
|
26787 + |
|
26788 + switch (i_bandwidth) |
|
26789 + { |
|
26790 + case TUNER_BANDWIDTH_8MHZ: |
|
26791 + // Do nothing. |
|
26792 + break; |
|
26793 + case TUNER_BANDWIDTH_7MHZ: i2cseq [0] |= TUNERs_TUA9001_BW_7; |
|
26794 + break; |
|
26795 + case TUNER_BANDWIDTH_6MHZ: i2cseq [0] |= TUNERs_TUA9001_BW_6; |
|
26796 + break; |
|
26797 + case TUNER_BANDWIDTH_5MHZ: i2cseq [0] |= TUNERs_TUA9001_BW_5; |
|
26798 + break; |
|
26799 + default: |
|
26800 + goto error_status; |
|
26801 + break; |
|
26802 + } |
|
26803 + |
|
26804 + if(i2cBusWrite (pTuner, DeviceAddr, 0x04, i2cseq, 2) != TUNER_OK) goto error_status; |
|
26805 + |
|
26806 + /* assert RXEN >> RX STATE */ |
|
26807 + if(setRXEN (pTuner, H_LEVEL) != TUNER_OK) goto error_status; |
|
26808 + |
|
26809 + /* This is to wait for the RX state to settle .. wait until RX mode is reached */ |
|
26810 + counter = 3; |
|
26811 + do |
|
26812 + { |
|
26813 + counter --; |
|
26814 + waitloop (pTuner, 1000); /* wait for 1 mS */ |
|
26815 + if(getReceiverStateTua9001 (pTuner, &tunerState) != TUNER_OK) goto error_status; |
|
26816 + }while ((tunerState != RX) && (counter)); |
|
26817 + |
|
26818 + if (tunerState != RX) |
|
26819 + { |
|
26820 + if(setRXEN (pTuner, L_LEVEL) != TUNER_OK) goto error_status; /* d-assert RXEN >> IDLE STATE */ |
|
26821 + return TUNER_ERR; /* error >> tuning fail */ |
|
26822 + } |
|
26823 + |
|
26824 + return TUNER_OK; |
|
26825 + |
|
26826 + |
|
26827 +error_status: |
|
26828 + return TUNER_ERR; |
|
26829 +} |
|
26830 + |
|
26831 + |
|
26832 +/** |
|
26833 + * Get pll locked state |
|
26834 + * @param o_pll pll locked state |
|
26835 + * @retval TUNER_OK No error |
|
26836 + * @retval TUNER_ERR Error |
|
26837 +*/ |
|
26838 + |
|
26839 +int getPllLockedStateTua9001 (TUNER_MODULE *pTuner, tunerPllLocked_t *o_pll) |
|
26840 +{ |
|
26841 + char i2cseq[2]; |
|
26842 + unsigned char DeviceAddr; |
|
26843 + |
|
26844 + // Get tuner deviece address. |
|
26845 + pTuner->GetDeviceAddr(pTuner, &DeviceAddr); |
|
26846 + |
|
26847 + if(i2cBusRead (pTuner, DeviceAddr, 0x69, i2cseq, 2) != TUNER_OK) goto error_status; /* get current register value */ |
|
26848 + |
|
26849 + o_pll[0] = (i2cseq[1] & 0x08) ? PLL_LOCKED : PLL_NOT_LOCKED; |
|
26850 + |
|
26851 + return TUNER_OK; |
|
26852 + |
|
26853 + |
|
26854 +error_status: |
|
26855 + return TUNER_ERR; |
|
26856 +} |
|
26857 + |
|
26858 + |
|
26859 +/** |
|
26860 + * Get tuner state |
|
26861 + * @param o_tunerState tuner state |
|
26862 + * @retval TUNER_OK No error |
|
26863 + * @retval TUNER_ERR Error |
|
26864 +*/ |
|
26865 + |
|
26866 +int getReceiverStateTua9001 (TUNER_MODULE *pTuner, tunerReceiverState_t *o_tunerState) |
|
26867 +{ |
|
26868 + char i2cseq[2]; |
|
26869 + unsigned char DeviceAddr; |
|
26870 + |
|
26871 + // Get tuner deviece address. |
|
26872 + pTuner->GetDeviceAddr(pTuner, &DeviceAddr); |
|
26873 + |
|
26874 + if(i2cBusRead (pTuner, DeviceAddr, 0x70, i2cseq, 2) != TUNER_OK) goto error_status; /* get current register value */ |
|
26875 + |
|
26876 +// switch (i2cseq[1] & ~0x1f) |
|
26877 + // Note: Maybe the MSB byte is i2cseq[0] |
|
26878 + // The original code looks like the MSB byte is i2cseq[1] |
|
26879 + // Note: ~0x0f = 0xffffffe0, not 0xe0 --> i2cseq[0] & ~0x1f result is wrong. |
|
26880 + switch (i2cseq[0] & 0xe0) |
|
26881 + { |
|
26882 + case 0x80: o_tunerState [0] = IDLE; break; |
|
26883 + case 0x40: o_tunerState [0] = RX; break; |
|
26884 + case 0x20: o_tunerState [0] = STANDBY; |
|
26885 + } |
|
26886 + |
|
26887 + return TUNER_OK; |
|
26888 + |
|
26889 + |
|
26890 +error_status: |
|
26891 + return TUNER_ERR; |
|
26892 +} |
|
26893 + |
|
26894 + |
|
26895 +/** |
|
26896 + * Get active input |
|
26897 + * @param o_activeInput active input info |
|
26898 + * @retval TUNER_OK No error |
|
26899 + * @retval TUNER_ERR Error |
|
26900 +*/ |
|
26901 + |
|
26902 +int getActiveInputTua9001 (TUNER_MODULE *pTuner, tunerActiveInput_t *o_activeInput) |
|
26903 +{ |
|
26904 + char i2cseq[2]; |
|
26905 + unsigned char DeviceAddr; |
|
26906 + |
|
26907 + // Get tuner deviece address. |
|
26908 + pTuner->GetDeviceAddr(pTuner, &DeviceAddr); |
|
26909 + |
|
26910 + if(i2cBusRead (pTuner, DeviceAddr, 0x71, i2cseq, 2) != TUNER_OK) goto error_status; /* get current register value */ |
|
26911 + |
|
26912 +// switch (i2cseq[1] & ~0x0f) |
|
26913 + // Note: Maybe the MSB byte is i2cseq[0] |
|
26914 + // The original code looks like the MSB byte is i2cseq[1] |
|
26915 + // Note: ~0x0f = 0xfffffff0, not 0xf0 --> i2cseq[0] & ~0x0f result is wrong. |
|
26916 + switch (i2cseq[0] & 0xf0) |
|
26917 + { |
|
26918 + case 0x80: o_activeInput [0] = L_INPUT_ACTIVE; break; |
|
26919 + case 0x20: o_activeInput [0] = UHF_INPUT_ACTIVE; break; |
|
26920 + case 0x10: o_activeInput [0] = VHF_INPUT_ACTIVE; |
|
26921 + } |
|
26922 + |
|
26923 + return TUNER_OK; |
|
26924 + |
|
26925 + |
|
26926 +error_status: |
|
26927 + return TUNER_ERR; |
|
26928 +} |
|
26929 + |
|
26930 + |
|
26931 +/** |
|
26932 + * Get baseband gain value |
|
26933 + * @param o_basebandGain baseband gain value |
|
26934 + * @retval TUNER_OK No error |
|
26935 + * @retval TUNER_ERR Error |
|
26936 +*/ |
|
26937 + |
|
26938 +int getBasebandGainTua9001 (TUNER_MODULE *pTuner, char *o_basebandGain) |
|
26939 +{ |
|
26940 + char i2cseq[2]; |
|
26941 + unsigned char DeviceAddr; |
|
26942 + |
|
26943 + // Get tuner deviece address. |
|
26944 + pTuner->GetDeviceAddr(pTuner, &DeviceAddr); |
|
26945 + |
|
26946 + if(i2cBusRead (pTuner, DeviceAddr, 0x72, i2cseq, 2) != TUNER_OK) goto error_status; /* get current register value */ |
|
26947 +// o_basebandGain [0] = i2cseq [1]; |
|
26948 + // Note: Maybe the MSB byte is i2cseq[0] |
|
26949 + // The original code looks like the MSB byte is i2cseq[1] |
|
26950 + o_basebandGain [0] = i2cseq [0]; |
|
26951 + |
|
26952 + return TUNER_OK; |
|
26953 + |
|
26954 + |
|
26955 +error_status: |
|
26956 + return TUNER_ERR; |
|
26957 +} |
|
26958 + |
|
26959 + |
|
26960 + |
|
26961 diff -r abd3aac6644e linux/drivers/media/dvb/dvb-usb/tuner_tua9001.h |
|
26962 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
26963 +++ b/linux/drivers/media/dvb/dvb-usb/tuner_tua9001.h Wed Oct 27 09:16:44 2010 +0200 |
|
26964 @@ -0,0 +1,572 @@ |
|
26965 +#ifndef __TUNER_TUA9001_H |
|
26966 +#define __TUNER_TUA9001_H |
|
26967 + |
|
26968 +/** |
|
26969 + |
|
26970 +@file |
|
26971 + |
|
26972 +@brief TUA9001 tuner module declaration |
|
26973 + |
|
26974 +One can manipulate TUA9001 tuner through TUA9001 module. |
|
26975 +TUA9001 module is derived from tunerd module. |
|
26976 + |
|
26977 + |
|
26978 + |
|
26979 +@par Example: |
|
26980 +@code |
|
26981 + |
|
26982 +// The example is the same as the tuner example in tuner_base.h except the listed lines. |
|
26983 + |
|
26984 + |
|
26985 + |
|
26986 +#include "tuner_tua9001.h" |
|
26987 + |
|
26988 + |
|
26989 +... |
|
26990 + |
|
26991 + |
|
26992 + |
|
26993 +int main(void) |
|
26994 +{ |
|
26995 + TUNER_MODULE *pTuner; |
|
26996 + TUA9001_EXTRA_MODULE *pTunerExtra; |
|
26997 + |
|
26998 + TUNER_MODULE TunerModuleMemory; |
|
26999 + TUA9001_EXTRA_MODULE Tua9001ExtraModuleMemory; |
|
27000 + BASE_INTERFACE_MODULE BaseInterfaceModuleMemory; |
|
27001 + I2C_BRIDGE_MODULE I2cBridgeModuleMemory; |
|
27002 + |
|
27003 + int BandwidthMode; |
|
27004 + |
|
27005 + |
|
27006 + ... |
|
27007 + |
|
27008 + |
|
27009 + |
|
27010 + // Build TUA9001 tuner module. |
|
27011 + BuildTua9001Module( |
|
27012 + &pTuner, |
|
27013 + &TunerModuleMemory, |
|
27014 + &Tua9001ExtraModuleMemory, |
|
27015 + &BaseInterfaceModuleMemory, |
|
27016 + &I2cBridgeModuleMemory, |
|
27017 + 0xc0 // I2C device address is 0xc0 in 8-bit format. |
|
27018 + ); |
|
27019 + |
|
27020 + |
|
27021 + |
|
27022 + |
|
27023 + |
|
27024 + // Get TUA9001 tuner extra module. |
|
27025 + pTunerExtra = (T2266_EXTRA_MODULE *)(pTuner->pExtra); |
|
27026 + |
|
27027 + |
|
27028 + |
|
27029 + |
|
27030 + |
|
27031 + // ==== Initialize tuner and set its parameters ===== |
|
27032 + |
|
27033 + ... |
|
27034 + |
|
27035 + // Set TUA9001 bandwidth. |
|
27036 + pTunerExtra->SetBandwidthMode(pTuner, TUA9001_BANDWIDTH_6MHZ); |
|
27037 + |
|
27038 + |
|
27039 + |
|
27040 + |
|
27041 + |
|
27042 + // ==== Get tuner information ===== |
|
27043 + |
|
27044 + ... |
|
27045 + |
|
27046 + // Get TUA9001 bandwidth. |
|
27047 + pTunerExtra->GetBandwidthMode(pTuner, &BandwidthMode); |
|
27048 + |
|
27049 + |
|
27050 + |
|
27051 + |
|
27052 + |
|
27053 + // See the example for other tuner functions in tuner_base.h |
|
27054 + |
|
27055 + |
|
27056 + return 0; |
|
27057 +} |
|
27058 + |
|
27059 + |
|
27060 +@endcode |
|
27061 + |
|
27062 +*/ |
|
27063 + |
|
27064 + |
|
27065 +#include "tuner_base.h" |
|
27066 +//#include "i2c_rtl2832usb.h" |
|
27067 + |
|
27068 + |
|
27069 + |
|
27070 + |
|
27071 + |
|
27072 +// The following context is source code provided by Infineon. |
|
27073 + |
|
27074 + |
|
27075 + |
|
27076 + |
|
27077 + |
|
27078 +// Infineon source code - driver_tua9001.h |
|
27079 + |
|
27080 + |
|
27081 + |
|
27082 +/* ============================================================================ |
|
27083 +** Copyright (C) 1997-2007 Infineon AG All rights reserved. |
|
27084 +** ============================================================================ |
|
27085 +** |
|
27086 +** ============================================================================ |
|
27087 +** Revision Information : |
|
27088 +** File name: driver_tua9001.h |
|
27089 +** Version: |
|
27090 +** Date: |
|
27091 +** |
|
27092 +** ============================================================================ |
|
27093 +** History: |
|
27094 +** |
|
27095 +** Date Author Comment |
|
27096 +** ---------------------------------------------------------------------------- |
|
27097 +** |
|
27098 +** 2007.11.06 Walter Pichler created. |
|
27099 +** ============================================================================ |
|
27100 +*/ |
|
27101 + |
|
27102 + |
|
27103 +/*============================================================================ |
|
27104 + Named Constants Definitions |
|
27105 +============================================================================*/ |
|
27106 + |
|
27107 +#define TUNER_OK 0 |
|
27108 +#define TUNER_ERR 0xff |
|
27109 + |
|
27110 +#define H_LEVEL 1 |
|
27111 +#define L_LEVEL 0 |
|
27112 + |
|
27113 + |
|
27114 +/*============================================================================ |
|
27115 + Types definition |
|
27116 +============================================================================*/ |
|
27117 + |
|
27118 + |
|
27119 +typedef enum { |
|
27120 + TUNER_BANDWIDTH_8MHZ, |
|
27121 + TUNER_BANDWIDTH_7MHZ, |
|
27122 + TUNER_BANDWIDTH_6MHZ, |
|
27123 + TUNER_BANDWIDTH_5MHZ, |
|
27124 + } tunerDriverBW_t; |
|
27125 + |
|
27126 + |
|
27127 +typedef enum { |
|
27128 + PLL_LOCKED, |
|
27129 + PLL_NOT_LOCKED |
|
27130 + }tunerPllLocked_t; |
|
27131 + |
|
27132 + |
|
27133 +typedef enum { |
|
27134 + STANDBY, |
|
27135 + IDLE, |
|
27136 + RX |
|
27137 + } tunerReceiverState_t; |
|
27138 + |
|
27139 + |
|
27140 +typedef enum { |
|
27141 + L_INPUT_ACTIVE, |
|
27142 + UHF_INPUT_ACTIVE, |
|
27143 + VHF_INPUT_ACTIVE |
|
27144 + } tunerActiveInput_t; |
|
27145 + |
|
27146 + |
|
27147 + |
|
27148 +/*============================================================================ |
|
27149 + Public functions |
|
27150 +============================================================================*/ |
|
27151 + |
|
27152 +/** |
|
27153 + * tuner initialisation |
|
27154 + * @retval TUNER_OK No error |
|
27155 + * @retval TUNER_ERR Error |
|
27156 +*/ |
|
27157 +extern int initializeTua9001 (TUNER_MODULE *pTuner); |
|
27158 + |
|
27159 + |
|
27160 +/** |
|
27161 + * tuner tune |
|
27162 + * @param i_freq tuning frequency |
|
27163 + * @param i_bandwidth channel bandwidth |
|
27164 + * @retval TUNER_OK No error |
|
27165 + * @retval TUNER_ERR Error |
|
27166 +*/ |
|
27167 +extern int tuneTua9001 (TUNER_MODULE *pTuner, long i_freq, tunerDriverBW_t i_bandwidth); |
|
27168 + |
|
27169 + |
|
27170 +/** |
|
27171 + * Get tuner state |
|
27172 + * @param o_tunerState tuner state |
|
27173 + * @retval TUNER_OK No error |
|
27174 + * @retval TUNER_ERR Error |
|
27175 +*/ |
|
27176 +extern int getReceiverStateTua9001 (TUNER_MODULE *pTuner, tunerReceiverState_t *o_tunerState); |
|
27177 + |
|
27178 +/** |
|
27179 + * Get active input |
|
27180 + * @param o_activeInput active input info |
|
27181 + * @retval TUNER_OK No error |
|
27182 + * @retval TUNER_ERR Error |
|
27183 +*/ |
|
27184 +extern int getActiveInputTua9001 (TUNER_MODULE *pTuner, tunerActiveInput_t *o_activeInput); |
|
27185 + |
|
27186 + |
|
27187 +/** |
|
27188 + * Get baseband gain value |
|
27189 + * @param o_basebandGain baseband gain value |
|
27190 + * @retval TUNER_OK No error |
|
27191 + * @retval TUNER_ERR Error |
|
27192 +*/ |
|
27193 +extern int getBasebandGainTua9001 (TUNER_MODULE *pTuner, char *o_basebandGain); |
|
27194 + |
|
27195 + |
|
27196 + |
|
27197 + |
|
27198 + |
|
27199 + |
|
27200 + |
|
27201 + |
|
27202 + |
|
27203 + |
|
27204 + |
|
27205 + |
|
27206 + |
|
27207 + |
|
27208 + |
|
27209 + |
|
27210 + |
|
27211 + |
|
27212 + |
|
27213 + |
|
27214 + |
|
27215 + |
|
27216 + |
|
27217 +// Infineon source code - driver_tua9001_NeededFunctions.h |
|
27218 + |
|
27219 + |
|
27220 + |
|
27221 +/*======================================================================================================================== |
|
27222 + additional needed external funtions ( have to be provided by the user! ) |
|
27223 +========================================================================================================================*/ |
|
27224 + |
|
27225 +/** |
|
27226 + * set / reset tuner reset input |
|
27227 + * @param i_state level |
|
27228 + * @retval TUNER_OK No error |
|
27229 + * @retval TUNER_ERR Error |
|
27230 +*/ |
|
27231 + |
|
27232 +int setRESETN (TUNER_MODULE *pTuner, unsigned int i_state); |
|
27233 + |
|
27234 + |
|
27235 +/** |
|
27236 + * set / reset tuner receive enable input |
|
27237 + * @param i_state level |
|
27238 + * @retval TUNER_OK No error |
|
27239 + * @retval TUNER_ERR Error |
|
27240 +*/ |
|
27241 + |
|
27242 +int setRXEN (TUNER_MODULE *pTuner, unsigned int i_state); |
|
27243 + |
|
27244 + |
|
27245 +/** |
|
27246 + * set / reset tuner chiop enable input |
|
27247 + * @param i_state level |
|
27248 + * @retval TUNER_OK No error |
|
27249 + * @retval TUNER_ERR Error |
|
27250 +*/ |
|
27251 + |
|
27252 +int setCEN (TUNER_MODULE *pTuner, unsigned int i_state); |
|
27253 + |
|
27254 + |
|
27255 +/** |
|
27256 + * waitloop |
|
27257 + * @param i_looptime * 1uS |
|
27258 + * @retval TUNER_OK No error |
|
27259 + * @retval TUNER_ERR Error |
|
27260 +*/ |
|
27261 + |
|
27262 +int waitloop (TUNER_MODULE *pTuner, unsigned int i_looptime); |
|
27263 + |
|
27264 + |
|
27265 +/** |
|
27266 + * i2cBusWrite |
|
27267 + * @param deviceAdress chip address |
|
27268 + * @param registerAdress register address |
|
27269 + * @param *data pointer to data source |
|
27270 + * @param length number of bytes to transmit |
|
27271 + * @retval TUNER_OK No error |
|
27272 + * @retval TUNER_ERR Error |
|
27273 +*/ |
|
27274 + |
|
27275 + int i2cBusWrite (TUNER_MODULE *pTuner, unsigned char deviceAddress, unsigned char registerAddress, char *data, |
|
27276 + unsigned int length); |
|
27277 + |
|
27278 + |
|
27279 +/** |
|
27280 + * i2cBusRead |
|
27281 + * @param deviceAdress chip address |
|
27282 + * @param registerAdress register address |
|
27283 + * @param *data pointer to data destination |
|
27284 + * @param length number of bytes to read |
|
27285 + * @retval TUNER_OK No error |
|
27286 + * @retval TUNER_ERR Error |
|
27287 +*/ |
|
27288 + |
|
27289 + int i2cBusRead (TUNER_MODULE *pTuner, unsigned char deviceAddress, unsigned char registerAddress, char *data, |
|
27290 + unsigned int length); |
|
27291 + |
|
27292 +/*======================================================================================================================== |
|
27293 + end of additional needed external funtions |
|
27294 +========================================================================================================================*/ |
|
27295 + |
|
27296 + |
|
27297 + |
|
27298 + |
|
27299 + |
|
27300 + |
|
27301 + |
|
27302 + |
|
27303 + |
|
27304 + |
|
27305 + |
|
27306 + |
|
27307 + |
|
27308 + |
|
27309 + |
|
27310 + |
|
27311 + |
|
27312 + |
|
27313 + |
|
27314 + |
|
27315 + |
|
27316 + |
|
27317 + |
|
27318 +// The following context is TUA9001 tuner API source code |
|
27319 + |
|
27320 + |
|
27321 + |
|
27322 + |
|
27323 + |
|
27324 +/** |
|
27325 + |
|
27326 +@file |
|
27327 + |
|
27328 +@brief TUA9001 tuner module declaration |
|
27329 + |
|
27330 +One can manipulate TUA9001 tuner through TUA9001 module. |
|
27331 +TUA9001 module is derived from tuner module. |
|
27332 + |
|
27333 +*/ |
|
27334 + |
|
27335 + |
|
27336 + |
|
27337 + |
|
27338 + |
|
27339 +// Definitions |
|
27340 + |
|
27341 +// Constant |
|
27342 +#define GPO_ADDR 0x1 |
|
27343 + |
|
27344 +// Bandwidth modes |
|
27345 +enum TUA9001_BANDWIDTH_MODE |
|
27346 +{ |
|
27347 + TUA9001_BANDWIDTH_5MHZ = TUNER_BANDWIDTH_5MHZ, |
|
27348 + TUA9001_BANDWIDTH_6MHZ = TUNER_BANDWIDTH_6MHZ, |
|
27349 + TUA9001_BANDWIDTH_7MHZ = TUNER_BANDWIDTH_7MHZ, |
|
27350 + TUA9001_BANDWIDTH_8MHZ = TUNER_BANDWIDTH_8MHZ, |
|
27351 +}; |
|
27352 + |
|
27353 +// Default value |
|
27354 +#define TUA9001_RF_FREQ_HZ_DEFAULT 50000000; |
|
27355 +#define TUA9001_BANDWIDTH_MODE_DEFAULT TUA9001_BANDWIDTH_5MHZ; |
|
27356 + |
|
27357 + |
|
27358 + |
|
27359 + |
|
27360 + |
|
27361 +/// TUA9001 extra module alias |
|
27362 +typedef struct TUA9001_EXTRA_MODULE_TAG TUA9001_EXTRA_MODULE; |
|
27363 + |
|
27364 + |
|
27365 + |
|
27366 + |
|
27367 + |
|
27368 +// Extra manipulaing function |
|
27369 +typedef int |
|
27370 +(*TUA9001_FP_SET_BANDWIDTH_MODE)( |
|
27371 + TUNER_MODULE *pTuner, |
|
27372 + int BandwidthMode |
|
27373 + ); |
|
27374 + |
|
27375 +typedef int |
|
27376 +(*TUA9001_FP_GET_BANDWIDTH_MODE)( |
|
27377 + TUNER_MODULE *pTuner, |
|
27378 + int *pBandwidthMode |
|
27379 + ); |
|
27380 + |
|
27381 +typedef int |
|
27382 +(*TUA9001_FP_GET_REG_BYTES_WITH_REG_ADDR)( |
|
27383 + TUNER_MODULE *pTuner, |
|
27384 + unsigned char DeviceAddr, |
|
27385 + unsigned char RegAddr, |
|
27386 + unsigned char *pReadingByte, |
|
27387 + unsigned char ByteNum |
|
27388 + ); |
|
27389 + |
|
27390 +typedef int |
|
27391 +(*TUA9001_FP_SET_SYS_REG_BYTE)( |
|
27392 + TUNER_MODULE *pTuner, |
|
27393 + unsigned short RegAddr, |
|
27394 + unsigned char WritingByte |
|
27395 + ); |
|
27396 + |
|
27397 +typedef int |
|
27398 +(*TUA9001_FP_GET_SYS_REG_BYTE)( |
|
27399 + TUNER_MODULE *pTuner, |
|
27400 + unsigned short RegAddr, |
|
27401 + unsigned char *pReadingByte |
|
27402 + ); |
|
27403 + |
|
27404 + |
|
27405 + |
|
27406 + |
|
27407 + |
|
27408 +// TUA9001 extra module |
|
27409 +struct TUA9001_EXTRA_MODULE_TAG |
|
27410 +{ |
|
27411 + // TUA9001 extra variables |
|
27412 + int BandwidthMode; |
|
27413 + int IsBandwidthModeSet; |
|
27414 + |
|
27415 + // TUA9001 extra function pointers |
|
27416 + TUA9001_FP_SET_BANDWIDTH_MODE SetBandwidthMode; |
|
27417 + TUA9001_FP_GET_BANDWIDTH_MODE GetBandwidthMode; |
|
27418 + TUA9001_FP_GET_REG_BYTES_WITH_REG_ADDR GetRegBytesWithRegAddr; |
|
27419 + TUA9001_FP_SET_SYS_REG_BYTE SetSysRegByte; |
|
27420 + TUA9001_FP_GET_SYS_REG_BYTE GetSysRegByte; |
|
27421 +}; |
|
27422 + |
|
27423 + |
|
27424 + |
|
27425 + |
|
27426 + |
|
27427 +// Builder |
|
27428 +void |
|
27429 +BuildTua9001Module( |
|
27430 + TUNER_MODULE **ppTuner, |
|
27431 + TUNER_MODULE *pTunerModuleMemory, |
|
27432 + TUA9001_EXTRA_MODULE *pTua9001ExtraModuleMemory, |
|
27433 + BASE_INTERFACE_MODULE *pBaseInterfaceModuleMemory, |
|
27434 + I2C_BRIDGE_MODULE *pI2cBridgeModuleMemory, |
|
27435 + unsigned char DeviceAddr |
|
27436 + ); |
|
27437 + |
|
27438 + |
|
27439 + |
|
27440 + |
|
27441 + |
|
27442 +// Manipulaing functions |
|
27443 +void |
|
27444 +tua9001_GetTunerType( |
|
27445 + TUNER_MODULE *pTuner, |
|
27446 + int *pTunerType |
|
27447 + ); |
|
27448 + |
|
27449 +void |
|
27450 +tua9001_GetDeviceAddr( |
|
27451 + TUNER_MODULE *pTuner, |
|
27452 + unsigned char *pDeviceAddr |
|
27453 + ); |
|
27454 + |
|
27455 +int |
|
27456 +tua9001_Initialize( |
|
27457 + TUNER_MODULE *pTuner |
|
27458 + ); |
|
27459 + |
|
27460 +int |
|
27461 +tua9001_SetRfFreqHz( |
|
27462 + TUNER_MODULE *pTuner, |
|
27463 + unsigned long RfFreqHz |
|
27464 + ); |
|
27465 + |
|
27466 +int |
|
27467 +tua9001_GetRfFreqHz( |
|
27468 + TUNER_MODULE *pTuner, |
|
27469 + unsigned long *pRfFreqHz |
|
27470 + ); |
|
27471 + |
|
27472 + |
|
27473 + |
|
27474 + |
|
27475 + |
|
27476 +// Extra manipulaing functions |
|
27477 +int |
|
27478 +tua9001_SetBandwidthMode( |
|
27479 + TUNER_MODULE *pTuner, |
|
27480 + int BandwidthMode |
|
27481 + ); |
|
27482 + |
|
27483 +int |
|
27484 +tua9001_GetBandwidthMode( |
|
27485 + TUNER_MODULE *pTuner, |
|
27486 + int *pBandwidthMode |
|
27487 + ); |
|
27488 + |
|
27489 +int |
|
27490 +tua9001_GetRegBytesWithRegAddr( |
|
27491 + TUNER_MODULE *pTuner, |
|
27492 + unsigned char DeviceAddr, |
|
27493 + unsigned char RegAddr, |
|
27494 + unsigned char *pReadingBytes, |
|
27495 + unsigned char ByteNum |
|
27496 + ); |
|
27497 + |
|
27498 +int |
|
27499 +tua9001_SetSysRegByte( |
|
27500 + TUNER_MODULE *pTuner, |
|
27501 + unsigned short RegAddr, |
|
27502 + unsigned char WritingByte |
|
27503 + ); |
|
27504 + |
|
27505 +int |
|
27506 +tua9001_GetSysRegByte( |
|
27507 + TUNER_MODULE *pTuner, |
|
27508 + unsigned short RegAddr, |
|
27509 + unsigned char *pReadingByte |
|
27510 + ); |
|
27511 + |
|
27512 + |
|
27513 + |
|
27514 + |
|
27515 + |
|
27516 +// I2C birdge module demod argument setting |
|
27517 +void |
|
27518 +tua9001_SetI2cBridgeModuleTunerArg( |
|
27519 + TUNER_MODULE *pTuner |
|
27520 + ); |
|
27521 + |
|
27522 + |
|
27523 + |
|
27524 + |
|
27525 + |
|
27526 + |
|
27527 + |
|
27528 + |
|
27529 + |
|
27530 + |
|
27531 + |
|
27532 + |
|
27533 + |
|
27534 + |
|
27535 + |
|
27536 +#endif |