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_RK27XX_CODEC)
72 #include "rk27xx_codec.h"
73 #elif defined(HAVE_AIC3X)
75 #elif defined(HAVE_CS42L55)
77 #elif defined(HAVE_IMX233_CODEC)
78 #include "imx233-codec.h"
79 #elif defined(HAVE_DUMMY_CODEC)
80 #include "dummy_codec.h"
82 #if (CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO|PLATFORM_PANDORA|PLATFORM_SDL))
83 /* #include <SDL_audio.h> gives errors in other code areas,
84 * we don't really need it here, so don't. but it should maybe be fixed */
85 #ifndef SIMULATOR /* simulator gets values from the target .h files */
86 #define VOLUME_MIN -990
95 #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
96 #warning define for VOLUME_MIN and VOLUME_MAX is missing
97 #define VOLUME_MIN -700
101 #ifndef AUDIOHW_NUM_TONE_CONTROLS
102 #define AUDIOHW_NUM_TONE_CONTROLS 0
105 /* volume/balance/treble/bass interdependency main part */
106 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
109 /* convert caps into defines */
112 #if (AUDIOHW_CAPS & TREBLE_CAP)
113 #define AUDIOHW_HAVE_TREBLE
116 #if (AUDIOHW_CAPS & BASS_CAP)
117 #define AUDIOHW_HAVE_BASS
120 #if (AUDIOHW_CAPS & BASS_CUTOFF_CAP)
121 #define AUDIOHW_HAVE_BASS_CUTOFF
124 #if (AUDIOHW_CAPS & TREBLE_CUTOFF_CAP)
125 #define AUDIOHW_HAVE_TREBLE_CUTOFF
128 #if (AUDIOHW_CAPS & BALANCE_CAP)
129 #define AUDIOHW_HAVE_BALANCE
132 #if (AUDIOHW_CAPS & CLIPPING_CAP)
133 #define AUDIOHW_HAVE_CLIPPING
136 #if (AUDIOHW_CAPS & PRESCALER_CAP)
137 #define AUDIOHW_HAVE_PRESCALER
140 /* Hardware EQ tone controls */
141 #if (AUDIOHW_CAPS & EQ_CAP)
142 /* A hardware equalizer is present (or perhaps some tone control variation
143 * that is not Bass and/or Treble) */
144 #define AUDIOHW_HAVE_EQ
146 /* Defined band indexes for supported bands */
149 /* Band 1 is implied; bands must be contiguous, 1 to N */
150 AUDIOHW_EQ_BAND1
= 0,
151 #define AUDIOHW_HAVE_EQ_BAND1
152 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 1))
154 #define AUDIOHW_HAVE_EQ_BAND2
155 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 2))
157 #define AUDIOHW_HAVE_EQ_BAND3
158 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 3))
160 #define AUDIOHW_HAVE_EQ_BAND4
161 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 4))
163 #define AUDIOHW_HAVE_EQ_BAND5
168 AUDIOHW_EQ_BAND_NUM
, /* Keep last */
171 #ifdef AUDIOHW_EQ_FREQUENCY_CAPS
172 /* One or more bands supports frequency cutoff or center adjustment */
173 #define AUDIOHW_HAVE_EQ_FREQUENCY
176 __AUDIOHW_EQ_BAND_FREQUENCY
= -1,
177 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
178 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 0))
179 AUDIOHW_EQ_BAND1_FREQUENCY
,
180 #define AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
182 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
183 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 1))
184 AUDIOHW_EQ_BAND2_FREQUENCY
,
185 #define AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
187 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
188 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 2))
189 AUDIOHW_EQ_BAND3_FREQUENCY
,
190 #define AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
192 #if defined(AUDIOHW_HAVE_EQ_BAND4) && \
193 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 3))
194 AUDIOHW_EQ_BAND4_FREQUENCY
,
195 #define AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
197 #if defined(AUDIOHW_HAVE_EQ_BAND5) && \
198 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 4))
199 AUDIOHW_EQ_BAND5_FREQUENCY
,
200 #define AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
202 AUDIOHW_EQ_FREQUENCY_NUM
,
204 #endif /* AUDIOHW_EQ_FREQUENCY_CAPS */
206 #ifdef AUDIOHW_EQ_WIDTH_CAPS
207 /* One or more bands supports bandwidth adjustment */
208 #define AUDIOHW_HAVE_EQ_WIDTH
211 __AUDIOHW_EQ_BAND_WIDTH
= -1,
212 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
213 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 1))
214 AUDIOHW_EQ_BAND2_WIDTH
,
215 #define AUDIOHW_HAVE_EQ_BAND2_WIDTH
217 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
218 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 2))
219 AUDIOHW_EQ_BAND3_WIDTH
,
220 #define AUDIOHW_HAVE_EQ_BAND3_WIDTH
222 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
223 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 3))
224 AUDIOHW_EQ_BAND4_WIDTH
,
225 #define AUDIOHW_HAVE_EQ_BAND4_WIDTH
227 AUDIOHW_EQ_WIDTH_NUM
, /* Keep last */
229 #endif /* AUDIOHW_EQ_WIDTH_CAPS */
231 /* Types and number of settings types (gain, frequency, width) */
232 enum AUDIOHW_EQ_SETTINGS
235 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
236 AUDIOHW_EQ_FREQUENCY
,
238 #ifdef AUDIOHW_HAVE_EQ_WIDTH
241 AUDIOHW_EQ_SETTING_NUM
244 #endif /* (AUDIOHW_CAPS & EQ_CAP) */
246 #if (AUDIOHW_CAPS & DEPTH_3D_CAP)
247 #define AUDIOHW_HAVE_DEPTH_3D
250 #if defined (HAVE_SW_TONE_CONTROLS)
251 /* Needed for proper sound support */
252 #define AUDIOHW_HAVE_BASS
253 #define AUDIOHW_HAVE_TREBLE
255 #endif /* AUDIOHW_CAPS */
260 #if defined(AUDIOHW_HAVE_BASS)
263 #if defined(AUDIOHW_HAVE_TREBLE)
269 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
279 #if defined(HAVE_RECORDING)
284 /* Bass and treble tone controls */
285 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
288 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
292 #if defined(AUDIOHW_HAVE_DEPTH_3D)
295 /* Hardware EQ tone controls */
297 #if defined(AUDIOHW_HAVE_EQ)
300 #if defined(AUDIOHW_HAVE_EQ_BAND2)
303 #if defined(AUDIOHW_HAVE_EQ_BAND3)
306 #if defined(AUDIOHW_HAVE_EQ_BAND4)
309 #if defined(AUDIOHW_HAVE_EQ_BAND5)
312 /* Band frequencies */
313 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
314 SOUND_EQ_BAND1_FREQUENCY
,
316 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
317 SOUND_EQ_BAND2_FREQUENCY
,
319 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
320 SOUND_EQ_BAND3_FREQUENCY
,
322 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
323 SOUND_EQ_BAND4_FREQUENCY
,
325 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
326 SOUND_EQ_BAND5_FREQUENCY
,
329 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
330 SOUND_EQ_BAND2_WIDTH
,
332 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
333 SOUND_EQ_BAND3_WIDTH
,
335 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
336 SOUND_EQ_BAND4_WIDTH
,
338 #endif /* AUDIOHW_HAVE_EQ */
339 SOUND_LAST_SETTING
, /* Keep this last */
346 SOUND_CHAN_MONO_LEFT
,
347 SOUND_CHAN_MONO_RIGHT
,
349 SOUND_CHAN_NUM_MODES
,
352 struct sound_settings_info
{
361 /* This struct is used by every driver to export its min/max/default values for
362 * its audio settings. Keep in mind that the order must be correct! */
363 extern const struct sound_settings_info audiohw_settings
[];
365 /* All usable functions implemented by a audio codec drivers. Most of
366 * the function in sound settings are only called, when in audio codecs
367 * .h file suitable defines are added.
371 * Initialize audio codec to a well defined state. Includes SoC-specific
374 void audiohw_init(void);
377 * Do initial audio codec setup. Usually called from audiohw_init.
379 void audiohw_preinit(void);
382 * Do some stuff (codec related) after audiohw_init that needs to be
383 * delayed such as enabling outputs to prevent popping. This lets
384 * other inits in the system complete in the meantime.
386 void audiohw_postinit(void);
391 void audiohw_close(void);
393 #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
395 * Set new volume value
397 * NOTE: AUDIOHW_CAPS need to contain
400 void audiohw_set_volume(int val
);
403 #ifdef AUDIOHW_HAVE_PRESCALER
405 * Set new prescaler value.
407 * NOTE: AUDIOHW_CAPS need to contain
410 void audiohw_set_prescaler(int val
);
413 #ifdef AUDIOHW_HAVE_BALANCE
415 * Set new balance value
417 * NOTE: AUDIOHW_CAPS need to contain
420 void audiohw_set_balance(int val
);
423 #ifdef AUDIOHW_HAVE_TREBLE
425 * Set new treble value.
427 * NOTE: AUDIOHW_CAPS need to contain
430 void audiohw_set_treble(int val
);
433 #ifdef AUDIOHW_HAVE_BASS
435 * Set new bass value.
437 * NOTE: AUDIOHW_CAPS need to contain
440 void audiohw_set_bass(int val
);
443 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
445 * Set new bass cut off value.
447 * NOTE: AUDIOHW_CAPS need to contain
450 void audiohw_set_bass_cutoff(int val
);
453 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
455 * Set new treble cut off value.
457 * NOTE: AUDIOHW_CAPS need to contain
460 void audiohw_set_treble_cutoff(int val
);
463 #ifdef AUDIOHW_HAVE_EQ
465 * Set new band gain value.
466 * @param band index to which val is set
468 * NOTE: AUDIOHW_CAPS need to contain
471 * AUDIOHW_EQ_BAND_CAPS must be defined as a bitmask
472 * of EQ_CAP each shifted by the zero-based band number
473 * for each band. Bands 1 to N are indexed 0 to N-1.
475 void audiohw_set_eq_band_gain(unsigned int band
, int val
);
478 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
480 * Set new band cutoff or center frequency value.
481 * @param band index to which val is set
483 * NOTE: AUDIOHW_CAPS need to contain
486 * AUDIOHW_EQ_FREQUENCY_CAPS must be defined as a bitmask
487 * of EQ_CAP each shifted by the zero-based band number
488 * for each band that supports frequency adjustment.
489 * Bands 1 to N are indexed 0 to N-1.
491 void audiohw_set_eq_band_frequency(unsigned int band
, int val
);
494 #ifdef AUDIOHW_HAVE_EQ_WIDTH
496 * Set new band cutoff or center frequency value.
497 * @param band index to which val is set
499 * NOTE: AUDIOHW_CAPS need to contain
502 * AUDIOHW_EQ_WIDTH_CAPS must be defined as a bitmask
503 * of EQ_CAP each shifted by the zero-based band number
504 * for each band that supports width adjustment.
505 * Bands 1 to N are indexed 0 to N-1.
507 void audiohw_set_eq_band_width(unsigned int band
, int val
);
510 #ifdef AUDIOHW_HAVE_DEPTH_3D
512 * Set new 3-d enhancement (stereo expansion) effect value.
514 * NOTE: AUDIOHW_CAPS need to contain
517 void audiohw_set_depth_3d(int val
);
521 void audiohw_set_frequency(int fsel
);
523 #ifdef HAVE_RECORDING
527 * @param source_mic if this is true, we want to record from microphone,
528 * else we want to record FM/LineIn.
530 void audiohw_enable_recording(bool source_mic
);
535 void audiohw_disable_recording(void);
538 * Set gain of recording source.
539 * @param left gain value.
540 * @param right will not be used if recording from micophone (mono).
541 * @param type AUDIO_GAIN_MIC, AUDIO_GAIN_LINEIN.
543 void audiohw_set_recvol(int left
, int right
, int type
);
545 #endif /* HAVE_RECORDING */
547 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
549 * Enable or disable recording monitor.
550 * @param enable true or false.
552 void audiohw_set_monitor(bool enable
);
557 #if CONFIG_CODEC != SWCODEC
559 /* functions which are only used by mas35xx codecs, but are also
560 aviable on SWCODECS through dsp */
563 * Set channel configuration.
564 * @param val new channel value (see enum Channel).
566 void audiohw_set_channel(int val
);
570 * @param val new stereo width value.
572 void audiohw_set_stereo_width(int val
);
574 #endif /* CONFIG_CODEC != SWCODEC */
578 void audiohw_enable_speaker(bool on
);
580 #endif /* HAVE_SPEAKER */
582 #endif /* _AUDIOHW_H_ */