Merge branch 'gsoc-dir-split' into gsoc-android-botloader
[kugel-rb.git] / firmware / export / audiohw.h
blob46ca9a89666bdd59b6a427c174c0b3ad4284ffe3
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) || defined(ANDROID)
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 #ifndef SIMULATOR /* simulator gets values from the target .h files */
73 #define VOLUME_MIN -990
74 #define VOLUME_MAX 0
75 #endif
76 #endif
80 #define ONE_DB 10
82 #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
83 #warning define for VOLUME_MIN and VOLUME_MAX is missing
84 #define VOLUME_MIN -700
85 #define VOLUME_MAX 0
86 #endif
88 #ifndef AUDIOHW_NUM_TONE_CONTROLS
89 #define AUDIOHW_NUM_TONE_CONTROLS 0
90 #endif
92 /* volume/balance/treble/bass interdependency main part */
93 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
96 /* convert caps into defines */
97 #ifdef AUDIOHW_CAPS
98 /* Tone controls */
99 #if (AUDIOHW_CAPS & TREBLE_CAP)
100 #define AUDIOHW_HAVE_TREBLE
101 #endif
103 #if (AUDIOHW_CAPS & BASS_CAP)
104 #define AUDIOHW_HAVE_BASS
105 #endif
107 #if (AUDIOHW_CAPS & BASS_CUTOFF_CAP)
108 #define AUDIOHW_HAVE_BASS_CUTOFF
109 #endif
111 #if (AUDIOHW_CAPS & TREBLE_CUTOFF_CAP)
112 #define AUDIOHW_HAVE_TREBLE_CUTOFF
113 #endif
115 #if (AUDIOHW_CAPS & BALANCE_CAP)
116 #define AUDIOHW_HAVE_BALANCE
117 #endif
119 #if (AUDIOHW_CAPS & CLIPPING_CAP)
120 #define AUDIOHW_HAVE_CLIPPING
121 #endif
123 #if (AUDIOHW_CAPS & PRESCALER_CAP)
124 #define AUDIOHW_HAVE_PRESCALER
125 #endif
127 /* Hardware EQ tone controls */
128 #if (AUDIOHW_CAPS & EQ_CAP)
129 /* A hardware equalizer is present (or perhaps some tone control variation
130 * that is not Bass and/or Treble) */
131 #define AUDIOHW_HAVE_EQ
133 /* Defined band indexes for supported bands */
134 enum
136 /* Band 1 is implied; bands must be contiguous, 1 to N */
137 AUDIOHW_EQ_BAND1 = 0,
138 #define AUDIOHW_HAVE_EQ_BAND1
139 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 1))
140 AUDIOHW_EQ_BAND2,
141 #define AUDIOHW_HAVE_EQ_BAND2
142 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 2))
143 AUDIOHW_EQ_BAND3,
144 #define AUDIOHW_HAVE_EQ_BAND3
145 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 3))
146 AUDIOHW_EQ_BAND4,
147 #define AUDIOHW_HAVE_EQ_BAND4
148 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 4))
149 AUDIOHW_EQ_BAND5,
150 #define AUDIOHW_HAVE_EQ_BAND5
151 #endif /* 5 */
152 #endif /* 4 */
153 #endif /* 3 */
154 #endif /* 2 */
155 AUDIOHW_EQ_BAND_NUM, /* Keep last */
158 #ifdef AUDIOHW_EQ_FREQUENCY_CAPS
159 /* One or more bands supports frequency cutoff or center adjustment */
160 #define AUDIOHW_HAVE_EQ_FREQUENCY
161 enum
163 __AUDIOHW_EQ_BAND_FREQUENCY = -1,
164 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
165 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 0))
166 AUDIOHW_EQ_BAND1_FREQUENCY,
167 #define AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
168 #endif
169 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
170 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 1))
171 AUDIOHW_EQ_BAND2_FREQUENCY,
172 #define AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
173 #endif
174 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
175 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 2))
176 AUDIOHW_EQ_BAND3_FREQUENCY,
177 #define AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
178 #endif
179 #if defined(AUDIOHW_HAVE_EQ_BAND4) && \
180 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 3))
181 AUDIOHW_EQ_BAND4_FREQUENCY,
182 #define AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
183 #endif
184 #if defined(AUDIOHW_HAVE_EQ_BAND5) && \
185 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 4))
186 AUDIOHW_EQ_BAND5_FREQUENCY,
187 #define AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
188 #endif
189 AUDIOHW_EQ_FREQUENCY_NUM,
191 #endif /* AUDIOHW_EQ_FREQUENCY_CAPS */
193 #ifdef AUDIOHW_EQ_WIDTH_CAPS
194 /* One or more bands supports bandwidth adjustment */
195 #define AUDIOHW_HAVE_EQ_WIDTH
196 enum
198 __AUDIOHW_EQ_BAND_WIDTH = -1,
199 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
200 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 1))
201 AUDIOHW_EQ_BAND2_WIDTH,
202 #define AUDIOHW_HAVE_EQ_BAND2_WIDTH
203 #endif
204 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
205 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 2))
206 AUDIOHW_EQ_BAND3_WIDTH,
207 #define AUDIOHW_HAVE_EQ_BAND3_WIDTH
208 #endif
209 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
210 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 3))
211 AUDIOHW_EQ_BAND4_WIDTH,
212 #define AUDIOHW_HAVE_EQ_BAND4_WIDTH
213 #endif
214 AUDIOHW_EQ_WIDTH_NUM, /* Keep last */
216 #endif /* AUDIOHW_EQ_WIDTH_CAPS */
218 /* Types and number of settings types (gain, frequency, width) */
219 enum AUDIOHW_EQ_SETTINGS
221 AUDIOHW_EQ_GAIN = 0,
222 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
223 AUDIOHW_EQ_FREQUENCY,
224 #endif
225 #ifdef AUDIOHW_HAVE_EQ_WIDTH
226 AUDIOHW_EQ_WIDTH,
227 #endif
228 AUDIOHW_EQ_SETTING_NUM
231 #endif /* (AUDIOHW_CAPS & EQ_CAP) */
233 #if (AUDIOHW_CAPS & DEPTH_3D_CAP)
234 #define AUDIOHW_HAVE_DEPTH_3D
235 #endif
236 #else
237 #if defined (HAVE_SW_TONE_CONTROLS)
238 /* Needed for proper sound support */
239 #define AUDIOHW_HAVE_BASS
240 #define AUDIOHW_HAVE_TREBLE
241 #endif
242 #endif /* AUDIOHW_CAPS */
244 enum {
245 SOUND_VOLUME = 0,
246 /* Tone control */
247 #if defined(AUDIOHW_HAVE_BASS)
248 SOUND_BASS,
249 #endif
250 #if defined(AUDIOHW_HAVE_TREBLE)
251 SOUND_TREBLE,
252 #endif
253 SOUND_BALANCE,
254 SOUND_CHANNELS,
255 SOUND_STEREO_WIDTH,
256 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
257 SOUND_LOUDNESS,
258 SOUND_AVC,
259 SOUND_MDB_STRENGTH,
260 SOUND_MDB_HARMONICS,
261 SOUND_MDB_CENTER,
262 SOUND_MDB_SHAPE,
263 SOUND_MDB_ENABLE,
264 SOUND_SUPERBASS,
265 #endif
266 #if defined(HAVE_RECORDING)
267 SOUND_LEFT_GAIN,
268 SOUND_RIGHT_GAIN,
269 SOUND_MIC_GAIN,
270 #endif
271 /* Bass and treble tone controls */
272 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
273 SOUND_BASS_CUTOFF,
274 #endif
275 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
276 SOUND_TREBLE_CUTOFF,
277 #endif
278 /* 3D effect */
279 #if defined(AUDIOHW_HAVE_DEPTH_3D)
280 SOUND_DEPTH_3D,
281 #endif
282 /* Hardware EQ tone controls */
283 /* Band gains */
284 #if defined(AUDIOHW_HAVE_EQ)
285 /* Band 1 implied */
286 SOUND_EQ_BAND1_GAIN,
287 #if defined(AUDIOHW_HAVE_EQ_BAND2)
288 SOUND_EQ_BAND2_GAIN,
289 #endif
290 #if defined(AUDIOHW_HAVE_EQ_BAND3)
291 SOUND_EQ_BAND3_GAIN,
292 #endif
293 #if defined(AUDIOHW_HAVE_EQ_BAND4)
294 SOUND_EQ_BAND4_GAIN,
295 #endif
296 #if defined(AUDIOHW_HAVE_EQ_BAND5)
297 SOUND_EQ_BAND5_GAIN,
298 #endif
299 /* Band frequencies */
300 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
301 SOUND_EQ_BAND1_FREQUENCY,
302 #endif
303 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
304 SOUND_EQ_BAND2_FREQUENCY,
305 #endif
306 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
307 SOUND_EQ_BAND3_FREQUENCY,
308 #endif
309 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
310 SOUND_EQ_BAND4_FREQUENCY,
311 #endif
312 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
313 SOUND_EQ_BAND5_FREQUENCY,
314 #endif
315 /* Band widths */
316 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
317 SOUND_EQ_BAND2_WIDTH,
318 #endif
319 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
320 SOUND_EQ_BAND3_WIDTH,
321 #endif
322 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
323 SOUND_EQ_BAND4_WIDTH,
324 #endif
325 #endif /* AUDIOHW_HAVE_EQ */
326 SOUND_LAST_SETTING, /* Keep this last */
329 enum Channel {
330 SOUND_CHAN_STEREO,
331 SOUND_CHAN_MONO,
332 SOUND_CHAN_CUSTOM,
333 SOUND_CHAN_MONO_LEFT,
334 SOUND_CHAN_MONO_RIGHT,
335 SOUND_CHAN_KARAOKE,
336 SOUND_CHAN_NUM_MODES,
339 struct sound_settings_info {
340 const char *unit;
341 char numdecimals;
342 char steps;
343 short minval;
344 short maxval;
345 short defaultval;
348 /* This struct is used by every driver to export its min/max/default values for
349 * its audio settings. Keep in mind that the order must be correct! */
350 extern const struct sound_settings_info audiohw_settings[];
352 /* All usable functions implemented by a audio codec drivers. Most of
353 * the function in sound settings are only called, when in audio codecs
354 * .h file suitable defines are added.
358 * Initialize audio codec to a well defined state. Includes SoC-specific
359 * setup.
361 void audiohw_init(void);
364 * Do initial audio codec setup. Usually called from audiohw_init.
366 void audiohw_preinit(void);
369 * Do some stuff (codec related) after audiohw_init that needs to be
370 * delayed such as enabling outputs to prevent popping. This lets
371 * other inits in the system complete in the meantime.
373 void audiohw_postinit(void);
376 * Close audio codec.
378 void audiohw_close(void);
380 #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO)
382 * Set new volume value
383 * @param val to set.
384 * NOTE: AUDIOHW_CAPS need to contain
385 * CLIPPING_CAP
387 void audiohw_set_volume(int val);
388 #endif
390 #ifdef AUDIOHW_HAVE_PRESCALER
392 * Set new prescaler value.
393 * @param val to set.
394 * NOTE: AUDIOHW_CAPS need to contain
395 * PRESCALER_CAP
397 void audiohw_set_prescaler(int val);
398 #endif
400 #ifdef AUDIOHW_HAVE_BALANCE
402 * Set new balance value
403 * @param val to set.
404 * NOTE: AUDIOHW_CAPS need to contain
405 * BALANCE_CAP
407 void audiohw_set_balance(int val);
408 #endif
410 #ifdef AUDIOHW_HAVE_TREBLE
412 * Set new treble value.
413 * @param val to set.
414 * NOTE: AUDIOHW_CAPS need to contain
415 * TREBLE_CAP
417 void audiohw_set_treble(int val);
418 #endif
420 #ifdef AUDIOHW_HAVE_BASS
422 * Set new bass value.
423 * @param val to set.
424 * NOTE: AUDIOHW_CAPS need to contain
425 * BASS_CAP
427 void audiohw_set_bass(int val);
428 #endif
430 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
432 * Set new bass cut off value.
433 * @param val to set.
434 * NOTE: AUDIOHW_CAPS need to contain
435 * BASS_CUTOFF_CAP
437 void audiohw_set_bass_cutoff(int val);
438 #endif
440 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
442 * Set new treble cut off value.
443 * @param val to set.
444 * NOTE: AUDIOHW_CAPS need to contain
445 * TREBLE_CUTOFF_CAP
447 void audiohw_set_treble_cutoff(int val);
448 #endif
450 #ifdef AUDIOHW_HAVE_EQ
452 * Set new band gain value.
453 * @param band index to which val is set
454 * @param val to set.
455 * NOTE: AUDIOHW_CAPS need to contain
456 * EQ_CAP
458 * AUDIOHW_EQ_BAND_CAPS must be defined as a bitmask
459 * of EQ_CAP each shifted by the zero-based band number
460 * for each band. Bands 1 to N are indexed 0 to N-1.
462 void audiohw_set_eq_band_gain(unsigned int band, int val);
463 #endif
465 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
467 * Set new band cutoff or center frequency value.
468 * @param band index to which val is set
469 * @param val to set.
470 * NOTE: AUDIOHW_CAPS need to contain
471 * EQ_CAP
473 * AUDIOHW_EQ_FREQUENCY_CAPS must be defined as a bitmask
474 * of EQ_CAP each shifted by the zero-based band number
475 * for each band that supports frequency adjustment.
476 * Bands 1 to N are indexed 0 to N-1.
478 void audiohw_set_eq_band_frequency(unsigned int band, int val);
479 #endif
481 #ifdef AUDIOHW_HAVE_EQ_WIDTH
483 * Set new band cutoff or center frequency value.
484 * @param band index to which val is set
485 * @param val to set.
486 * NOTE: AUDIOHW_CAPS need to contain
487 * EQ_CAP
489 * AUDIOHW_EQ_WIDTH_CAPS must be defined as a bitmask
490 * of EQ_CAP each shifted by the zero-based band number
491 * for each band that supports width adjustment.
492 * Bands 1 to N are indexed 0 to N-1.
494 void audiohw_set_eq_band_width(unsigned int band, int val);
495 #endif
497 #ifdef AUDIOHW_HAVE_DEPTH_3D
499 * Set new 3-d enhancement (stereo expansion) effect value.
500 * @param val to set.
501 * NOTE: AUDIOHW_CAPS need to contain
502 * DEPTH_3D_CAP
504 void audiohw_set_depth_3d(int val);
505 #endif
508 void audiohw_set_frequency(int fsel);
510 #ifdef HAVE_RECORDING
513 * Enable recording.
514 * @param source_mic if this is true, we want to record from microphone,
515 * else we want to record FM/LineIn.
517 void audiohw_enable_recording(bool source_mic);
520 * Disable recording.
522 void audiohw_disable_recording(void);
525 * Set gain of recording source.
526 * @param left gain value.
527 * @param right will not be used if recording from micophone (mono).
528 * @param type AUDIO_GAIN_MIC, AUDIO_GAIN_LINEIN.
530 void audiohw_set_recvol(int left, int right, int type);
533 * Enable or disable recording monitor.
534 * @param enable ture or false.
536 void audiohw_set_monitor(bool enable);
538 #endif /* HAVE_RECORDING */
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_ */