Gigabeat S: Fully enable access to hardware tone controls and 3-D effect feature...
[kugel-rb.git] / firmware / export / audiohw.h
blob12c4738f7c94df77a5100990daf8b17fc5ee75dc
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
72 #define ONE_DB 10
74 #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX)
75 #warning define for VOLUME_MIN and VOLUME_MAX is missing
76 #define VOLUME_MIN -700
77 #define VOLUME_MAX 0
78 #endif
80 #ifndef AUDIOHW_NUM_TONE_CONTROLS
81 #define AUDIOHW_NUM_TONE_CONTROLS 0
82 #endif
84 /* volume/balance/treble/bass interdependency main part */
85 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
88 /* convert caps into defines */
89 #ifdef AUDIOHW_CAPS
90 /* Tone controls */
91 #if (AUDIOHW_CAPS & TREBLE_CAP)
92 #define AUDIOHW_HAVE_TREBLE
93 #endif
95 #if (AUDIOHW_CAPS & BASS_CAP)
96 #define AUDIOHW_HAVE_BASS
97 #endif
99 #if (AUDIOHW_CAPS & BASS_CUTOFF_CAP)
100 #define AUDIOHW_HAVE_BASS_CUTOFF
101 #endif
103 #if (AUDIOHW_CAPS & TREBLE_CUTOFF_CAP)
104 #define AUDIOHW_HAVE_TREBLE_CUTOFF
105 #endif
107 #if (AUDIOHW_CAPS & BALANCE_CAP)
108 #define AUDIOHW_HAVE_BALANCE
109 #endif
111 #if (AUDIOHW_CAPS & CLIPPING_CAP)
112 #define AUDIOHW_HAVE_CLIPPING
113 #endif
115 #if (AUDIOHW_CAPS & PRESCALER_CAP)
116 #define AUDIOHW_HAVE_PRESCALER
117 #endif
119 /* Hardware EQ tone controls */
120 #if (AUDIOHW_CAPS & EQ_CAP)
121 /* A hardware equalizer is present (or perhaps some tone control variation
122 * that is not Bass and/or Treble) */
123 #define AUDIOHW_HAVE_EQ
125 /* Defined band indexes for supported bands */
126 enum
128 /* Band 1 is implied; bands must be contiguous, 1 to N */
129 AUDIOHW_EQ_BAND1 = 0,
130 #define AUDIOHW_HAVE_EQ_BAND1
131 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 1))
132 AUDIOHW_EQ_BAND2,
133 #define AUDIOHW_HAVE_EQ_BAND2
134 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 2))
135 AUDIOHW_EQ_BAND3,
136 #define AUDIOHW_HAVE_EQ_BAND3
137 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 3))
138 AUDIOHW_EQ_BAND4,
139 #define AUDIOHW_HAVE_EQ_BAND4
140 #if (AUDIOHW_EQ_BAND_CAPS & (EQ_CAP << 4))
141 AUDIOHW_EQ_BAND5,
142 #define AUDIOHW_HAVE_EQ_BAND5
143 #endif /* 5 */
144 #endif /* 4 */
145 #endif /* 3 */
146 #endif /* 2 */
147 AUDIOHW_EQ_BAND_NUM, /* Keep last */
150 #ifdef AUDIOHW_EQ_FREQUENCY_CAPS
151 /* One or more bands supports frequency cutoff or center adjustment */
152 #define AUDIOHW_HAVE_EQ_FREQUENCY
153 enum
155 __AUDIOHW_EQ_BAND_FREQUENCY = -1,
156 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
157 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 0))
158 AUDIOHW_EQ_BAND1_FREQUENCY,
159 #define AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
160 #endif
161 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
162 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 1))
163 AUDIOHW_EQ_BAND2_FREQUENCY,
164 #define AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
165 #endif
166 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
167 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 2))
168 AUDIOHW_EQ_BAND3_FREQUENCY,
169 #define AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
170 #endif
171 #if defined(AUDIOHW_HAVE_EQ_BAND4) && \
172 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 3))
173 AUDIOHW_EQ_BAND4_FREQUENCY,
174 #define AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
175 #endif
176 #if defined(AUDIOHW_HAVE_EQ_BAND5) && \
177 (AUDIOHW_EQ_FREQUENCY_CAPS & (EQ_CAP << 4))
178 AUDIOHW_EQ_BAND5_FREQUENCY,
179 #define AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
180 #endif
181 AUDIOHW_EQ_FREQUENCY_NUM,
183 #endif /* AUDIOHW_EQ_FREQUENCY_CAPS */
185 #ifdef AUDIOHW_EQ_WIDTH_CAPS
186 /* One or more bands supports bandwidth adjustment */
187 #define AUDIOHW_HAVE_EQ_WIDTH
188 enum
190 __AUDIOHW_EQ_BAND_WIDTH = -1,
191 #if defined(AUDIOHW_HAVE_EQ_BAND1) && \
192 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 1))
193 AUDIOHW_EQ_BAND2_WIDTH,
194 #define AUDIOHW_HAVE_EQ_BAND2_WIDTH
195 #endif
196 #if defined(AUDIOHW_HAVE_EQ_BAND2) && \
197 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 2))
198 AUDIOHW_EQ_BAND3_WIDTH,
199 #define AUDIOHW_HAVE_EQ_BAND3_WIDTH
200 #endif
201 #if defined(AUDIOHW_HAVE_EQ_BAND3) && \
202 (AUDIOHW_EQ_WIDTH_CAPS & (EQ_CAP << 3))
203 AUDIOHW_EQ_BAND4_WIDTH,
204 #define AUDIOHW_HAVE_EQ_BAND4_WIDTH
205 #endif
206 AUDIOHW_EQ_WIDTH_NUM, /* Keep last */
208 #endif /* AUDIOHW_EQ_WIDTH_CAPS */
210 /* Types and number of settings types (gain, frequency, width) */
211 enum AUDIOHW_EQ_SETTINGS
213 AUDIOHW_EQ_GAIN = 0,
214 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
215 AUDIOHW_EQ_FREQUENCY,
216 #endif
217 #ifdef AUDIOHW_HAVE_EQ_WIDTH
218 AUDIOHW_EQ_WIDTH,
219 #endif
220 AUDIOHW_EQ_SETTING_NUM
223 #endif /* (AUDIOHW_CAPS & EQ_CAP) */
225 #if (AUDIOHW_CAPS & DEPTH_3D_CAP)
226 #define AUDIOHW_HAVE_DEPTH_3D
227 #endif
229 #endif /* AUDIOHW_CAPS */
231 enum {
232 SOUND_VOLUME = 0,
233 /* Tone control */
234 #if defined(AUDIOHW_HAVE_BASS)
235 SOUND_BASS,
236 #endif
237 #if defined(AUDIOHW_HAVE_TREBLE)
238 SOUND_TREBLE,
239 #endif
240 SOUND_BALANCE,
241 SOUND_CHANNELS,
242 SOUND_STEREO_WIDTH,
243 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
244 SOUND_LOUDNESS,
245 SOUND_AVC,
246 SOUND_MDB_STRENGTH,
247 SOUND_MDB_HARMONICS,
248 SOUND_MDB_CENTER,
249 SOUND_MDB_SHAPE,
250 SOUND_MDB_ENABLE,
251 SOUND_SUPERBASS,
252 #endif
253 #if defined(HAVE_RECORDING)
254 SOUND_LEFT_GAIN,
255 SOUND_RIGHT_GAIN,
256 SOUND_MIC_GAIN,
257 #endif
258 /* Bass and treble tone controls */
259 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
260 SOUND_BASS_CUTOFF,
261 #endif
262 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
263 SOUND_TREBLE_CUTOFF,
264 #endif
265 /* 3D effect */
266 #if defined(AUDIOHW_HAVE_DEPTH_3D)
267 SOUND_DEPTH_3D,
268 #endif
269 /* Hardware EQ tone controls */
270 /* Band gains */
271 #if defined(AUDIOHW_HAVE_EQ)
272 /* Band 1 implied */
273 SOUND_EQ_BAND1_GAIN,
274 #if defined(AUDIOHW_HAVE_EQ_BAND2)
275 SOUND_EQ_BAND2_GAIN,
276 #endif
277 #if defined(AUDIOHW_HAVE_EQ_BAND3)
278 SOUND_EQ_BAND3_GAIN,
279 #endif
280 #if defined(AUDIOHW_HAVE_EQ_BAND4)
281 SOUND_EQ_BAND4_GAIN,
282 #endif
283 #if defined(AUDIOHW_HAVE_EQ_BAND5)
284 SOUND_EQ_BAND5_GAIN,
285 #endif
286 /* Band frequencies */
287 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
288 SOUND_EQ_BAND1_FREQUENCY,
289 #endif
290 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
291 SOUND_EQ_BAND2_FREQUENCY,
292 #endif
293 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
294 SOUND_EQ_BAND3_FREQUENCY,
295 #endif
296 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
297 SOUND_EQ_BAND4_FREQUENCY,
298 #endif
299 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
300 SOUND_EQ_BAND5_FREQUENCY,
301 #endif
302 /* Band widths */
303 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
304 SOUND_EQ_BAND2_WIDTH,
305 #endif
306 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
307 SOUND_EQ_BAND3_WIDTH,
308 #endif
309 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
310 SOUND_EQ_BAND4_WIDTH,
311 #endif
312 #endif /* AUDIOHW_HAVE_EQ */
313 SOUND_LAST_SETTING, /* Keep this last */
316 enum Channel {
317 SOUND_CHAN_STEREO,
318 SOUND_CHAN_MONO,
319 SOUND_CHAN_CUSTOM,
320 SOUND_CHAN_MONO_LEFT,
321 SOUND_CHAN_MONO_RIGHT,
322 SOUND_CHAN_KARAOKE,
323 SOUND_CHAN_NUM_MODES,
326 struct sound_settings_info {
327 const char *unit;
328 char numdecimals;
329 char steps;
330 short minval;
331 short maxval;
332 short defaultval;
335 /* This struct is used by every driver to export its min/max/default values for
336 * its audio settings. Keep in mind that the order must be correct! */
337 extern const struct sound_settings_info audiohw_settings[];
339 /* All usable functions implemented by a audio codec drivers. Most of
340 * the function in sound settings are only called, when in audio codecs
341 * .h file suitable defines are added.
345 * Initialize audio codec to a well defined state. Includes SoC-specific
346 * setup.
348 void audiohw_init(void);
351 * Do initial audio codec setup. Usually called from audiohw_init.
353 void audiohw_preinit(void);
356 * Do some stuff (codec related) after audiohw_init that needs to be
357 * delayed such as enabling outputs to prevent popping. This lets
358 * other inits in the system complete in the meantime.
360 void audiohw_postinit(void);
363 * Close audio codec.
365 void audiohw_close(void);
367 #ifdef AUDIOHW_HAVE_CLIPPING
369 * Set new volume value
370 * @param val to set.
371 * NOTE: AUDIOHW_CAPS need to contain
372 * CLIPPING_CAP
374 void audiohw_set_volume(int val);
375 #endif
377 #ifdef AUDIOHW_HAVE_PRESCALER
379 * Set new prescaler value.
380 * @param val to set.
381 * NOTE: AUDIOHW_CAPS need to contain
382 * PRESCALER_CAP
384 void audiohw_set_prescaler(int val);
385 #endif
387 #ifdef AUDIOHW_HAVE_BALANCE
389 * Set new balance value
390 * @param val to set.
391 * NOTE: AUDIOHW_CAPS need to contain
392 * BALANCE_CAP
394 void audiohw_set_balance(int val);
395 #endif
397 #ifdef AUDIOHW_HAVE_TREBLE
399 * Set new treble value.
400 * @param val to set.
401 * NOTE: AUDIOHW_CAPS need to contain
402 * TREBLE_CAP
404 void audiohw_set_treble(int val);
405 #endif
407 #ifdef AUDIOHW_HAVE_BASS
409 * Set new bass value.
410 * @param val to set.
411 * NOTE: AUDIOHW_CAPS need to contain
412 * BASS_CAP
414 void audiohw_set_bass(int val);
415 #endif
417 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
419 * Set new bass cut off value.
420 * @param val to set.
421 * NOTE: AUDIOHW_CAPS need to contain
422 * BASS_CUTOFF_CAP
424 void audiohw_set_bass_cutoff(int val);
425 #endif
427 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
429 * Set new treble cut off value.
430 * @param val to set.
431 * NOTE: AUDIOHW_CAPS need to contain
432 * TREBLE_CUTOFF_CAP
434 void audiohw_set_treble_cutoff(int val);
435 #endif
437 #ifdef AUDIOHW_HAVE_EQ
439 * Set new band gain value.
440 * @param band index to which val is set
441 * @param val to set.
442 * NOTE: AUDIOHW_CAPS need to contain
443 * EQ_CAP
445 * AUDIOHW_EQ_BAND_CAPS must be defined as a bitmask
446 * of EQ_CAP each shifted by the zero-based band number
447 * for each band. Bands 1 to N are indexed 0 to N-1.
449 void audiohw_set_eq_band_gain(unsigned int band, int val);
450 #endif
452 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
454 * Set new band cutoff or center frequency value.
455 * @param band index to which val is set
456 * @param val to set.
457 * NOTE: AUDIOHW_CAPS need to contain
458 * EQ_CAP
460 * AUDIOHW_EQ_FREQUENCY_CAPS must be defined as a bitmask
461 * of EQ_CAP each shifted by the zero-based band number
462 * for each band that supports frequency adjustment.
463 * Bands 1 to N are indexed 0 to N-1.
465 void audiohw_set_eq_band_frequency(unsigned int band, int val);
466 #endif
468 #ifdef AUDIOHW_HAVE_EQ_WIDTH
470 * Set new band cutoff or center frequency value.
471 * @param band index to which val is set
472 * @param val to set.
473 * NOTE: AUDIOHW_CAPS need to contain
474 * EQ_CAP
476 * AUDIOHW_EQ_WIDTH_CAPS must be defined as a bitmask
477 * of EQ_CAP each shifted by the zero-based band number
478 * for each band that supports width adjustment.
479 * Bands 1 to N are indexed 0 to N-1.
481 void audiohw_set_eq_band_width(unsigned int band, int val);
482 #endif
484 #ifdef AUDIOHW_HAVE_DEPTH_3D
486 * Set new 3-d enhancement (stereo expansion) effect value.
487 * @param val to set.
488 * NOTE: AUDIOHW_CAPS need to contain
489 * DEPTH_3D_CAP
491 void audiohw_set_depth_3d(int val);
492 #endif
495 void audiohw_set_frequency(int fsel);
497 #ifdef HAVE_RECORDING
500 * Enable recording.
501 * @param source_mic if this is true, we want to record from microphone,
502 * else we want to record FM/LineIn.
504 void audiohw_enable_recording(bool source_mic);
507 * Disable recording.
509 void audiohw_disable_recording(void);
512 * Set gain of recording source.
513 * @param left gain value.
514 * @param right will not be used if recording from micophone (mono).
515 * @param type AUDIO_GAIN_MIC, AUDIO_GAIN_LINEIN.
517 void audiohw_set_recvol(int left, int right, int type);
519 #endif /*HAVE_RECORDING*/
521 #if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
524 * Enable or disable recording monitor.
525 * @param enable ture or false.
527 void audiohw_set_monitor(bool enable);
529 #endif /* HAVE_RECORDING || HAVE_FMRADIO_IN */
531 #if CONFIG_CODEC != SWCODEC
533 /* functions which are only used by mas35xx codecs, but are also
534 aviable on SWCODECS through dsp */
537 * Set channel configuration.
538 * @param val new channel value (see enum Channel).
540 void audiohw_set_channel(int val);
543 * Set stereo width.
544 * @param val new stereo width value.
546 void audiohw_set_stereo_width(int val);
548 #endif /* CONFIG_CODEC != SWCODEC */
550 #ifdef HAVE_SPEAKER
552 void audiohw_enable_speaker(bool on);
554 #endif /* HAVE_SPEAKER */
556 #endif /* _AUDIOHW_H_ */