Prepare new maemo release
[maemo-rb.git] / firmware / export / audiohw.h
blob304c5aa4600aace9732246c05820df7b4ed2dc6a
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_RK27XX_CODEC)
72 #include "rk27xx_codec.h"
73 #elif defined(HAVE_AIC3X)
74 #include "aic3x.h"
75 #elif defined(HAVE_CS42L55)
76 #include "cs42l55.h"
77 #elif defined(HAVE_IMX233_CODEC)
78 #include "imx233-codec.h"
79 #elif defined(HAVE_DUMMY_CODEC)
80 #include "dummy_codec.h"
81 #endif
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
87 #define VOLUME_MAX 0
88 #endif
89 #endif
93 #define ONE_DB 10
95 #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
96 #warning define for VOLUME_MIN and VOLUME_MAX is missing
97 #define VOLUME_MIN -700
98 #define VOLUME_MAX 0
99 #endif
101 #ifndef AUDIOHW_NUM_TONE_CONTROLS
102 #define AUDIOHW_NUM_TONE_CONTROLS 0
103 #endif
105 /* volume/balance/treble/bass interdependency main part */
106 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
109 /* convert caps into defines */
110 #ifdef AUDIOHW_CAPS
111 /* Tone controls */
112 #if (AUDIOHW_CAPS & TREBLE_CAP)
113 #define AUDIOHW_HAVE_TREBLE
114 #endif
116 #if (AUDIOHW_CAPS & BASS_CAP)
117 #define AUDIOHW_HAVE_BASS
118 #endif
120 #if (AUDIOHW_CAPS & BASS_CUTOFF_CAP)
121 #define AUDIOHW_HAVE_BASS_CUTOFF
122 #endif
124 #if (AUDIOHW_CAPS & TREBLE_CUTOFF_CAP)
125 #define AUDIOHW_HAVE_TREBLE_CUTOFF
126 #endif
128 #if (AUDIOHW_CAPS & BALANCE_CAP)
129 #define AUDIOHW_HAVE_BALANCE
130 #endif
132 #if (AUDIOHW_CAPS & CLIPPING_CAP)
133 #define AUDIOHW_HAVE_CLIPPING
134 #endif
136 #if (AUDIOHW_CAPS & PRESCALER_CAP)
137 #define AUDIOHW_HAVE_PRESCALER
138 #endif
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 */
147 enum
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))
153 AUDIOHW_EQ_BAND2,
154 #define AUDIOHW_HAVE_EQ_BAND2
155 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 2))
156 AUDIOHW_EQ_BAND3,
157 #define AUDIOHW_HAVE_EQ_BAND3
158 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 3))
159 AUDIOHW_EQ_BAND4,
160 #define AUDIOHW_HAVE_EQ_BAND4
161 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 4))
162 AUDIOHW_EQ_BAND5,
163 #define AUDIOHW_HAVE_EQ_BAND5
164 #endif /* 5 */
165 #endif /* 4 */
166 #endif /* 3 */
167 #endif /* 2 */
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
174 enum
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
181 #endif
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
186 #endif
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
191 #endif
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
196 #endif
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
201 #endif
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
209 enum
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
216 #endif
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
221 #endif
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
226 #endif
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
234 AUDIOHW_EQ_GAIN = 0,
235 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
236 AUDIOHW_EQ_FREQUENCY,
237 #endif
238 #ifdef AUDIOHW_HAVE_EQ_WIDTH
239 AUDIOHW_EQ_WIDTH,
240 #endif
241 AUDIOHW_EQ_SETTING_NUM
244 #endif /* (AUDIOHW_CAPS & EQ_CAP) */
246 #if (AUDIOHW_CAPS & DEPTH_3D_CAP)
247 #define AUDIOHW_HAVE_DEPTH_3D
248 #endif
249 #else
250 #if defined (HAVE_SW_TONE_CONTROLS)
251 /* Needed for proper sound support */
252 #define AUDIOHW_HAVE_BASS
253 #define AUDIOHW_HAVE_TREBLE
254 #endif
255 #endif /* AUDIOHW_CAPS */
257 enum {
258 SOUND_VOLUME = 0,
259 /* Tone control */
260 #if defined(AUDIOHW_HAVE_BASS)
261 SOUND_BASS,
262 #endif
263 #if defined(AUDIOHW_HAVE_TREBLE)
264 SOUND_TREBLE,
265 #endif
266 SOUND_BALANCE,
267 SOUND_CHANNELS,
268 SOUND_STEREO_WIDTH,
269 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
270 SOUND_LOUDNESS,
271 SOUND_AVC,
272 SOUND_MDB_STRENGTH,
273 SOUND_MDB_HARMONICS,
274 SOUND_MDB_CENTER,
275 SOUND_MDB_SHAPE,
276 SOUND_MDB_ENABLE,
277 SOUND_SUPERBASS,
278 #endif
279 #if defined(HAVE_RECORDING)
280 SOUND_LEFT_GAIN,
281 SOUND_RIGHT_GAIN,
282 SOUND_MIC_GAIN,
283 #endif
284 /* Bass and treble tone controls */
285 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
286 SOUND_BASS_CUTOFF,
287 #endif
288 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
289 SOUND_TREBLE_CUTOFF,
290 #endif
291 /* 3D effect */
292 #if defined(AUDIOHW_HAVE_DEPTH_3D)
293 SOUND_DEPTH_3D,
294 #endif
295 /* Hardware EQ tone controls */
296 /* Band gains */
297 #if defined(AUDIOHW_HAVE_EQ)
298 /* Band 1 implied */
299 SOUND_EQ_BAND1_GAIN,
300 #if defined(AUDIOHW_HAVE_EQ_BAND2)
301 SOUND_EQ_BAND2_GAIN,
302 #endif
303 #if defined(AUDIOHW_HAVE_EQ_BAND3)
304 SOUND_EQ_BAND3_GAIN,
305 #endif
306 #if defined(AUDIOHW_HAVE_EQ_BAND4)
307 SOUND_EQ_BAND4_GAIN,
308 #endif
309 #if defined(AUDIOHW_HAVE_EQ_BAND5)
310 SOUND_EQ_BAND5_GAIN,
311 #endif
312 /* Band frequencies */
313 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
314 SOUND_EQ_BAND1_FREQUENCY,
315 #endif
316 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
317 SOUND_EQ_BAND2_FREQUENCY,
318 #endif
319 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
320 SOUND_EQ_BAND3_FREQUENCY,
321 #endif
322 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
323 SOUND_EQ_BAND4_FREQUENCY,
324 #endif
325 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
326 SOUND_EQ_BAND5_FREQUENCY,
327 #endif
328 /* Band widths */
329 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
330 SOUND_EQ_BAND2_WIDTH,
331 #endif
332 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
333 SOUND_EQ_BAND3_WIDTH,
334 #endif
335 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
336 SOUND_EQ_BAND4_WIDTH,
337 #endif
338 #endif /* AUDIOHW_HAVE_EQ */
339 SOUND_LAST_SETTING, /* Keep this last */
342 enum Channel {
343 SOUND_CHAN_STEREO,
344 SOUND_CHAN_MONO,
345 SOUND_CHAN_CUSTOM,
346 SOUND_CHAN_MONO_LEFT,
347 SOUND_CHAN_MONO_RIGHT,
348 SOUND_CHAN_KARAOKE,
349 SOUND_CHAN_NUM_MODES,
352 struct sound_settings_info {
353 const char *unit;
354 char numdecimals;
355 char steps;
356 short minval;
357 short maxval;
358 short defaultval;
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
372 * setup.
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);
389 * Close audio codec.
391 void audiohw_close(void);
393 #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
395 * Set new volume value
396 * @param val to set.
397 * NOTE: AUDIOHW_CAPS need to contain
398 * CLIPPING_CAP
400 void audiohw_set_volume(int val);
401 #endif
403 #ifdef AUDIOHW_HAVE_PRESCALER
405 * Set new prescaler value.
406 * @param val to set.
407 * NOTE: AUDIOHW_CAPS need to contain
408 * PRESCALER_CAP
410 void audiohw_set_prescaler(int val);
411 #endif
413 #ifdef AUDIOHW_HAVE_BALANCE
415 * Set new balance value
416 * @param val to set.
417 * NOTE: AUDIOHW_CAPS need to contain
418 * BALANCE_CAP
420 void audiohw_set_balance(int val);
421 #endif
423 #ifdef AUDIOHW_HAVE_TREBLE
425 * Set new treble value.
426 * @param val to set.
427 * NOTE: AUDIOHW_CAPS need to contain
428 * TREBLE_CAP
430 void audiohw_set_treble(int val);
431 #endif
433 #ifdef AUDIOHW_HAVE_BASS
435 * Set new bass value.
436 * @param val to set.
437 * NOTE: AUDIOHW_CAPS need to contain
438 * BASS_CAP
440 void audiohw_set_bass(int val);
441 #endif
443 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
445 * Set new bass cut off value.
446 * @param val to set.
447 * NOTE: AUDIOHW_CAPS need to contain
448 * BASS_CUTOFF_CAP
450 void audiohw_set_bass_cutoff(int val);
451 #endif
453 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
455 * Set new treble cut off value.
456 * @param val to set.
457 * NOTE: AUDIOHW_CAPS need to contain
458 * TREBLE_CUTOFF_CAP
460 void audiohw_set_treble_cutoff(int val);
461 #endif
463 #ifdef AUDIOHW_HAVE_EQ
465 * Set new band gain value.
466 * @param band index to which val is set
467 * @param val to set.
468 * NOTE: AUDIOHW_CAPS need to contain
469 * EQ_CAP
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);
476 #endif
478 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
480 * Set new band cutoff or center frequency value.
481 * @param band index to which val is set
482 * @param val to set.
483 * NOTE: AUDIOHW_CAPS need to contain
484 * EQ_CAP
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);
492 #endif
494 #ifdef AUDIOHW_HAVE_EQ_WIDTH
496 * Set new band cutoff or center frequency value.
497 * @param band index to which val is set
498 * @param val to set.
499 * NOTE: AUDIOHW_CAPS need to contain
500 * EQ_CAP
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);
508 #endif
510 #ifdef AUDIOHW_HAVE_DEPTH_3D
512 * Set new 3-d enhancement (stereo expansion) effect value.
513 * @param val to set.
514 * NOTE: AUDIOHW_CAPS need to contain
515 * DEPTH_3D_CAP
517 void audiohw_set_depth_3d(int val);
518 #endif
521 void audiohw_set_frequency(int fsel);
523 #ifdef HAVE_RECORDING
526 * Enable 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);
533 * Disable recording.
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);
553 #endif
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);
569 * Set stereo width.
570 * @param val new stereo width value.
572 void audiohw_set_stereo_width(int val);
574 #endif /* CONFIG_CODEC != SWCODEC */
576 #ifdef HAVE_SPEAKER
578 void audiohw_enable_speaker(bool on);
580 #endif /* HAVE_SPEAKER */
582 #endif /* _AUDIOHW_H_ */