Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

781 lines
23 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Philips Semiconductors-CSU and Microsoft 1999
  4. // All rights are reserved. Reproduction in whole or in part is prohibited
  5. // without the written consent of the copyright owner.
  6. //
  7. // Philips reserves the right to make changes without notice at any time.
  8. // Philips makes no warranty, expressed, implied or statutory, including but
  9. // not limited to any implied warranty of merchantibility or fitness for any
  10. // particular purpose, or that the use will not infringe any third party
  11. // patent, copyright or trademark. Philips must not be liable for any loss
  12. // or damage arising from its use.
  13. //
  14. // TUNER.CPP
  15. //////////////////////////////////////////////////////////////////////////////
  16. #include "philtune.h"
  17. /*
  18. * CTuner()
  19. * Input :
  20. * Output: TRUE - if initialization data can be written to I2C
  21. * FALSE - if there is an I2C error
  22. * Description: CTuner Constructor.
  23. */
  24. CTuner::CTuner(CI2CScript *p_I2CScript, BoardInfoType *p_BoardInfo, NTSTATUS *pStatus)
  25. {
  26. m_pI2CScript = p_I2CScript;
  27. m_ucTunerAddress = TUNER_I2C_ADDRESS;
  28. m_ulInput = 0L; // unknown input or the only one
  29. m_ulCurrentFrequency = 0L; // unknown tuning frequency
  30. m_ulMode = 0;
  31. m_ulPrevMode = 0;
  32. m_TunerID = TD1536;
  33. m_ulPreviousFrequency = 0L;
  34. //m_FrequencyParam.ulCurrentCFrequency = 0L;
  35. LONG lPLLOffset;
  36. BOOL bBusyStatus;
  37. //GetPLLOffsetBusyStatus(&lPLLOffset, &bBusyStatus);
  38. m_uiBoardID = 0;
  39. if(p_BoardInfo != NULL)
  40. {
  41. NTSTATUS status;
  42. status = SetCapabilities(p_BoardInfo);
  43. if(pStatus != NULL)
  44. *pStatus = status;
  45. }
  46. }
  47. /*
  48. * ~CTuner()
  49. * Input :
  50. * Output:
  51. * Description: CTuner Destructor.
  52. */
  53. CTuner::~CTuner()
  54. {
  55. }
  56. /*
  57. * SetCapabilities()
  58. * Purpose : Sets the capabilities based upon the Tuner Id
  59. *
  60. * Inputs : UINT tuner : Tuner Id
  61. *
  62. * Outputs : returns TRUE, if there is a supported Tuner Id specified;
  63. *
  64. * Author : MM
  65. */
  66. NTSTATUS
  67. CTuner::SetCapabilities(BoardInfoType *p_BoardInfo)
  68. {
  69. NTSTATUS nStatus = STATUS_SUCCESS;
  70. m_TunerID = (TunerTypes)(p_BoardInfo->uiTunerID);
  71. m_ucTunerAddress = p_BoardInfo->ucTunerAddress;
  72. m_uiBoardID = p_BoardInfo->uiBoardID;
  73. // Note:
  74. // If mode is KSPROPERTY_TUNER_MODE_ATSC, then the IF is
  75. // 43.75MHz, else it is 44MHz. But as the frequency
  76. // being passed (ulFrequency) is the Video Signal freq,
  77. // the calculation should take into consideration that the video signal
  78. // is 1.75 MHz from the centre of the band. This 1.75MHz should be
  79. // added to the actual IF hence for ATSC IF = 43.75 + 1.75 = 45.5MHz
  80. // and NTSC IF = 44 + 1.75 = 45.75MHz
  81. // Currently , supporting only TD1536, other tune support can be added later
  82. // as necessary
  83. switch(m_TunerID)
  84. {
  85. case TD1536: // Digital Tuner
  86. {
  87. // Check to determine if it is a single input or a dual input
  88. // tuner
  89. ULONG inputs = 1;
  90. GetNumberOfInputs(&inputs);
  91. int i = 0;
  92. if(p_BoardInfo->ulSupportedModes & KSPROPERTY_TUNER_MODE_TV)
  93. {
  94. // Set mode capabilities for TV mode
  95. m_ModeCaps[i].ModeCaps.ulMode = KSPROPERTY_TUNER_MODE_TV;
  96. m_ModeCaps[i].ModeCaps.ulNumberOfInputs = inputs; //2;
  97. m_ModeCaps[i].ModeCaps.ulMinFrequency = 55250000L;
  98. m_ModeCaps[i].ModeCaps.ulMaxFrequency = 801250000L;
  99. m_ModeCaps[i].ModeCaps.ulStrategy = KS_TUNER_STRATEGY_PLL;
  100. m_ModeCaps[i].ulIntermediateFrequency = 45750000L;
  101. m_ModeCaps[i].ModeCaps.ulStandardsSupported = KS_AnalogVideo_NTSC_M;
  102. m_ModeCaps[i].ulNumberOfStandards = 1;
  103. m_ModeCaps[i].ModeCaps.ulTuningGranularity = 62500L;
  104. m_ModeCaps[i].ModeCaps.ulSettlingTime = 150; // 150 ms
  105. i++;
  106. }
  107. if(p_BoardInfo->ulSupportedModes & KSPROPERTY_TUNER_MODE_ATSC)
  108. {
  109. // Set mode capabilities for ATSC mode
  110. m_ModeCaps[i].ModeCaps.ulMode = KSPROPERTY_TUNER_MODE_ATSC;
  111. m_ModeCaps[i].ModeCaps.ulNumberOfInputs = inputs; //2;
  112. m_ModeCaps[i].ModeCaps.ulMinFrequency = 55250000L;
  113. m_ModeCaps[i].ModeCaps.ulMaxFrequency = 801250000L;
  114. m_ModeCaps[i].ModeCaps.ulStrategy =
  115. KS_TUNER_STRATEGY_DRIVER_TUNES;
  116. if((m_uiBoardID == BOARD_CATALINA) ||
  117. (m_uiBoardID == BOARD_CORFU))
  118. m_ModeCaps[i].ulIntermediateFrequency = 45750000L;
  119. else
  120. m_ModeCaps[i].ulIntermediateFrequency = 45500000L;
  121. m_ModeCaps[i].ModeCaps.ulStandardsSupported = KS_AnalogVideo_NTSC_M;
  122. m_ModeCaps[i].ulNumberOfStandards = 0;
  123. m_ModeCaps[i].ModeCaps.ulTuningGranularity = 62500L;
  124. m_ModeCaps[i].ModeCaps.ulSettlingTime = 800; // 800ms
  125. i++;
  126. }
  127. m_ulSupportedModes = p_BoardInfo->ulSupportedModes;
  128. m_ulNumSupportedModes = p_BoardInfo->ulNumSupportedModes;
  129. m_ucTunerAddress = TUNER_I2C_ADDRESS;
  130. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice::Supported Modes = %x \n", m_ulSupportedModes));
  131. }
  132. break;
  133. default:
  134. return STATUS_INVALID_PARAMETER;
  135. }
  136. SetMode(KSPROPERTY_TUNER_MODE_ATSC);
  137. m_ulVideoStandard = KS_AnalogVideo_NTSC_M;
  138. return nStatus;
  139. }
  140. /*
  141. * GetModeCapabilities()
  142. * Inputs: TunerModeCapsType *p_TunerModeCaps : pointer to
  143. * mode capability structure of the tuner
  144. * Outputs: Filled TunerModeCapsType structure
  145. * Returns: BOOL: returns TRUE, if the operation succeeds else FALSE
  146. * Description: Returns the mode capabilities of tuner for a particluar mode.
  147. */
  148. NTSTATUS
  149. CTuner::GetModeCapabilities(TunerModeCapsType *p_TunerModeCaps)
  150. {
  151. ULONG ulOperationMode = p_TunerModeCaps->ulMode;
  152. _DbgPrintF( DEBUGLVL_VERBOSE,("CTuner::GetTunerModeCapbilities Mode = %x Mode in obj %x\n",
  153. ulOperationMode, m_ulMode ));
  154. // QF:This is a work-around, as the mode passed by the filter the 1st time
  155. // is not correct. Will have to be removed later.
  156. p_TunerModeCaps->ulMode = m_ulMode;
  157. ulOperationMode = m_ulMode;
  158. if (!(ulOperationMode & m_ulSupportedModes))
  159. {
  160. // TRAP;
  161. return STATUS_INVALID_PARAMETER;
  162. }
  163. // There is support for TVTuner at this time only.
  164. // It will be enchanced later on to support FM Tuner as well.
  165. for(ULONG i = 0; i < m_ulNumSupportedModes; i++)
  166. {
  167. if(ulOperationMode == m_ModeCaps[m_ulModeCapIndex].ModeCaps.ulMode)
  168. break;
  169. }
  170. MemoryCopy(&p_TunerModeCaps->ulMode, &m_ModeCaps[m_ulModeCapIndex].ModeCaps,
  171. sizeof(TunerModeCapsType));
  172. return STATUS_SUCCESS;
  173. }
  174. /*
  175. * SetMode()
  176. * Inputs: ULONG ulMode : an operation mode required to be set
  177. * Outputs:
  178. * Returns: UINT: 0 - if mode is not supported
  179. * 1 - if mode is same as previous mode
  180. * 2 - if new mode has been set
  181. * Description: Set TV mode
  182. */
  183. NTSTATUS
  184. CTuner::SetMode(ULONG ulMode)
  185. {
  186. ULONG i;
  187. // Check if mod eis supported
  188. if(ulMode & m_ulSupportedModes)
  189. {
  190. m_ulPrevMode = m_ulMode;
  191. // Change mode only if it is different from the previous mode
  192. if(ulMode != m_ulMode)
  193. {
  194. // Check if the mode supported is part of the mode capability
  195. // structure array for the tuner. If it is , get the index into the
  196. // array for the given mode and change the mode.
  197. for(i = 0; i < m_ulNumSupportedModes; i++)
  198. {
  199. if(m_ModeCaps[i].ModeCaps.ulMode == ulMode)
  200. {
  201. m_ulModeCapIndex = i;
  202. break;
  203. }
  204. }
  205. if(i == m_ulNumSupportedModes)
  206. {
  207. _DbgPrintF( DEBUGLVL_ERROR,("CTuner::SetMode: Couldn't find mode in capability array\n"));
  208. return STATUS_INVALID_PARAMETER;
  209. }
  210. else
  211. m_ulMode = ulMode;
  212. }
  213. return STATUS_SUCCESS;
  214. }
  215. else
  216. {
  217. _DbgPrintF( DEBUGLVL_ERROR,("CTuner: Mode not supported : %x %x \n", ulMode, m_ulSupportedModes));
  218. return STATUS_INVALID_PARAMETER;
  219. }
  220. }
  221. /*
  222. * GetMode()
  223. * Inputs: ULONG *p_ulMode : pointer to operation mode that has to be read
  224. * Outputs: operation mode
  225. * Returns:
  226. * Description: Get Mode (TV/ATSC)
  227. */
  228. void CTuner::GetMode(ULONG *p_ulMode)
  229. {
  230. *p_ulMode = m_ulMode ;
  231. }
  232. /*
  233. * SetVideoStandard()
  234. * Inputs: ULONG ulStandard : a standard required to be set
  235. * Outputs:
  236. * Returns: NTSTATUS: STATUS_INVALID_PARAMETER - if standard is not supported
  237. * STATUS_SUCCESS - if operation succeeded
  238. * Description: Set the TV video standard requested.
  239. */
  240. NTSTATUS
  241. CTuner::SetVideoStandard(ULONG ulStandard)
  242. {
  243. if(ulStandard &
  244. m_ModeCaps[m_ulModeCapIndex].ModeCaps.ulStandardsSupported)
  245. {
  246. if(ulStandard != m_ulVideoStandard)
  247. {
  248. m_ulVideoStandard = ulStandard;
  249. }
  250. return STATUS_SUCCESS;
  251. }
  252. return STATUS_INVALID_PARAMETER;
  253. }
  254. /*
  255. * GetVideoStandard()
  256. * Inputs: ULONG *p_ulStandard : pointer to standard required to be filled
  257. * Outputs: standard
  258. * Returns:
  259. * Description: Get the TV video standard requested.
  260. */
  261. void CTuner::GetVideoStandard(ULONG *p_ulStandard)
  262. {
  263. *p_ulStandard = m_ulVideoStandard;
  264. }
  265. /*
  266. * GetPLLOffsetBusyStatus()
  267. * Purpose: Returns tuner Busy status and PLLOffset, if the tuner is not busy
  268. * The function reads the hardware in order to accomplish the task
  269. * The operation might be carried on either synchronously or asynchronously
  270. * Inputs : PLONG plPLLOffset : a pointer to write a PLLOffset value
  271. * PBOOL pbBusyStatus : a pointer to write a Busy status
  272. *
  273. * Outputs: BOOL : returns TRUE, if the operation succeded
  274. * Author : MM
  275. */
  276. NTSTATUS
  277. CTuner::GetPLLOffsetBusyStatus(PLONG plPLLOffset, PBOOL pbBusyStatus)
  278. {
  279. UCHAR ucI2CValue = 0;
  280. NTSTATUS nResult = STATUS_SUCCESS;
  281. if( Read(&ucI2CValue, 1, 0) != WDMMINI_NOERROR)
  282. nResult = STATUS_ADAPTER_HARDWARE_ERROR;
  283. if (nResult == STATUS_SUCCESS)
  284. {
  285. // bit 6 - PLL locked indicator
  286. *pbBusyStatus = !((BOOL)(ucI2CValue & 0x40));
  287. if (!(* pbBusyStatus))
  288. {
  289. ucI2CValue &= 0x07; // only 3 LSBits are PLLOffset
  290. // let's map the result into MS defined values
  291. // from -2 to 2
  292. *plPLLOffset = ucI2CValue - 2;
  293. }
  294. }
  295. // Read only busy bit for TD1536 as the tuner does not provide
  296. // PLL offset information.
  297. if (m_TunerID == TD1536)
  298. {
  299. *plPLLOffset = 0;
  300. // *pbBusyStatus = 0;
  301. // return TRUE;
  302. }
  303. return nResult;
  304. }
  305. /*
  306. * SetFrequency()
  307. * Purpose: Sets a new Tuner frequency
  308. * Inputs : ULONG ulFrequency : a frequency required to be set
  309. *
  310. * Outputs: BOOL : returns TRUE, if the operation succeded
  311. * Author : MM
  312. */
  313. BOOL CTuner::SetFrequency(ULONG ulFrequency)
  314. {
  315. ASSERT(m_ModeCaps[m_ulModeCapIndex].ulIntermediateFrequency != 0L);
  316. // Change frequency
  317. if (!ChangeFrequency(ulFrequency))
  318. return FALSE;
  319. m_ulCurrentFrequency = ulFrequency;
  320. if (m_ulPreviousFrequency != ulFrequency)
  321. {
  322. // Mini: Delay for 400ms to let the tuner settle to a tuned state and to let
  323. // the VSB acquire equalizer lock
  324. if (m_ulMode == KSPROPERTY_TUNER_MODE_ATSC)
  325. Delay(400000);
  326. }
  327. _DbgPrintF( DEBUGLVL_VERBOSE,("CTuner::SetTunerFrequency(): PrevFreq = %d CurrentFreq = %d\n",
  328. m_ulPreviousFrequency,m_ulCurrentFrequency));
  329. m_ulPreviousFrequency = ulFrequency;
  330. return TRUE;
  331. }
  332. /*
  333. * GetFrequency()
  334. * Purpose: Gets the Tuner frequency
  335. * Inputs : ULONG *p_ulFrequency : a frequency required
  336. *
  337. * Outputs:
  338. * Author : MM
  339. */
  340. void CTuner::GetFrequency(ULONG *p_ulFrequency)
  341. {
  342. *p_ulFrequency = m_ulCurrentFrequency;
  343. }
  344. /*
  345. * ChangeFrequency()
  346. * Input : frequency
  347. * Output: TRUE if able to to tune to the frequency
  348. * FALSE if unable to tune to the frequency
  349. * Description: Change the frequency of tuner to that specified
  350. */
  351. BOOL CTuner::ChangeFrequency(ULONG ulFrequency)
  352. {
  353. ULONG ulFrequenceDivider;
  354. USHORT usControlCode;
  355. UCHAR ucI2CBuffer[6];
  356. I2CPacket i2cPacket;
  357. BOOL bResult;
  358. ULONG IF = m_ModeCaps[m_ulModeCapIndex].ulIntermediateFrequency;
  359. // Set the video carrier frequency by controlling the programmable divider
  360. // N = (16 * (FreqRF + FreqIntermediate)) / 1000000
  361. _DbgPrintF( DEBUGLVL_VERBOSE,("CTuner: ulFrequency = %x \n", ulFrequency));
  362. ulFrequenceDivider = ulFrequency + IF;
  363. _DbgPrintF( DEBUGLVL_VERBOSE,("CTuner::ChangeFrequency: IF = %d\n", IF));
  364. ulFrequenceDivider /= (1000000 / 16); // divide by 62,500
  365. usControlCode = GetControlCode(ulFrequenceDivider);
  366. if(!usControlCode)
  367. return(FALSE);
  368. // _DbgPrintF( DEBUGLVL_VERBOSE,("PhilTune: ulFrequencyDivider before %x \n", ulFrequenceDivider));
  369. // _DbgPrintF( DEBUGLVL_VERBOSE,("PhilTune: ulFrequencyDivider after %x \n", ulFrequenceDivider));
  370. ucI2CBuffer[0] = 0xCE;
  371. ucI2CBuffer[1] = (UCHAR)usControlCode;
  372. ucI2CBuffer[2] = (UCHAR)(ulFrequenceDivider >> 8);
  373. ucI2CBuffer[3] = (UCHAR)ulFrequenceDivider;
  374. ucI2CBuffer[4] = (UCHAR)(usControlCode >> 8);
  375. ucI2CBuffer[5] = (UCHAR)usControlCode;
  376. _DbgPrintF( DEBUGLVL_TERSE,("\n CPhilipsWDMTuner:Tuner Control Code = %x %x %x %x \n",
  377. ucI2CBuffer[0], ucI2CBuffer[1], ucI2CBuffer[2], ucI2CBuffer[3]));
  378. /*i2cPacket.uchChipAddress = m_uchTunerI2CAddress;
  379. i2cPacket.cbReadCount = 0;
  380. i2cPacket.cbWriteCount = 4;
  381. i2cPacket.puchReadBuffer = NULL;
  382. i2cPacket.puchWriteBuffer = auchI2CBuffer;
  383. i2cPacket.usFlags = 0;
  384. bResult = m_pI2CScript->PerformI2CPacketOperation(&i2cPacket);
  385. return bResult;
  386. */
  387. if(Write(ucI2CBuffer, sizeof(ucI2CBuffer), 0) == WDMMINI_NOERROR)
  388. return TRUE;
  389. else
  390. return FALSE;
  391. }
  392. BOOL CTuner::TweakChannel(LONG lTweak, int iTweakReference)
  393. {
  394. // Should change the routine later to support tweak reference
  395. // if tweak reference is TUNER_ABSOLUTE_TWEAK, then tweaking is about the centre
  396. // frequency else if tweak reference is TUNER_RELATIVE_TWEAK, then tweaking is about
  397. // the current frequency
  398. LONG lTweakFrq = (lTweak * 62500) + m_ulCurrentFrequency;
  399. if (lTweakFrq > 0)
  400. if (!ChangeFrequency((ULONG)lTweakFrq))
  401. return FALSE;
  402. else
  403. return FALSE;
  404. m_ulCurrentFrequency = (ULONG)lTweakFrq;
  405. return TRUE;
  406. }
  407. /*
  408. * GetNumberOfInputs()
  409. * Input : pointer to ULONG variable which will be filled with number of inputs
  410. * Output: TRUE - if the number of inputs can be determined
  411. * FALSE - if there is an I2C error & number of inputs can't be determined
  412. * Description: Determine the number of tuner inputs
  413. */
  414. BOOL CTuner::GetNumberOfInputs(ULONG *p_ulInputs)
  415. {
  416. UCHAR ucMode = 0;
  417. _DbgPrintF( DEBUGLVL_VERBOSE,("CTuner::GetNumberOfInputs: Inside\n"));
  418. if(m_uiBoardID == BOARD_CONEY)
  419. {
  420. if(!m_pI2CScript->ReadSeq(CONEY_I2C_PARALLEL_PORT, &ucMode, 1))
  421. {
  422. _DbgPrintF( DEBUGLVL_ERROR,("CTuner::GetNumberOfInputs: Error\n"));
  423. return(FALSE);
  424. }
  425. // If the mode bit 0 = 1,then its a dual input tuner , else its a single input tuner
  426. if ((ucMode & 0x1) == 0)
  427. *p_ulInputs = 1;
  428. else
  429. *p_ulInputs = 2;
  430. }
  431. else //if(m_uiBoardID == BOARD_CATALINA)
  432. *p_ulInputs = 1;
  433. // else
  434. // {
  435. // *p_ulInputs = 1;
  436. // _DbgPrintF( DEBUGLVL_ERROR,("CTuner::GetNumberOfInputs:Invalid Board ID\n"));
  437. // }
  438. m_uiNumInputs = *p_ulInputs;
  439. _DbgPrintF( DEBUGLVL_VERBOSE,("CTuner::GetNumberOfInputs: Number of input pins = %d Mode = %x\n",
  440. *p_ulInputs, ucMode));
  441. return(TRUE);
  442. }
  443. /*
  444. * GetInput()
  445. * Purpose: Gets the current tuner inputs as an active one
  446. * Inputs : ULONG nInput : input number required to be set as an active
  447. * (begins from 0)
  448. *
  449. * Outputs: BOOL : returns TRUE, if the operation succeded
  450. * Author : MM
  451. */
  452. BOOL CTuner::GetInput(ULONG *p_ulInput)
  453. {
  454. *p_ulInput = m_ulInput;
  455. return(TRUE);
  456. }
  457. /*
  458. * SetInput()
  459. * Purpose: Sets one of the possible Tuner inputs as an active one
  460. * Inputs : ULONG nInput : input number required to be set as an active
  461. * (begins from 0)
  462. *
  463. * Returns: UINT: 0 - if tuner input is out of range
  464. * 1 - if tuner input is same as previous tuner input
  465. * 2 - if new tuner input has been set
  466. * Author : MM
  467. */
  468. UINT CTuner::SetInput(ULONG ulInput)
  469. {
  470. if(ulInput < m_ModeCaps[m_ulModeCapIndex].ModeCaps.ulNumberOfInputs)
  471. {
  472. if(ulInput != m_ulInput)
  473. m_ulInput = ulInput;
  474. else
  475. return 1;
  476. return 2;
  477. }
  478. else
  479. return 0;
  480. }
  481. /*
  482. * GetControlCode()
  483. * Purpose: Determines the Tuner control code to be send to tuner with a new frequency value
  484. *
  485. * Inputs : ULONG ulFrequencyDivider : new frequency divider
  486. *
  487. * Outputs: USHORT : value, the tuner should be programmed, when the new frequency is set
  488. * id the is no valid uiTunerId is passed as paramter, 0 is returned
  489. * Author : MM
  490. */
  491. USHORT CTuner::GetControlCode(ULONG ulFrequencyDivider)
  492. {
  493. USHORT usLowBandFrequencyHigh, usMiddleBandFrequencyHigh;
  494. USHORT usLowBandControl, usMiddleBandControl, usHighBandControl;
  495. USHORT usControlCode = 0;
  496. usLowBandFrequencyHigh = kUpperLowBand;
  497. usMiddleBandFrequencyHigh = kUpperMidBand;
  498. usLowBandControl = kLowBand;
  499. usMiddleBandControl = kMidBand;
  500. usHighBandControl = kHighBand;
  501. switch(m_TunerID)
  502. {
  503. case TD1536:
  504. {
  505. if (m_ulMode != KSPROPERTY_TUNER_MODE_ATSC)
  506. {
  507. usLowBandControl = kLowBand_1536_NTSC_A;
  508. usMiddleBandControl = kMidBand_1536_NTSC_A;
  509. usHighBandControl = kHighBand_1536_NTSC_A;
  510. if(m_uiBoardID == BOARD_CORONADO)
  511. {
  512. usLowBandControl &= 0xffbf;
  513. usMiddleBandControl &= 0xffbf;
  514. usHighBandControl &= 0xffbf;
  515. }
  516. }
  517. else
  518. {
  519. usLowBandControl = kLowBand_1536_NTSC_D;
  520. usMiddleBandControl = kMidBand_1536_NTSC_D;
  521. usHighBandControl = kHighBand_1536_NTSC_D;
  522. if(m_uiBoardID == BOARD_CORONADO)
  523. {
  524. usLowBandControl |= 0x40;
  525. usMiddleBandControl |= 0x40;
  526. usHighBandControl |= 0x40;
  527. }
  528. }
  529. // Based on the tuner input modify control word
  530. // Test
  531. ULONG ulInp = m_ulInput; //1
  532. if (ulInp == 1)
  533. {
  534. usLowBandControl |= 0x1;
  535. usMiddleBandControl |= 0x1;
  536. usHighBandControl |= 0x1;
  537. }
  538. else
  539. {
  540. usLowBandControl &= 0xfffe;
  541. usMiddleBandControl &= 0xfffe;
  542. usHighBandControl &= 0xfffe;
  543. }
  544. _DbgPrintF( DEBUGLVL_VERBOSE,("CPhilipsWDMTuner::GetControlCode(): LBand = %x, MBand = %x, HBand = %x\n", usLowBandControl,
  545. usMiddleBandControl, usHighBandControl));
  546. }
  547. break;
  548. default :
  549. return(usControlCode);
  550. }
  551. if(ulFrequencyDivider <= (ULONG)usLowBandFrequencyHigh)
  552. usControlCode = usLowBandControl;
  553. else
  554. {
  555. if(ulFrequencyDivider <= (ULONG)usMiddleBandFrequencyHigh)
  556. usControlCode = usMiddleBandControl;
  557. else
  558. usControlCode = usHighBandControl;
  559. }
  560. return(usControlCode);
  561. }
  562. /*
  563. * Write()
  564. * Input:UCHAR *p_ucBuffer - buffer to be written
  565. * int uiNumReg - Number of registers to be written
  566. * UINT uiStartAddr - start address
  567. * Output : UINT - Error code
  568. * Description: Write data to chip
  569. */
  570. UINT CTuner::Write(UCHAR *p_ucBuffer, UINT uiNumReg, UINT uiStartAddr)
  571. {
  572. UINT uiResult = WDMMINI_NOERROR;
  573. // The present versions of the chip do not support sub-addressing, hence
  574. // uiStartAddr is not used.
  575. // write to chip
  576. //$REVIEW - Should change function decl to make uiNumReg be USHORT - TCP
  577. if(!m_pI2CScript->WriteSeq(m_ucTunerAddress, p_ucBuffer, (USHORT) uiNumReg))
  578. uiResult = WDMMINI_HARDWAREFAILURE;
  579. return uiResult;
  580. }
  581. /*
  582. * Read()
  583. * Input:UCHAR *p_ucBuffer - buffer to be filled
  584. * int uiNumReg - Number of registers to be read
  585. * UINT uiStartAddr - start address
  586. * Output : UINT - Error code
  587. * Description: Read data from chip
  588. */
  589. UINT CTuner::Read(UCHAR *p_ucBuffer, UINT uiNumReg, UINT uiStartAddr)
  590. {
  591. UINT uiResult = WDMMINI_NOERROR;
  592. // The present versions of the chip do not support sub-addressing, hence
  593. // uiStartAddr is not used.
  594. // write to chip
  595. //$REVIEW - Should change function decl to make uiNumReg be USHORT - TCP
  596. if(!m_pI2CScript->ReadSeq(m_ucTunerAddress, p_ucBuffer, (USHORT) uiNumReg))
  597. uiResult = WDMMINI_HARDWAREFAILURE;
  598. return uiResult;
  599. }
  600. #if 0
  601. /*
  602. * operator new
  603. * Purpose: CTuner class overrides operator new.
  604. *
  605. * Inputs : UINT uiSize : size of the object to be placed
  606. *
  607. * Outputs: PVOID : pointer of the CTuner class object
  608. * Author : MM
  609. */
  610. PVOID CTuner::operator new(UINT uiSize)
  611. {
  612. if (uiSize != sizeof(CTuner))
  613. {
  614. _DbgPrintF( DEBUGLVL_ERROR,("CTuner: operator new() fails\n"));
  615. return(NULL);
  616. }
  617. return (AllocateFixedMemory(uiSize));
  618. }
  619. /*
  620. * operator delete
  621. * Purpose: CTuner class overrides operator delete
  622. *
  623. * Inputs : PVOID p_Buffer : pointer to object being deleted
  624. *
  625. * Outputs:
  626. * Author : MM
  627. */
  628. void CTuner::operator delete(PVOID p_Object)
  629. {
  630. if(p_Object != NULL)
  631. FreeFixedMemory(p_Object);
  632. _DbgPrintF( DEBUGLVL_VERBOSE,("CTuner: operator delete() succeeds\n"));
  633. }
  634. /*
  635. * SetFrequencyParam()
  636. * Purpose: Sets the frequency parameters for the tuner
  637. * Inputs : TunerFrequencyType *p_Frequency : a frequency required to be set
  638. *
  639. * Returns: UINT: 0 - if frequency is out of range or frequency setting fails
  640. * 1 - if frequency is same as previous frequency
  641. * 2 - if new frequency has been set
  642. * Author : MM
  643. */
  644. UINT CTuner::SetFrequencyParam(TunerFrequencyType *p_Frequency)
  645. {
  646. ULONG ulFrequency = p_Frequency->ulCurrentCFrequency;
  647. if((ulFrequency < m_ModeCaps[m_ulModeCapIndex].ModeCaps.ulMinFrequency) ||
  648. (ulFrequency > m_ModeCaps[m_ulModeCapIndex].ModeCaps.ulMaxFrequency))
  649. return 0;
  650. // If the tuning frequency has changed or the tuner mode has changed ,
  651. // then change the tuner frequency
  652. if((ulFrequency != m_ulCurrentFrequency) ||
  653. (m_ulPrevMode != m_ulMode))
  654. {
  655. // Set the tuner frequency
  656. if(!SetFrequency(ulFrequency))
  657. return 0;
  658. // Update the CTuner's frequency parameters
  659. MemoryCopy(&m_FrequencyParam, p_Frequency, sizeof(TunerFrequencyType));
  660. return 2;
  661. }
  662. return 1;
  663. }
  664. /*
  665. * GetFrequencyParam()
  666. * Purpose: Gets the frequency parameters for the tuner
  667. * Inputs : TunerFrequencyType *p_Frequency : a frequency required to be filled
  668. * Output:
  669. * Author : MM
  670. */
  671. void CTuner::GetFrequencyParam(TunerFrequencyType *p_Frequency)
  672. {
  673. MemoryCopy(p_Frequency, &m_FrequencyParam, sizeof(TunerFrequencyType));
  674. return;
  675. }
  676. #endif