- Move uisimulator/sdl/*.[ch] into the target tree, under firmware/target/hosted...
[kugel-rb.git] / firmware / export / audiohw.h
blobb8214e67b9b6b345b62746230228004c2713496b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #ifndef _AUDIOHW_H_
23 #define _AUDIOHW_H_
25 #include "config.h"
26 #include <stdbool.h>
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)
39 #ifdef HAVE_UDA1380
40 #include "uda1380.h"
41 #elif defined(HAVE_UDA1341)
42 #include "uda1341.h"
43 #elif defined(HAVE_WM8750) || defined(HAVE_WM8751)
44 #include "wm8751.h"
45 #elif defined(HAVE_WM8978)
46 #include "wm8978.h"
47 #elif defined(HAVE_WM8975)
48 #include "wm8975.h"
49 #elif defined(HAVE_WM8985)
50 #include "wm8985.h"
51 #elif defined(HAVE_WM8758)
52 #include "wm8758.h"
53 #elif defined(HAVE_WM8711) || defined(HAVE_WM8721) || \
54 defined(HAVE_WM8731)
55 #include "wm8731.h"
56 #elif defined(HAVE_TLV320)
57 #include "tlv320.h"
58 #elif defined(HAVE_AS3514)
59 #include "as3514.h"
60 #elif defined(HAVE_MAS35XX)
61 #include "mas35xx.h"
62 #elif defined(HAVE_TSC2100)
63 #include "tsc2100.h"
64 #elif defined(HAVE_JZ4740_CODEC)
65 #include "jz4740-codec.h"
66 #elif defined(HAVE_AK4537)
67 #include "ak4537.h"
68 #endif
69 #if defined(HAVE_SDL_AUDIO)
70 /* #include <SDL_audio.h> gives errors in other code areas,
71 * we don't really need it here, so don't. but it should maybe be fixed */
72 #endif
76 #define ONE_DB 10
78 #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
79 #warning define for VOLUME_MIN and VOLUME_MAX is missing
80 #define VOLUME_MIN -700
81 #define VOLUME_MAX 0
82 #endif
84 #ifndef AUDIOHW_NUM_TONE_CONTROLS
85 #define AUDIOHW_NUM_TONE_CONTROLS 0
86 #endif
88 /* volume/balance/treble/bass interdependency main part */
89 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
92 /* convert caps into defines */
93 #ifdef AUDIOHW_CAPS
94 /* Tone controls */
95 #if (AUDIOHW_CAPS & TREBLE_CAP)
96 #define AUDIOHW_HAVE_TREBLE
97 #endif
99 #if (AUDIOHW_CAPS & BASS_CAP)
100 #define AUDIOHW_HAVE_BASS
101 #endif
103 #if (AUDIOHW_CAPS & BASS_CUTOFF_CAP)
104 #define AUDIOHW_HAVE_BASS_CUTOFF
105 #endif
107 #if (AUDIOHW_CAPS & TREBLE_CUTOFF_CAP)
108 #define AUDIOHW_HAVE_TREBLE_CUTOFF
109 #endif
111 #if (AUDIOHW_CAPS & BALANCE_CAP)
112 #define AUDIOHW_HAVE_BALANCE
113 #endif
115 #if (AUDIOHW_CAPS & CLIPPING_CAP)
116 #define AUDIOHW_HAVE_CLIPPING
117 #endif
119 #if (AUDIOHW_CAPS & PRESCALER_CAP)
120 #define AUDIOHW_HAVE_PRESCALER
121 #endif
123 /* Hardware EQ tone controls */
124 #if (AUDIOHW_CAPS & EQ_CAP)
125 /* A hardware equalizer is present (or perhaps some tone control variation
126 * that is not Bass and/or Treble) */
127 #define AUDIOHW_HAVE_EQ
129 /* Defined band indexes for supported bands */
130 enum
132 /* Band 1 is implied; bands must be contiguous, 1 to N */
133 AUDIOHW_EQ_BAND1 = 0,
134 #define AUDIOHW_HAVE_EQ_BAND1
135 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 1))
136 AUDIOHW_EQ_BAND2,
137 #define AUDIOHW_HAVE_EQ_BAND2
138 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 2))
139 AUDIOHW_EQ_BAND3,
140 #define AUDIOHW_HAVE_EQ_BAND3
141 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 3))
142 AUDIOHW_EQ_BAND4,
143 #define AUDIOHW_HAVE_EQ_BAND4
144 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 4))
145 AUDIOHW_EQ_BAND5,
146 #define AUDIOHW_HAVE_EQ_BAND5
147 #endif /* 5 */
148 #endif /* 4 */
149 #endif /* 3 */
150 #endif /* 2 */
151 AUDIOHW_EQ_BAND_NUM, /* Keep last */
154 #ifdef AUDIOHW_EQ_FREQUENCY_CAPS
155 /* One or more bands supports frequency cutoff or center adjustment */
156 #define AUDIOHW_HAVE_EQ_FREQUENCY
157 enum
159 __AUDIOHW_EQ_BAND_FREQUENCY = -1,
160 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
161 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 0))
162 AUDIOHW_EQ_BAND1_FREQUENCY,
163 #define AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
164 #endif
165 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
166 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 1))
167 AUDIOHW_EQ_BAND2_FREQUENCY,
168 #define AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
169 #endif
170 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
171 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 2))
172 AUDIOHW_EQ_BAND3_FREQUENCY,
173 #define AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
174 #endif
175 #if defined(AUDIOHW_HAVE_EQ_BAND4) && \
176 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 3))
177 AUDIOHW_EQ_BAND4_FREQUENCY,
178 #define AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
179 #endif
180 #if defined(AUDIOHW_HAVE_EQ_BAND5) && \
181 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 4))
182 AUDIOHW_EQ_BAND5_FREQUENCY,
183 #define AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
184 #endif
185 AUDIOHW_EQ_FREQUENCY_NUM,
187 #endif /* AUDIOHW_EQ_FREQUENCY_CAPS */
189 #ifdef AUDIOHW_EQ_WIDTH_CAPS
190 /* One or more bands supports bandwidth adjustment */
191 #define AUDIOHW_HAVE_EQ_WIDTH
192 enum
194 __AUDIOHW_EQ_BAND_WIDTH = -1,
195 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
196 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 1))
197 AUDIOHW_EQ_BAND2_WIDTH,
198 #define AUDIOHW_HAVE_EQ_BAND2_WIDTH
199 #endif
200 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
201 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 2))
202 AUDIOHW_EQ_BAND3_WIDTH,
203 #define AUDIOHW_HAVE_EQ_BAND3_WIDTH
204 #endif
205 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
206 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 3))
207 AUDIOHW_EQ_BAND4_WIDTH,
208 #define AUDIOHW_HAVE_EQ_BAND4_WIDTH
209 #endif
210 AUDIOHW_EQ_WIDTH_NUM, /* Keep last */
212 #endif /* AUDIOHW_EQ_WIDTH_CAPS */
214 /* Types and number of settings types (gain, frequency, width) */
215 enum AUDIOHW_EQ_SETTINGS
217 AUDIOHW_EQ_GAIN = 0,
218 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
219 AUDIOHW_EQ_FREQUENCY,
220 #endif
221 #ifdef AUDIOHW_HAVE_EQ_WIDTH
222 AUDIOHW_EQ_WIDTH,
223 #endif
224 AUDIOHW_EQ_SETTING_NUM
227 #endif /* (AUDIOHW_CAPS & EQ_CAP) */
229 #if (AUDIOHW_CAPS & DEPTH_3D_CAP)
230 #define AUDIOHW_HAVE_DEPTH_3D
231 #endif
232 #else
233 #if defined (HAVE_SW_TONE_CONTROLS)
234 /* Needed for proper sound support */
235 #define AUDIOHW_HAVE_BASS
236 #define AUDIOHW_HAVE_TREBLE
237 #endif
238 #endif /* AUDIOHW_CAPS */
240 enum {
241 SOUND_VOLUME = 0,
242 /* Tone control */
243 #if defined(AUDIOHW_HAVE_BASS)
244 SOUND_BASS,
245 #endif
246 #if defined(AUDIOHW_HAVE_TREBLE)
247 SOUND_TREBLE,
248 #endif
249 SOUND_BALANCE,
250 SOUND_CHANNELS,
251 SOUND_STEREO_WIDTH,
252 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
253 SOUND_LOUDNESS,
254 SOUND_AVC,
255 SOUND_MDB_STRENGTH,
256 SOUND_MDB_HARMONICS,
257 SOUND_MDB_CENTER,
258 SOUND_MDB_SHAPE,
259 SOUND_MDB_ENABLE,
260 SOUND_SUPERBASS,
261 #endif
262 #if defined(HAVE_RECORDING)
263 SOUND_LEFT_GAIN,
264 SOUND_RIGHT_GAIN,
265 SOUND_MIC_GAIN,
266 #endif
267 /* Bass and treble tone controls */
268 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
269 SOUND_BASS_CUTOFF,
270 #endif
271 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
272 SOUND_TREBLE_CUTOFF,
273 #endif
274 /* 3D effect */
275 #if defined(AUDIOHW_HAVE_DEPTH_3D)
276 SOUND_DEPTH_3D,
277 #endif
278 /* Hardware EQ tone controls */
279 /* Band gains */
280 #if defined(AUDIOHW_HAVE_EQ)
281 /* Band 1 implied */
282 SOUND_EQ_BAND1_GAIN,
283 #if defined(AUDIOHW_HAVE_EQ_BAND2)
284 SOUND_EQ_BAND2_GAIN,
285 #endif
286 #if defined(AUDIOHW_HAVE_EQ_BAND3)
287 SOUND_EQ_BAND3_GAIN,
288 #endif
289 #if defined(AUDIOHW_HAVE_EQ_BAND4)
290 SOUND_EQ_BAND4_GAIN,
291 #endif
292 #if defined(AUDIOHW_HAVE_EQ_BAND5)
293 SOUND_EQ_BAND5_GAIN,
294 #endif
295 /* Band frequencies */
296 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
297 SOUND_EQ_BAND1_FREQUENCY,
298 #endif
299 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
300 SOUND_EQ_BAND2_FREQUENCY,
301 #endif
302 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
303 SOUND_EQ_BAND3_FREQUENCY,
304 #endif
305 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
306 SOUND_EQ_BAND4_FREQUENCY,
307 #endif
308 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
309 SOUND_EQ_BAND5_FREQUENCY,
310 #endif
311 /* Band widths */
312 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
313 SOUND_EQ_BAND2_WIDTH,
314 #endif
315 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
316 SOUND_EQ_BAND3_WIDTH,
317 #endif
318 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
319 SOUND_EQ_BAND4_WIDTH,
320 #endif
321 #endif /* AUDIOHW_HAVE_EQ */
322 SOUND_LAST_SETTING, /* Keep this last */
325 enum Channel {
326 SOUND_CHAN_STEREO,
327 SOUND_CHAN_MONO,
328 SOUND_CHAN_CUSTOM,
329 SOUND_CHAN_MONO_LEFT,
330 SOUND_CHAN_MONO_RIGHT,
331 SOUND_CHAN_KARAOKE,
332 SOUND_CHAN_NUM_MODES,
335 struct sound_settings_info {
336 const char *unit;
337 char numdecimals;
338 char steps;
339 short minval;
340 short maxval;
341 short defaultval;
344 /* This struct is used by every driver to export its min/max/default values for
345 * its audio settings. Keep in mind that the order must be correct! */
346 extern const struct sound_settings_info audiohw_settings[];
348 /* All usable functions implemented by a audio codec drivers. Most of
349 * the function in sound settings are only called, when in audio codecs
350 * .h file suitable defines are added.
354 * Initialize audio codec to a well defined state. Includes SoC-specific
355 * setup.
357 void audiohw_init(void);
360 * Do initial audio codec setup. Usually called from audiohw_init.
362 void audiohw_preinit(void);
365 * Do some stuff (codec related) after audiohw_init that needs to be
366 * delayed such as enabling outputs to prevent popping. This lets
367 * other inits in the system complete in the meantime.
369 void audiohw_postinit(void);
372 * Close audio codec.
374 void audiohw_close(void);
376 #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO)
378 * Set new volume value
379 * @param val to set.
380 * NOTE: AUDIOHW_CAPS need to contain
381 * CLIPPING_CAP
383 void audiohw_set_volume(int val);
384 #endif
386 #ifdef AUDIOHW_HAVE_PRESCALER
388 * Set new prescaler value.
389 * @param val to set.
390 * NOTE: AUDIOHW_CAPS need to contain
391 * PRESCALER_CAP
393 void audiohw_set_prescaler(int val);
394 #endif
396 #ifdef AUDIOHW_HAVE_BALANCE
398 * Set new balance value
399 * @param val to set.
400 * NOTE: AUDIOHW_CAPS need to contain
401 * BALANCE_CAP
403 void audiohw_set_balance(int val);
404 #endif
406 #ifdef AUDIOHW_HAVE_TREBLE
408 * Set new treble value.
409 * @param val to set.
410 * NOTE: AUDIOHW_CAPS need to contain
411 * TREBLE_CAP
413 void audiohw_set_treble(int val);
414 #endif
416 #ifdef AUDIOHW_HAVE_BASS
418 * Set new bass value.
419 * @param val to set.
420 * NOTE: AUDIOHW_CAPS need to contain
421 * BASS_CAP
423 void audiohw_set_bass(int val);
424 #endif
426 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
428 * Set new bass cut off value.
429 * @param val to set.
430 * NOTE: AUDIOHW_CAPS need to contain
431 * BASS_CUTOFF_CAP
433 void audiohw_set_bass_cutoff(int val);
434 #endif
436 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
438 * Set new treble cut off value.
439 * @param val to set.
440 * NOTE: AUDIOHW_CAPS need to contain
441 * TREBLE_CUTOFF_CAP
443 void audiohw_set_treble_cutoff(int val);
444 #endif
446 #ifdef AUDIOHW_HAVE_EQ
448 * Set new band gain value.
449 * @param band index to which val is set
450 * @param val to set.
451 * NOTE: AUDIOHW_CAPS need to contain
452 * EQ_CAP
454 * AUDIOHW_EQ_BAND_CAPS must be defined as a bitmask
455 * of EQ_CAP each shifted by the zero-based band number
456 * for each band. Bands 1 to N are indexed 0 to N-1.
458 void audiohw_set_eq_band_gain(unsigned int band, int val);
459 #endif
461 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
463 * Set new band cutoff or center frequency value.
464 * @param band index to which val is set
465 * @param val to set.
466 * NOTE: AUDIOHW_CAPS need to contain
467 * EQ_CAP
469 * AUDIOHW_EQ_FREQUENCY_CAPS must be defined as a bitmask
470 * of EQ_CAP each shifted by the zero-based band number
471 * for each band that supports frequency adjustment.
472 * Bands 1 to N are indexed 0 to N-1.
474 void audiohw_set_eq_band_frequency(unsigned int band, int val);
475 #endif
477 #ifdef AUDIOHW_HAVE_EQ_WIDTH
479 * Set new band cutoff or center frequency value.
480 * @param band index to which val is set
481 * @param val to set.
482 * NOTE: AUDIOHW_CAPS need to contain
483 * EQ_CAP
485 * AUDIOHW_EQ_WIDTH_CAPS must be defined as a bitmask
486 * of EQ_CAP each shifted by the zero-based band number
487 * for each band that supports width adjustment.
488 * Bands 1 to N are indexed 0 to N-1.
490 void audiohw_set_eq_band_width(unsigned int band, int val);
491 #endif
493 #ifdef AUDIOHW_HAVE_DEPTH_3D
495 * Set new 3-d enhancement (stereo expansion) effect value.
496 * @param val to set.
497 * NOTE: AUDIOHW_CAPS need to contain
498 * DEPTH_3D_CAP
500 void audiohw_set_depth_3d(int val);
501 #endif
504 void audiohw_set_frequency(int fsel);
506 #ifdef HAVE_RECORDING
509 * Enable recording.
510 * @param source_mic if this is true, we want to record from microphone,
511 * else we want to record FM/LineIn.
513 void audiohw_enable_recording(bool source_mic);
516 * Disable recording.
518 void audiohw_disable_recording(void);
521 * Set gain of recording source.
522 * @param left gain value.
523 * @param right will not be used if recording from micophone (mono).
524 * @param type AUDIO_GAIN_MIC, AUDIO_GAIN_LINEIN.
526 void audiohw_set_recvol(int left, int right, int type);
528 #endif /*HAVE_RECORDING*/
530 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
533 * Enable or disable recording monitor.
534 * @param enable ture or false.
536 void audiohw_set_monitor(bool enable);
538 #endif /* HAVE_RECORDING || HAVE_FMRADIO_IN */
540 #if CONFIG_CODEC != SWCODEC
542 /* functions which are only used by mas35xx codecs, but are also
543 aviable on SWCODECS through dsp */
546 * Set channel configuration.
547 * @param val new channel value (see enum Channel).
549 void audiohw_set_channel(int val);
552 * Set stereo width.
553 * @param val new stereo width value.
555 void audiohw_set_stereo_width(int val);
557 #endif /* CONFIG_CODEC != SWCODEC */
559 #ifdef HAVE_SPEAKER
561 void audiohw_enable_speaker(bool on);
563 #endif /* HAVE_SPEAKER */
565 #endif /* _AUDIOHW_H_ */