1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
29 #elif defined(HAVE_WM8975) || defined(HAVE_WM8751)
31 #elif defined(HAVE_WM8758)
33 #elif defined(HAVE_WM8731) || defined(HAVE_WM8721)
35 #elif defined(HAVE_TLV320)
37 #elif CONFIG_CPU == PNX0101
43 #if CONFIG_CODEC == SWCODEC
44 #include "pcm_playback.h"
49 extern bool audio_is_initialized
;
51 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
52 extern unsigned long shadow_io_control_main
;
53 extern unsigned shadow_codec_reg0
;
55 #endif /* SIMULATOR */
57 struct sound_settings_info
{
64 sound_set_type
*setfn
;
67 static const struct sound_settings_info sound_settings_table
[] = {
68 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
69 [SOUND_VOLUME
] = {"dB", 0, 1,-100, 12, -25, sound_set_volume
},
70 [SOUND_BASS
] = {"dB", 0, 1, -12, 12, 6, sound_set_bass
},
71 [SOUND_TREBLE
] = {"dB", 0, 1, -12, 12, 6, sound_set_treble
},
72 #elif defined(HAVE_UDA1380)
73 [SOUND_VOLUME
] = {"dB", 0, 1, -84, 0, -25, sound_set_volume
},
74 [SOUND_BASS
] = {"dB", 0, 2, 0, 24, 0, sound_set_bass
},
75 [SOUND_TREBLE
] = {"dB", 0, 2, 0, 6, 0, sound_set_treble
},
76 #elif defined(HAVE_TLV320)
77 [SOUND_VOLUME
] = {"dB", 0, 1, -73, 6, -20, sound_set_volume
},
78 #elif defined(HAVE_WM8975) || defined(HAVE_WM8751)
79 [SOUND_VOLUME
] = {"dB", 0, 1, -74, 6, -25, sound_set_volume
},
80 [SOUND_BASS
] = {"dB", 0, 1, -6, 9, 0, sound_set_bass
},
81 [SOUND_TREBLE
] = {"dB", 0, 1, -6, 9, 0, sound_set_treble
},
82 #elif defined(HAVE_WM8758)
83 [SOUND_VOLUME
] = {"dB", 0, 1, -58, 6, -25, sound_set_volume
},
84 [SOUND_BASS
] = {"dB", 0, 1, -6, 9, 0, sound_set_bass
},
85 [SOUND_TREBLE
] = {"dB", 0, 1, -6, 9, 0, sound_set_treble
},
86 #elif defined(HAVE_WM8731) || defined(HAVE_WM8721)
87 [SOUND_VOLUME
] = {"dB", 0, 1, -74, 6, -25, sound_set_volume
},
88 [SOUND_BASS
] = {"dB", 0, 1, -6, 9, 0, sound_set_bass
},
89 [SOUND_TREBLE
] = {"dB", 0, 1, -6, 9, 0, sound_set_treble
},
90 #elif (CONFIG_CPU == PNX0101)
91 [SOUND_VOLUME
] = {"dB", 0, 1, -48, 15, 0, sound_set_volume
},
93 [SOUND_VOLUME
] = {"dB", 0, 1, -78, 18, -18, sound_set_volume
},
94 [SOUND_BASS
] = {"dB", 0, 1, -15, 15, 7, sound_set_bass
},
95 [SOUND_TREBLE
] = {"dB", 0, 1, -15, 15, 7, sound_set_treble
},
97 [SOUND_BALANCE
] = {"%", 0, 1,-100, 100, 0, sound_set_balance
},
98 [SOUND_CHANNELS
] = {"", 0, 1, 0, 5, 0, sound_set_channels
},
99 [SOUND_STEREO_WIDTH
] = {"%", 0, 1, 0, 255, 100, sound_set_stereo_width
},
100 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
101 [SOUND_LOUDNESS
] = {"dB", 0, 1, 0, 17, 0, sound_set_loudness
},
102 [SOUND_AVC
] = {"", 0, 1, -1, 4, 0, sound_set_avc
},
103 [SOUND_MDB_STRENGTH
] = {"dB", 0, 1, 0, 127, 48, sound_set_mdb_strength
},
104 [SOUND_MDB_HARMONICS
] = {"%", 0, 1, 0, 100, 50, sound_set_mdb_harmonics
},
105 [SOUND_MDB_CENTER
] = {"Hz", 0, 10, 20, 300, 60, sound_set_mdb_center
},
106 [SOUND_MDB_SHAPE
] = {"Hz", 0, 10, 50, 300, 90, sound_set_mdb_shape
},
107 [SOUND_MDB_ENABLE
] = {"", 0, 1, 0, 1, 0, sound_set_mdb_enable
},
108 [SOUND_SUPERBASS
] = {"", 0, 1, 0, 1, 0, sound_set_superbass
},
110 #if CONFIG_CODEC == MAS3587F
111 [SOUND_LEFT_GAIN
] = {"dB", 1, 1, 0, 15, 8, NULL
},
112 [SOUND_RIGHT_GAIN
] = {"dB", 1, 1, 0, 15, 8, NULL
},
113 [SOUND_MIC_GAIN
] = {"dB", 1, 1, 0, 15, 2, NULL
},
114 #elif defined(HAVE_UDA1380)
115 [SOUND_LEFT_GAIN
] = {"dB", 1, 1,-128, 96, 0, NULL
},
116 [SOUND_RIGHT_GAIN
] = {"dB", 1, 1,-128, 96, 0, NULL
},
117 [SOUND_MIC_GAIN
] = {"dB", 1, 1,-128, 108, 16, NULL
},
118 #elif defined(HAVE_TLV320)
119 [SOUND_LEFT_GAIN
] = {"dB", 1, 1, 0, 31, 23, NULL
},
120 [SOUND_RIGHT_GAIN
] = {"dB", 1, 1, 0, 31, 23, NULL
},
121 [SOUND_MIC_GAIN
] = {"dB", 1, 1, 0, 1, 1, NULL
},
125 const char *sound_unit(int setting
)
127 return sound_settings_table
[setting
].unit
;
130 int sound_numdecimals(int setting
)
132 return sound_settings_table
[setting
].numdecimals
;
135 int sound_steps(int setting
)
137 return sound_settings_table
[setting
].steps
;
140 int sound_min(int setting
)
142 return sound_settings_table
[setting
].minval
;
145 int sound_max(int setting
)
147 return sound_settings_table
[setting
].maxval
;
150 int sound_default(int setting
)
152 return sound_settings_table
[setting
].defaultval
;
155 sound_set_type
* sound_get_fn(int setting
)
157 if ((unsigned)setting
< (sizeof(sound_settings_table
)
158 / sizeof(struct sound_settings_info
)))
159 return sound_settings_table
[setting
].setfn
;
165 #if CONFIG_CODEC == MAS3507D /* volume/balance/treble/bass interdependency */
166 #define VOLUME_MIN -780
167 #define VOLUME_MAX 180
169 static const unsigned int bass_table
[] =
204 static const unsigned int treble_table
[] =
239 static const unsigned int prescale_table
[] =
259 /* convert tenth of dB volume (-780..+180) to dac3550 register value */
260 static int tenthdb2reg(int db
)
262 if (db
< -540) /* 3 dB steps */
263 return (db
+ 780) / 30;
264 else /* 1.5 dB steps */
265 return (db
+ 660) / 15;
269 #ifdef HAVE_UDA1380 /* volume/balance/treble/bass interdependency */
270 #define VOLUME_MIN -840
273 /* convert tenth of dB volume (-840..0) to master volume register value */
274 static int tenthdb2master(int db
)
276 if (db
< -720) /* 1.5 dB steps */
277 return (2940 - db
) / 15;
278 else if (db
< -660) /* 0.75 dB steps */
279 return (1110 - db
) * 2 / 15;
280 else if (db
< -520) /* 0.5 dB steps */
281 return (520 - db
) / 5;
282 else /* 0.25 dB steps */
286 /* convert tenth of dB volume (-780..0) to mixer volume register value */
287 static int tenthdb2mixer(int db
)
289 if (db
< -660) /* 1.5 dB steps */
290 return (2640 - db
) / 15;
291 else if (db
< -600) /* 0.75 dB steps */
292 return (990 - db
) * 2 / 15;
293 else if (db
< -460) /* 0.5 dB steps */
294 return (460 - db
) / 5;
295 else /* 0.25 dB steps */
299 #elif defined(HAVE_TLV320)
300 #define VOLUME_MIN -730
301 #define VOLUME_MAX 60
303 /* convert tenth of dB volume (-840..0) to master volume register value */
304 static int tenthdb2master(int db
)
306 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
307 /* 1111111 == +6dB (0x7f) */
308 /* 1111001 == 0dB (0x79) */
309 /* 0110000 == -73dB (0x30 */
310 /* 0101111 == mute (0x2f) */
312 if (db
< VOLUME_MIN
) {
315 return((db
/10)+73+0x30);
319 #elif defined(HAVE_WM8975) || defined(HAVE_WM8751)
320 /* volume/balance/treble/bass interdependency */
321 #define VOLUME_MIN -730
322 #define VOLUME_MAX 60
324 /* convert tenth of dB volume (-730..60) to master volume register value */
325 static int tenthdb2master(int db
)
327 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
328 /* 1111111 == +6dB (0x7f) */
329 /* 1111001 == 0dB (0x79) */
330 /* 0110000 == -73dB (0x30 */
331 /* 0101111 == mute (0x2f) */
333 if (db
< VOLUME_MIN
) {
336 return((db
/10)+73+0x30);
340 /* convert tenth of dB volume (-780..0) to mixer volume register value */
341 static int tenthdb2mixer(int db
)
343 if (db
< -660) /* 1.5 dB steps */
344 return (2640 - db
) / 15;
345 else if (db
< -600) /* 0.75 dB steps */
346 return (990 - db
) * 2 / 15;
347 else if (db
< -460) /* 0.5 dB steps */
348 return (460 - db
) / 5;
349 else /* 0.25 dB steps */
353 #elif defined(HAVE_WM8758)
354 /* volume/balance/treble/bass interdependency */
355 #define VOLUME_MIN -570
356 #define VOLUME_MAX 60
358 /* convert tenth of dB volume (-57..6) to master volume register value */
359 static int tenthdb2master(int db
)
361 /* +6 to -57dB in 1dB steps == 64 levels = 6 bits */
362 /* 0111111 == +6dB (0x3f) = 63) */
363 /* 0111001 == 0dB (0x39) = 57) */
364 /* 0000001 == -56dB (0x01) = */
365 /* 0000000 == -57dB (0x00) */
367 /* 1000000 == Mute (0x40) */
369 if (db
< VOLUME_MIN
) {
376 /* convert tenth of dB volume (-780..0) to mixer volume register value */
377 static int tenthdb2mixer(int db
)
379 if (db
< -660) /* 1.5 dB steps */
380 return (2640 - db
) / 15;
381 else if (db
< -600) /* 0.75 dB steps */
382 return (990 - db
) * 2 / 15;
383 else if (db
< -460) /* 0.5 dB steps */
384 return (460 - db
) / 5;
385 else /* 0.25 dB steps */
389 #elif defined(HAVE_WM8731) || defined(HAVE_WM8721)
390 /* volume/balance/treble/bass interdependency */
391 #define VOLUME_MIN -730
392 #define VOLUME_MAX 60
394 /* convert tenth of dB volume (-730..60) to master volume register value */
395 static int tenthdb2master(int db
)
397 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
398 /* 1111111 == +6dB (0x7f) */
399 /* 1111001 == 0dB (0x79) */
400 /* 0110000 == -73dB (0x30 */
401 /* 0101111 == mute (0x2f) */
403 if (db
< VOLUME_MIN
) {
406 return((db
/10)+0x30+73);
410 /* convert tenth of dB volume (-780..0) to mixer volume register value */
411 static int tenthdb2mixer(int db
)
413 if (db
< -660) /* 1.5 dB steps */
414 return (2640 - db
) / 15;
415 else if (db
< -600) /* 0.75 dB steps */
416 return (990 - db
) * 2 / 15;
417 else if (db
< -460) /* 0.5 dB steps */
418 return (460 - db
) / 5;
419 else /* 0.25 dB steps */
425 #if (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 \
426 || defined HAVE_WM8975 || defined HAVE_WM8758 || defined(HAVE_WM8731) \
427 || defined(HAVE_WM8721) || defined(HAVE_TLV320) || defined(HAVE_WM8751)
428 /* volume/balance/treble/bass interdependency main part */
429 #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
431 /* all values in tenth of dB MAS3507D UDA1380 */
432 int current_volume
= 0; /* -780..+180 -840.. 0 */
433 int current_balance
= 0; /* -960..+960 -840..+840 */
434 int current_treble
= 0; /* -150..+150 0.. +60 */
435 int current_bass
= 0; /* -150..+150 0..+240 */
437 static void set_prescaled_volume(void)
443 prescale
= MAX(current_bass
, current_treble
);
445 prescale
= 0; /* no need to prescale if we don't boost
448 /* Gain up the analog volume to compensate the prescale gain reduction,
449 * but if this would push the volume over the top, reduce prescaling
450 * instead (might cause clipping). */
451 if (current_volume
+ prescale
> VOLUME_MAX
)
452 prescale
= VOLUME_MAX
- current_volume
;
455 #if CONFIG_CODEC == MAS3507D
456 mas_writereg(MAS_REG_KPRESCALE
, prescale_table
[prescale
/10]);
457 #elif defined(HAVE_UDA1380)
458 uda1380_set_mixer_vol(tenthdb2mixer(-prescale
), tenthdb2mixer(-prescale
));
459 #elif defined(HAVE_WM8975) || defined(HAVE_WM8758) \
460 || defined(HAVE_WM8731) || defined(HAVE_WM8721) || defined(HAVE_WM8751)
461 wmcodec_set_mixer_vol(tenthdb2mixer(-prescale
), tenthdb2mixer(-prescale
));
464 if (current_volume
== VOLUME_MIN
)
465 prescale
= 0; /* Make sure the chip gets muted at VOLUME_MIN */
467 l
= r
= current_volume
+ prescale
;
469 if (current_balance
> 0)
471 l
-= current_balance
;
475 if (current_balance
< 0)
477 r
+= current_balance
;
482 #if CONFIG_CODEC == MAS3507D
483 dac_volume(tenthdb2reg(l
), tenthdb2reg(r
), false);
484 #elif defined(HAVE_UDA1380)
485 uda1380_set_master_vol(tenthdb2master(l
), tenthdb2master(r
));
486 #elif defined(HAVE_WM8975) || defined(HAVE_WM8758) \
487 || defined(HAVE_WM8731) || defined(HAVE_WM8721) || defined(HAVE_WM8751)
488 wmcodec_set_master_vol(tenthdb2master(l
), tenthdb2master(r
));
489 #if defined(HAVE_WM8975) || defined(HAVE_WM8758) || defined(HAVE_WM8751)
490 wmcodec_set_lineout_vol(tenthdb2master(0), tenthdb2master(0));
493 #elif defined(HAVE_TLV320)
494 tlv320_set_headphone_vol(tenthdb2master(l
), tenthdb2master(r
));
497 #endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */
498 #endif /* !SIMULATOR */
500 #if CONFIG_CODEC != SWCODEC
501 int channel_configuration
= SOUND_CHAN_STEREO
;
502 int stereo_width
= 100;
507 #if CONFIG_CODEC != SWCODEC
508 static void set_channel_config(void)
510 /* default values: stereo */
511 unsigned long val_ll
= 0x80000;
512 unsigned long val_lr
= 0;
513 unsigned long val_rl
= 0;
514 unsigned long val_rr
= 0x80000;
516 switch(channel_configuration
)
518 /* case SOUND_CHAN_STEREO unnecessary */
520 case SOUND_CHAN_MONO
:
527 case SOUND_CHAN_CUSTOM
:
529 /* fixed point variables (matching MAS internal format)
530 integer part: upper 13 bits (inlcuding sign)
531 fractional part: lower 19 bits */
532 long fp_width
, fp_straight
, fp_cross
;
534 fp_width
= (stereo_width
<< 19) / 100;
535 if (stereo_width
<= 100)
537 fp_straight
= - ((1<<19) + fp_width
) / 2;
538 fp_cross
= fp_straight
+ fp_width
;
542 /* straight = - (1 + width) / (2 * width) */
543 fp_straight
= - ((((1<<19) + fp_width
) / (fp_width
>> 9)) << 9);
544 fp_cross
= (1<<19) + fp_straight
;
546 val_ll
= val_rr
= fp_straight
& 0xfffff;
547 val_lr
= val_rl
= fp_cross
& 0xfffff;
551 case SOUND_CHAN_MONO_LEFT
:
558 case SOUND_CHAN_MONO_RIGHT
:
565 case SOUND_CHAN_KARAOKE
:
573 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
574 mas_writemem(MAS_BANK_D0
, MAS_D0_OUT_LL
, &val_ll
, 1); /* LL */
575 mas_writemem(MAS_BANK_D0
, MAS_D0_OUT_LR
, &val_lr
, 1); /* LR */
576 mas_writemem(MAS_BANK_D0
, MAS_D0_OUT_RL
, &val_rl
, 1); /* RL */
577 mas_writemem(MAS_BANK_D0
, MAS_D0_OUT_RR
, &val_rr
, 1); /* RR */
578 #elif CONFIG_CODEC == MAS3507D
579 mas_writemem(MAS_BANK_D1
, 0x7f8, &val_ll
, 1); /* LL */
580 mas_writemem(MAS_BANK_D1
, 0x7f9, &val_lr
, 1); /* LR */
581 mas_writemem(MAS_BANK_D1
, 0x7fa, &val_rl
, 1); /* RL */
582 mas_writemem(MAS_BANK_D1
, 0x7fb, &val_rr
, 1); /* RR */
586 #endif /* CONFIG_CODEC != SWCODEC */
588 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
589 unsigned long mdb_shape_shadow
= 0;
590 unsigned long loudness_shadow
= 0;
593 void sound_set_volume(int value
)
595 if(!audio_is_initialized
)
597 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
598 unsigned tmp
= ((unsigned)(value
+ 115) & 0xff) << 8;
599 mas_codec_writereg(0x10, tmp
);
600 #elif (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 \
601 || defined HAVE_WM8975 || defined HAVE_WM8758 || defined HAVE_WM8731 \
602 || defined(HAVE_WM8721) || defined(HAVE_TLV320) || defined(HAVE_WM8751)
603 current_volume
= value
* 10; /* tenth of dB */
604 set_prescaled_volume();
605 #elif CONFIG_CPU == PNX0101
606 int tmp
= (60 - value
* 4) & 0xff;
607 CODECVOL
= tmp
| (tmp
<< 8);
611 void sound_set_balance(int value
)
613 if(!audio_is_initialized
)
615 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
616 unsigned tmp
= ((unsigned)(value
* 127 / 100) & 0xff) << 8;
617 mas_codec_writereg(0x11, tmp
);
618 #elif CONFIG_CODEC == MAS3507D || defined HAVE_UDA1380 \
619 || defined HAVE_WM8975 || defined HAVE_WM8758 || defined HAVE_WM8731 \
620 || defined(HAVE_WM8721) || defined(HAVE_TLV320) || defined(HAVE_WM8751)
621 current_balance
= value
* VOLUME_RANGE
/ 100; /* tenth of dB */
622 set_prescaled_volume();
623 #elif CONFIG_CPU == PNX0101
624 /* TODO: implement for iFP */
630 void sound_set_bass(int value
)
632 if(!audio_is_initialized
)
634 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
635 unsigned tmp
= ((unsigned)(value
* 8) & 0xff) << 8;
636 mas_codec_writereg(0x14, tmp
);
637 #elif CONFIG_CODEC == MAS3507D
638 mas_writereg(MAS_REG_KBASS
, bass_table
[value
+15]);
639 current_bass
= value
* 10;
640 set_prescaled_volume();
641 #elif defined(HAVE_UDA1380)
642 uda1380_set_bass(value
>> 1);
643 current_bass
= value
* 10;
644 set_prescaled_volume();
645 #elif defined HAVE_WM8975 || defined HAVE_WM8758 \
646 || defined HAVE_WM8731 || defined(HAVE_WM8721) || defined(HAVE_WM8751)
647 current_bass
= value
* 10;
648 wmcodec_set_bass(value
);
649 set_prescaled_volume();
650 #elif CONFIG_CPU == PNX0101
651 /* TODO: implement for iFP */
656 void sound_set_treble(int value
)
658 if(!audio_is_initialized
)
660 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
661 unsigned tmp
= ((unsigned)(value
* 8) & 0xff) << 8;
662 mas_codec_writereg(0x15, tmp
);
663 #elif CONFIG_CODEC == MAS3507D
664 mas_writereg(MAS_REG_KTREBLE
, treble_table
[value
+15]);
665 current_treble
= value
* 10;
666 set_prescaled_volume();
667 #elif defined(HAVE_UDA1380)
668 uda1380_set_treble(value
>> 1);
669 current_treble
= value
* 10;
670 set_prescaled_volume();
671 #elif defined(HAVE_WM8975) || defined(HAVE_WM8758) \
672 || defined(HAVE_WM8731) || defined(HAVE_WM8721) || defined(HAVE_WM8751)
673 wmcodec_set_treble(value
);
674 current_treble
= value
* 10;
675 set_prescaled_volume();
676 #elif CONFIG_CPU == PNX0101
677 /* TODO: implement for iFP */
681 #endif /* HAVE_TLV320 */
683 void sound_set_channels(int value
)
685 #if CONFIG_CODEC == SWCODEC
688 if(!audio_is_initialized
)
690 channel_configuration
= value
;
691 set_channel_config();
695 void sound_set_stereo_width(int value
)
697 #if CONFIG_CODEC == SWCODEC
700 if(!audio_is_initialized
)
702 stereo_width
= value
;
703 if (channel_configuration
== SOUND_CHAN_CUSTOM
)
704 set_channel_config();
708 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
709 void sound_set_loudness(int value
)
711 if(!audio_is_initialized
)
713 loudness_shadow
= (loudness_shadow
& 0x04) |
714 (MAX(MIN(value
* 4, 0x44), 0) << 8);
715 mas_codec_writereg(MAS_REG_KLOUDNESS
, loudness_shadow
);
718 void sound_set_avc(int value
)
720 if(!audio_is_initialized
)
725 tmp
= (0x1 << 8) | (0x8 << 12);
728 tmp
= (0x2 << 8) | (0x8 << 12);
731 tmp
= (0x4 << 8) | (0x8 << 12);
734 tmp
= (0x8 << 8) | (0x8 << 12);
736 case -1: /* turn off and then turn on again to decay quickly */
737 tmp
= mas_codec_readreg(MAS_REG_KAVC
);
738 mas_codec_writereg(MAS_REG_KAVC
, 0);
744 mas_codec_writereg(MAS_REG_KAVC
, tmp
);
747 void sound_set_mdb_strength(int value
)
749 if(!audio_is_initialized
)
751 mas_codec_writereg(MAS_REG_KMDB_STR
, (value
& 0x7f) << 8);
754 void sound_set_mdb_harmonics(int value
)
756 if(!audio_is_initialized
)
758 int tmp
= value
* 127 / 100;
759 mas_codec_writereg(MAS_REG_KMDB_HAR
, (tmp
& 0x7f) << 8);
762 void sound_set_mdb_center(int value
)
764 if(!audio_is_initialized
)
766 mas_codec_writereg(MAS_REG_KMDB_FC
, (value
/10) << 8);
769 void sound_set_mdb_shape(int value
)
771 if(!audio_is_initialized
)
773 mdb_shape_shadow
= (mdb_shape_shadow
& 0x02) | ((value
/10) << 8);
774 mas_codec_writereg(MAS_REG_KMDB_SWITCH
, mdb_shape_shadow
);
777 void sound_set_mdb_enable(int value
)
779 if(!audio_is_initialized
)
781 mdb_shape_shadow
= (mdb_shape_shadow
& ~0x02) | (value
?2:0);
782 mas_codec_writereg(MAS_REG_KMDB_SWITCH
, mdb_shape_shadow
);
785 void sound_set_superbass(int value
)
787 if(!audio_is_initialized
)
789 loudness_shadow
= (loudness_shadow
& ~0x04) | (value
?4:0);
790 mas_codec_writereg(MAS_REG_KLOUDNESS
, loudness_shadow
);
792 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
794 #else /* SIMULATOR */
795 void sound_set_volume(int value
)
800 void sound_set_balance(int value
)
805 void sound_set_bass(int value
)
810 void sound_set_treble(int value
)
815 void sound_set_channels(int value
)
820 void sound_set_stereo_width(int value
)
825 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
826 void sound_set_loudness(int value
)
831 void sound_set_avc(int value
)
836 void sound_set_mdb_strength(int value
)
841 void sound_set_mdb_harmonics(int value
)
846 void sound_set_mdb_center(int value
)
851 void sound_set_mdb_shape(int value
)
856 void sound_set_mdb_enable(int value
)
861 void sound_set_superbass(int value
)
865 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
866 #endif /* SIMULATOR */
868 void sound_set(int setting
, int value
)
870 sound_set_type
* sound_set_val
= sound_get_fn(setting
);
872 sound_set_val(value
);
875 int sound_val2phys(int setting
, int value
)
877 #if CONFIG_CODEC == MAS3587F
882 case SOUND_LEFT_GAIN
:
883 case SOUND_RIGHT_GAIN
:
884 result
= (value
- 2) * 15;
888 result
= value
* 15 + 210;
896 #elif defined(HAVE_UDA1380)
901 case SOUND_LEFT_GAIN
:
902 case SOUND_RIGHT_GAIN
:
904 result
= value
* 5; /* (1/2) * 10 */
912 #elif defined(HAVE_TLV320)
917 case SOUND_LEFT_GAIN
:
918 case SOUND_RIGHT_GAIN
:
919 result
= (value
- 23) * 15; /* (x - 23)/1.5 *10 */
923 result
= value
* 200; /* 0 or 20 dB */
937 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
939 /* This function works by telling the decoder that we have another
940 crystal frequency than we actually have. It will adjust its internal
941 parameters and the result is that the audio is played at another pitch.
943 The pitch value is in tenths of percent.
945 static int last_pitch
= 1000;
947 void sound_set_pitch(int pitch
)
951 if (pitch
!= last_pitch
)
953 /* Calculate the new (bogus) frequency */
954 val
= 18432 * 1000 / pitch
;
956 mas_writemem(MAS_BANK_D0
, MAS_D0_OFREQ_CONTROL
, &val
, 1);
958 /* We must tell the MAS that the frequency has changed.
959 * This will unfortunately cause a short silence. */
960 mas_writemem(MAS_BANK_D0
, MAS_D0_IO_CONTROL_MAIN
, &shadow_io_control_main
, 1);
966 int sound_get_pitch(void)
970 #else /* SIMULATOR */
971 void sound_set_pitch(int pitch
)
976 int sound_get_pitch(void)
980 #endif /* SIMULATOR */
981 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */