1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Christian Gmeiner
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
28 /* define some audiohw caps */
29 #define TREBLE_CAP (1 << 0)
30 #define BASS_CAP (1 << 1)
31 #define BALANCE_CAP (1 << 2)
32 #define CLIPPING_CAP (1 << 3)
33 #define PRESCALER_CAP (1 << 4)
34 #define BASS_CUTOFF_CAP (1 << 5)
35 #define TREBLE_CUTOFF_CAP (1 << 6)
36 #define EQ_CAP (1 << 7)
37 #define DEPTH_3D_CAP (1 << 8)
41 #elif defined(HAVE_UDA1341)
43 #elif defined(HAVE_WM8750) || defined(HAVE_WM8751)
45 #elif defined(HAVE_WM8978)
47 #elif defined(HAVE_WM8975)
49 #elif defined(HAVE_WM8985)
51 #elif defined(HAVE_WM8758)
53 #elif defined(HAVE_WM8711) || defined(HAVE_WM8721) || \
56 #elif defined(HAVE_TLV320)
58 #elif defined(HAVE_AS3514)
60 #elif defined(HAVE_MAS35XX)
62 #if defined(HAVE_DAC3550A)
64 #endif /* HAVE_DAC3550A */
65 #elif defined(HAVE_TSC2100)
67 #elif defined(HAVE_JZ4740_CODEC)
68 #include "jz4740-codec.h"
69 #elif defined(HAVE_AK4537)
71 #elif defined(HAVE_CS42L55)
73 #elif defined(HAVE_IMX233_CODEC)
74 #include "imx233-codec.h"
76 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
77 /* #include <SDL_audio.h> gives errors in other code areas,
78 * we don't really need it here, so don't. but it should maybe be fixed */
79 #ifndef SIMULATOR /* simulator gets values from the target .h files */
80 #define VOLUME_MIN -990
89 #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
90 #warning define for VOLUME_MIN and VOLUME_MAX is missing
91 #define VOLUME_MIN -700
95 #ifndef AUDIOHW_NUM_TONE_CONTROLS
96 #define AUDIOHW_NUM_TONE_CONTROLS 0
99 /* volume/balance/treble/bass interdependency main part */
100 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
103 /* convert caps into defines */
106 #if (AUDIOHW_CAPS & TREBLE_CAP)
107 #define AUDIOHW_HAVE_TREBLE
110 #if (AUDIOHW_CAPS & BASS_CAP)
111 #define AUDIOHW_HAVE_BASS
114 #if (AUDIOHW_CAPS & BASS_CUTOFF_CAP)
115 #define AUDIOHW_HAVE_BASS_CUTOFF
118 #if (AUDIOHW_CAPS & TREBLE_CUTOFF_CAP)
119 #define AUDIOHW_HAVE_TREBLE_CUTOFF
122 #if (AUDIOHW_CAPS & BALANCE_CAP)
123 #define AUDIOHW_HAVE_BALANCE
126 #if (AUDIOHW_CAPS & CLIPPING_CAP)
127 #define AUDIOHW_HAVE_CLIPPING
130 #if (AUDIOHW_CAPS & PRESCALER_CAP)
131 #define AUDIOHW_HAVE_PRESCALER
134 /* Hardware EQ tone controls */
135 #if (AUDIOHW_CAPS & EQ_CAP)
136 /* A hardware equalizer is present (or perhaps some tone control variation
137 * that is not Bass and/or Treble) */
138 #define AUDIOHW_HAVE_EQ
140 /* Defined band indexes for supported bands */
143 /* Band 1 is implied; bands must be contiguous, 1 to N */
144 AUDIOHW_EQ_BAND1
= 0,
145 #define AUDIOHW_HAVE_EQ_BAND1
146 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 1))
148 #define AUDIOHW_HAVE_EQ_BAND2
149 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 2))
151 #define AUDIOHW_HAVE_EQ_BAND3
152 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 3))
154 #define AUDIOHW_HAVE_EQ_BAND4
155 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 4))
157 #define AUDIOHW_HAVE_EQ_BAND5
162 AUDIOHW_EQ_BAND_NUM
, /* Keep last */
165 #ifdef AUDIOHW_EQ_FREQUENCY_CAPS
166 /* One or more bands supports frequency cutoff or center adjustment */
167 #define AUDIOHW_HAVE_EQ_FREQUENCY
170 __AUDIOHW_EQ_BAND_FREQUENCY
= -1,
171 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
172 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 0))
173 AUDIOHW_EQ_BAND1_FREQUENCY
,
174 #define AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
176 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
177 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 1))
178 AUDIOHW_EQ_BAND2_FREQUENCY
,
179 #define AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
181 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
182 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 2))
183 AUDIOHW_EQ_BAND3_FREQUENCY
,
184 #define AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
186 #if defined(AUDIOHW_HAVE_EQ_BAND4) && \
187 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 3))
188 AUDIOHW_EQ_BAND4_FREQUENCY
,
189 #define AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
191 #if defined(AUDIOHW_HAVE_EQ_BAND5) && \
192 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 4))
193 AUDIOHW_EQ_BAND5_FREQUENCY
,
194 #define AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
196 AUDIOHW_EQ_FREQUENCY_NUM
,
198 #endif /* AUDIOHW_EQ_FREQUENCY_CAPS */
200 #ifdef AUDIOHW_EQ_WIDTH_CAPS
201 /* One or more bands supports bandwidth adjustment */
202 #define AUDIOHW_HAVE_EQ_WIDTH
205 __AUDIOHW_EQ_BAND_WIDTH
= -1,
206 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
207 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 1))
208 AUDIOHW_EQ_BAND2_WIDTH
,
209 #define AUDIOHW_HAVE_EQ_BAND2_WIDTH
211 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
212 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 2))
213 AUDIOHW_EQ_BAND3_WIDTH
,
214 #define AUDIOHW_HAVE_EQ_BAND3_WIDTH
216 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
217 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 3))
218 AUDIOHW_EQ_BAND4_WIDTH
,
219 #define AUDIOHW_HAVE_EQ_BAND4_WIDTH
221 AUDIOHW_EQ_WIDTH_NUM
, /* Keep last */
223 #endif /* AUDIOHW_EQ_WIDTH_CAPS */
225 /* Types and number of settings types (gain, frequency, width) */
226 enum AUDIOHW_EQ_SETTINGS
229 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
230 AUDIOHW_EQ_FREQUENCY
,
232 #ifdef AUDIOHW_HAVE_EQ_WIDTH
235 AUDIOHW_EQ_SETTING_NUM
238 #endif /* (AUDIOHW_CAPS & EQ_CAP) */
240 #if (AUDIOHW_CAPS & DEPTH_3D_CAP)
241 #define AUDIOHW_HAVE_DEPTH_3D
244 #if defined (HAVE_SW_TONE_CONTROLS)
245 /* Needed for proper sound support */
246 #define AUDIOHW_HAVE_BASS
247 #define AUDIOHW_HAVE_TREBLE
249 #endif /* AUDIOHW_CAPS */
254 #if defined(AUDIOHW_HAVE_BASS)
257 #if defined(AUDIOHW_HAVE_TREBLE)
263 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
273 #if defined(HAVE_RECORDING)
278 /* Bass and treble tone controls */
279 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
282 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
286 #if defined(AUDIOHW_HAVE_DEPTH_3D)
289 /* Hardware EQ tone controls */
291 #if defined(AUDIOHW_HAVE_EQ)
294 #if defined(AUDIOHW_HAVE_EQ_BAND2)
297 #if defined(AUDIOHW_HAVE_EQ_BAND3)
300 #if defined(AUDIOHW_HAVE_EQ_BAND4)
303 #if defined(AUDIOHW_HAVE_EQ_BAND5)
306 /* Band frequencies */
307 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
308 SOUND_EQ_BAND1_FREQUENCY
,
310 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
311 SOUND_EQ_BAND2_FREQUENCY
,
313 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
314 SOUND_EQ_BAND3_FREQUENCY
,
316 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
317 SOUND_EQ_BAND4_FREQUENCY
,
319 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
320 SOUND_EQ_BAND5_FREQUENCY
,
323 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
324 SOUND_EQ_BAND2_WIDTH
,
326 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
327 SOUND_EQ_BAND3_WIDTH
,
329 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
330 SOUND_EQ_BAND4_WIDTH
,
332 #endif /* AUDIOHW_HAVE_EQ */
333 SOUND_LAST_SETTING
, /* Keep this last */
340 SOUND_CHAN_MONO_LEFT
,
341 SOUND_CHAN_MONO_RIGHT
,
343 SOUND_CHAN_NUM_MODES
,
346 struct sound_settings_info
{
355 /* This struct is used by every driver to export its min/max/default values for
356 * its audio settings. Keep in mind that the order must be correct! */
357 extern const struct sound_settings_info audiohw_settings
[];
359 /* All usable functions implemented by a audio codec drivers. Most of
360 * the function in sound settings are only called, when in audio codecs
361 * .h file suitable defines are added.
365 * Initialize audio codec to a well defined state. Includes SoC-specific
368 void audiohw_init(void);
371 * Do initial audio codec setup. Usually called from audiohw_init.
373 void audiohw_preinit(void);
376 * Do some stuff (codec related) after audiohw_init that needs to be
377 * delayed such as enabling outputs to prevent popping. This lets
378 * other inits in the system complete in the meantime.
380 void audiohw_postinit(void);
385 void audiohw_close(void);
387 #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
389 * Set new volume value
391 * NOTE: AUDIOHW_CAPS need to contain
394 void audiohw_set_volume(int val
);
397 #ifdef AUDIOHW_HAVE_PRESCALER
399 * Set new prescaler value.
401 * NOTE: AUDIOHW_CAPS need to contain
404 void audiohw_set_prescaler(int val
);
407 #ifdef AUDIOHW_HAVE_BALANCE
409 * Set new balance value
411 * NOTE: AUDIOHW_CAPS need to contain
414 void audiohw_set_balance(int val
);
417 #ifdef AUDIOHW_HAVE_TREBLE
419 * Set new treble value.
421 * NOTE: AUDIOHW_CAPS need to contain
424 void audiohw_set_treble(int val
);
427 #ifdef AUDIOHW_HAVE_BASS
429 * Set new bass value.
431 * NOTE: AUDIOHW_CAPS need to contain
434 void audiohw_set_bass(int val
);
437 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
439 * Set new bass cut off value.
441 * NOTE: AUDIOHW_CAPS need to contain
444 void audiohw_set_bass_cutoff(int val
);
447 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
449 * Set new treble cut off value.
451 * NOTE: AUDIOHW_CAPS need to contain
454 void audiohw_set_treble_cutoff(int val
);
457 #ifdef AUDIOHW_HAVE_EQ
459 * Set new band gain value.
460 * @param band index to which val is set
462 * NOTE: AUDIOHW_CAPS need to contain
465 * AUDIOHW_EQ_BAND_CAPS must be defined as a bitmask
466 * of EQ_CAP each shifted by the zero-based band number
467 * for each band. Bands 1 to N are indexed 0 to N-1.
469 void audiohw_set_eq_band_gain(unsigned int band
, int val
);
472 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
474 * Set new band cutoff or center frequency value.
475 * @param band index to which val is set
477 * NOTE: AUDIOHW_CAPS need to contain
480 * AUDIOHW_EQ_FREQUENCY_CAPS must be defined as a bitmask
481 * of EQ_CAP each shifted by the zero-based band number
482 * for each band that supports frequency adjustment.
483 * Bands 1 to N are indexed 0 to N-1.
485 void audiohw_set_eq_band_frequency(unsigned int band
, int val
);
488 #ifdef AUDIOHW_HAVE_EQ_WIDTH
490 * Set new band cutoff or center frequency value.
491 * @param band index to which val is set
493 * NOTE: AUDIOHW_CAPS need to contain
496 * AUDIOHW_EQ_WIDTH_CAPS must be defined as a bitmask
497 * of EQ_CAP each shifted by the zero-based band number
498 * for each band that supports width adjustment.
499 * Bands 1 to N are indexed 0 to N-1.
501 void audiohw_set_eq_band_width(unsigned int band
, int val
);
504 #ifdef AUDIOHW_HAVE_DEPTH_3D
506 * Set new 3-d enhancement (stereo expansion) effect value.
508 * NOTE: AUDIOHW_CAPS need to contain
511 void audiohw_set_depth_3d(int val
);
515 void audiohw_set_frequency(int fsel
);
517 #ifdef HAVE_RECORDING
521 * @param source_mic if this is true, we want to record from microphone,
522 * else we want to record FM/LineIn.
524 void audiohw_enable_recording(bool source_mic
);
529 void audiohw_disable_recording(void);
532 * Set gain of recording source.
533 * @param left gain value.
534 * @param right will not be used if recording from micophone (mono).
535 * @param type AUDIO_GAIN_MIC, AUDIO_GAIN_LINEIN.
537 void audiohw_set_recvol(int left
, int right
, int type
);
539 #endif /* HAVE_RECORDING */
541 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
543 * Enable or disable recording monitor.
544 * @param enable true or false.
546 void audiohw_set_monitor(bool enable
);
551 #if CONFIG_CODEC != SWCODEC
553 /* functions which are only used by mas35xx codecs, but are also
554 aviable on SWCODECS through dsp */
557 * Set channel configuration.
558 * @param val new channel value (see enum Channel).
560 void audiohw_set_channel(int val
);
564 * @param val new stereo width value.
566 void audiohw_set_stereo_width(int val
);
568 #endif /* CONFIG_CODEC != SWCODEC */
572 void audiohw_enable_speaker(bool on
);
574 #endif /* HAVE_SPEAKER */
576 #endif /* _AUDIOHW_H_ */