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.

510 lines
16 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. // VSBPROP.CPP
  15. //////////////////////////////////////////////////////////////////////////////
  16. #include "philtune.h"
  17. /*
  18. * VsbReset()
  19. * Inputs: UINT reset
  20. * Outputs:
  21. * Return: BOOL: returns TRUE, if the operation succeeds else FALSE
  22. * Description: Hardware/software reset of VSB. A software reset would imply
  23. * writing to the reset registers of VSB and hardware reset would be a hardware
  24. * VSB reset.
  25. * Author : MM
  26. */
  27. NTSTATUS CDevice::VsbReset(UINT uiReset)
  28. {
  29. BOOL bResult = TRUE;
  30. UCHAR ucPin, ucValue;
  31. if (uiReset & HARDWARE_RESET)
  32. {
  33. if (m_BoardInfo.uiBoardID == BOARD_CONEY)
  34. {
  35. // DO hardware reset
  36. // ********** VSB reset . GPIO pin 0 high - low- high
  37. // GPIO HIGH
  38. ucPin = GPIO_VSB_RESET_PIN ; // use as a PinMask
  39. ucValue = GPIO_VSB_SET ;
  40. if(!m_pGpio->WriteGPIO(&ucPin, &ucValue))
  41. { _DbgPrintF( DEBUGLVL_ERROR,("CReceiverFE::VsbReset: GPIO write failed"));
  42. return STATUS_ADAPTER_HARDWARE_ERROR;
  43. }
  44. // GPIO LOW
  45. ucValue = GPIO_VSB_RESET ;
  46. if(!m_pGpio->WriteGPIO(&ucPin, &ucValue))
  47. { _DbgPrintF( DEBUGLVL_ERROR,("CReceiverFE::VsbReset: GPIO write failed"));
  48. return STATUS_ADAPTER_HARDWARE_ERROR;
  49. }
  50. // GPIO HIGH
  51. ucValue = GPIO_VSB_SET ;
  52. if(!m_pGpio->WriteGPIO(&ucPin, &ucValue))
  53. { _DbgPrintF( DEBUGLVL_ERROR,("CReceiverFE::VsbReset: GPIO write failed"));
  54. return STATUS_ADAPTER_HARDWARE_ERROR;
  55. }
  56. // ((CVSB1Demod *)(m_pDemod))->InitVSB();
  57. m_pDemod->InitVSB();
  58. }
  59. else if(m_BoardInfo.uiBoardID == BOARD_CATALINA)
  60. {
  61. ucValue = m_ucModeInit;
  62. // To reset VSB, pull Miscellaneous register bit 1 low,
  63. // then high and then low again
  64. // Some boards have resets going from 0 to 1 to 0
  65. // and others have 1 to 0 to 1
  66. // Bit 1 = 0
  67. // For old board
  68. #if 0
  69. ucValue &= ~CATALINA_HARDWARE_RESET;
  70. if(!m_pI2CScript->WriteSeq(CATALINA_MISC_CONTROL_REGISTER, &ucValue, 1))
  71. return STATUS_ADAPTER_HARDWARE_ERROR;
  72. // 10ms delay
  73. Delay(10000);
  74. // Bit 1 = 1
  75. #endif
  76. ucValue |= CATALINA_HARDWARE_RESET;
  77. if(!m_pI2CScript->WriteSeq(CATALINA_MISC_CONTROL_REGISTER, &ucValue, 1))
  78. return STATUS_ADAPTER_HARDWARE_ERROR;
  79. // 50ms delay
  80. Delay(500000);
  81. // Bit 1 = 0
  82. ucValue &= ~CATALINA_HARDWARE_RESET;
  83. if(!m_pI2CScript->WriteSeq(CATALINA_MISC_CONTROL_REGISTER, &ucValue, 1))
  84. return STATUS_ADAPTER_HARDWARE_ERROR;
  85. // 50ms delay
  86. Delay(500000);
  87. #if 1
  88. ucValue |= CATALINA_HARDWARE_RESET;
  89. if(!m_pI2CScript->WriteSeq(CATALINA_MISC_CONTROL_REGISTER, &ucValue, 1))
  90. return STATUS_ADAPTER_HARDWARE_ERROR;
  91. // 50ms delay
  92. Delay(500000);
  93. #endif
  94. m_ucModeInit = ucValue;
  95. // Initialize VSB2 chip
  96. // ((CVSB2Demod *)(m_pDemod))->InitVSB();
  97. m_pDemod->InitVSB();
  98. }
  99. else
  100. {
  101. // For boards that don't support Hardware reset, just initialize the
  102. // chip
  103. m_pDemod->InitVSB();
  104. // _DbgPrintF( DEBUGLVL_ERROR,("CReceiverFE::VsbReset: Invalid Board ID"));
  105. // return FALSE;
  106. }
  107. }
  108. else
  109. {
  110. if ((m_BoardInfo.uiVsbChipVersion >> 8)== VSB1)
  111. {
  112. if(!m_pDemod->SoftwareReset(uiReset))
  113. return STATUS_ADAPTER_HARDWARE_ERROR;
  114. }
  115. else if((m_BoardInfo.uiVsbChipVersion >> 8) == VSB2)
  116. {
  117. if(!m_pDemod->SoftwareReset(uiReset))
  118. return STATUS_ADAPTER_HARDWARE_ERROR;
  119. }
  120. else
  121. {
  122. _DbgPrintF( DEBUGLVL_ERROR,("CReceiverFE::VsbReset: Invalid VSB Chip version"));
  123. return STATUS_INVALID_PARAMETER;
  124. }
  125. // if(!m_pDemod->SoftwareReset(uiReset))
  126. // return FALSE;
  127. }
  128. // delay for 50 ms
  129. Delay(50000);
  130. return STATUS_SUCCESS;
  131. }
  132. /*
  133. * SetVsbCapabilities()
  134. * Inputs: PKSPROPERTY_VSB_CAP_S p_Caps - pointer to VSB capability structure
  135. * Outputs:
  136. * Return: BOOL: returns TRUE, if the operation succeeds else FALSE
  137. * Description: Sets the VSB capabilities (VSB demodulator scheme - VSB-16 or
  138. * VSB-8), VSB version, modes of operation .
  139. * Author : MM
  140. */
  141. NTSTATUS CDevice::SetVsbCapabilities(PKSPROPERTY_VSB_CAP_S p_Caps)
  142. {
  143. return SetBoard(p_Caps->BoardID);
  144. }
  145. /*
  146. * GetVsbCapabilities()
  147. * Inputs: PKSPROPERTY_VSB_CAP_S p_Caps - pointer to VSB capability structure
  148. * Outputs: Filled p_Caps
  149. * Return: BOOL: returns TRUE, if the operation succeeds else FALSE
  150. * Description: Gets the VSB capabilities (VSB demodulator scheme - VSB-16 or
  151. * VSB-8), VSB version, modes of operation .
  152. * Author : MM
  153. */
  154. NTSTATUS CDevice::GetVsbCapabilities(PKSPROPERTY_VSB_CAP_S p_Caps)
  155. {
  156. p_Caps->ChipVersion = (VSBCHIPTYPE)(m_BoardInfo.uiVsbChipVersion);
  157. p_Caps->Modulation = VSB8;
  158. p_Caps->BoardID = m_BoardInfo.uiBoardID;
  159. return STATUS_SUCCESS;
  160. }
  161. /*
  162. * AccessRegisterList()
  163. * Inputs: PKSPROPERTY_VSB_REG_CTRL_S p_VsbCoeff - pointer to register
  164. * control property set structure
  165. * UINT uiOperation - Operation (Read or Write)
  166. * Outputs:
  167. * Return: NTSTATUS:
  168. * Description: Based on the operataion requested , Reads/Writes the registers
  169. *
  170. * Author : MM
  171. */
  172. NTSTATUS CDevice::AccessRegisterList(PKSPROPERTY_VSB_REG_CTRL_S p_RegCtrl,
  173. UINT uiOperation)
  174. {
  175. RegisterType *p_Registers;
  176. UINT uiResult = WDMMINI_NOERROR;
  177. // Allocate memory for registers
  178. p_Registers = (RegisterType *)(AllocateFixedMemory(sizeof(RegisterType) *
  179. p_RegCtrl->NumRegisters));
  180. if (p_Registers == NULL)
  181. return STATUS_NO_MEMORY;
  182. // Create a RegisterType array
  183. UINT uiLength = 0;
  184. for (UINT i = 0; i < p_RegCtrl->NumRegisters; i++)
  185. {
  186. p_Registers[i].uiAddress = p_RegCtrl->RegisterList[i].Address;
  187. p_Registers[i].uiLength = p_RegCtrl->RegisterList[i].Length;
  188. p_Registers[i].p_ucBuffer = &p_RegCtrl->Buffer[uiLength];
  189. uiLength += p_RegCtrl->RegisterList[i].Length;
  190. }
  191. if(uiOperation == WRITE_REGISTERS)
  192. {
  193. // Set the registers in chip
  194. uiResult = SetRegisterList(p_Registers, i);
  195. }
  196. else
  197. {
  198. // Get the registers in chip
  199. uiResult = GetRegisterList(p_Registers, i, p_RegCtrl->RegisterType);
  200. }
  201. // Free memory
  202. FreeFixedMemory(p_Registers);
  203. return MapErrorToNTSTATUS(uiResult);
  204. }
  205. /*
  206. * AccessVsbCoeffList()
  207. * Inputs: PKSPROPERTY_VSB_COEFF_CTRL_S p_VsbCoeff - pointer to register
  208. * coefficient property set structure
  209. * UINT uiOperation - Operation (Read or Write)
  210. * Outputs:
  211. * Return: BOOL: returns TRUE, if the operation succeeds else FALSE
  212. * Description: Based on the operataion requested , Reads/Writes the coefficients
  213. * and puts them into the buffer
  214. * Author : MM
  215. */
  216. NTSTATUS CDevice::AccessVsbCoeffList(PKSPROPERTY_VSB_COEFF_CTRL_S p_VsbCoeff,
  217. UINT uiOperation)
  218. {
  219. VsbCoeffType VsbCoeff[4];
  220. UINT i = 0;
  221. UINT uiLength = 0;
  222. UINT uiResult ;
  223. for(i = 0; i < p_VsbCoeff->NumRegisters; i++)
  224. {
  225. VsbCoeff[i].uiID = p_VsbCoeff->CoeffList[i].ID;
  226. if(!m_pDemod->CoeffIDToAddress(p_VsbCoeff->CoeffList[i].ID,
  227. &VsbCoeff[i].uiAddress, uiOperation))
  228. return STATUS_INVALID_PARAMETER;
  229. VsbCoeff[i].uiLength = p_VsbCoeff->CoeffList[i].Length;
  230. VsbCoeff[i].p_ucBuffer = &p_VsbCoeff->Buffer[uiLength];
  231. uiLength += VsbCoeff[i].uiLength;
  232. }
  233. if(uiOperation == WRITE_REGISTERS)
  234. {
  235. uiResult = m_pDemod->SetCoeff(VsbCoeff, i);
  236. }
  237. else
  238. {
  239. uiResult = m_pDemod->GetCoeff(VsbCoeff, i);
  240. }
  241. return MapErrorToNTSTATUS(uiResult);
  242. }
  243. /*
  244. * SetVsbDiagMode()
  245. * Inputs: ULONG ulOperationMode - Operation mode (Diagnostic/Normal)
  246. * ULONG ulType - Diagnostic type (valid only when Operation mode is Diagnostic
  247. * Outputs:
  248. * Return: BOOL: returns TRUE, if the operation succeeds else FALSE
  249. * Description: Sets the output to diagnostic or data(normal) mode
  250. * Called in response to property ID KSPROPERTY_VSB_DIAG_CTRL by SetProperty().
  251. * Author : Mini
  252. */
  253. NTSTATUS CDevice::SetVsbDiagMode(ULONG ulOperationMode, VSBDIAGTYPE ulType)
  254. {
  255. BOOL bResult = TRUE;
  256. UCHAR ucPin, ucValue;
  257. // VSB1 does not support Diagnostic streaming
  258. if((m_BoardInfo.uiVsbChipVersion >> 8)== VSB1)
  259. return STATUS_NOT_IMPLEMENTED;
  260. // If the mode is NTSC, then don't put changes into effect. These will come into
  261. // effect next time we swith to ATSC mode
  262. ULONG ulTunerMode;
  263. m_pTuner->GetMode(&ulTunerMode);
  264. if(ulTunerMode == KSPROPERTY_TUNER_MODE_TV)
  265. {
  266. if(ulOperationMode == VSB_OPERATION_MODE_DATA)
  267. m_uiOutputMode = VSB_OUTPUT_MODE_NORMAL;
  268. else
  269. {
  270. m_uiOutputMode = VSB_OUTPUT_MODE_DIAGNOSTIC;
  271. // Based on type passed, set the diagnostic type in the chip
  272. if(!m_pDemod->SetDiagMode(ulType))
  273. return STATUS_UNSUCCESSFUL;
  274. }
  275. return STATUS_SUCCESS;
  276. }
  277. if(ulOperationMode == VSB_OPERATION_MODE_DATA)
  278. {
  279. m_uiOutputMode = VSB_OUTPUT_MODE_NORMAL;
  280. // Set VSB output mode to normal mode
  281. if(!m_pDemod->SetOutputMode(VSB_OUTPUT_MODE_NORMAL))
  282. return STATUS_UNSUCCESSFUL;
  283. if(m_BoardInfo.uiBoardID == BOARD_CATALINA)
  284. {
  285. // Set mode bits (bits 7 - 5 corresponding to bits Mode1 Mode0 Mode2) to 000
  286. ucValue = m_ucModeInit;
  287. ucValue &= 0x1F;
  288. m_pI2CScript->WriteSeq(CATALINA_MISC_CONTROL_REGISTER, &ucValue, 1);
  289. m_ucModeInit = ucValue;
  290. }
  291. else{}
  292. }
  293. else if(ulOperationMode == VSB_OPERATION_MODE_DIAG)
  294. {
  295. m_uiOutputMode = VSB_OUTPUT_MODE_DIAGNOSTIC;
  296. // Set VSB output mode to diagnostic mode
  297. if(!m_pDemod->SetOutputMode(VSB_OUTPUT_MODE_DIAGNOSTIC))
  298. return STATUS_UNSUCCESSFUL;
  299. // Based on type passed, set the diagnostic type in the chip
  300. if(!m_pDemod->SetDiagMode(ulType))
  301. return STATUS_UNSUCCESSFUL;
  302. ULONG ulDiagRate = m_pDemod->GetDiagSpeed(ulType);
  303. if(m_BoardInfo.uiBoardID == BOARD_CATALINA)
  304. {
  305. // Set mode bits (bits 7 - 5 corresponding to bits Mode1 Mode0 Mode2)
  306. // to 100
  307. ucValue = m_ucModeInit;
  308. ucValue &= 0x1F;
  309. ucValue |= 0x80;
  310. m_pI2CScript->WriteSeq(CATALINA_MISC_CONTROL_REGISTER, &ucValue, 1);
  311. m_ucModeInit = ucValue;
  312. // MM; Commented out now. Once I find a way of sending IRPs to apture driver,
  313. //this can be restored
  314. // SendCurrentDiagInfo(ulDiagRate, DIAG_FIELD);
  315. }
  316. else{}
  317. }
  318. else
  319. {
  320. // Invalid operation
  321. _DbgPrintF( DEBUGLVL_ERROR,("CReceiverFE::VsbReset: Invalid Option"));
  322. return STATUS_INVALID_PARAMETER;
  323. }
  324. return STATUS_SUCCESS;
  325. }
  326. /*
  327. * GetVsbDiagMode()
  328. * Inputs: ULONG *p_ulOperationMode - pointer to Operation mode (Diagnostic/Normal)
  329. * ULONG *p_ulType - pointer to Diagnostic type (valid only when Operation mode is Diagnostic
  330. * Outputs: Operation mode and diagnostic type
  331. * Return: NTSTATUS: returns STATUS_SUCCESS, if the operation succeeds
  332. * STATUS_NOT_IMPLEMENTED if its VSB2
  333. * STATUS_UNSUCCESSFUL if the operation didn't succeed
  334. * Description: Gets the diagnostic type and diagnostic or data(normal) mode
  335. * Author : MM
  336. */
  337. NTSTATUS CDevice::GetVsbDiagMode(ULONG *p_ulOperationMode, ULONG *p_ulType)
  338. {
  339. UINT uiOutputMode;
  340. // VSB1 does not support Diagnostic streaming
  341. if((m_BoardInfo.uiVsbChipVersion >> 8) == VSB1)
  342. return STATUS_NOT_IMPLEMENTED;
  343. if(!m_pDemod->GetOutputMode(&uiOutputMode))
  344. return STATUS_UNSUCCESSFUL;
  345. if(!m_pDemod->GetDiagMode(p_ulType))
  346. return STATUS_UNSUCCESSFUL;
  347. if(uiOutputMode == VSB_OUTPUT_MODE_DIAGNOSTIC)
  348. *p_ulOperationMode = VSB_OPERATION_MODE_DIAG;
  349. else if(uiOutputMode == VSB_OUTPUT_MODE_NORMAL)
  350. *p_ulOperationMode = VSB_OPERATION_MODE_DATA;
  351. else
  352. *p_ulOperationMode = VSB_OPERATION_MODE_INVALID;
  353. return STATUS_SUCCESS;
  354. }
  355. /*
  356. * VsbQuality()
  357. * Inputs: UINT quality
  358. * Outputs:
  359. * Return: NTSTATUS: returns STATUS_SUCCESS, if the operation succeeds
  360. * else STATUS_NOT_IMPLEMENTED if its VSB2
  361. * Description: Enables/Disables quality check and improvement routines. Currently
  362. * it only enables or disables chip hang in VSB1. But can be extended later if necessary
  363. * Author : MM
  364. */
  365. NTSTATUS CDevice::VsbQuality(UINT uiQu)
  366. {
  367. // This property set is only supported for VSB1
  368. if ((m_BoardInfo.uiVsbChipVersion >> 8) == VSB1)
  369. {
  370. if(uiQu & VSB_HANG_CHECK_ENABLE)
  371. m_bHangCheckFlag = TRUE;
  372. else
  373. m_bHangCheckFlag = FALSE;
  374. return STATUS_SUCCESS;
  375. }
  376. else
  377. return STATUS_NOT_IMPLEMENTED;
  378. }
  379. /*
  380. * SetRegList()
  381. * Inputs: RegListType *p_Registers - pointer to register list structure
  382. * UINT uiNumRegisters : number of registers
  383. * Outputs:
  384. * Return: BOOL: returns TRUE, if the operation succeeds else FALSE
  385. * Description: Writes to registers with the values given in the list.
  386. * Called in response to property ID KSPROPERTY_VSB_ REG_CTRL by SetProperty().
  387. * Author : Mini
  388. */
  389. UINT CDevice::SetRegisterList(RegisterType *p_Registers, UINT uiNumRegisters)
  390. {
  391. return (m_pDemod->SetRegisterList(p_Registers, uiNumRegisters));
  392. }
  393. /*
  394. * GetRegList()
  395. * Inputs: RegListType *p_reg - pointer to register list structure
  396. * UINT uiNumRegisters : number of registers
  397. * UINT uiRegisterType : Type of Regsiter (Control or Status)
  398. * Outputs: Filled p_reg
  399. * Return: BOOL: returns TRUE, if the operation succeeds else FALSE
  400. * Description: Reads from registers given in the list and fills their values back
  401. * into the list. This is a shadow operation as the control registers cannot be
  402. * read.
  403. * Called in response to property ID KSPROPERTY_VSB_REG_CTRL by GetProperty().
  404. * Author : Mini
  405. */
  406. UINT CDevice::GetRegisterList(RegisterType *p_Registers, UINT uiNumRegisters,
  407. UINT uiRegisterType)
  408. {
  409. return (m_pDemod->GetRegisterList(p_Registers, uiNumRegisters, uiRegisterType));
  410. }
  411. /*
  412. * MapErrorToNTSTATUS()
  413. * Maps the WDMMINI error code to NTSTATUS status code
  414. */
  415. NTSTATUS CDevice::MapErrorToNTSTATUS(UINT uiErr)
  416. {
  417. if(uiErr == WDMMINI_NOERROR)
  418. return STATUS_SUCCESS;
  419. else if((uiErr == WDMMINI_HARDWAREFAILURE) ||
  420. (uiErr == WDMMINI_NOHARDWARE) ||
  421. (uiErr == WDMMINI_ERROR_NOI2CPROVIDER) ||
  422. (uiErr == WDMMINI_ERROR_NOGPIOPROVIDER) ||
  423. (uiErr == WDMMINI_UNKNOWNHARDWARE))
  424. return STATUS_ADAPTER_HARDWARE_ERROR;
  425. else if(uiErr == WDMMINI_INVALIDPARAM)
  426. return STATUS_INVALID_PARAMETER;
  427. else if(uiErr == WDMMINI_ERROR_MEMORYALLOCATION)
  428. return STATUS_NO_MEMORY;
  429. else if(uiErr == WDMMINI_ERROR_REGISTRY)
  430. return STATUS_NO_MATCH;
  431. else
  432. return STATUS_UNSUCCESSFUL;
  433. }