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.

767 lines
17 KiB

  1. #include "common.h"
  2. #include "ksvsb.h"
  3. #include "i2script.h"
  4. #include "gpio.h"
  5. #include "tunerdef.h"
  6. #include "bdadebug.h"
  7. #include "wdmdrv.h"
  8. #include "mpoc.h"
  9. #include "util.h"
  10. #include "tuner.h"
  11. #include "vsb1.h"
  12. #include "vsb2.h"
  13. #define DYNAMIC_TOPOLOGY TRUE
  14. #define ANTENNA TRUE
  15. #define IsEqualGUID(rguid1, rguid2) (!memcmp(rguid1, rguid2, sizeof(GUID)))
  16. /**************************************************************/
  17. /* Driver Name - Change this to reflect your executable name! */
  18. /**************************************************************/
  19. #define MODULENAME "PhilTune"
  20. #define MODULENAMEUNICODE L"PhilTune"
  21. #define STR_MODULENAME MODULENAME
  22. // This defines the name of the WMI device that manages service IOCTLS
  23. #define DEVICENAME (L"\\\\.\\" MODULENAMEUNICODE)
  24. #define SYMBOLICNAME (L"\\DosDevices\\" MODULENAMEUNICODE)
  25. // This structure represents what the underlying device can do.
  26. //
  27. // Note - It is possible to set conflicting settings. In this case
  28. // it is the responsibilty of the CheckChanges code to return an
  29. // error. Only a self-consistent tuner resource should be submitted to
  30. // the underlying device.
  31. //
  32. typedef struct _PHILIPS_TUNER_RESOURCE
  33. {
  34. GUID guidDemodulatorNode;
  35. ULONG ulhzCarrierFrequency;// The channel frequency without
  36. // The IMFrequency added in.
  37. } PHILIPS_TUNER_RESOURCE, * PPHILIPS_TUNER_RESOURCE;
  38. #define MAX_FILTER_PINS 2
  39. typedef struct _PHILIPS_PIN_INFO
  40. {
  41. ULONG ulPinType;
  42. ULONG ulIdConnectedPin;
  43. } PHILIPS_PIN_INFO, * PPHILIPS_PIN_INFO;
  44. extern const KSDEVICE_DESCRIPTOR DeviceDescriptor;
  45. class CFilter {
  46. public:
  47. //
  48. // AVStream Filter Dispatch Functions
  49. //
  50. static
  51. STDMETHODIMP_(NTSTATUS)
  52. Create(
  53. IN OUT PKSFILTER Filter,
  54. IN PIRP Irp
  55. );
  56. static
  57. STDMETHODIMP_(NTSTATUS)
  58. FilterClose(
  59. IN OUT PKSFILTER Filter,
  60. IN PIRP Irp
  61. );
  62. static
  63. STDMETHODIMP
  64. Process(
  65. IN PKSFILTER Filter,
  66. IN PKSPROCESSPIN_INDEXENTRY ProcessPinsIndex
  67. );
  68. //
  69. // KSMETHODSETID_BdaChangeSync - Filter change sync methods
  70. //
  71. static
  72. STDMETHODIMP_(NTSTATUS)
  73. StartChanges(
  74. IN PIRP pIrp,
  75. IN PKSMETHOD pKSMethod,
  76. OPTIONAL PVOID pvIgnored
  77. );
  78. static
  79. STDMETHODIMP_(NTSTATUS)
  80. CheckChanges(
  81. IN PIRP pIrp,
  82. IN PKSMETHOD pKSMethod,
  83. OPTIONAL PVOID pvIgnored
  84. );
  85. static
  86. STDMETHODIMP_(NTSTATUS)
  87. CommitChanges(
  88. IN PIRP pIrp,
  89. IN PKSMETHOD pKSMethod,
  90. OPTIONAL PVOID pvIgnored
  91. );
  92. static
  93. STDMETHODIMP_(NTSTATUS)
  94. GetChangeState(
  95. IN PIRP pIrp,
  96. IN PKSMETHOD pKSMethod,
  97. OUT PULONG pulChangeState
  98. );
  99. //
  100. // KSMETHODSETID_BdaDeviceConfiguration - Methods to modify filter topology.
  101. //
  102. static
  103. STDMETHODIMP_(NTSTATUS)
  104. CreateTopology(
  105. IN PIRP pIrp,
  106. IN PKSMETHOD pKSMethod,
  107. OPTIONAL PVOID pvIgnored
  108. );
  109. //
  110. // PROPSETID_VSB - Private Property Set
  111. //
  112. static
  113. STDMETHODIMP_(NTSTATUS)
  114. GetVsbCapabilitiesProperty(
  115. IN PIRP pIrp,
  116. IN PKSPROPERTY pKSProperty,
  117. OUT PKSPROPERTY_VSB_CAP_S pProperty
  118. );
  119. static
  120. STDMETHODIMP_(NTSTATUS)
  121. SetVsbCapabilitiesProperty(
  122. IN PIRP pIrp,
  123. IN PKSPROPERTY pKSProperty,
  124. IN PKSPROPERTY_VSB_CAP_S pProperty
  125. );
  126. static
  127. STDMETHODIMP_(NTSTATUS)
  128. GetVsbRegisterProperty(
  129. IN PIRP pIrp,
  130. IN PKSPROPERTY pKSProperty,
  131. OUT PKSPROPERTY_VSB_REG_CTRL_S pProperty
  132. );
  133. static
  134. STDMETHODIMP_(NTSTATUS)
  135. SetVsbRegisterProperty(
  136. IN PIRP pIrp,
  137. IN PKSPROPERTY pKSProperty,
  138. IN PKSPROPERTY_VSB_REG_CTRL_S pProperty
  139. );
  140. static
  141. STDMETHODIMP_(NTSTATUS)
  142. GetVsbCoefficientProperty(
  143. IN PIRP pIrp,
  144. IN PKSPROPERTY pKSProperty,
  145. OUT PKSPROPERTY_VSB_COEFF_CTRL_S pProperty
  146. );
  147. static
  148. STDMETHODIMP_(NTSTATUS)
  149. SetVsbCoefficientProperty(
  150. IN PIRP pIrp,
  151. IN PKSPROPERTY pKSProperty,
  152. IN PKSPROPERTY_VSB_COEFF_CTRL_S pProperty
  153. );
  154. static
  155. STDMETHODIMP_(NTSTATUS)
  156. GetVsbDiagControlProperty(
  157. IN PIRP pIrp,
  158. IN PKSPROPERTY pKSProperty,
  159. OUT PKSPROPERTY_VSB_DIAG_CTRL_S pProperty
  160. );
  161. static
  162. STDMETHODIMP_(NTSTATUS)
  163. SetVsbDiagControlProperty(
  164. IN PIRP pIrp,
  165. IN PKSPROPERTY pKSProperty,
  166. IN PKSPROPERTY_VSB_DIAG_CTRL_S pProperty
  167. );
  168. static
  169. STDMETHODIMP_(NTSTATUS)
  170. SetVsbQualityControlProperty(
  171. IN PIRP pIrp,
  172. IN PKSPROPERTY pKSProperty,
  173. IN PKSPROPERTY_VSB_CTRL_S pProperty
  174. );
  175. static
  176. STDMETHODIMP_(NTSTATUS)
  177. SetVsbResetProperty(
  178. IN PIRP pIrp,
  179. IN PKSPROPERTY pKSProperty,
  180. IN PKSPROPERTY_VSB_CTRL_S pProperty
  181. );
  182. STDMETHODIMP_(BDA_CHANGE_STATE)
  183. ChangeState();
  184. STDMETHODIMP_(class CDevice *)
  185. GetDevice() { return m_pDevice;};
  186. STDMETHODIMP_(NTSTATUS)
  187. ChangeFrequency(
  188. IN ULONG ulhzCarrierFrequency
  189. )
  190. {
  191. //$Review - Should we validate the frequency here?
  192. //
  193. m_NewTunerResource.ulhzCarrierFrequency = ulhzCarrierFrequency;
  194. m_BdaChangeState = BDA_CHANGES_PENDING;
  195. return STATUS_SUCCESS;
  196. };
  197. STDMETHODIMP_(NTSTATUS)
  198. ChangeDemodulator(
  199. IN const GUID * pguidNetworkType
  200. );
  201. STDMETHODIMP_(NTSTATUS)
  202. SetDeviceState(
  203. KSSTATE newKsState
  204. )
  205. {
  206. m_KsState = newKsState;
  207. return STATUS_SUCCESS;
  208. };
  209. STDMETHODIMP_(NTSTATUS)
  210. AcquireResources();
  211. STDMETHODIMP_(NTSTATUS)
  212. ReleaseResources();
  213. private:
  214. class CDevice * m_pDevice;
  215. // Topology information
  216. //
  217. // We know the maximum number of pins that this filter
  218. // can create. The Id of the pin we want information for is
  219. // the index into the PinInfo array.
  220. //
  221. ULONG m_ulcPins;
  222. PPHILIPS_PIN_INFO m_rgPinInfo[MAX_FILTER_PINS];
  223. // Filter Properties
  224. //
  225. ULONG m_ulExampleProperty;
  226. ULONG m_ulSignalSource;
  227. GUID m_guidTuningSpace;
  228. GUID m_guidNetworkType;
  229. ULONG m_ulSignalState;
  230. // Filter Resources
  231. //
  232. KSSTATE m_KsState;
  233. BDA_CHANGE_STATE m_BdaChangeState;
  234. PHILIPS_TUNER_RESOURCE m_CurTunerResource;
  235. ULONG m_ulCurResourceID;
  236. PHILIPS_TUNER_RESOURCE m_NewTunerResource;
  237. ULONG m_ulNewResourceID;
  238. };
  239. class CDevice {
  240. public:
  241. //
  242. // AVStream Device Dispatch Functions
  243. //
  244. static
  245. STDMETHODIMP_(NTSTATUS)
  246. Create(
  247. IN PKSDEVICE pKSDevice
  248. );
  249. static
  250. STDMETHODIMP_(NTSTATUS)
  251. Start(
  252. IN PKSDEVICE pKSDevice,
  253. IN PIRP pIrp,
  254. IN PCM_RESOURCE_LIST pTranslatedResourceList OPTIONAL,
  255. IN PCM_RESOURCE_LIST pUntranslatedResourceList OPTIONAL
  256. );
  257. static
  258. STDMETHODIMP
  259. PnpStop(
  260. IN PKSDEVICE pKSDevice,
  261. IN PIRP pIrp
  262. );
  263. static
  264. STDMETHODIMP
  265. PnpRemove(
  266. IN PKSDEVICE pKSDevice,
  267. IN PIRP pIrp
  268. );
  269. //
  270. // Utility functions
  271. //
  272. NTSTATUS
  273. GetRegistryULONG(
  274. PWCHAR pwcKeyName,
  275. PULONG pulValue
  276. );
  277. NTSTATUS
  278. AcquireResources(
  279. PPHILIPS_TUNER_RESOURCE pNewTunerResource,
  280. PULONG pulAquiredResourceID
  281. );
  282. NTSTATUS
  283. ReleaseResources(
  284. ULONG ulResourceID
  285. );
  286. //
  287. // VSB property related methods
  288. //
  289. //$TCP - Add these to the resource
  290. //
  291. NTSTATUS VsbReset(UINT uiReset);
  292. NTSTATUS SetVsbCapabilities(PKSPROPERTY_VSB_CAP_S p_Caps);
  293. NTSTATUS GetVsbCapabilities(PKSPROPERTY_VSB_CAP_S p_Caps);
  294. NTSTATUS
  295. AccessRegisterList(
  296. PKSPROPERTY_VSB_REG_CTRL_S p_RegCtrl,
  297. UINT uiOperation);
  298. NTSTATUS
  299. AccessVsbCoeffList(
  300. PKSPROPERTY_VSB_COEFF_CTRL_S p_VsbCoeff,
  301. UINT uiOperation);
  302. NTSTATUS SetVsbDiagMode(ULONG ulOperationMode, VSBDIAGTYPE ulType);
  303. NTSTATUS GetVsbDiagMode(ULONG *p_ulOperationMode, ULONG *p_ulType);
  304. NTSTATUS VsbQuality(UINT uiQu);
  305. // Tuner property related methods
  306. //OOL GetTunerModeCapbilities(KSPROPERTY_TUNER_MODE_CAPS_S *p_TunerModeCaps);
  307. NTSTATUS GetTunerMode(ULONG *p_ulMode);
  308. NTSTATUS GetTunerVideoStandard(ULONG *p_ulStandard);
  309. NTSTATUS GetTunerStatus(PTunerStatusType p_Status);
  310. NTSTATUS GetTunerInput(ULONG *p_ulTunerInput);
  311. NTSTATUS SetTunerMode(ULONG ulModeToSet);
  312. NTSTATUS GetTunerFrequency(ULONG *p_ulFreq);
  313. NTSTATUS SetTunerFrequency(ULONG *p_ulFreq);
  314. NTSTATUS SetTunerVideoStandard(ULONG ulStandard);
  315. NTSTATUS SetTunerInput(ULONG ulInput);
  316. //$REVIEW - Should this be done in Ring 0? - TCP
  317. //
  318. BOOL CreateQualityCheckThread();
  319. void TimerRoutine();
  320. void QualityCheckThread();
  321. // void STREAMAPI TimerRoutine();
  322. // void STREAMAPI QualityCheckThread();
  323. public:
  324. CVSBDemod *m_pDemod;
  325. CTuner *m_pTuner;
  326. BoardInfoType m_BoardInfo;
  327. private:
  328. PKSDEVICE m_pKSDevice;
  329. CGpio * m_pGpio;
  330. CI2CScript * m_pI2CScript;
  331. CPhilTimer m_QualityCheckTimer;
  332. BOOL m_bFirstEntry;
  333. BOOL m_bQualityCheckActiveFlag;
  334. // Signal Quality check parameters
  335. UINT m_uiQualityCheckMode;
  336. UINT m_uiQualityCheckModeAck;
  337. CMutex m_QualityCheckMutex;
  338. UINT m_State1Cnt;
  339. BOOL m_bHangCheckFlag;
  340. // Data in Misc./Mode Register
  341. UCHAR m_ucModeInit;
  342. UINT m_uiOutputMode;
  343. Register m_MpocRegisters;
  344. PHILIPS_TUNER_RESOURCE m_CurTunerResource;
  345. NTSTATUS InitFromRegistry();
  346. NTSTATUS SetBoard(UINT uiBoardID);
  347. NTSTATUS BoardInitialize();
  348. NTSTATUS ModeInit();
  349. UINT SetRegisterList(RegisterType *p_Registers,
  350. UINT uiNumRegisters);
  351. UINT GetRegisterList(RegisterType *p_Registers,
  352. UINT uiNumRegisters,
  353. UINT uiRegisterType);
  354. NTSTATUS MapErrorToNTSTATUS(UINT err);
  355. // MPOC related functions
  356. NTSTATUS MpocInit();
  357. NTSTATUS SetMpocIFMode(ULONG ulMode);
  358. NTSTATUS GetMpocVersion(UINT *p_version);
  359. NTSTATUS GetMpocStatus(UINT StatusType, UINT *puiStatus);
  360. };
  361. class CAntennaPin {
  362. public:
  363. static
  364. STDMETHODIMP_(NTSTATUS)
  365. PinCreate(
  366. IN OUT PKSPIN Pin,
  367. IN PIRP Irp
  368. );
  369. static
  370. STDMETHODIMP_(NTSTATUS)
  371. PinClose(
  372. IN OUT PKSPIN Pin,
  373. IN PIRP Irp
  374. );
  375. static
  376. STDMETHODIMP_(NTSTATUS)
  377. PinSetDeviceState(
  378. IN PKSPIN Pin,
  379. IN KSSTATE ToState,
  380. IN KSSTATE FromState
  381. );
  382. static
  383. STDMETHODIMP_(NTSTATUS)
  384. GetSignalSource(
  385. IN PIRP Irp,
  386. IN PKSPROPERTY pKSProperty,
  387. IN PULONG pulProperty
  388. );
  389. static
  390. STDMETHODIMP_(NTSTATUS)
  391. PutSignalSource(
  392. IN PIRP Irp,
  393. IN PKSPROPERTY pKSProperty,
  394. IN PULONG pulProperty
  395. );
  396. static
  397. STDMETHODIMP_(NTSTATUS)
  398. GetTuningSpace(
  399. IN PIRP Irp,
  400. IN PKSPROPERTY pKSProperty,
  401. IN PGUID pguidProperty
  402. );
  403. static
  404. STDMETHODIMP_(NTSTATUS)
  405. PutTuningSpace(
  406. IN PIRP Irp,
  407. IN PKSPROPERTY pKSProperty,
  408. IN PGUID pguidProperty
  409. );
  410. static
  411. STDMETHODIMP_(NTSTATUS)
  412. GetNetworkType(
  413. IN PIRP Irp,
  414. IN PKSPROPERTY pKSProperty,
  415. IN PGUID pguidProperty
  416. );
  417. static
  418. STDMETHODIMP_(NTSTATUS)
  419. PutNetworkType(
  420. IN PIRP Irp,
  421. IN PKSPROPERTY pKSProperty,
  422. IN PGUID pguidProperty
  423. );
  424. static
  425. STDMETHODIMP_(NTSTATUS)
  426. GetSignalState(
  427. IN PIRP Irp,
  428. IN PKSPROPERTY pKSProperty,
  429. IN PULONG pulProperty
  430. );
  431. static
  432. STDMETHODIMP_(NTSTATUS)
  433. PutSignalState(
  434. IN PIRP Irp,
  435. IN PKSPROPERTY pKSProperty,
  436. IN PULONG pulProperty
  437. );
  438. static
  439. STDMETHODIMP_(NTSTATUS)
  440. GetCenterFrequency(
  441. IN PIRP Irp,
  442. IN PKSPROPERTY pKSProperty,
  443. IN PULONG pulProperty
  444. );
  445. static
  446. STDMETHODIMP_(NTSTATUS)
  447. PutCenterFrequency(
  448. IN PIRP Irp,
  449. IN PKSPROPERTY pKSProperty,
  450. IN PULONG pulProperty
  451. );
  452. STDMETHODIMP_(class CFilter *)
  453. GetFilter() { return m_pFilter;};
  454. STDMETHODIMP_(void)
  455. SetFilter(class CFilter * pFilter) { m_pFilter = pFilter;};
  456. private:
  457. class CFilter* m_pFilter;
  458. ULONG ulReserved;
  459. KSSTATE m_KsState;
  460. // BDA Signal Properties
  461. //
  462. ULONG m_ulSignalSource;
  463. GUID m_guidTuningSpace;
  464. GUID m_guidNetworkType;
  465. ULONG m_ulSignalState;
  466. // RF Tuner Node Properties
  467. //
  468. BOOLEAN m_fFrequencyChanged;
  469. ULONG m_ulCurrentFrequency;
  470. ULONG m_ulPendingFrequency;
  471. };
  472. class CTransportPin
  473. {
  474. public:
  475. static
  476. STDMETHODIMP_(NTSTATUS)
  477. PinCreate(
  478. IN OUT PKSPIN Pin,
  479. IN PIRP Irp
  480. );
  481. static
  482. STDMETHODIMP_(NTSTATUS)
  483. PinClose(
  484. IN OUT PKSPIN Pin,
  485. IN PIRP Irp
  486. );
  487. static
  488. STDMETHODIMP_(NTSTATUS)
  489. GetSignalSource(
  490. IN PIRP Irp,
  491. IN PKSPROPERTY pKSProperty,
  492. IN PULONG pulProperty
  493. );
  494. static
  495. STDMETHODIMP_(NTSTATUS)
  496. PutSignalSource(
  497. IN PIRP Irp,
  498. IN PKSPROPERTY pKSProperty,
  499. IN PULONG pulProperty
  500. );
  501. static
  502. STDMETHODIMP_(NTSTATUS)
  503. GetTuningSpace(
  504. IN PIRP Irp,
  505. IN PKSPROPERTY pKSProperty,
  506. IN PGUID pguidProperty
  507. );
  508. static
  509. STDMETHODIMP_(NTSTATUS)
  510. PutTuningSpace(
  511. IN PIRP Irp,
  512. IN PKSPROPERTY pKSProperty,
  513. IN PGUID pguidProperty
  514. );
  515. static
  516. STDMETHODIMP_(NTSTATUS)
  517. GetNetworkType(
  518. IN PIRP Irp,
  519. IN PKSPROPERTY pKSProperty,
  520. IN PGUID pguidProperty
  521. );
  522. static
  523. STDMETHODIMP_(NTSTATUS)
  524. PutNetworkType(
  525. IN PIRP Irp,
  526. IN PKSPROPERTY pKSProperty,
  527. IN PGUID pguidProperty
  528. );
  529. static
  530. STDMETHODIMP_(NTSTATUS)
  531. GetSignalState(
  532. IN PIRP Irp,
  533. IN PKSPROPERTY pKSProperty,
  534. IN PULONG pulProperty
  535. );
  536. static
  537. STDMETHODIMP_(NTSTATUS)
  538. PutSignalState(
  539. IN PIRP Irp,
  540. IN PKSPROPERTY pKSProperty,
  541. IN PULONG pulProperty
  542. );
  543. STDMETHODIMP_(class CFilter *)
  544. GetFilter() { return m_pFilter;};
  545. STDMETHODIMP_(void)
  546. SetFilter(class CFilter * pFilter) { m_pFilter = pFilter;};
  547. static
  548. STDMETHODIMP_(NTSTATUS)
  549. StartDemodulation(
  550. IN PIRP Irp,
  551. IN PKSPROPERTY pKSProperty,
  552. IN PULONG pulProperty
  553. );
  554. static
  555. STDMETHODIMP_(NTSTATUS)
  556. StopDemodulation(
  557. IN PIRP Irp,
  558. IN PKSPROPERTY pKSProperty,
  559. IN PULONG pulProperty
  560. );
  561. private:
  562. KSSTATE m_KsState;
  563. CFilter * m_pFilter;
  564. // BDA Signal Properties
  565. //
  566. ULONG m_ulSignalSource;
  567. GUID m_guidTuningSpace;
  568. GUID m_guidNetworkType;
  569. ULONG m_ulSignalState;
  570. };
  571. //
  572. // Helper routines
  573. //
  574. NTSTATUS
  575. PinSetDeviceState(
  576. IN PKSPIN Pin,
  577. IN KSSTATE ToState,
  578. IN KSSTATE FromState
  579. );
  580. __inline CFilter *
  581. FilterFromIRP(
  582. PIRP pIrp
  583. )
  584. {
  585. PKSFILTER pKSFilter;
  586. pKSFilter = KsGetFilterFromIrp( pIrp);
  587. if (!pKSFilter || !pKSFilter->Context)
  588. {
  589. return NULL;
  590. }
  591. return reinterpret_cast<CFilter*>(pKSFilter->Context);
  592. }
  593. __inline CAntennaPin *
  594. AntennaPinFromIRP(
  595. PIRP pIrp
  596. )
  597. {
  598. PKSPIN pKSPin;
  599. pKSPin = KsGetPinFromIrp( pIrp);
  600. if (!pKSPin || !pKSPin->Context)
  601. {
  602. return NULL;
  603. }
  604. return reinterpret_cast<CAntennaPin*>(pKSPin->Context);
  605. }
  606. __inline CTransportPin *
  607. TransportPinFromIRP(
  608. PIRP pIrp
  609. )
  610. {
  611. PKSPIN pKSPin;
  612. pKSPin = KsGetPinFromIrp( pIrp);
  613. if (!pKSPin || !pKSPin->Context)
  614. {
  615. return NULL;
  616. }
  617. return reinterpret_cast<CTransportPin*>(pKSPin->Context);
  618. }
  619. //
  620. // Data declarations
  621. //
  622. extern const BDA_FILTER_TEMPLATE TunerBdaFilterTemplate;
  623. extern const KSFILTER_DESCRIPTOR InitialTunerFilterDescriptor;
  624. extern const KSFILTER_DESCRIPTOR TemplateTunerFilterDescriptor;