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)
72 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
73 /* #include <SDL_audio.h> gives errors in other code areas,
74 * we don't really need it here, so don't. but it should maybe be fixed */
75 #ifndef SIMULATOR /* simulator gets values from the target .h files */
76 #define VOLUME_MIN -990
85 #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
86 #warning define for VOLUME_MIN and VOLUME_MAX is missing
87 #define VOLUME_MIN -700
91 #ifndef AUDIOHW_NUM_TONE_CONTROLS
92 #define AUDIOHW_NUM_TONE_CONTROLS 0
95 /* volume/balance/treble/bass interdependency main part */
96 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
99 /* convert caps into defines */
102 #if (AUDIOHW_CAPS & TREBLE_CAP)
103 #define AUDIOHW_HAVE_TREBLE
106 #if (AUDIOHW_CAPS & BASS_CAP)
107 #define AUDIOHW_HAVE_BASS
110 #if (AUDIOHW_CAPS & BASS_CUTOFF_CAP)
111 #define AUDIOHW_HAVE_BASS_CUTOFF
114 #if (AUDIOHW_CAPS & TREBLE_CUTOFF_CAP)
115 #define AUDIOHW_HAVE_TREBLE_CUTOFF
118 #if (AUDIOHW_CAPS & BALANCE_CAP)
119 #define AUDIOHW_HAVE_BALANCE
122 #if (AUDIOHW_CAPS & CLIPPING_CAP)
123 #define AUDIOHW_HAVE_CLIPPING
126 #if (AUDIOHW_CAPS & PRESCALER_CAP)
127 #define AUDIOHW_HAVE_PRESCALER
130 /* Hardware EQ tone controls */
131 #if (AUDIOHW_CAPS & EQ_CAP)
132 /* A hardware equalizer is present (or perhaps some tone control variation
133 * that is not Bass and/or Treble) */
134 #define AUDIOHW_HAVE_EQ
136 /* Defined band indexes for supported bands */
139 /* Band 1 is implied; bands must be contiguous, 1 to N */
140 AUDIOHW_EQ_BAND1
= 0,
141 #define AUDIOHW_HAVE_EQ_BAND1
142 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 1))
144 #define AUDIOHW_HAVE_EQ_BAND2
145 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 2))
147 #define AUDIOHW_HAVE_EQ_BAND3
148 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 3))
150 #define AUDIOHW_HAVE_EQ_BAND4
151 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 4))
153 #define AUDIOHW_HAVE_EQ_BAND5
158 AUDIOHW_EQ_BAND_NUM
, /* Keep last */
161 #ifdef AUDIOHW_EQ_FREQUENCY_CAPS
162 /* One or more bands supports frequency cutoff or center adjustment */
163 #define AUDIOHW_HAVE_EQ_FREQUENCY
166 __AUDIOHW_EQ_BAND_FREQUENCY
= -1,
167 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
168 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 0))
169 AUDIOHW_EQ_BAND1_FREQUENCY
,
170 #define AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
172 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
173 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 1))
174 AUDIOHW_EQ_BAND2_FREQUENCY
,
175 #define AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
177 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
178 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 2))
179 AUDIOHW_EQ_BAND3_FREQUENCY
,
180 #define AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
182 #if defined(AUDIOHW_HAVE_EQ_BAND4) && \
183 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 3))
184 AUDIOHW_EQ_BAND4_FREQUENCY
,
185 #define AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
187 #if defined(AUDIOHW_HAVE_EQ_BAND5) && \
188 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 4))
189 AUDIOHW_EQ_BAND5_FREQUENCY
,
190 #define AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
192 AUDIOHW_EQ_FREQUENCY_NUM
,
194 #endif /* AUDIOHW_EQ_FREQUENCY_CAPS */
196 #ifdef AUDIOHW_EQ_WIDTH_CAPS
197 /* One or more bands supports bandwidth adjustment */
198 #define AUDIOHW_HAVE_EQ_WIDTH
201 __AUDIOHW_EQ_BAND_WIDTH
= -1,
202 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
203 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 1))
204 AUDIOHW_EQ_BAND2_WIDTH
,
205 #define AUDIOHW_HAVE_EQ_BAND2_WIDTH
207 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
208 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 2))
209 AUDIOHW_EQ_BAND3_WIDTH
,
210 #define AUDIOHW_HAVE_EQ_BAND3_WIDTH
212 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
213 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 3))
214 AUDIOHW_EQ_BAND4_WIDTH
,
215 #define AUDIOHW_HAVE_EQ_BAND4_WIDTH
217 AUDIOHW_EQ_WIDTH_NUM
, /* Keep last */
219 #endif /* AUDIOHW_EQ_WIDTH_CAPS */
221 /* Types and number of settings types (gain, frequency, width) */
222 enum AUDIOHW_EQ_SETTINGS
225 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
226 AUDIOHW_EQ_FREQUENCY
,
228 #ifdef AUDIOHW_HAVE_EQ_WIDTH
231 AUDIOHW_EQ_SETTING_NUM
234 #endif /* (AUDIOHW_CAPS & EQ_CAP) */
236 #if (AUDIOHW_CAPS & DEPTH_3D_CAP)
237 #define AUDIOHW_HAVE_DEPTH_3D
240 #if defined (HAVE_SW_TONE_CONTROLS)
241 /* Needed for proper sound support */
242 #define AUDIOHW_HAVE_BASS
243 #define AUDIOHW_HAVE_TREBLE
245 #endif /* AUDIOHW_CAPS */
250 #if defined(AUDIOHW_HAVE_BASS)
253 #if defined(AUDIOHW_HAVE_TREBLE)
259 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
269 #if defined(HAVE_RECORDING)
274 /* Bass and treble tone controls */
275 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
278 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
282 #if defined(AUDIOHW_HAVE_DEPTH_3D)
285 /* Hardware EQ tone controls */
287 #if defined(AUDIOHW_HAVE_EQ)
290 #if defined(AUDIOHW_HAVE_EQ_BAND2)
293 #if defined(AUDIOHW_HAVE_EQ_BAND3)
296 #if defined(AUDIOHW_HAVE_EQ_BAND4)
299 #if defined(AUDIOHW_HAVE_EQ_BAND5)
302 /* Band frequencies */
303 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
304 SOUND_EQ_BAND1_FREQUENCY
,
306 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
307 SOUND_EQ_BAND2_FREQUENCY
,
309 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
310 SOUND_EQ_BAND3_FREQUENCY
,
312 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
313 SOUND_EQ_BAND4_FREQUENCY
,
315 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
316 SOUND_EQ_BAND5_FREQUENCY
,
319 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
320 SOUND_EQ_BAND2_WIDTH
,
322 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
323 SOUND_EQ_BAND3_WIDTH
,
325 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
326 SOUND_EQ_BAND4_WIDTH
,
328 #endif /* AUDIOHW_HAVE_EQ */
329 SOUND_LAST_SETTING
, /* Keep this last */
336 SOUND_CHAN_MONO_LEFT
,
337 SOUND_CHAN_MONO_RIGHT
,
339 SOUND_CHAN_NUM_MODES
,
342 struct sound_settings_info
{
351 /* This struct is used by every driver to export its min/max/default values for
352 * its audio settings. Keep in mind that the order must be correct! */
353 extern const struct sound_settings_info audiohw_settings
[];
355 /* All usable functions implemented by a audio codec drivers. Most of
356 * the function in sound settings are only called, when in audio codecs
357 * .h file suitable defines are added.
361 * Initialize audio codec to a well defined state. Includes SoC-specific
364 void audiohw_init(void);
367 * Do initial audio codec setup. Usually called from audiohw_init.
369 void audiohw_preinit(void);
372 * Do some stuff (codec related) after audiohw_init that needs to be
373 * delayed such as enabling outputs to prevent popping. This lets
374 * other inits in the system complete in the meantime.
376 void audiohw_postinit(void);
381 void audiohw_close(void);
383 #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
385 * Set new volume value
387 * NOTE: AUDIOHW_CAPS need to contain
390 void audiohw_set_volume(int val
);
393 #ifdef AUDIOHW_HAVE_PRESCALER
395 * Set new prescaler value.
397 * NOTE: AUDIOHW_CAPS need to contain
400 void audiohw_set_prescaler(int val
);
403 #ifdef AUDIOHW_HAVE_BALANCE
405 * Set new balance value
407 * NOTE: AUDIOHW_CAPS need to contain
410 void audiohw_set_balance(int val
);
413 #ifdef AUDIOHW_HAVE_TREBLE
415 * Set new treble value.
417 * NOTE: AUDIOHW_CAPS need to contain
420 void audiohw_set_treble(int val
);
423 #ifdef AUDIOHW_HAVE_BASS
425 * Set new bass value.
427 * NOTE: AUDIOHW_CAPS need to contain
430 void audiohw_set_bass(int val
);
433 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
435 * Set new bass cut off value.
437 * NOTE: AUDIOHW_CAPS need to contain
440 void audiohw_set_bass_cutoff(int val
);
443 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
445 * Set new treble cut off value.
447 * NOTE: AUDIOHW_CAPS need to contain
450 void audiohw_set_treble_cutoff(int val
);
453 #ifdef AUDIOHW_HAVE_EQ
455 * Set new band gain value.
456 * @param band index to which val is set
458 * NOTE: AUDIOHW_CAPS need to contain
461 * AUDIOHW_EQ_BAND_CAPS must be defined as a bitmask
462 * of EQ_CAP each shifted by the zero-based band number
463 * for each band. Bands 1 to N are indexed 0 to N-1.
465 void audiohw_set_eq_band_gain(unsigned int band
, int val
);
468 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
470 * Set new band cutoff or center frequency value.
471 * @param band index to which val is set
473 * NOTE: AUDIOHW_CAPS need to contain
476 * AUDIOHW_EQ_FREQUENCY_CAPS must be defined as a bitmask
477 * of EQ_CAP each shifted by the zero-based band number
478 * for each band that supports frequency adjustment.
479 * Bands 1 to N are indexed 0 to N-1.
481 void audiohw_set_eq_band_frequency(unsigned int band
, int val
);
484 #ifdef AUDIOHW_HAVE_EQ_WIDTH
486 * Set new band cutoff or center frequency value.
487 * @param band index to which val is set
489 * NOTE: AUDIOHW_CAPS need to contain
492 * AUDIOHW_EQ_WIDTH_CAPS must be defined as a bitmask
493 * of EQ_CAP each shifted by the zero-based band number
494 * for each band that supports width adjustment.
495 * Bands 1 to N are indexed 0 to N-1.
497 void audiohw_set_eq_band_width(unsigned int band
, int val
);
500 #ifdef AUDIOHW_HAVE_DEPTH_3D
502 * Set new 3-d enhancement (stereo expansion) effect value.
504 * NOTE: AUDIOHW_CAPS need to contain
507 void audiohw_set_depth_3d(int val
);
511 void audiohw_set_frequency(int fsel
);
513 #ifdef HAVE_RECORDING
517 * @param source_mic if this is true, we want to record from microphone,
518 * else we want to record FM/LineIn.
520 void audiohw_enable_recording(bool source_mic
);
525 void audiohw_disable_recording(void);
528 * Set gain of recording source.
529 * @param left gain value.
530 * @param right will not be used if recording from micophone (mono).
531 * @param type AUDIO_GAIN_MIC, AUDIO_GAIN_LINEIN.
533 void audiohw_set_recvol(int left
, int right
, int type
);
535 #endif /* HAVE_RECORDING */
537 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
539 * Enable or disable recording monitor.
540 * @param enable true or false.
542 void audiohw_set_monitor(bool enable
);
547 #if CONFIG_CODEC != SWCODEC
549 /* functions which are only used by mas35xx codecs, but are also
550 aviable on SWCODECS through dsp */
553 * Set channel configuration.
554 * @param val new channel value (see enum Channel).
556 void audiohw_set_channel(int val
);
560 * @param val new stereo width value.
562 void audiohw_set_stereo_width(int val
);
564 #endif /* CONFIG_CODEC != SWCODEC */
568 void audiohw_enable_speaker(bool on
);
570 #endif /* HAVE_SPEAKER */
572 #endif /* _AUDIOHW_H_ */