xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CMona.cpp (revision 5d9e40fe9252c8f9c5e5e41594545bfa4419fcc7)
1 // ****************************************************************************
2 //
3 //		CMona.cpp
4 //
5 //		Implementation file for the CMona driver class.
6 //		Set editor tabs to 3 for your viewing pleasure.
7 //
8 //		Copyright Echo Digital Audio Corporation (c) 1998 - 2002
9 //		All rights reserved
10 //		www.echoaudio.com
11 //
12 //		Permission is hereby granted, free of charge, to any person obtaining a
13 //		copy of this software and associated documentation files (the
14 //		"Software"), to deal with the Software without restriction, including
15 //		without limitation the rights to use, copy, modify, merge, publish,
16 //		distribute, sublicense, and/or sell copies of the Software, and to
17 //		permit persons to whom the Software is furnished to do so, subject to
18 //		the following conditions:
19 //
20 //		- Redistributions of source code must retain the above copyright
21 //		notice, this list of conditions and the following disclaimers.
22 //
23 //		- Redistributions in binary form must reproduce the above copyright
24 //		notice, this list of conditions and the following disclaimers in the
25 //		documentation and/or other materials provided with the distribution.
26 //
27 //		- Neither the name of Echo Digital Audio, nor the names of its
28 //		contributors may be used to endorse or promote products derived from
29 //		this Software without specific prior written permission.
30 //
31 //		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 //		EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 //		MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34 //		IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
35 //		ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
36 //		TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
37 //		SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
38 //
39 // ****************************************************************************
40 
41 #include "CMona.h"
42 
43 
44 /****************************************************************************
45 
46 	Construction and destruction
47 
48  ****************************************************************************/
49 
50 //===========================================================================
51 //
52 // Overload new & delete so memory for this object is allocated
53 //	from non-paged memory.
54 //
55 //===========================================================================
56 
57 PVOID CMona::operator new( size_t Size )
58 {
59 	PVOID 		pMemory;
60 	ECHOSTATUS 	Status;
61 
62 	Status = OsAllocateNonPaged(Size,&pMemory);
63 
64 	if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
65 	{
66 		ECHO_DEBUGPRINTF(("CMona::operator new - memory allocation failed\n"));
67 
68 		pMemory = NULL;
69 	}
70 	else
71 	{
72 		memset( pMemory, 0, Size );
73 	}
74 
75 	return pMemory;
76 
77 }	// PVOID CMona::operator new( size_t Size )
78 
79 
80 VOID  CMona::operator delete( PVOID pVoid )
81 {
82 	if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
83 	{
84 		ECHO_DEBUGPRINTF(("CMona::operator delete memory free failed\n"));
85 	}
86 }	// VOID CMona::operator delete( PVOID pVoid )
87 
88 
89 //===========================================================================
90 //
91 // Constructor and destructor
92 //
93 //===========================================================================
94 
95 CMona::CMona( PCOsSupport pOsSupport )
96 		: CEchoGals( pOsSupport )
97 {
98 	ECHO_DEBUGPRINTF( ( "CMona::CMona() is born!\n" ) );
99 }
100 
101 CMona::~CMona()
102 {
103 	ECHO_DEBUGPRINTF( ( "CMona::~CMona() is toast!\n" ) );
104 }
105 
106 
107 
108 
109 /****************************************************************************
110 
111 	Setup and hardware initialization
112 
113  ****************************************************************************/
114 
115 //===========================================================================
116 //
117 // Every card has an InitHw method
118 //
119 //===========================================================================
120 
121 ECHOSTATUS CMona::InitHw()
122 {
123 	ECHOSTATUS	Status;
124 
125 	//
126 	// Call the base method
127 	//
128 	if ( ECHOSTATUS_OK != ( Status = CEchoGals::InitHw() ) )
129 		return Status;
130 
131 	//
132 	// Create the DSP comm object
133 	//
134 	ASSERT( NULL == m_pDspCommObject );
135 	m_pDspCommObject = new CMonaDspCommObject( (PDWORD) m_pvSharedMemory,
136 															 m_pOsSupport );
137 	if (NULL == m_pDspCommObject)
138 	{
139 		ECHO_DEBUGPRINTF(("CMona::InitHw - could not create DSP comm object\n"));
140 		return ECHOSTATUS_NO_MEM;
141 	}
142 
143 	//
144 	// Load the DSP, the PCI card ASIC, and the external box ASIC
145 	//
146 	GetDspCommObject()->LoadFirmware();
147 	if ( GetDspCommObject()->IsBoardBad() )
148 		return ECHOSTATUS_DSP_DEAD;
149 
150 	//
151 	// Clear the "bad board" flag; set the flags to indicate that
152 	// Mona can handle super-interleave and supports the digital
153 	// input auto-mute.
154 	//
155 	m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
156 	m_wFlags |= ECHOGALS_ROFLAG_SUPER_INTERLEAVE_OK |
157 				ECHOGALS_ROFLAG_DIGITAL_IN_AUTOMUTE;
158 
159 	//
160 	//	Must call this here after DSP is init to
161 	//	init gains and mutes
162 	//
163 	Status = InitLineLevels();
164 	if ( ECHOSTATUS_OK != Status )
165 		return Status;
166 
167 	//
168 	// Set the digital mode to S/PDIF RCA
169 	//
170 	SetDigitalMode( DIGITAL_MODE_SPDIF_RCA );
171 
172 	//
173 	// Set the S/PDIF output format to "professional"
174 	//
175 	SetProfessionalSpdif( TRUE );
176 
177 	//
178 	//	Get default sample rate from DSP
179 	//
180 	m_dwSampleRate = GetDspCommObject()->GetSampleRate();
181 
182 	ECHO_DEBUGPRINTF( ( "CMona::InitHw()\n" ) );
183 	return Status;
184 
185 }	// ECHOSTATUS CMona::InitHw()
186 
187 
188 
189 
190 /****************************************************************************
191 
192 	Informational methods
193 
194  ****************************************************************************/
195 
196 //===========================================================================
197 //
198 // Override GetCapabilities to enumerate unique capabilties for this card
199 //
200 //===========================================================================
201 
202 ECHOSTATUS CMona::GetCapabilities
203 (
204 	PECHOGALS_CAPS	pCapabilities
205 )
206 {
207 	ECHOSTATUS	Status;
208 
209 	Status = GetBaseCapabilities(pCapabilities);
210 	if ( ECHOSTATUS_OK != Status )
211 		return Status;
212 
213 	pCapabilities->dwInClockTypes |= ECHO_CLOCK_BIT_WORD		|
214 												ECHO_CLOCK_BIT_SPDIF		|
215 												ECHO_CLOCK_BIT_ADAT;
216 
217 	return Status;
218 
219 }	// ECHOSTATUS CMona::GetCapabilities
220 
221 
222 //===========================================================================
223 //
224 // QueryAudioSampleRate is used to find out if this card can handle a
225 // given sample rate.
226 //
227 //===========================================================================
228 
229 ECHOSTATUS CMona::QueryAudioSampleRate
230 (
231 	DWORD		dwSampleRate
232 )
233 {
234 	if ( dwSampleRate !=  8000 &&
235 		  dwSampleRate != 11025 &&
236 		  dwSampleRate != 16000 &&
237 		  dwSampleRate != 22050 &&
238 		  dwSampleRate != 32000 &&
239 		  dwSampleRate != 44100 &&
240 		  dwSampleRate != 48000 &&
241 		  dwSampleRate != 88200 &&
242 		  dwSampleRate != 96000 )
243 	{
244 		ECHO_DEBUGPRINTF(
245 			("CMona::QueryAudioSampleRate() Sample rate must be "
246 			 " 8,000 Hz, 11,025 Hz, 16,000 Hz, 22,050 Hz, 32,000 Hz, "
247 			 "44,100 Hz, 48,000 Hz, 88,200 Hz or 96,000 Hz\n") );
248 		return ECHOSTATUS_BAD_FORMAT;
249 	}
250 	if ( dwSampleRate >= 88200 && DIGITAL_MODE_ADAT == GetDigitalMode() )
251 	{
252 		ECHO_DEBUGPRINTF(
253 			("CMona::QueryAudioSampleRate() Sample rate cannot be "
254 			 "set to 88,200 Hz or 96,000 Hz in ADAT mode\n") );
255 		return ECHOSTATUS_BAD_FORMAT;
256 	}
257 
258 	ECHO_DEBUGPRINTF( ( "CMona::QueryAudioSampleRate()\n" ) );
259 	return ECHOSTATUS_OK;
260 }	// ECHOSTATUS CMona::QueryAudioSampleRate
261 
262 
263 //===========================================================================
264 //
265 // GetInputClockDetect returns a bitmask consisting of all the input
266 // clocks currently connected to the hardware; this changes as the user
267 // connects and disconnects clock inputs.
268 //
269 // You should use this information to determine which clocks the user is
270 // allowed to select.
271 //
272 // Mona supports S/PDIF, word, and ADAT input clocks.
273 //
274 //===========================================================================
275 
276 ECHOSTATUS CMona::GetInputClockDetect(DWORD &dwClockDetectBits)
277 {
278 	//ECHO_DEBUGPRINTF(("CMona::GetInputClockDetect\n"));
279 
280 	if ( NULL == GetDspCommObject() || GetDspCommObject()->IsBoardBad() )
281 	{
282 		ECHO_DEBUGPRINTF( ("CMona::GetInputClockDetect: DSP Dead!\n") );
283 		return ECHOSTATUS_DSP_DEAD;
284 	}
285 
286 	//
287 	// Map the DSP clock detect bits to the generic driver clock detect bits
288 	//
289 	DWORD dwClocksFromDsp = GetDspCommObject()->GetInputClockDetect();
290 
291 	dwClockDetectBits = ECHO_CLOCK_BIT_INTERNAL;
292 
293 	if (0 != (dwClocksFromDsp & GML_CLOCK_DETECT_BIT_SPDIF))
294 		dwClockDetectBits |= ECHO_CLOCK_BIT_SPDIF;
295 
296 	if (0 != (dwClocksFromDsp & GML_CLOCK_DETECT_BIT_ADAT))
297 		dwClockDetectBits |= ECHO_CLOCK_BIT_ADAT;
298 
299 	if (0 != (dwClocksFromDsp & GML_CLOCK_DETECT_BIT_WORD))
300 		dwClockDetectBits |= ECHO_CLOCK_BIT_WORD;
301 
302 	return ECHOSTATUS_OK;
303 
304 }	// GetInputClockDetect
305 
306 
307 // *** CMona.cpp ***
308