We have a 3.9 release, update builds.pm
[maemo-rb.git] / firmware / export / audiohw.h
blob651c9cd2543f3f4a274fb4d4297e191f8c70e787
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 #if defined(HAVE_DAC3550A)
63 #include "dac3550a.h"
64 #endif /* HAVE_DAC3550A */
65 #elif defined(HAVE_TSC2100)
66 #include "tsc2100.h"
67 #elif defined(HAVE_JZ4740_CODEC)
68 #include "jz4740-codec.h"
69 #elif defined(HAVE_AK4537)
70 #include "ak4537.h"
71 #elif defined(HAVE_CS42L55)
72 #include "cs42l55.h"
73 #endif
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
79 #define VOLUME_MAX 0
80 #endif
81 #endif
85 #define ONE_DB 10
87 #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
88 #warning define for VOLUME_MIN and VOLUME_MAX is missing
89 #define VOLUME_MIN -700
90 #define VOLUME_MAX 0
91 #endif
93 #ifndef AUDIOHW_NUM_TONE_CONTROLS
94 #define AUDIOHW_NUM_TONE_CONTROLS 0
95 #endif
97 /* volume/balance/treble/bass interdependency main part */
98 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
101 /* convert caps into defines */
102 #ifdef AUDIOHW_CAPS
103 /* Tone controls */
104 #if (AUDIOHW_CAPS & TREBLE_CAP)
105 #define AUDIOHW_HAVE_TREBLE
106 #endif
108 #if (AUDIOHW_CAPS & BASS_CAP)
109 #define AUDIOHW_HAVE_BASS
110 #endif
112 #if (AUDIOHW_CAPS & BASS_CUTOFF_CAP)
113 #define AUDIOHW_HAVE_BASS_CUTOFF
114 #endif
116 #if (AUDIOHW_CAPS & TREBLE_CUTOFF_CAP)
117 #define AUDIOHW_HAVE_TREBLE_CUTOFF
118 #endif
120 #if (AUDIOHW_CAPS & BALANCE_CAP)
121 #define AUDIOHW_HAVE_BALANCE
122 #endif
124 #if (AUDIOHW_CAPS & CLIPPING_CAP)
125 #define AUDIOHW_HAVE_CLIPPING
126 #endif
128 #if (AUDIOHW_CAPS & PRESCALER_CAP)
129 #define AUDIOHW_HAVE_PRESCALER
130 #endif
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 */
139 enum
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))
145 AUDIOHW_EQ_BAND2,
146 #define AUDIOHW_HAVE_EQ_BAND2
147 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 2))
148 AUDIOHW_EQ_BAND3,
149 #define AUDIOHW_HAVE_EQ_BAND3
150 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 3))
151 AUDIOHW_EQ_BAND4,
152 #define AUDIOHW_HAVE_EQ_BAND4
153 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 4))
154 AUDIOHW_EQ_BAND5,
155 #define AUDIOHW_HAVE_EQ_BAND5
156 #endif /* 5 */
157 #endif /* 4 */
158 #endif /* 3 */
159 #endif /* 2 */
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
166 enum
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
173 #endif
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
178 #endif
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
183 #endif
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
188 #endif
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
193 #endif
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
201 enum
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
208 #endif
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
213 #endif
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
218 #endif
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
226 AUDIOHW_EQ_GAIN = 0,
227 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
228 AUDIOHW_EQ_FREQUENCY,
229 #endif
230 #ifdef AUDIOHW_HAVE_EQ_WIDTH
231 AUDIOHW_EQ_WIDTH,
232 #endif
233 AUDIOHW_EQ_SETTING_NUM
236 #endif /* (AUDIOHW_CAPS & EQ_CAP) */
238 #if (AUDIOHW_CAPS & DEPTH_3D_CAP)
239 #define AUDIOHW_HAVE_DEPTH_3D
240 #endif
241 #else
242 #if defined (HAVE_SW_TONE_CONTROLS)
243 /* Needed for proper sound support */
244 #define AUDIOHW_HAVE_BASS
245 #define AUDIOHW_HAVE_TREBLE
246 #endif
247 #endif /* AUDIOHW_CAPS */
249 enum {
250 SOUND_VOLUME = 0,
251 /* Tone control */
252 #if defined(AUDIOHW_HAVE_BASS)
253 SOUND_BASS,
254 #endif
255 #if defined(AUDIOHW_HAVE_TREBLE)
256 SOUND_TREBLE,
257 #endif
258 SOUND_BALANCE,
259 SOUND_CHANNELS,
260 SOUND_STEREO_WIDTH,
261 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
262 SOUND_LOUDNESS,
263 SOUND_AVC,
264 SOUND_MDB_STRENGTH,
265 SOUND_MDB_HARMONICS,
266 SOUND_MDB_CENTER,
267 SOUND_MDB_SHAPE,
268 SOUND_MDB_ENABLE,
269 SOUND_SUPERBASS,
270 #endif
271 #if defined(HAVE_RECORDING)
272 SOUND_LEFT_GAIN,
273 SOUND_RIGHT_GAIN,
274 SOUND_MIC_GAIN,
275 #endif
276 /* Bass and treble tone controls */
277 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
278 SOUND_BASS_CUTOFF,
279 #endif
280 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
281 SOUND_TREBLE_CUTOFF,
282 #endif
283 /* 3D effect */
284 #if defined(AUDIOHW_HAVE_DEPTH_3D)
285 SOUND_DEPTH_3D,
286 #endif
287 /* Hardware EQ tone controls */
288 /* Band gains */
289 #if defined(AUDIOHW_HAVE_EQ)
290 /* Band 1 implied */
291 SOUND_EQ_BAND1_GAIN,
292 #if defined(AUDIOHW_HAVE_EQ_BAND2)
293 SOUND_EQ_BAND2_GAIN,
294 #endif
295 #if defined(AUDIOHW_HAVE_EQ_BAND3)
296 SOUND_EQ_BAND3_GAIN,
297 #endif
298 #if defined(AUDIOHW_HAVE_EQ_BAND4)
299 SOUND_EQ_BAND4_GAIN,
300 #endif
301 #if defined(AUDIOHW_HAVE_EQ_BAND5)
302 SOUND_EQ_BAND5_GAIN,
303 #endif
304 /* Band frequencies */
305 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
306 SOUND_EQ_BAND1_FREQUENCY,
307 #endif
308 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
309 SOUND_EQ_BAND2_FREQUENCY,
310 #endif
311 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
312 SOUND_EQ_BAND3_FREQUENCY,
313 #endif
314 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
315 SOUND_EQ_BAND4_FREQUENCY,
316 #endif
317 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
318 SOUND_EQ_BAND5_FREQUENCY,
319 #endif
320 /* Band widths */
321 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
322 SOUND_EQ_BAND2_WIDTH,
323 #endif
324 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
325 SOUND_EQ_BAND3_WIDTH,
326 #endif
327 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
328 SOUND_EQ_BAND4_WIDTH,
329 #endif
330 #endif /* AUDIOHW_HAVE_EQ */
331 SOUND_LAST_SETTING, /* Keep this last */
334 enum Channel {
335 SOUND_CHAN_STEREO,
336 SOUND_CHAN_MONO,
337 SOUND_CHAN_CUSTOM,
338 SOUND_CHAN_MONO_LEFT,
339 SOUND_CHAN_MONO_RIGHT,
340 SOUND_CHAN_KARAOKE,
341 SOUND_CHAN_NUM_MODES,
344 struct sound_settings_info {
345 const char *unit;
346 char numdecimals;
347 char steps;
348 short minval;
349 short maxval;
350 short defaultval;
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
364 * setup.
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);
381 * Close audio codec.
383 void audiohw_close(void);
385 #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
387 * Set new volume value
388 * @param val to set.
389 * NOTE: AUDIOHW_CAPS need to contain
390 * CLIPPING_CAP
392 void audiohw_set_volume(int val);
393 #endif
395 #ifdef AUDIOHW_HAVE_PRESCALER
397 * Set new prescaler value.
398 * @param val to set.
399 * NOTE: AUDIOHW_CAPS need to contain
400 * PRESCALER_CAP
402 void audiohw_set_prescaler(int val);
403 #endif
405 #ifdef AUDIOHW_HAVE_BALANCE
407 * Set new balance value
408 * @param val to set.
409 * NOTE: AUDIOHW_CAPS need to contain
410 * BALANCE_CAP
412 void audiohw_set_balance(int val);
413 #endif
415 #ifdef AUDIOHW_HAVE_TREBLE
417 * Set new treble value.
418 * @param val to set.
419 * NOTE: AUDIOHW_CAPS need to contain
420 * TREBLE_CAP
422 void audiohw_set_treble(int val);
423 #endif
425 #ifdef AUDIOHW_HAVE_BASS
427 * Set new bass value.
428 * @param val to set.
429 * NOTE: AUDIOHW_CAPS need to contain
430 * BASS_CAP
432 void audiohw_set_bass(int val);
433 #endif
435 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
437 * Set new bass cut off value.
438 * @param val to set.
439 * NOTE: AUDIOHW_CAPS need to contain
440 * BASS_CUTOFF_CAP
442 void audiohw_set_bass_cutoff(int val);
443 #endif
445 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
447 * Set new treble cut off value.
448 * @param val to set.
449 * NOTE: AUDIOHW_CAPS need to contain
450 * TREBLE_CUTOFF_CAP
452 void audiohw_set_treble_cutoff(int val);
453 #endif
455 #ifdef AUDIOHW_HAVE_EQ
457 * Set new band gain value.
458 * @param band index to which val is set
459 * @param val to set.
460 * NOTE: AUDIOHW_CAPS need to contain
461 * EQ_CAP
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);
468 #endif
470 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
472 * Set new band cutoff or center frequency value.
473 * @param band index to which val is set
474 * @param val to set.
475 * NOTE: AUDIOHW_CAPS need to contain
476 * EQ_CAP
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);
484 #endif
486 #ifdef AUDIOHW_HAVE_EQ_WIDTH
488 * Set new band cutoff or center frequency value.
489 * @param band index to which val is set
490 * @param val to set.
491 * NOTE: AUDIOHW_CAPS need to contain
492 * EQ_CAP
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);
500 #endif
502 #ifdef AUDIOHW_HAVE_DEPTH_3D
504 * Set new 3-d enhancement (stereo expansion) effect value.
505 * @param val to set.
506 * NOTE: AUDIOHW_CAPS need to contain
507 * DEPTH_3D_CAP
509 void audiohw_set_depth_3d(int val);
510 #endif
513 void audiohw_set_frequency(int fsel);
515 #ifdef HAVE_RECORDING
518 * Enable 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);
525 * Disable recording.
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);
545 #endif
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);
561 * Set stereo width.
562 * @param val new stereo width value.
564 void audiohw_set_stereo_width(int val);
566 #endif /* CONFIG_CODEC != SWCODEC */
568 #ifdef HAVE_SPEAKER
570 void audiohw_enable_speaker(bool on);
572 #endif /* HAVE_SPEAKER */
574 #endif /* _AUDIOHW_H_ */