- Fix building of cmidriver
[reactos.git] / reactos / drivers / wdm / audio / drivers / CMIDriver / common.hpp
1 /*
2 Copyright (c) 2006-2007 dogbert <dogber1@gmail.com>
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef _COMMON_HPP_
29 #define _COMMON_HPP_
30
31 #include "ntddk.h"
32 #include "stdunk.h"
33 #include "portcls.h"
34 #include "dmusicks.h"
35 #include "ksdebug.h"
36 #include "kcom.h"
37 #include "ksmedia.h"
38
39 #include "interfaces.hpp"
40 #include "debug.hpp"
41 #include "cmireg.hpp"
42
43 class CCMIAdapter : public ICMIAdapter,
44 public IAdapterPowerManagement
45 {
46 private:
47 PDEVICE_OBJECT DeviceObject;
48 PINTERRUPTSYNC InterruptSync;
49 DEVICE_POWER_STATE CurrentPowerState;
50 UInt8 mixerCache[0xFF];
51
52 CMI8738Info cm;
53
54 bool queryChip();
55 void resetController();
56
57 public:
58 STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
59 STDMETHODIMP_(ULONG) AddRef()
60 {
61 InterlockedIncrement(&m_Ref);
62 return m_Ref;
63 }
64 STDMETHODIMP_(ULONG) Release()
65 {
66 InterlockedDecrement(&m_Ref);
67
68 if (!m_Ref)
69 {
70 delete this;
71 return 0;
72 }
73 return m_Ref;
74 }
75
76 CCMIAdapter(IUnknown *OuterUnknown){}
77 ~CCMIAdapter();
78
79 IMP_IAdapterPowerManagement;
80
81 STDMETHODIMP_(NTSTATUS) init(PRESOURCELIST ResourceList, PDEVICE_OBJECT aDeviceObject);
82 STDMETHODIMP_(NTSTATUS) activateMPU(ULONG* MPUBase);
83 STDMETHODIMP_(NTSTATUS) loadSBMixerFromMemory();
84
85 STDMETHODIMP_(UInt8) readUInt8(UInt8 reg);
86 STDMETHODIMP_(void) writeUInt8(UInt8 reg, UInt8 value);
87
88 STDMETHODIMP_(void) setUInt8Bit(UInt8 reg, UInt8 flag);
89 STDMETHODIMP_(void) clearUInt8Bit(UInt8 reg, UInt8 flag);
90
91 STDMETHODIMP_(UInt16) readUInt16(UInt8 reg);
92 STDMETHODIMP_(void) writeUInt16(UInt8 reg, UInt16 value);
93
94 STDMETHODIMP_(UInt32) readUInt32(UInt8 reg);
95 STDMETHODIMP_(void) writeUInt32(UInt8 reg, UInt32 value);
96
97 STDMETHODIMP_(void) setUInt32Bit(UInt8 reg, UInt32 flag);
98 STDMETHODIMP_(void) clearUInt32Bit(UInt8 reg, UInt32 flag);
99
100 STDMETHODIMP_(UInt8) readMixer(UInt8 index);
101 STDMETHODIMP_(void) writeMixer(UInt8 index, UInt8 value);
102 STDMETHODIMP_(void) setMixerBit(UInt8 index, UInt8 flag);
103 STDMETHODIMP_(void) clearMixerBit(UInt8 index, UInt8 flag);
104
105 STDMETHODIMP_(void) resetMixer();
106
107 static NTSTATUS NTAPI InterruptServiceRoutine(PINTERRUPTSYNC InterruptSync, PVOID StaticContext);
108
109 STDMETHODIMP_(PCMI8738Info) getCMI8738Info(void)
110 {
111 return &cm;
112 };
113
114 STDMETHODIMP_(PINTERRUPTSYNC) getInterruptSync(void)
115 {
116 return InterruptSync;
117 };
118 STDMETHODIMP_(PDEVICE_OBJECT) getDeviceObject(void)
119 {
120 return DeviceObject;
121 };
122
123 friend NTSTATUS NewCCMIAdapter(PCMIADAPTER* OutCMIAdapter, PRESOURCELIST ResourceList);
124
125 LONG m_Ref;
126
127 };
128
129 NTSTATUS NewCMIAdapter(PUNKNOWN* Unknown, REFCLSID, PUNKNOWN UnknownOuter, POOL_TYPE PoolType);
130
131 #endif //_COMMON_HPP_