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.

420 lines
13 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. // TUNERPROP.CPP
  15. //////////////////////////////////////////////////////////////////////////////
  16. #include "philtune.h"
  17. #define MPOC_TUNER_ATSC 0x0
  18. #define MPOC_TUNER_NTSC 0x3
  19. #if 0
  20. /*
  21. * GetTunerModeCapbilities()
  22. * Inputs: KSPROPERTY_TUNER_MODE_CAPS_S *p_tuner_mode_cap : pointer to
  23. * mode capability structure of the tuner
  24. * Outputs: Filled KSPROPERTY_TUNER_MODE_CAPS_S
  25. * Returns: BOOL: returns TRUE, if the operation succeeds else FALSE
  26. * Description: Returns the mode capabilities of tuner for a particluar mode.
  27. */
  28. NTSTATUS CDevice::GetTunerModeCapbilities(KSPROPERTY_TUNER_MODE_CAPS_S *p_TunerModeCaps)
  29. {
  30. m_pTuner->GetModeCapabilities((TunerModeCapsType *)&p_TunerModeCaps->Mode);
  31. return STATUS_SUCCESS;
  32. }
  33. #endif
  34. /*
  35. * GetTunerMode ()
  36. * Inputs: ULONG *p_ulMode : pointer to mode
  37. * Outputs: Fills p_ulMode
  38. * Returns: BOOL: returns TRUE, if the operation succeeds else FALSE
  39. * Description: Returns the current tuner mode. Called in response to
  40. * property ID KSPROPERTY_TUNER_MODE by GetProperty(). The modes could be
  41. * either ATSC or TV (NTSC).
  42. */
  43. NTSTATUS CDevice::GetTunerMode(ULONG *p_ulMode)
  44. {
  45. m_pTuner->GetMode(p_ulMode);
  46. return STATUS_SUCCESS;
  47. }
  48. /*
  49. * GetTunerVideoStandard ()
  50. * Inputs: ULONG *p_ulStandard : pointer to standard
  51. * Outputs: Fills p_ulStandard
  52. * Returns: BOOL: returns TRUE, if the operation succeeds else FALSE
  53. * Description: Returns the current standard. Applicable only for TV mode.
  54. */
  55. NTSTATUS CDevice::GetTunerVideoStandard(ULONG *p_ulStandard)
  56. {
  57. m_pTuner->GetVideoStandard(p_ulStandard);
  58. return STATUS_SUCCESS;
  59. }
  60. /*
  61. * GetTunerStatus ()
  62. * Inputs: PTunerStatusType *p_status : pointer to status
  63. * Outputs: Fills p_status
  64. * Returns: BOOL: returns TRUE, if the operation succeeds else FALSE
  65. * Description: Returns the status of the tuner.
  66. */
  67. NTSTATUS CDevice::GetTunerStatus(PTunerStatusType p_Status)
  68. {
  69. NTSTATUS nStatus = STATUS_SUCCESS;
  70. long lPLLOffset = 0;
  71. BOOL bBusy = FALSE;
  72. if (m_pTuner->GetPLLOffsetBusyStatus(&lPLLOffset, &bBusy))
  73. {
  74. p_Status->Busy = bBusy;
  75. if(bBusy)
  76. {
  77. // If tuner is busy , return FALSE
  78. p_Status->Busy = TRUE;
  79. _DbgPrintF( DEBUGLVL_ERROR,("CDevice:GetStatus() fails\n"));
  80. return STATUS_DEVICE_BUSY;
  81. }
  82. if(m_BoardInfo.uiIFStage == IF_MPOC)
  83. {
  84. GetMpocStatus(MPOC_STATUS_PLL_OFFSET, (UINT *)(&p_Status->PLLOffset));
  85. if(p_Status->PLLOffset == 0)
  86. p_Status->PLLOffset = -2;
  87. else if(p_Status->PLLOffset == 1)
  88. p_Status->PLLOffset = 2;
  89. else
  90. p_Status->PLLOffset = 0;
  91. }
  92. else
  93. p_Status->PLLOffset = lPLLOffset;
  94. m_pTuner->GetFrequency(&p_Status->CurrentFrequency);
  95. p_Status->SignalStrength = m_pDemod->IsVSBLocked();
  96. }
  97. else
  98. nStatus = STATUS_UNSUCCESSFUL;
  99. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice::GetTunerStatus() Busy = %d, Offset = %d Frequency = %ld\n",bBusy, p_Status->PLLOffset, p_Status->CurrentFrequency));
  100. return nStatus;
  101. }
  102. /*
  103. * GetTunerInput ()
  104. * Inputs: ULONG *p_ulTuner_input : pointer to tuner input index
  105. * Outputs: Fills p_ulTuner_input
  106. * Returns: BOOL: returns TRUE, if the operation succeeds else FALSE
  107. * Description: Returns the current tuner input index. The input index is 0 based.
  108. */
  109. NTSTATUS CDevice::GetTunerInput(ULONG *p_ulTunerInput)
  110. {
  111. m_pTuner->GetInput(p_ulTunerInput);
  112. return STATUS_SUCCESS;
  113. }
  114. /*
  115. * SetTunerMode()
  116. * Inputs: ULONG ulModeToSet : an operation mode required to be set
  117. * Outputs:
  118. * Returns: NTSTATUS: returns STATUS_SUCCESS, if the operation succeeds
  119. * Description: Set device into tuner mode requested.
  120. * Do required I2C or GPIO writes to do a mode change for the chips.
  121. * On 1st entry into this section, create a new thread to check hang and
  122. * signal quality. In ATSC mode, enable signal quality check & in NTSC mode,
  123. * disable signal quality check.
  124. * Called in response to property ID KSPROPERTY_TUNER_MODE by SetProperty().
  125. */
  126. NTSTATUS CDevice::SetTunerMode(ULONG ulModeToSet)
  127. {
  128. UCHAR ucPin;
  129. UCHAR ucValue;
  130. BOOL bResult = TRUE;
  131. ULONG ulPrevMode;
  132. UINT uiResult;
  133. UCHAR ucDataWr[4];
  134. NTSTATUS nStatus;
  135. m_pTuner->GetMode(&ulPrevMode);
  136. nStatus = m_pTuner->SetMode(ulModeToSet);
  137. if (!NT_SUCCESS( nStatus))
  138. {
  139. return STATUS_INVALID_PARAMETER;
  140. }
  141. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice::SetTunerMode: prev Mode = %d CurentMode = %d",
  142. ulPrevMode, ulModeToSet));
  143. // Take actions based on board ID
  144. if (m_BoardInfo.uiBoardID == BOARD_CONEY)
  145. {
  146. // Based on mode, set GPIO pins.
  147. // GPIO pin 2 = HIGH for ATSC
  148. // LOW for NTSC
  149. // In ATSC mode - the first time create a thread to check
  150. // signal quality and hang check . At other times enable the thread.
  151. // in TV mode, disable the thread.
  152. ucPin = GPIO_TUNER_MODE_SELECT_PIN; // use as a PinMask
  153. if (ulModeToSet == KSPROPERTY_TUNER_MODE_ATSC)
  154. {
  155. ucValue = GPIO_TUNER_MODE_ATSC;
  156. if(!m_pGpio->WriteGPIO(&ucPin, &ucValue))
  157. { _DbgPrintF( DEBUGLVL_ERROR,("CDevice: GPIO write failed"));
  158. nStatus = STATUS_ADAPTER_HARDWARE_ERROR;
  159. goto errexit;
  160. }
  161. if(!(m_pDemod->SetOutputMode(m_uiOutputMode)))
  162. {
  163. nStatus = STATUS_ADAPTER_HARDWARE_ERROR;
  164. goto errexit;
  165. }
  166. }
  167. else if(ulModeToSet == KSPROPERTY_TUNER_MODE_TV)
  168. {
  169. ucValue = GPIO_TUNER_MODE_NTSC;
  170. if(!m_pGpio->WriteGPIO(&ucPin, &ucValue))
  171. {
  172. _DbgPrintF( DEBUGLVL_ERROR,("CDevice: GPIO write failed"));
  173. nStatus = STATUS_ADAPTER_HARDWARE_ERROR;
  174. goto errexit;
  175. }
  176. }
  177. else
  178. {
  179. _DbgPrintF( DEBUGLVL_ERROR,("CDevice:SetTunerMode: Invalid Mode"));
  180. nStatus = STATUS_INVALID_PARAMETER_1;
  181. goto errexit;
  182. }
  183. }
  184. else if(m_BoardInfo.uiBoardID == BOARD_CATALINA)
  185. {
  186. if (ulModeToSet == KSPROPERTY_TUNER_MODE_TV)
  187. {
  188. if(!(m_pDemod->SetOutputMode(VSB_OUTPUT_MODE_ITU656)))
  189. {
  190. nStatus = STATUS_ADAPTER_HARDWARE_ERROR;
  191. goto errexit;
  192. }
  193. // Set MiscRegister Tuner AGC to external (bit 4 = 1)
  194. // Set MiscRegister PLD mode to NTSC ( bit 5-7 = 010)
  195. // Set Misc Register DTV IF disable (bit 2 = 0)
  196. // Set Misc Register NTSC IF enable (bit 3 = 1)
  197. ucDataWr[0] = m_ucModeInit;
  198. ucDataWr[0] &= 0x03;
  199. ucDataWr[0] |= 0x58;
  200. m_pI2CScript->WriteSeq(CATALINA_MISC_CONTROL_REGISTER, ucDataWr, 1);
  201. m_ucModeInit = ucDataWr[0];
  202. }
  203. else if (ulModeToSet == KSPROPERTY_TUNER_MODE_ATSC)
  204. {
  205. if(!(m_pDemod->SetOutputMode(m_uiOutputMode)))
  206. {
  207. nStatus = STATUS_ADAPTER_HARDWARE_ERROR;
  208. goto errexit;
  209. }
  210. // Set MiscRegister Tuner AGC to internal (bit 4 = 0)
  211. // Set MiscRegister PLD mode to DTV ( bit 5-7 = 000)
  212. // Set Misc Register DTV IF enable (bit 2 = 1)
  213. // Set Misc Register NTSC IF disable (bit 3 = 0)
  214. ucDataWr[0] = m_ucModeInit;
  215. ucDataWr[0] &= 0x03;
  216. ucDataWr[0] |= 0x04;
  217. if(m_uiOutputMode == VSB_OUTPUT_MODE_DIAGNOSTIC)
  218. ucDataWr[0] |= 0x80;
  219. m_pI2CScript->WriteSeq(CATALINA_MISC_CONTROL_REGISTER, ucDataWr, 1);
  220. m_ucModeInit = ucDataWr[0];
  221. }
  222. else
  223. {
  224. _DbgPrintF( DEBUGLVL_ERROR,("CDevice:SetTunerMode: Invalid Mode"));
  225. nStatus = STATUS_INVALID_PARAMETER_1;
  226. goto errexit;
  227. }
  228. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice:SetTunerMode: Misc Reg = %x", m_ucModeInit));
  229. // SendTunerMode(ulModeToSet);
  230. //Set Mode in MPOC
  231. nStatus = SetMpocIFMode(ulModeToSet);
  232. if (!NT_SUCCESS( nStatus))
  233. {
  234. _DbgPrintF( DEBUGLVL_ERROR,("CDevice:SetTunerMode: Cannot set MPOC IF Mode"));
  235. goto errexit;
  236. }
  237. }
  238. else
  239. {
  240. // TRAP;
  241. // _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice:SetTunerMode: Invalid Board ID"));
  242. // FAIL;
  243. }
  244. if((m_BoardInfo.uiVsbChipVersion >> 8) == VSB1)
  245. {
  246. if (ulModeToSet == KSPROPERTY_TUNER_MODE_ATSC)
  247. {
  248. if (m_bFirstEntry == TRUE)
  249. {
  250. m_bFirstEntry = FALSE;
  251. // Create a new thread to constantly monitor the quality of
  252. // the input signal and check hang
  253. CreateQualityCheckThread();
  254. }
  255. // Get Mutex and enable QCM
  256. m_QualityCheckMutex.Lock();
  257. m_uiQualityCheckMode = QCM_ENABLE;
  258. m_QualityCheckMutex.Unlock();
  259. }
  260. else if(ulModeToSet == KSPROPERTY_TUNER_MODE_TV)
  261. {
  262. if (m_bFirstEntry == FALSE)
  263. {
  264. // Get Mutex and enable QCM
  265. m_QualityCheckMutex.Lock();
  266. m_uiQualityCheckMode = QCM_DISABLE;
  267. m_QualityCheckMutex.Unlock();
  268. }
  269. }
  270. else
  271. {}
  272. }
  273. m_pDemod->IsVSBLocked();
  274. // Mini: Test
  275. VsbStatusType Status;
  276. m_pDemod->GetStatus(&Status);
  277. return STATUS_SUCCESS;
  278. errexit:
  279. // If the mode cannot be changed , restore the previous mode
  280. uiResult = m_pTuner->SetMode(ulPrevMode);
  281. return nStatus;
  282. }
  283. /*
  284. * GetTunerFrequency ()
  285. * Inputs: ULONG *p_ulFreq: pointer to frequency
  286. * Outputs: Filled *p_ulfreq
  287. * Return: NTSTATUS: returns STATUS_SUCCESS
  288. * Description: Gets the tuner frequency parameters.
  289. */
  290. NTSTATUS CDevice::GetTunerFrequency(ULONG *p_ulFreq)
  291. {
  292. m_pTuner->GetFrequency(p_ulFreq);
  293. return STATUS_SUCCESS;
  294. }
  295. /*
  296. * SetTunerFrequency()
  297. * Inputs: ULONG *p_ulFreq: pointer to frequency
  298. * Outputs:
  299. * Return: NTSTATUS: returns STATUS_SUCCESS, if the operation succeeds
  300. * else STATUS_UNSUCCESSFUL
  301. * Description: Set the frequency parameters and change to tuner frequency
  302. * specified. In ATSC mode, introduce a small delay (~400ms) to let the VSB
  303. * settle. If the quality check thread is created, disable it.
  304. */
  305. NTSTATUS CDevice::SetTunerFrequency(ULONG *p_ulFreq)
  306. {
  307. UINT uiQcm;
  308. BOOL bResult;
  309. if((m_BoardInfo.uiVsbChipVersion >> 8) == VSB1)
  310. {
  311. if (m_bFirstEntry == FALSE)
  312. {
  313. // Disable Quality Check mode
  314. m_QualityCheckMutex.Lock();
  315. uiQcm = m_uiQualityCheckMode;
  316. m_uiQualityCheckMode = QCM_DISABLE;
  317. m_QualityCheckMutex.Unlock();
  318. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice::GetTunerFrequency(): Disable QCM\n"));
  319. // Wait for ~400ms to let the Tuner and VSB settle down
  320. //Delay(400000);
  321. }
  322. bResult = m_pTuner->SetFrequency(*p_ulFreq);
  323. if (m_bFirstEntry == FALSE)
  324. {
  325. // Restore Quality Check mode
  326. m_QualityCheckMutex.Lock();
  327. m_uiQualityCheckMode = uiQcm;
  328. m_QualityCheckMutex.Unlock();
  329. }
  330. }
  331. else
  332. bResult = m_pTuner->SetFrequency(*p_ulFreq);
  333. m_pDemod->IsVSBLocked();
  334. if(bResult) return STATUS_SUCCESS;
  335. else return STATUS_UNSUCCESSFUL;
  336. }
  337. /*
  338. * SetTunerVideoStandard ()
  339. * Inputs: ULONG ulStandard : a standard required to be set
  340. * Outputs:
  341. * Return: NTSTATUS: returns STATUS_SUCCESS, if the operation succeeds
  342. * else STATUS_UNSUCCESSFUL
  343. * Description: Set Tuner Video standard.
  344. */
  345. NTSTATUS CDevice::SetTunerVideoStandard(ULONG ulStandard)
  346. {
  347. if(!m_pTuner->SetVideoStandard(ulStandard))
  348. return STATUS_UNSUCCESSFUL;
  349. else
  350. return STATUS_SUCCESS;
  351. }
  352. /*
  353. * SetTunerInput
  354. * Inputs: ULONG ulInput : input number required to be set as an active
  355. * (begins from 0)
  356. * Outputs:
  357. * Return: NTSTATUS: returns STATUS_SUCCESS, if the operation succeeds
  358. * else STATUS_UNSUCCESSFUL
  359. * Description: Set Tuner input to that requested.
  360. */
  361. NTSTATUS CDevice::SetTunerInput(ULONG ulInput)
  362. {
  363. if(!m_pTuner->SetInput(ulInput))
  364. return STATUS_UNSUCCESSFUL;
  365. else
  366. return STATUS_SUCCESS;
  367. }