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.

919 lines
24 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. device.cpp
  5. Abstract:
  6. Device driver core, initialization, etc.
  7. --*/
  8. #define KSDEBUG_INIT
  9. #include "PhilTune.h"
  10. #include "wdmdebug.h"
  11. #ifdef ALLOC_DATA_PRAGMA
  12. #pragma const_seg("PAGECONST")
  13. #endif // ALLOC_DATA_PRAGMA
  14. #ifdef ALLOC_PRAGMA
  15. #pragma code_seg("PAGE")
  16. #endif // ALLOC_PRAGMA
  17. extern "C"
  18. NTSTATUS
  19. DriverEntry(
  20. IN PDRIVER_OBJECT DriverObject,
  21. IN PUNICODE_STRING RegistryPathName
  22. )
  23. /*++
  24. Routine Description:
  25. Sets up the driver object.
  26. Arguments:
  27. DriverObject -
  28. Driver object for this instance.
  29. RegistryPathName -
  30. Contains the registry path which was used to load this instance.
  31. Return Values:
  32. Returns STATUS_SUCCESS if the driver was initialized.
  33. --*/
  34. {
  35. NTSTATUS Status = STATUS_SUCCESS;
  36. _DbgPrintF(DEBUGLVL_VERBOSE,("DriverEntry"));
  37. // DEBUG_BREAK;
  38. Status = KsInitializeDriver( DriverObject,
  39. RegistryPathName,
  40. &DeviceDescriptor);
  41. // DEBUG_BREAK;
  42. return Status;
  43. }
  44. STDMETHODIMP_(NTSTATUS)
  45. CDevice::
  46. Create(
  47. IN PKSDEVICE Device
  48. )
  49. {
  50. NTSTATUS Status = STATUS_SUCCESS;
  51. CDevice * pDevice = NULL;
  52. // DEBUG_BREAK;
  53. _DbgPrintF(DEBUGLVL_VERBOSE,("CDevice::Create"));
  54. ASSERT(Device);
  55. // Allocate memory for the our device class.
  56. //
  57. pDevice = new(NonPagedPool,'IDsK') CDevice;
  58. if (pDevice)
  59. {
  60. Device->Context = pDevice;
  61. } else
  62. {
  63. Status = STATUS_INSUFFICIENT_RESOURCES;
  64. goto errExit;
  65. }
  66. // Point back to the KSDEVICE.
  67. //
  68. pDevice->m_pKSDevice = Device;
  69. pDevice->m_pDemod = NULL;
  70. pDevice->m_pTuner = NULL;
  71. errExit:
  72. return Status;
  73. }
  74. STDMETHODIMP_(NTSTATUS)
  75. CDevice::
  76. Start(
  77. IN PKSDEVICE pKSDevice,
  78. IN PIRP pIrp,
  79. IN PCM_RESOURCE_LIST pTranslatedResourceList OPTIONAL,
  80. IN PCM_RESOURCE_LIST pUntranslatedResourceList OPTIONAL
  81. )
  82. {
  83. NTSTATUS Status = STATUS_SUCCESS;
  84. CDevice * pDevice;
  85. PDEVICE_OBJECT pPhysicalDeviceObject;
  86. CI2CScript * pI2CScript;
  87. CGpio * pCGpio;
  88. // DEBUG_BREAK;
  89. _DbgPrintF( DEBUGLVL_VERBOSE, ("CDevice::Start"));
  90. ASSERT( pKSDevice);
  91. // DEBUG_BREAK;
  92. pDevice = reinterpret_cast<CDevice *>(pKSDevice->Context);
  93. ASSERT(pDevice);
  94. pDevice->m_bHangCheckFlag = TRUE;
  95. pDevice->m_bQualityCheckActiveFlag = FALSE;
  96. pDevice->m_uiOutputMode = VSB_OUTPUT_MODE_NORMAL;
  97. // Delete any existing tuner and VSB objects
  98. if (pDevice->m_pTuner != NULL)
  99. {
  100. delete(pDevice->m_pTuner);
  101. pDevice->m_pTuner = NULL;
  102. }
  103. if (pDevice->m_pDemod != NULL)
  104. {
  105. // Create a demodulator object based on VSB chip type
  106. if((VSBCHIPTYPE)(pDevice->m_BoardInfo.uiVsbChipVersion >> 8) == VSB1)
  107. {
  108. CVSB1Demod *p_Demod = (CVSB1Demod *)(pDevice->m_pDemod);
  109. delete (p_Demod);
  110. }
  111. else
  112. {
  113. CVSB2Demod *p_Demod = (CVSB2Demod *)(pDevice->m_pDemod);
  114. delete (p_Demod);
  115. }
  116. pDevice->m_pDemod = NULL;
  117. }
  118. // Get the Device capabilities, etc, from the registry.
  119. //
  120. Status = pDevice->InitFromRegistry();
  121. // Get the GPIO interface on the parent device.
  122. //
  123. // The GPIO interface is used by a child device to control specific
  124. // pins on the parent PIO hardware. The tuner minidriver uses
  125. // PIO pins to control the mode of the tuner hardware and to reset
  126. // the tuner hardware.
  127. //
  128. pCGpio = (CGpio *) new(NonPagedPool,'oipG')
  129. CGpio( pKSDevice->PhysicalDeviceObject, &Status);
  130. if (Status != STATUS_SUCCESS)
  131. {
  132. _DbgPrintF( DEBUGLVL_ERROR, ("CGPIO creation failure."));
  133. goto errExit;
  134. }
  135. else
  136. _DbgPrintF( DEBUGLVL_VERBOSE, ("CGPIO created."));
  137. pDevice->m_pGpio = pCGpio;
  138. // Get the I2C interface on the parent device.
  139. //
  140. // The I2C interface is used by a child device to exchange data
  141. // with a chip on the parents I2C bus. The tuner minidriver uses
  142. // the I2C bus to set a frequency and control code on the RF
  143. // tuner device as well as to initialize the 8VSB decoder.
  144. //
  145. pI2CScript = (CI2CScript *) new(NonPagedPool,' C2I')
  146. CI2CScript( pKSDevice->PhysicalDeviceObject,
  147. &Status
  148. );
  149. if (Status != STATUS_SUCCESS)
  150. {
  151. _DbgPrintF( DEBUGLVL_ERROR, ("I2CScript creation failure."));
  152. goto errExit;
  153. }
  154. else if (!pI2CScript)
  155. {
  156. Status = STATUS_NO_MEMORY;
  157. _DbgPrintF( DEBUGLVL_ERROR, ("I2CScript creation failure."));
  158. goto errExit;
  159. }
  160. else
  161. _DbgPrintF( DEBUGLVL_VERBOSE, ("I2CScript created."));
  162. pDevice->m_pI2CScript = pI2CScript;
  163. // Set the board and initialize all required data structures pertaining
  164. // to the board
  165. Status = pDevice->SetBoard(pDevice->m_BoardInfo.uiBoardID);
  166. if (Status != STATUS_SUCCESS)
  167. {
  168. goto errExit;
  169. }
  170. /*
  171. // Initialize the tuner hardware.
  172. //
  173. Status = pDevice->Initialize();
  174. if (Status != STATUS_SUCCESS)
  175. {
  176. goto errExit;
  177. }
  178. */
  179. // Create the the Tuner Filter Factory. This factory is used to
  180. // create instances of the tuner filter.
  181. //
  182. Status = BdaCreateFilterFactory( pKSDevice,
  183. &InitialTunerFilterDescriptor,
  184. &TunerBdaFilterTemplate
  185. );
  186. if (!NT_SUCCESS(Status))
  187. {
  188. goto errExit;
  189. }
  190. errExit:
  191. return Status;
  192. }
  193. NTSTATUS
  194. CDevice::
  195. InitFromRegistry()
  196. {
  197. NTSTATUS Status = STATUS_SUCCESS;
  198. HANDLE hRegistry;
  199. UNICODE_STRING KeyName;
  200. ULONG rgulValueInfo[10];
  201. ULONG ulcbValueInfo;
  202. PKEY_VALUE_PARTIAL_INFORMATION pPartialValueInfo;
  203. PULONG pulData;
  204. ASSERT(KeGetCurrentIrql() <= PASSIVE_LEVEL);
  205. pPartialValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION) rgulValueInfo;
  206. pulData = (PULONG) pPartialValueInfo->Data;
  207. // Open the registry key for this device.
  208. //
  209. Status = IoOpenDeviceRegistryKey( m_pKSDevice->PhysicalDeviceObject,
  210. PLUGPLAY_REGKEY_DRIVER,
  211. STANDARD_RIGHTS_ALL,
  212. &hRegistry
  213. );
  214. if (!NT_SUCCESS( Status))
  215. {
  216. _DbgPrintF( DEBUGLVL_ERROR, ("Can't open device registry key."));
  217. return Status;
  218. }
  219. // Get the I2C address of the tuner chip.
  220. //
  221. RtlInitUnicodeString(&KeyName, L"TunerI2cAddress");
  222. Status = ZwQueryValueKey( hRegistry,
  223. &KeyName,
  224. KeyValuePartialInformation,
  225. (PVOID) rgulValueInfo,
  226. sizeof( rgulValueInfo),
  227. &ulcbValueInfo
  228. );
  229. if (!NT_SUCCESS( Status))
  230. {
  231. _DbgPrintF( DEBUGLVL_ERROR, ("Tuner I2C address is not in registry."));
  232. goto errExit;
  233. }
  234. ASSERT( ulcbValueInfo >= sizeof( KEY_VALUE_PARTIAL_INFORMATION));
  235. // Make sure the date is of the correct type.
  236. //
  237. if ( ( (pPartialValueInfo->Type != REG_DWORD)
  238. && (pPartialValueInfo->Type != REG_BINARY))
  239. || (pPartialValueInfo->DataLength != sizeof( DWORD))
  240. || (*pulData >= 256)
  241. )
  242. {
  243. _DbgPrintF( DEBUGLVL_ERROR, ("Invalid tuner I2C address in registry."));
  244. goto errExit;
  245. }
  246. m_BoardInfo.ucTunerAddress = (UCHAR) (*pulData);
  247. // Get the I2C address of the 8VSB demodulator chip.
  248. //
  249. // Get the I2C address of the tuner chip.
  250. //
  251. RtlInitUnicodeString(&KeyName, L"8VsbI2cAddress");
  252. Status = ZwQueryValueKey( hRegistry,
  253. &KeyName,
  254. KeyValuePartialInformation,
  255. (PVOID) rgulValueInfo,
  256. sizeof( rgulValueInfo),
  257. &ulcbValueInfo
  258. );
  259. if (!NT_SUCCESS( Status))
  260. {
  261. _DbgPrintF( DEBUGLVL_ERROR, ("8VSB I2C address is not in registry."));
  262. goto errExit;
  263. }
  264. ASSERT( ulcbValueInfo >= sizeof( KEY_VALUE_PARTIAL_INFORMATION));
  265. // Make sure the date is of the correct type.
  266. //
  267. if ( ( (pPartialValueInfo->Type != REG_DWORD)
  268. && (pPartialValueInfo->Type != REG_BINARY))
  269. || (pPartialValueInfo->DataLength != sizeof( DWORD))
  270. || (*pulData >= 256)
  271. )
  272. {
  273. _DbgPrintF( DEBUGLVL_ERROR, ("Invalid 8VSB I2C address in registry."));
  274. goto errExit;
  275. }
  276. m_BoardInfo.ucVsbAddress = (UCHAR) (*pulData);
  277. #ifdef NEVER
  278. // Get the I2C address of the parallel port.
  279. //
  280. RtlInitUnicodeString(&KeyName, L"ParallelPortI2cAddress");
  281. Status = ZwQueryValueKey( hRegistry,
  282. &KeyName,
  283. KeyValuePartialInformation,
  284. (PVOID) rgulValueInfo,
  285. sizeof( rgulValueInfo),
  286. &ulcbValueInfo
  287. );
  288. if (!NT_SUCCESS( Status))
  289. {
  290. _DbgPrintF( DEBUGLVL_ERROR, ("Parallel port I2C address is not in registry."));
  291. goto errExit;
  292. }
  293. ASSERT( ulcbValueInfo >= sizeof( KEY_VALUE_PARTIAL_INFORMATION));
  294. // Make sure the date is of the correct type.
  295. //
  296. if ( ( (pPartialValueInfo->Type != REG_DWORD)
  297. && (pPartialValueInfo->Type != REG_BINARY))
  298. || (pPartialValueInfo->DataLength != sizeof( DWORD))
  299. || (*pulData >= 256)
  300. )
  301. {
  302. _DbgPrintF( DEBUGLVL_ERROR, ("Invalid parallel port I2C address in registry."));
  303. goto errExit;
  304. }
  305. m_BoardInfo.ucParallelPortI2cAddress = (UCHAR) (*pulData);
  306. #endif // NEVER
  307. // Get the tuner type identifier.
  308. //
  309. RtlInitUnicodeString(&KeyName, L"TunerType");
  310. Status = ZwQueryValueKey( hRegistry,
  311. &KeyName,
  312. KeyValuePartialInformation,
  313. (PVOID) rgulValueInfo,
  314. sizeof( rgulValueInfo),
  315. &ulcbValueInfo
  316. );
  317. if (!NT_SUCCESS( Status))
  318. {
  319. _DbgPrintF( DEBUGLVL_ERROR, ("Tuner type is not in registry."));
  320. goto errExit;
  321. }
  322. ASSERT( ulcbValueInfo >= sizeof( KEY_VALUE_PARTIAL_INFORMATION));
  323. // Make sure the date is of the correct type.
  324. //
  325. if (pPartialValueInfo->Type != REG_SZ)
  326. {
  327. _DbgPrintF( DEBUGLVL_ERROR, ("Tuner type in registry is not REG_SZ."));
  328. goto errExit;
  329. }
  330. if((StringsEqual((PWCHAR)(pPartialValueInfo->Data), L"TD1536")))
  331. {
  332. m_BoardInfo.uiTunerID = TD1536;
  333. Status = STATUS_SUCCESS;
  334. }
  335. else
  336. {
  337. Status = STATUS_DEVICE_CONFIGURATION_ERROR ;
  338. _DbgPrintF( DEBUGLVL_ERROR, ("Unknown tuner type in registry."));
  339. goto errExit;
  340. }
  341. RtlInitUnicodeString(&KeyName, L"BoardType");
  342. Status = ZwQueryValueKey( hRegistry,
  343. &KeyName,
  344. KeyValuePartialInformation,
  345. (PVOID) rgulValueInfo,
  346. sizeof( rgulValueInfo),
  347. &ulcbValueInfo
  348. );
  349. if (!NT_SUCCESS( Status))
  350. {
  351. _DbgPrintF( DEBUGLVL_ERROR, ("Board type is not in registry."));
  352. goto errExit;
  353. }
  354. ASSERT( ulcbValueInfo >= sizeof( KEY_VALUE_PARTIAL_INFORMATION));
  355. //
  356. if ( ( (pPartialValueInfo->Type != REG_DWORD)
  357. && (pPartialValueInfo->Type != REG_BINARY))
  358. || (pPartialValueInfo->DataLength != sizeof( DWORD))
  359. )
  360. {
  361. _DbgPrintF( DEBUGLVL_ERROR, ("Invalid Board type in registry."));
  362. goto errExit;
  363. }
  364. m_BoardInfo.uiBoardID = (UINT)(*pulData);
  365. _DbgPrintF( DEBUGLVL_VERBOSE, ("CDevice: Board ID = %d", m_BoardInfo.uiBoardID));
  366. errExit:
  367. ZwClose( hRegistry);
  368. return Status;
  369. }
  370. NTSTATUS
  371. CDevice::
  372. GetRegistryULONG( PWCHAR pwcKeyName,
  373. PULONG pulValue
  374. )
  375. {
  376. NTSTATUS Status = STATUS_SUCCESS;
  377. HANDLE hRegistry;
  378. UNICODE_STRING KeyName;
  379. ULONG rgulValueInfo[10];
  380. ULONG ulcbValueInfo;
  381. PKEY_VALUE_PARTIAL_INFORMATION pPartialValueInfo;
  382. PULONG pulData;
  383. ASSERT(KeGetCurrentIrql() <= PASSIVE_LEVEL);
  384. pPartialValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION) rgulValueInfo;
  385. pulData = (PULONG) pPartialValueInfo->Data;
  386. // Open the registry key for this device.
  387. //
  388. Status = IoOpenDeviceRegistryKey( m_pKSDevice->PhysicalDeviceObject,
  389. PLUGPLAY_REGKEY_DRIVER,
  390. STANDARD_RIGHTS_ALL,
  391. &hRegistry
  392. );
  393. if (!NT_SUCCESS( Status))
  394. {
  395. _DbgPrintF( DEBUGLVL_ERROR, ("Can't open device registry key."));
  396. goto errExit;
  397. }
  398. // Get the registry entry.
  399. //
  400. RtlInitUnicodeString(&KeyName, pwcKeyName);
  401. Status = ZwQueryValueKey( hRegistry,
  402. &KeyName,
  403. KeyValuePartialInformation,
  404. (PVOID) rgulValueInfo,
  405. sizeof( rgulValueInfo),
  406. &ulcbValueInfo
  407. );
  408. if (!NT_SUCCESS( Status))
  409. {
  410. _DbgPrintF( DEBUGLVL_ERROR, ("Key is not in registry."));
  411. ZwClose( hRegistry);
  412. goto errExit;
  413. }
  414. ASSERT( ulcbValueInfo >= sizeof( KEY_VALUE_PARTIAL_INFORMATION));
  415. if ( ( (pPartialValueInfo->Type != REG_DWORD)
  416. && (pPartialValueInfo->Type != REG_BINARY))
  417. || (pPartialValueInfo->DataLength != sizeof( DWORD))
  418. )
  419. {
  420. _DbgPrintF( DEBUGLVL_ERROR, ("Invalid key value in registry."));
  421. ZwClose( hRegistry);
  422. goto errExit;
  423. }
  424. *pulValue = *pulData;
  425. ZwClose( hRegistry);
  426. errExit:
  427. return Status;
  428. }
  429. NTSTATUS
  430. CDevice::
  431. AcquireResources(
  432. PPHILIPS_TUNER_RESOURCE pNewTunerResource,
  433. PULONG pulAquiredResourceID
  434. )
  435. {
  436. NTSTATUS Status = STATUS_SUCCESS;
  437. TunerStatusType tunerStatus;
  438. VsbStatusType vsbStatus;
  439. //$Review - Add resource managment code here.
  440. //
  441. //Status = STATUS_RESOURCE_NOT_OWNED;
  442. // Only ATSC mode is supported for now. Just check that
  443. // ATSC mode is requested.
  444. //
  445. if (!IsEqualGUID( &pNewTunerResource->guidDemodulatorNode,
  446. &KSNODE_BDA_8VSB_DEMODULATOR)
  447. )
  448. {
  449. Status = STATUS_NOT_IMPLEMENTED;
  450. goto errExit;
  451. }
  452. // If we haven't yet set ATSC mode, then go ahead and set it.
  453. //
  454. if (!IsEqualGUID( &m_CurTunerResource.guidDemodulatorNode,
  455. &KSNODE_BDA_8VSB_DEMODULATOR)
  456. )
  457. {
  458. Status = SetTunerMode(KSPROPERTY_TUNER_MODE_ATSC);
  459. if (!NT_SUCCESS( Status))
  460. {
  461. goto errExit;
  462. }
  463. m_CurTunerResource.guidDemodulatorNode
  464. = KSNODE_BDA_8VSB_DEMODULATOR;
  465. }
  466. // Set a new tuner frequency if it is different.
  467. //
  468. if (pNewTunerResource->ulhzCarrierFrequency != m_CurTunerResource.ulhzCarrierFrequency)
  469. {
  470. m_CurTunerResource.ulhzCarrierFrequency
  471. = pNewTunerResource->ulhzCarrierFrequency;
  472. SetTunerFrequency( &m_CurTunerResource.ulhzCarrierFrequency);
  473. }
  474. // Get the Tuner and VSB status
  475. //
  476. GetTunerStatus(&tunerStatus);
  477. m_pDemod->GetStatus(&vsbStatus);
  478. errExit:
  479. return Status;
  480. }
  481. NTSTATUS
  482. CDevice::
  483. ReleaseResources(
  484. ULONG ulAquiredResourceID
  485. )
  486. {
  487. NTSTATUS Status = STATUS_SUCCESS;
  488. //$REVIEW - Put Resource management code here.
  489. return Status;
  490. }
  491. /*
  492. * SetBoard()
  493. */
  494. NTSTATUS CDevice::SetBoard(UINT uiBoardID)
  495. {
  496. NTSTATUS Status = STATUS_SUCCESS;
  497. if(uiBoardID == BOARD_CONEY)
  498. {
  499. // if IF type = 0, then the IF is not MPOC
  500. // else IF is MPOC
  501. m_BoardInfo.uiBoardID = uiBoardID;
  502. m_BoardInfo.uiIFStage = IF_OTHER;
  503. m_BoardInfo.uiVsbChipVersion = VSB1 << 8;
  504. m_BoardInfo.ulSupportedModes =
  505. KSPROPERTY_TUNER_MODE_TV | KSPROPERTY_TUNER_MODE_ATSC;
  506. m_BoardInfo.ulNumSupportedModes = 2;
  507. // m_ulNumberOfPins = 4;
  508. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice::Loading Coney Drivers\n"));
  509. }
  510. else if(uiBoardID == BOARD_CATALINA)
  511. {
  512. // if IF type = 0, then the IF is not MPOC
  513. // else IF is MPOC
  514. m_BoardInfo.uiBoardID = uiBoardID;
  515. m_BoardInfo.uiIFStage = IF_MPOC;
  516. m_BoardInfo.uiVsbChipVersion = VSB2 << 8;
  517. m_BoardInfo.ulSupportedModes =
  518. KSPROPERTY_TUNER_MODE_TV | KSPROPERTY_TUNER_MODE_ATSC;
  519. m_BoardInfo.ulNumSupportedModes = 2;
  520. // m_ulNumberOfPins = 4;
  521. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice::Loading Catalina Drivers\n"));
  522. }
  523. else if(uiBoardID == BOARD_CORONADO)
  524. {
  525. // if IF type = 0, then the IF is not MPOC
  526. // else IF is MPOC
  527. m_BoardInfo.uiBoardID = uiBoardID;
  528. m_BoardInfo.uiIFStage = IF_OTHER;
  529. m_BoardInfo.uiVsbChipVersion = VSB1 << 8;
  530. m_BoardInfo.ulSupportedModes =
  531. KSPROPERTY_TUNER_MODE_TV | KSPROPERTY_TUNER_MODE_ATSC;
  532. m_BoardInfo.ulNumSupportedModes = 2;
  533. // m_ulNumberOfPins = 4;
  534. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice::Loading Coronado Drivers\n"));
  535. }
  536. else if(uiBoardID == BOARD_CES)
  537. {
  538. // if IF type = 0, then the IF is not MPOC
  539. // else IF is MPOC
  540. m_BoardInfo.uiBoardID = uiBoardID;
  541. m_BoardInfo.uiIFStage = IF_OTHER;
  542. m_BoardInfo.uiVsbChipVersion = VSB1 << 8;
  543. m_BoardInfo.ulSupportedModes = KSPROPERTY_TUNER_MODE_ATSC;
  544. m_BoardInfo.ulNumSupportedModes = 1;
  545. // m_ulNumberOfPins = 4;
  546. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice::Loading CES Drivers\n"));
  547. }
  548. else if(uiBoardID == BOARD_CORFU)
  549. {
  550. // if IF type = 0, then the IF is not MPOC
  551. // else IF is MPOC
  552. m_BoardInfo.uiBoardID = uiBoardID;
  553. m_BoardInfo.uiIFStage = IF_OTHER;
  554. m_BoardInfo.uiVsbChipVersion = VSB2 << 8;
  555. m_BoardInfo.ulSupportedModes =
  556. KSPROPERTY_TUNER_MODE_ATSC;
  557. m_BoardInfo.ulNumSupportedModes = 1;
  558. // m_ulNumberOfPins = 4;
  559. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice::Loading Corfu Drivers\n"));
  560. }
  561. else
  562. {
  563. _DbgPrintF( DEBUGLVL_ERROR,("CDevice::Invalid Board ID\n"));
  564. Status = STATUS_DEVICE_CONFIGURATION_ERROR;
  565. goto errexit;
  566. }
  567. // Create a tuner object
  568. // m_pTuner = new CTuner(&m_I2CScript);
  569. m_pTuner = new(NonPagedPool,'Tune') CTuner(m_pI2CScript, &m_BoardInfo, &Status);
  570. if (!NT_SUCCESS( Status))
  571. {
  572. _DbgPrintF( DEBUGLVL_ERROR,("CDevice::Could not create Tuner Object\n"));
  573. goto errexit;
  574. }
  575. if (!m_pTuner)
  576. {
  577. Status = STATUS_NO_MEMORY;
  578. goto errexit;
  579. }
  580. // Create a demodulator object based on VSB chip type
  581. if((VSBCHIPTYPE)(m_BoardInfo.uiVsbChipVersion >> 8) == VSB1)
  582. // m_pDemod = (CVSBDemod *)(new CVSB1Demod(&m_I2CScript));
  583. m_pDemod = (CVSBDemod *)(new(NonPagedPool,'VSB1') CVSB1Demod(m_pI2CScript, &m_BoardInfo, &Status));
  584. else
  585. // m_pDemod = (CVSBDemod *)(new CVSB2Demod(&m_I2CScript));
  586. m_pDemod = (CVSBDemod *)(new(NonPagedPool,'VSB2')CVSB2Demod(m_pI2CScript, &m_BoardInfo, &Status));
  587. if (!NT_SUCCESS( Status))
  588. {
  589. _DbgPrintF( DEBUGLVL_ERROR,("CDevice::Could not create VSB Object\n"));
  590. goto errexit;
  591. }
  592. #if 0
  593. // Set tuner capabilities (RO properties) based upon the TunerId
  594. if(!m_pTuner->SetCapabilities(&m_BoardInfo))
  595. {
  596. // there is unsupported hardware was found
  597. Status = STATUS_ADAPTER_HARDWARE_ERROR;
  598. goto errexit;
  599. }
  600. #endif
  601. // If board initialize fails, don't return FALSE as this could affect
  602. // the non-PnP devices such as PP boards from loading. We would like these
  603. // Non PnP drivers to load and when the devices are attached to the PP,
  604. // we would like it to function as a pseudo PnP device.
  605. // Initialize the board
  606. BoardInitialize();
  607. m_bFirstEntry = TRUE;
  608. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice:SetBoard() ok\n"));
  609. errexit:
  610. return Status;
  611. }
  612. /*
  613. * BoardInitialize()
  614. * Purpose: Initialize the board
  615. *
  616. * Inputs :
  617. * Outputs: BOOL - FALSE if board initialization fails, else TRUE
  618. * Author : MM
  619. */
  620. NTSTATUS CDevice::BoardInitialize()
  621. {
  622. NTSTATUS Status = STATUS_SUCCESS;
  623. ULONG ulhzFrequency = 373250000;
  624. if(m_BoardInfo.uiIFStage == IF_MPOC)
  625. {
  626. // Get MPOC interface
  627. //GetIFInterface();
  628. Status = MpocInit();
  629. if (!NT_SUCCESS( Status))
  630. {
  631. _DbgPrintF( DEBUGLVL_ERROR,("CDevice::MPOC Initialization failure\n"));
  632. goto errexit;
  633. }
  634. Status = GetMpocVersion(&m_BoardInfo.uiMpocVersion);
  635. if (!NT_SUCCESS( Status))
  636. {
  637. _DbgPrintF( DEBUGLVL_ERROR,("CDevice::MPOC Version failure\n"));
  638. goto errexit;
  639. }
  640. }
  641. // Initialize mode register
  642. Status = ModeInit();
  643. if (!NT_SUCCESS( Status))
  644. {
  645. _DbgPrintF( DEBUGLVL_ERROR,("CDevice::Mode Initialization failure\n"));
  646. goto errexit;
  647. }
  648. // DO a VSB hardware reset
  649. Status = VsbReset(HARDWARE_RESET);
  650. if (!NT_SUCCESS( Status))
  651. {
  652. _DbgPrintF( DEBUGLVL_ERROR,("CDevice::Hardware reset failure\n"));
  653. goto errexit;
  654. }
  655. // DO a VSB software reset
  656. Status = VsbReset(VSB_INITIAL_RESET);
  657. if (!NT_SUCCESS( Status))
  658. {
  659. _DbgPrintF( DEBUGLVL_ERROR,("CDevice::Software reset failure\n"));
  660. goto errexit;
  661. }
  662. // Set TV System to NTSC
  663. Status = SetTunerMode(KSPROPERTY_TUNER_MODE_ATSC);
  664. if (!NT_SUCCESS( Status))
  665. {
  666. _DbgPrintF( DEBUGLVL_ERROR,("CDevice::TV System change failure\n"));
  667. goto errexit;
  668. }
  669. // Get the initial tuner frequency from the registry.
  670. // Set it to 37325000 if registry value is absent.
  671. //
  672. // ulhzFrequency = 615250000;
  673. // ulhzFrequency = 531250000;
  674. // ulhzFrequency = 307250000;
  675. //
  676. Status = GetRegistryULONG( L"InitialFrequency", &ulhzFrequency);
  677. // Set the intial frequency on the tuner.
  678. //
  679. Status = SetTunerFrequency( &ulhzFrequency);
  680. if (!NT_SUCCESS( Status))
  681. {
  682. _DbgPrintF( DEBUGLVL_ERROR,("CDevice::Channel change failure\n"));
  683. goto errexit;
  684. }
  685. if((m_BoardInfo.uiBoardID == BOARD_CATALINA) || (m_BoardInfo.uiBoardID == BOARD_CONEY))
  686. {
  687. #define BTSC_CONTROL_REGISTER 0xB6
  688. //Mini: Adding Initialization of BTSC decoder here so that it functions
  689. // 2/17/2000
  690. // BTSC decoder settings:
  691. // AVL Attack time = 420ohm
  692. // Normal load current
  693. // Automatic Volume control ON
  694. // No Mute
  695. // Stereo bit 0
  696. UCHAR ucDataWr = 0x4;
  697. m_pI2CScript->WriteSeq(BTSC_CONTROL_REGISTER, &ucDataWr, 1);
  698. }
  699. errexit:
  700. return Status;
  701. }
  702. UCHAR ConeyModeInitArray[1]=
  703. {
  704. 0x3F,
  705. };
  706. UCHAR CatalinaModeInitArray[1]=
  707. {
  708. 0x02,
  709. };
  710. /*
  711. * ModeInit()
  712. * Input
  713. * Output : TRUE - mode initialization succeeds
  714. * FALSE - if there is an I2C error & mode initialization fails
  715. * Description: Initialize mode register
  716. */
  717. NTSTATUS CDevice::ModeInit()
  718. {
  719. NTSTATUS Status = STATUS_SUCCESS;
  720. _DbgPrintF( DEBUGLVL_VERBOSE,("CDevice::ModeInit(): Inside\n"));
  721. if(m_BoardInfo.uiBoardID == BOARD_CONEY)
  722. {
  723. m_ucModeInit = ConeyModeInitArray[0];
  724. if(!m_pI2CScript->WriteSeq(CONEY_I2C_PARALLEL_PORT, ConeyModeInitArray,
  725. sizeof (ConeyModeInitArray)))
  726. Status = STATUS_ADAPTER_HARDWARE_ERROR;
  727. }
  728. else if (m_BoardInfo.uiBoardID == BOARD_CATALINA)
  729. {
  730. m_ucModeInit = CatalinaModeInitArray[0];
  731. // CATALINA specific initializations
  732. if(!m_pI2CScript->WriteSeq(CATALINA_MISC_CONTROL_REGISTER,
  733. CatalinaModeInitArray, sizeof (CatalinaModeInitArray)))
  734. Status = STATUS_ADAPTER_HARDWARE_ERROR;
  735. }
  736. else
  737. {
  738. }
  739. if (!NT_SUCCESS( Status))
  740. {
  741. _DbgPrintF( DEBUGLVL_ERROR,("CDevice: Demodulator Mode Init FAILED !!! ------------ \n"));
  742. }
  743. else
  744. {
  745. _DbgPrintF( DEBUGLVL_TERSE,("CDevice: Demodulator Mode Init PASSED !!! ------------ \n"));
  746. }
  747. return Status;
  748. }