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)
74 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
75 /* #include <SDL_audio.h> gives errors in other code areas,
76 * we don't really need it here, so don't. but it should maybe be fixed */
77 #ifndef SIMULATOR /* simulator gets values from the target .h files */
78 #define VOLUME_MIN -990
87 #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
88 #warning define for VOLUME_MIN and VOLUME_MAX is missing
89 #define VOLUME_MIN -700
93 #ifndef AUDIOHW_NUM_TONE_CONTROLS
94 #define AUDIOHW_NUM_TONE_CONTROLS 0
97 /* volume/balance/treble/bass interdependency main part */
98 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
101 /* convert caps into defines */
104 #if (AUDIOHW_CAPS & TREBLE_CAP)
105 #define AUDIOHW_HAVE_TREBLE
108 #if (AUDIOHW_CAPS & BASS_CAP)
109 #define AUDIOHW_HAVE_BASS
112 #if (AUDIOHW_CAPS & BASS_CUTOFF_CAP)
113 #define AUDIOHW_HAVE_BASS_CUTOFF
116 #if (AUDIOHW_CAPS & TREBLE_CUTOFF_CAP)
117 #define AUDIOHW_HAVE_TREBLE_CUTOFF
120 #if (AUDIOHW_CAPS & BALANCE_CAP)
121 #define AUDIOHW_HAVE_BALANCE
124 #if (AUDIOHW_CAPS & CLIPPING_CAP)
125 #define AUDIOHW_HAVE_CLIPPING
128 #if (AUDIOHW_CAPS & PRESCALER_CAP)
129 #define AUDIOHW_HAVE_PRESCALER
132 /* Hardware EQ tone controls */
133 #if (AUDIOHW_CAPS & EQ_CAP)
134 /* A hardware equalizer is present (or perhaps some tone control variation
135 * that is not Bass and/or Treble) */
136 #define AUDIOHW_HAVE_EQ
138 /* Defined band indexes for supported bands */
141 /* Band 1 is implied; bands must be contiguous, 1 to N */
142 AUDIOHW_EQ_BAND1
= 0,
143 #define AUDIOHW_HAVE_EQ_BAND1
144 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 1))
146 #define AUDIOHW_HAVE_EQ_BAND2
147 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 2))
149 #define AUDIOHW_HAVE_EQ_BAND3
150 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 3))
152 #define AUDIOHW_HAVE_EQ_BAND4
153 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 4))
155 #define AUDIOHW_HAVE_EQ_BAND5
160 AUDIOHW_EQ_BAND_NUM
, /* Keep last */
163 #ifdef AUDIOHW_EQ_FREQUENCY_CAPS
164 /* One or more bands supports frequency cutoff or center adjustment */
165 #define AUDIOHW_HAVE_EQ_FREQUENCY
168 __AUDIOHW_EQ_BAND_FREQUENCY
= -1,
169 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
170 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 0))
171 AUDIOHW_EQ_BAND1_FREQUENCY
,
172 #define AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
174 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
175 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 1))
176 AUDIOHW_EQ_BAND2_FREQUENCY
,
177 #define AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
179 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
180 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 2))
181 AUDIOHW_EQ_BAND3_FREQUENCY
,
182 #define AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
184 #if defined(AUDIOHW_HAVE_EQ_BAND4) && \
185 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 3))
186 AUDIOHW_EQ_BAND4_FREQUENCY
,
187 #define AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
189 #if defined(AUDIOHW_HAVE_EQ_BAND5) && \
190 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 4))
191 AUDIOHW_EQ_BAND5_FREQUENCY
,
192 #define AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
194 AUDIOHW_EQ_FREQUENCY_NUM
,
196 #endif /* AUDIOHW_EQ_FREQUENCY_CAPS */
198 #ifdef AUDIOHW_EQ_WIDTH_CAPS
199 /* One or more bands supports bandwidth adjustment */
200 #define AUDIOHW_HAVE_EQ_WIDTH
203 __AUDIOHW_EQ_BAND_WIDTH
= -1,
204 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
205 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 1))
206 AUDIOHW_EQ_BAND2_WIDTH
,
207 #define AUDIOHW_HAVE_EQ_BAND2_WIDTH
209 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
210 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 2))
211 AUDIOHW_EQ_BAND3_WIDTH
,
212 #define AUDIOHW_HAVE_EQ_BAND3_WIDTH
214 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
215 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 3))
216 AUDIOHW_EQ_BAND4_WIDTH
,
217 #define AUDIOHW_HAVE_EQ_BAND4_WIDTH
219 AUDIOHW_EQ_WIDTH_NUM
, /* Keep last */
221 #endif /* AUDIOHW_EQ_WIDTH_CAPS */
223 /* Types and number of settings types (gain, frequency, width) */
224 enum AUDIOHW_EQ_SETTINGS
227 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
228 AUDIOHW_EQ_FREQUENCY
,
230 #ifdef AUDIOHW_HAVE_EQ_WIDTH
233 AUDIOHW_EQ_SETTING_NUM
236 #endif /* (AUDIOHW_CAPS & EQ_CAP) */
238 #if (AUDIOHW_CAPS & DEPTH_3D_CAP)
239 #define AUDIOHW_HAVE_DEPTH_3D
242 #if defined (HAVE_SW_TONE_CONTROLS)
243 /* Needed for proper sound support */
244 #define AUDIOHW_HAVE_BASS
245 #define AUDIOHW_HAVE_TREBLE
247 #endif /* AUDIOHW_CAPS */
252 #if defined(AUDIOHW_HAVE_BASS)
255 #if defined(AUDIOHW_HAVE_TREBLE)
261 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
271 #if defined(HAVE_RECORDING)
276 /* Bass and treble tone controls */
277 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
280 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
284 #if defined(AUDIOHW_HAVE_DEPTH_3D)
287 /* Hardware EQ tone controls */
289 #if defined(AUDIOHW_HAVE_EQ)
292 #if defined(AUDIOHW_HAVE_EQ_BAND2)
295 #if defined(AUDIOHW_HAVE_EQ_BAND3)
298 #if defined(AUDIOHW_HAVE_EQ_BAND4)
301 #if defined(AUDIOHW_HAVE_EQ_BAND5)
304 /* Band frequencies */
305 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
306 SOUND_EQ_BAND1_FREQUENCY
,
308 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
309 SOUND_EQ_BAND2_FREQUENCY
,
311 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
312 SOUND_EQ_BAND3_FREQUENCY
,
314 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
315 SOUND_EQ_BAND4_FREQUENCY
,
317 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
318 SOUND_EQ_BAND5_FREQUENCY
,
321 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
322 SOUND_EQ_BAND2_WIDTH
,
324 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
325 SOUND_EQ_BAND3_WIDTH
,
327 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
328 SOUND_EQ_BAND4_WIDTH
,
330 #endif /* AUDIOHW_HAVE_EQ */
331 SOUND_LAST_SETTING
, /* Keep this last */
338 SOUND_CHAN_MONO_LEFT
,
339 SOUND_CHAN_MONO_RIGHT
,
341 SOUND_CHAN_NUM_MODES
,
344 struct sound_settings_info
{
353 /* This struct is used by every driver to export its min/max/default values for
354 * its audio settings. Keep in mind that the order must be correct! */
355 extern const struct sound_settings_info audiohw_settings
[];
357 /* All usable functions implemented by a audio codec drivers. Most of
358 * the function in sound settings are only called, when in audio codecs
359 * .h file suitable defines are added.
363 * Initialize audio codec to a well defined state. Includes SoC-specific
366 void audiohw_init(void);
369 * Do initial audio codec setup. Usually called from audiohw_init.
371 void audiohw_preinit(void);
374 * Do some stuff (codec related) after audiohw_init that needs to be
375 * delayed such as enabling outputs to prevent popping. This lets
376 * other inits in the system complete in the meantime.
378 void audiohw_postinit(void);
383 void audiohw_close(void);
385 #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
387 * Set new volume value
389 * NOTE: AUDIOHW_CAPS need to contain
392 void audiohw_set_volume(int val
);
395 #ifdef AUDIOHW_HAVE_PRESCALER
397 * Set new prescaler value.
399 * NOTE: AUDIOHW_CAPS need to contain
402 void audiohw_set_prescaler(int val
);
405 #ifdef AUDIOHW_HAVE_BALANCE
407 * Set new balance value
409 * NOTE: AUDIOHW_CAPS need to contain
412 void audiohw_set_balance(int val
);
415 #ifdef AUDIOHW_HAVE_TREBLE
417 * Set new treble value.
419 * NOTE: AUDIOHW_CAPS need to contain
422 void audiohw_set_treble(int val
);
425 #ifdef AUDIOHW_HAVE_BASS
427 * Set new bass value.
429 * NOTE: AUDIOHW_CAPS need to contain
432 void audiohw_set_bass(int val
);
435 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
437 * Set new bass cut off value.
439 * NOTE: AUDIOHW_CAPS need to contain
442 void audiohw_set_bass_cutoff(int val
);
445 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
447 * Set new treble cut off value.
449 * NOTE: AUDIOHW_CAPS need to contain
452 void audiohw_set_treble_cutoff(int val
);
455 #ifdef AUDIOHW_HAVE_EQ
457 * Set new band gain value.
458 * @param band index to which val is set
460 * NOTE: AUDIOHW_CAPS need to contain
463 * AUDIOHW_EQ_BAND_CAPS must be defined as a bitmask
464 * of EQ_CAP each shifted by the zero-based band number
465 * for each band. Bands 1 to N are indexed 0 to N-1.
467 void audiohw_set_eq_band_gain(unsigned int band
, int val
);
470 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
472 * Set new band cutoff or center frequency value.
473 * @param band index to which val is set
475 * NOTE: AUDIOHW_CAPS need to contain
478 * AUDIOHW_EQ_FREQUENCY_CAPS must be defined as a bitmask
479 * of EQ_CAP each shifted by the zero-based band number
480 * for each band that supports frequency adjustment.
481 * Bands 1 to N are indexed 0 to N-1.
483 void audiohw_set_eq_band_frequency(unsigned int band
, int val
);
486 #ifdef AUDIOHW_HAVE_EQ_WIDTH
488 * Set new band cutoff or center frequency value.
489 * @param band index to which val is set
491 * NOTE: AUDIOHW_CAPS need to contain
494 * AUDIOHW_EQ_WIDTH_CAPS must be defined as a bitmask
495 * of EQ_CAP each shifted by the zero-based band number
496 * for each band that supports width adjustment.
497 * Bands 1 to N are indexed 0 to N-1.
499 void audiohw_set_eq_band_width(unsigned int band
, int val
);
502 #ifdef AUDIOHW_HAVE_DEPTH_3D
504 * Set new 3-d enhancement (stereo expansion) effect value.
506 * NOTE: AUDIOHW_CAPS need to contain
509 void audiohw_set_depth_3d(int val
);
513 void audiohw_set_frequency(int fsel
);
515 #ifdef HAVE_RECORDING
519 * @param source_mic if this is true, we want to record from microphone,
520 * else we want to record FM/LineIn.
522 void audiohw_enable_recording(bool source_mic
);
527 void audiohw_disable_recording(void);
530 * Set gain of recording source.
531 * @param left gain value.
532 * @param right will not be used if recording from micophone (mono).
533 * @param type AUDIO_GAIN_MIC, AUDIO_GAIN_LINEIN.
535 void audiohw_set_recvol(int left
, int right
, int type
);
537 #endif /* HAVE_RECORDING */
539 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
541 * Enable or disable recording monitor.
542 * @param enable true or false.
544 void audiohw_set_monitor(bool enable
);
549 #if CONFIG_CODEC != SWCODEC
551 /* functions which are only used by mas35xx codecs, but are also
552 aviable on SWCODECS through dsp */
555 * Set channel configuration.
556 * @param val new channel value (see enum Channel).
558 void audiohw_set_channel(int val
);
562 * @param val new stereo width value.
564 void audiohw_set_stereo_width(int val
);
566 #endif /* CONFIG_CODEC != SWCODEC */
570 void audiohw_enable_speaker(bool on
);
572 #endif /* HAVE_SPEAKER */
574 #endif /* _AUDIOHW_H_ */