Leaked source code of windows server 2003
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.

272 lines
7.3 KiB

  1. //==========================================================================;
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright (c) 1992 - 1996 Microsoft Corporation. All Rights Reserved.
  9. //
  10. //==========================================================================;
  11. extern "C"
  12. {
  13. #include "strmini.h"
  14. #include "ksmedia.h"
  15. #include "wdmdebug.h"
  16. }
  17. #include "wdmdrv.h"
  18. #include "atitunep.h"
  19. #include "aticonfg.h"
  20. #include "tunerhdw.h"
  21. /*^^*
  22. * GetTunerPLLOffsetBusyStatus()
  23. * Purpose : Returns tuner Busy status and PLLOffset, if the tuner is not busy
  24. * The function reads the hardware in order to accomplish the task
  25. * The operation might be carried on either synchronously or asynchronously
  26. * Inputs : PLONG plPLLOffset : a pointer to write a PLLOffset value
  27. * PBOOL pbBusyStatus : a pointer to write a Busy status
  28. *
  29. * Outputs : BOOL : returns TRUE, if the operation succeded
  30. * Author : IKLEBANOV
  31. *^^*/
  32. BOOL CATIWDMTuner::GetTunerPLLOffsetBusyStatus( PLONG plPLLOffset, PBOOL pbBusyStatus)
  33. {
  34. UCHAR uchI2CValue;
  35. I2CPacket i2cPacket;
  36. BOOL bResult;
  37. i2cPacket.uchChipAddress = m_uchTunerI2CAddress;
  38. i2cPacket.cbReadCount = 1;
  39. i2cPacket.cbWriteCount = 0;
  40. i2cPacket.puchReadBuffer = &uchI2CValue;
  41. i2cPacket.puchWriteBuffer = NULL;
  42. i2cPacket.usFlags = 0;
  43. bResult = m_pI2CScript->PerformI2CPacketOperation( &i2cPacket);
  44. if( bResult)
  45. bResult = ( i2cPacket.uchI2CResult == I2C_STATUS_NOERROR);
  46. if( bResult)
  47. {
  48. * pbBusyStatus = !(( BOOL)( uchI2CValue & 0x40)); // bit 6 - PLL locked indicator
  49. if( !( * pbBusyStatus))
  50. {
  51. uchI2CValue &= 0x07; // only 3 LSBits are PLLOffset
  52. // let's map the result into MS defined values from -2 to 2
  53. * plPLLOffset = uchI2CValue - 2;
  54. }
  55. }
  56. return( bResult);
  57. }
  58. /*^^*
  59. * SetTunerMode()
  60. * Purpose : Sets one of the possible Tuner modes to operate
  61. * Inputs : ULONG ulModeToSet : an operation mode required to be set
  62. *
  63. * Outputs : BOOL : returns TRUE, if the operation succeded
  64. * Author : IKLEBANOV
  65. *^^*/
  66. BOOL CATIWDMTuner::SetTunerMode( ULONG ulModeToSet)
  67. {
  68. return( TRUE);
  69. }
  70. /*^^*
  71. * SetTunerVideoStandard()
  72. * Purpose : Sets one of the possible Tuner standards as an active one
  73. * Inputs : ULONG ulStandard : a standard required to be set
  74. *
  75. * Outputs : BOOL : returns TRUE, if the operation succeded
  76. * Author : IKLEBANOV
  77. *^^*/
  78. BOOL CATIWDMTuner::SetTunerVideoStandard( ULONG ulStandard)
  79. {
  80. return( TRUE);
  81. }
  82. /*^^*
  83. * SetTunerFrequency()
  84. * Purpose : Sets a new Tuner frequency
  85. * The operation might be carried on either synchronously or asynchronously
  86. * Inputs : ULONG ulFrequency : a frequency required to be set
  87. *
  88. * Outputs : BOOL : returns TRUE, if the operation succeded
  89. * Author : IKLEBANOV
  90. *^^*/
  91. BOOL CATIWDMTuner::SetTunerFrequency( ULONG ulFrequency)
  92. {
  93. ULONG ulFrequenceDivider;
  94. USHORT usControlCode;
  95. UCHAR auchI2CBuffer[4];
  96. I2CPacket i2cPacket;
  97. BOOL bResult;
  98. ASSERT( m_ulIntermediateFrequency != 0L);
  99. // Set the video carrier frequency by controlling the programmable divider
  100. // N = ( 16 * ( FreqRF + FreqIntermediate)) / 1000000
  101. ulFrequenceDivider = ( ulFrequency + m_ulIntermediateFrequency);
  102. ulFrequenceDivider /= ( 1000000 / 16);
  103. usControlCode = GetTunerControlCode( ulFrequenceDivider);
  104. if( !usControlCode)
  105. return( FALSE);
  106. auchI2CBuffer[0] = ( UCHAR)( ulFrequenceDivider >> 8);
  107. auchI2CBuffer[1] = ( UCHAR)ulFrequenceDivider;
  108. auchI2CBuffer[2] = ( UCHAR)( usControlCode >> 8);
  109. auchI2CBuffer[3] = ( UCHAR)usControlCode;
  110. i2cPacket.uchChipAddress = m_uchTunerI2CAddress;
  111. i2cPacket.cbReadCount = 0;
  112. i2cPacket.cbWriteCount = 4;
  113. i2cPacket.puchReadBuffer = NULL;
  114. i2cPacket.puchWriteBuffer = auchI2CBuffer;
  115. i2cPacket.usFlags = 0;
  116. bResult = m_pI2CScript->PerformI2CPacketOperation( &i2cPacket);
  117. if( bResult)
  118. bResult = ( i2cPacket.uchI2CResult == I2C_STATUS_NOERROR) ? TRUE : FALSE;
  119. return( bResult);
  120. }
  121. /*^^*
  122. * SetTunerInput()
  123. * Purpose : Sets one of the possible Tuner inputs as an active one
  124. * Inputs : ULONG nInput : input number required to be set as an active ( begins from 0)
  125. *
  126. * Outputs : BOOL : returns TRUE, if the operation succeded
  127. * Author : IKLEBANOV
  128. *^^*/
  129. BOOL CATIWDMTuner::SetTunerInput( ULONG nInput)
  130. {
  131. // no real things to do at all
  132. return( TRUE);
  133. }
  134. /*^^*
  135. * GetTunerControlCode()
  136. * Purpose : Determines the Tuner control code to be send to tuner with a new frequency value
  137. *
  138. * Inputs : ULONG ulFrequencyDivider : new frequency divider
  139. *
  140. * Outputs : USHORT : value, the tuner should be programmed, when the new frequency is set
  141. * id the is no valid uiTunerId is passed as paramter, 0 is returned
  142. * Author : IKLEBANOV
  143. *^^*/
  144. USHORT CATIWDMTuner::GetTunerControlCode( ULONG ulFrequencyDivider)
  145. {
  146. USHORT usLowBandFrequencyHigh, usMiddleBandFrequencyHigh;
  147. USHORT usLowBandControl, usMiddleBandControl, usHighBandControl;
  148. USHORT usControlCode = 0;
  149. usLowBandFrequencyHigh = kUpperLowBand;
  150. usMiddleBandFrequencyHigh = kUpperMidBand;
  151. usLowBandControl = kLowBand;
  152. usMiddleBandControl = kMidBand;
  153. usHighBandControl = kHighBand;
  154. switch( m_uiTunerId)
  155. {
  156. case 0x01 : // NTSC N/A
  157. case 0x02 : // NTSC Japan
  158. case 0x06 : // NTSC Japan Philips MK2, PAL
  159. // these tuners support NTSC standard
  160. if(( m_ulVideoStandard == KS_AnalogVideo_NTSC_M) &&
  161. (( ulFrequencyDivider == kAirChannel63) ||
  162. ( ulFrequencyDivider == kAirChannel64)))
  163. {
  164. // special case for TEMIC tuner
  165. return( kTemicControl);
  166. }
  167. break;
  168. case 0x08 : // FM Tuner
  169. usLowBandControl = kLowBand_NTSC_FM;
  170. usMiddleBandControl = kMidBand_NTSC_FM;
  171. usHighBandControl = kHighBand_NTSC_FM;
  172. break;
  173. case 0x03 : // PAL B/G
  174. case 0x04 : // PAL I
  175. break;
  176. case 0x05 : // SECAM & PAL B/G
  177. if ( m_ulVideoStandard == KS_AnalogVideo_SECAM_L)
  178. {
  179. usLowBandFrequencyHigh = kUpperLowBand_SECAM;
  180. usMiddleBandFrequencyHigh = kUpperMidBand_SECAM;
  181. usLowBandControl = kLowBand_SECAM;
  182. usMiddleBandControl = kMidBand_SECAM;
  183. usHighBandControl = kHighBand_SECAM;
  184. }
  185. else
  186. {
  187. usLowBandControl = kLowBand_PALBG;
  188. usMiddleBandControl = kMidBand_PALBG;
  189. usHighBandControl = kHighBand_PALBG;
  190. }
  191. break;
  192. case 0x07 : // PAL D China
  193. usLowBandFrequencyHigh = kUpperLowBand_PALD;
  194. usMiddleBandFrequencyHigh = kUpperMidBand_PALD;
  195. break;
  196. case 0x10: // NTSC NA Alps Tuner
  197. case 0x11:
  198. case 0x12:
  199. usLowBandFrequencyHigh = kUpperLowBand_ALPS;
  200. usMiddleBandFrequencyHigh = kUpperMidBand_ALPS;
  201. usLowBandControl = kLowBand_ALPS;
  202. usMiddleBandControl = kMidBand_ALPS;
  203. usHighBandControl = kHighBand_ALPS;
  204. break;
  205. case 0x0D: // PAL B/G + PAL/I + PAL D + SECAM D/K
  206. break;
  207. default :
  208. return( usControlCode);
  209. }
  210. if( ulFrequencyDivider <= ( ULONG)usLowBandFrequencyHigh)
  211. usControlCode = usLowBandControl;
  212. else
  213. {
  214. if( ulFrequencyDivider <= ( ULONG)usMiddleBandFrequencyHigh)
  215. usControlCode = usMiddleBandControl;
  216. else
  217. usControlCode = usHighBandControl;
  218. }
  219. return( usControlCode);
  220. }