Reload the current playlist after reboot even if it has ended. (FS#11644)
[kugel-rb.git] / firmware / export / audiohw.h
blob593924d37030f4793bfc37b2a0e7163a690e176d
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 #elif defined(HAVE_IMX233_CODEC)
74 #include "imx233-codec.h"
75 #endif
76 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
77 /* #include <SDL_audio.h> gives errors in other code areas,
78 * we don't really need it here, so don't. but it should maybe be fixed */
79 #ifndef SIMULATOR /* simulator gets values from the target .h files */
80 #define VOLUME_MIN -990
81 #define VOLUME_MAX 0
82 #endif
83 #endif
87 #define ONE_DB 10
89 #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
90 #warning define for VOLUME_MIN and VOLUME_MAX is missing
91 #define VOLUME_MIN -700
92 #define VOLUME_MAX 0
93 #endif
95 #ifndef AUDIOHW_NUM_TONE_CONTROLS
96 #define AUDIOHW_NUM_TONE_CONTROLS 0
97 #endif
99 /* volume/balance/treble/bass interdependency main part */
100 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
103 /* convert caps into defines */
104 #ifdef AUDIOHW_CAPS
105 /* Tone controls */
106 #if (AUDIOHW_CAPS & TREBLE_CAP)
107 #define AUDIOHW_HAVE_TREBLE
108 #endif
110 #if (AUDIOHW_CAPS & BASS_CAP)
111 #define AUDIOHW_HAVE_BASS
112 #endif
114 #if (AUDIOHW_CAPS & BASS_CUTOFF_CAP)
115 #define AUDIOHW_HAVE_BASS_CUTOFF
116 #endif
118 #if (AUDIOHW_CAPS & TREBLE_CUTOFF_CAP)
119 #define AUDIOHW_HAVE_TREBLE_CUTOFF
120 #endif
122 #if (AUDIOHW_CAPS & BALANCE_CAP)
123 #define AUDIOHW_HAVE_BALANCE
124 #endif
126 #if (AUDIOHW_CAPS & CLIPPING_CAP)
127 #define AUDIOHW_HAVE_CLIPPING
128 #endif
130 #if (AUDIOHW_CAPS & PRESCALER_CAP)
131 #define AUDIOHW_HAVE_PRESCALER
132 #endif
134 /* Hardware EQ tone controls */
135 #if (AUDIOHW_CAPS & EQ_CAP)
136 /* A hardware equalizer is present (or perhaps some tone control variation
137 * that is not Bass and/or Treble) */
138 #define AUDIOHW_HAVE_EQ
140 /* Defined band indexes for supported bands */
141 enum
143 /* Band 1 is implied; bands must be contiguous, 1 to N */
144 AUDIOHW_EQ_BAND1 = 0,
145 #define AUDIOHW_HAVE_EQ_BAND1
146 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 1))
147 AUDIOHW_EQ_BAND2,
148 #define AUDIOHW_HAVE_EQ_BAND2
149 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 2))
150 AUDIOHW_EQ_BAND3,
151 #define AUDIOHW_HAVE_EQ_BAND3
152 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 3))
153 AUDIOHW_EQ_BAND4,
154 #define AUDIOHW_HAVE_EQ_BAND4
155 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 4))
156 AUDIOHW_EQ_BAND5,
157 #define AUDIOHW_HAVE_EQ_BAND5
158 #endif /* 5 */
159 #endif /* 4 */
160 #endif /* 3 */
161 #endif /* 2 */
162 AUDIOHW_EQ_BAND_NUM, /* Keep last */
165 #ifdef AUDIOHW_EQ_FREQUENCY_CAPS
166 /* One or more bands supports frequency cutoff or center adjustment */
167 #define AUDIOHW_HAVE_EQ_FREQUENCY
168 enum
170 __AUDIOHW_EQ_BAND_FREQUENCY = -1,
171 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
172 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 0))
173 AUDIOHW_EQ_BAND1_FREQUENCY,
174 #define AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
175 #endif
176 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
177 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 1))
178 AUDIOHW_EQ_BAND2_FREQUENCY,
179 #define AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
180 #endif
181 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
182 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 2))
183 AUDIOHW_EQ_BAND3_FREQUENCY,
184 #define AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
185 #endif
186 #if defined(AUDIOHW_HAVE_EQ_BAND4) && \
187 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 3))
188 AUDIOHW_EQ_BAND4_FREQUENCY,
189 #define AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
190 #endif
191 #if defined(AUDIOHW_HAVE_EQ_BAND5) && \
192 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 4))
193 AUDIOHW_EQ_BAND5_FREQUENCY,
194 #define AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
195 #endif
196 AUDIOHW_EQ_FREQUENCY_NUM,
198 #endif /* AUDIOHW_EQ_FREQUENCY_CAPS */
200 #ifdef AUDIOHW_EQ_WIDTH_CAPS
201 /* One or more bands supports bandwidth adjustment */
202 #define AUDIOHW_HAVE_EQ_WIDTH
203 enum
205 __AUDIOHW_EQ_BAND_WIDTH = -1,
206 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
207 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 1))
208 AUDIOHW_EQ_BAND2_WIDTH,
209 #define AUDIOHW_HAVE_EQ_BAND2_WIDTH
210 #endif
211 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
212 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 2))
213 AUDIOHW_EQ_BAND3_WIDTH,
214 #define AUDIOHW_HAVE_EQ_BAND3_WIDTH
215 #endif
216 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
217 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 3))
218 AUDIOHW_EQ_BAND4_WIDTH,
219 #define AUDIOHW_HAVE_EQ_BAND4_WIDTH
220 #endif
221 AUDIOHW_EQ_WIDTH_NUM, /* Keep last */
223 #endif /* AUDIOHW_EQ_WIDTH_CAPS */
225 /* Types and number of settings types (gain, frequency, width) */
226 enum AUDIOHW_EQ_SETTINGS
228 AUDIOHW_EQ_GAIN = 0,
229 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
230 AUDIOHW_EQ_FREQUENCY,
231 #endif
232 #ifdef AUDIOHW_HAVE_EQ_WIDTH
233 AUDIOHW_EQ_WIDTH,
234 #endif
235 AUDIOHW_EQ_SETTING_NUM
238 #endif /* (AUDIOHW_CAPS & EQ_CAP) */
240 #if (AUDIOHW_CAPS & DEPTH_3D_CAP)
241 #define AUDIOHW_HAVE_DEPTH_3D
242 #endif
243 #else
244 #if defined (HAVE_SW_TONE_CONTROLS)
245 /* Needed for proper sound support */
246 #define AUDIOHW_HAVE_BASS
247 #define AUDIOHW_HAVE_TREBLE
248 #endif
249 #endif /* AUDIOHW_CAPS */
251 enum {
252 SOUND_VOLUME = 0,
253 /* Tone control */
254 #if defined(AUDIOHW_HAVE_BASS)
255 SOUND_BASS,
256 #endif
257 #if defined(AUDIOHW_HAVE_TREBLE)
258 SOUND_TREBLE,
259 #endif
260 SOUND_BALANCE,
261 SOUND_CHANNELS,
262 SOUND_STEREO_WIDTH,
263 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
264 SOUND_LOUDNESS,
265 SOUND_AVC,
266 SOUND_MDB_STRENGTH,
267 SOUND_MDB_HARMONICS,
268 SOUND_MDB_CENTER,
269 SOUND_MDB_SHAPE,
270 SOUND_MDB_ENABLE,
271 SOUND_SUPERBASS,
272 #endif
273 #if defined(HAVE_RECORDING)
274 SOUND_LEFT_GAIN,
275 SOUND_RIGHT_GAIN,
276 SOUND_MIC_GAIN,
277 #endif
278 /* Bass and treble tone controls */
279 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
280 SOUND_BASS_CUTOFF,
281 #endif
282 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
283 SOUND_TREBLE_CUTOFF,
284 #endif
285 /* 3D effect */
286 #if defined(AUDIOHW_HAVE_DEPTH_3D)
287 SOUND_DEPTH_3D,
288 #endif
289 /* Hardware EQ tone controls */
290 /* Band gains */
291 #if defined(AUDIOHW_HAVE_EQ)
292 /* Band 1 implied */
293 SOUND_EQ_BAND1_GAIN,
294 #if defined(AUDIOHW_HAVE_EQ_BAND2)
295 SOUND_EQ_BAND2_GAIN,
296 #endif
297 #if defined(AUDIOHW_HAVE_EQ_BAND3)
298 SOUND_EQ_BAND3_GAIN,
299 #endif
300 #if defined(AUDIOHW_HAVE_EQ_BAND4)
301 SOUND_EQ_BAND4_GAIN,
302 #endif
303 #if defined(AUDIOHW_HAVE_EQ_BAND5)
304 SOUND_EQ_BAND5_GAIN,
305 #endif
306 /* Band frequencies */
307 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
308 SOUND_EQ_BAND1_FREQUENCY,
309 #endif
310 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
311 SOUND_EQ_BAND2_FREQUENCY,
312 #endif
313 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
314 SOUND_EQ_BAND3_FREQUENCY,
315 #endif
316 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
317 SOUND_EQ_BAND4_FREQUENCY,
318 #endif
319 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
320 SOUND_EQ_BAND5_FREQUENCY,
321 #endif
322 /* Band widths */
323 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
324 SOUND_EQ_BAND2_WIDTH,
325 #endif
326 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
327 SOUND_EQ_BAND3_WIDTH,
328 #endif
329 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
330 SOUND_EQ_BAND4_WIDTH,
331 #endif
332 #endif /* AUDIOHW_HAVE_EQ */
333 SOUND_LAST_SETTING, /* Keep this last */
336 enum Channel {
337 SOUND_CHAN_STEREO,
338 SOUND_CHAN_MONO,
339 SOUND_CHAN_CUSTOM,
340 SOUND_CHAN_MONO_LEFT,
341 SOUND_CHAN_MONO_RIGHT,
342 SOUND_CHAN_KARAOKE,
343 SOUND_CHAN_NUM_MODES,
346 struct sound_settings_info {
347 const char *unit;
348 char numdecimals;
349 char steps;
350 short minval;
351 short maxval;
352 short defaultval;
355 /* This struct is used by every driver to export its min/max/default values for
356 * its audio settings. Keep in mind that the order must be correct! */
357 extern const struct sound_settings_info audiohw_settings[];
359 /* All usable functions implemented by a audio codec drivers. Most of
360 * the function in sound settings are only called, when in audio codecs
361 * .h file suitable defines are added.
365 * Initialize audio codec to a well defined state. Includes SoC-specific
366 * setup.
368 void audiohw_init(void);
371 * Do initial audio codec setup. Usually called from audiohw_init.
373 void audiohw_preinit(void);
376 * Do some stuff (codec related) after audiohw_init that needs to be
377 * delayed such as enabling outputs to prevent popping. This lets
378 * other inits in the system complete in the meantime.
380 void audiohw_postinit(void);
383 * Close audio codec.
385 void audiohw_close(void);
387 #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
389 * Set new volume value
390 * @param val to set.
391 * NOTE: AUDIOHW_CAPS need to contain
392 * CLIPPING_CAP
394 void audiohw_set_volume(int val);
395 #endif
397 #ifdef AUDIOHW_HAVE_PRESCALER
399 * Set new prescaler value.
400 * @param val to set.
401 * NOTE: AUDIOHW_CAPS need to contain
402 * PRESCALER_CAP
404 void audiohw_set_prescaler(int val);
405 #endif
407 #ifdef AUDIOHW_HAVE_BALANCE
409 * Set new balance value
410 * @param val to set.
411 * NOTE: AUDIOHW_CAPS need to contain
412 * BALANCE_CAP
414 void audiohw_set_balance(int val);
415 #endif
417 #ifdef AUDIOHW_HAVE_TREBLE
419 * Set new treble value.
420 * @param val to set.
421 * NOTE: AUDIOHW_CAPS need to contain
422 * TREBLE_CAP
424 void audiohw_set_treble(int val);
425 #endif
427 #ifdef AUDIOHW_HAVE_BASS
429 * Set new bass value.
430 * @param val to set.
431 * NOTE: AUDIOHW_CAPS need to contain
432 * BASS_CAP
434 void audiohw_set_bass(int val);
435 #endif
437 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
439 * Set new bass cut off value.
440 * @param val to set.
441 * NOTE: AUDIOHW_CAPS need to contain
442 * BASS_CUTOFF_CAP
444 void audiohw_set_bass_cutoff(int val);
445 #endif
447 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
449 * Set new treble cut off value.
450 * @param val to set.
451 * NOTE: AUDIOHW_CAPS need to contain
452 * TREBLE_CUTOFF_CAP
454 void audiohw_set_treble_cutoff(int val);
455 #endif
457 #ifdef AUDIOHW_HAVE_EQ
459 * Set new band gain value.
460 * @param band index to which val is set
461 * @param val to set.
462 * NOTE: AUDIOHW_CAPS need to contain
463 * EQ_CAP
465 * AUDIOHW_EQ_BAND_CAPS must be defined as a bitmask
466 * of EQ_CAP each shifted by the zero-based band number
467 * for each band. Bands 1 to N are indexed 0 to N-1.
469 void audiohw_set_eq_band_gain(unsigned int band, int val);
470 #endif
472 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
474 * Set new band cutoff or center frequency value.
475 * @param band index to which val is set
476 * @param val to set.
477 * NOTE: AUDIOHW_CAPS need to contain
478 * EQ_CAP
480 * AUDIOHW_EQ_FREQUENCY_CAPS must be defined as a bitmask
481 * of EQ_CAP each shifted by the zero-based band number
482 * for each band that supports frequency adjustment.
483 * Bands 1 to N are indexed 0 to N-1.
485 void audiohw_set_eq_band_frequency(unsigned int band, int val);
486 #endif
488 #ifdef AUDIOHW_HAVE_EQ_WIDTH
490 * Set new band cutoff or center frequency value.
491 * @param band index to which val is set
492 * @param val to set.
493 * NOTE: AUDIOHW_CAPS need to contain
494 * EQ_CAP
496 * AUDIOHW_EQ_WIDTH_CAPS must be defined as a bitmask
497 * of EQ_CAP each shifted by the zero-based band number
498 * for each band that supports width adjustment.
499 * Bands 1 to N are indexed 0 to N-1.
501 void audiohw_set_eq_band_width(unsigned int band, int val);
502 #endif
504 #ifdef AUDIOHW_HAVE_DEPTH_3D
506 * Set new 3-d enhancement (stereo expansion) effect value.
507 * @param val to set.
508 * NOTE: AUDIOHW_CAPS need to contain
509 * DEPTH_3D_CAP
511 void audiohw_set_depth_3d(int val);
512 #endif
515 void audiohw_set_frequency(int fsel);
517 #ifdef HAVE_RECORDING
520 * Enable recording.
521 * @param source_mic if this is true, we want to record from microphone,
522 * else we want to record FM/LineIn.
524 void audiohw_enable_recording(bool source_mic);
527 * Disable recording.
529 void audiohw_disable_recording(void);
532 * Set gain of recording source.
533 * @param left gain value.
534 * @param right will not be used if recording from micophone (mono).
535 * @param type AUDIO_GAIN_MIC, AUDIO_GAIN_LINEIN.
537 void audiohw_set_recvol(int left, int right, int type);
539 #endif /* HAVE_RECORDING */
541 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
543 * Enable or disable recording monitor.
544 * @param enable true or false.
546 void audiohw_set_monitor(bool enable);
547 #endif
551 #if CONFIG_CODEC != SWCODEC
553 /* functions which are only used by mas35xx codecs, but are also
554 aviable on SWCODECS through dsp */
557 * Set channel configuration.
558 * @param val new channel value (see enum Channel).
560 void audiohw_set_channel(int val);
563 * Set stereo width.
564 * @param val new stereo width value.
566 void audiohw_set_stereo_width(int val);
568 #endif /* CONFIG_CODEC != SWCODEC */
570 #ifdef HAVE_SPEAKER
572 void audiohw_enable_speaker(bool on);
574 #endif /* HAVE_SPEAKER */
576 #endif /* _AUDIOHW_H_ */