summaryrefslogtreecommitdiff
path: root/firmware/sound.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/sound.c')
-rw-r--r--firmware/sound.c54
1 files changed, 47 insertions, 7 deletions
diff --git a/firmware/sound.c b/firmware/sound.c
index a039cca609..f1c9ff79e7 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -30,6 +30,8 @@
30#include "wm8975.h" 30#include "wm8975.h"
31#elif defined(HAVE_WM8758) 31#elif defined(HAVE_WM8758)
32#include "wm8758.h" 32#include "wm8758.h"
33#elif defined(HAVE_WM8731)
34#include "wm8731l.h"
33#elif defined(HAVE_TLV320) 35#elif defined(HAVE_TLV320)
34#include "tlv320.h" 36#include "tlv320.h"
35#endif 37#endif
@@ -77,6 +79,10 @@ static const struct sound_settings_info sound_settings_table[] = {
77 [SOUND_VOLUME] = {"dB", 0, 1, -57, 6, -25, sound_set_volume}, 79 [SOUND_VOLUME] = {"dB", 0, 1, -57, 6, -25, sound_set_volume},
78 [SOUND_BASS] = {"dB", 0, 1, -6, 9, 0, sound_set_bass}, 80 [SOUND_BASS] = {"dB", 0, 1, -6, 9, 0, sound_set_bass},
79 [SOUND_TREBLE] = {"dB", 0, 1, -6, 9, 0, sound_set_treble}, 81 [SOUND_TREBLE] = {"dB", 0, 1, -6, 9, 0, sound_set_treble},
82#elif defined(HAVE_WM8731)
83 [SOUND_VOLUME] = {"dB", 0, 1, -73, 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},
80#else /* MAS3507D */ 86#else /* MAS3507D */
81 [SOUND_VOLUME] = {"dB", 0, 1, -78, 18, -18, sound_set_volume}, 87 [SOUND_VOLUME] = {"dB", 0, 1, -78, 18, -18, sound_set_volume},
82 [SOUND_BASS] = {"dB", 0, 1, -15, 15, 7, sound_set_bass}, 88 [SOUND_BASS] = {"dB", 0, 1, -15, 15, 7, sound_set_bass},
@@ -350,10 +356,44 @@ static int tenthdb2mixer(int db)
350 return -db * 2 / 5; 356 return -db * 2 / 5;
351} 357}
352 358
359#elif defined(HAVE_WM8731)
360/* volume/balance/treble/bass interdependency */
361#define VOLUME_MIN -730
362#define VOLUME_MAX 60
363
364/* convert tenth of dB volume (-730..60) to master volume register value */
365static int tenthdb2master(int db)
366{
367 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
368 /* 1111111 == +6dB (0x7f) */
369 /* 1111001 == 0dB (0x79) */
370 /* 0110000 == -73dB (0x30 */
371 /* 0101111 == mute (0x2f) */
372
373 if (db <= -570) {
374 return 0x0;
375 } else {
376 return((db/10)+57);
377 }
378}
379
380/* convert tenth of dB volume (-780..0) to mixer volume register value */
381static int tenthdb2mixer(int db)
382{
383 if (db < -660) /* 1.5 dB steps */
384 return (2640 - db) / 15;
385 else if (db < -600) /* 0.75 dB steps */
386 return (990 - db) * 2 / 15;
387 else if (db < -460) /* 0.5 dB steps */
388 return (460 - db) / 5;
389 else /* 0.25 dB steps */
390 return -db * 2 / 5;
391}
392
353#endif 393#endif
354 394
355#if (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 || \ 395#if (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 || \
356 defined HAVE_WM8975 || defined HAVE_WM8758 396 defined HAVE_WM8975 || defined HAVE_WM8758 || defined(HAVE_WM8731)
357 /* volume/balance/treble/bass interdependency main part */ 397 /* volume/balance/treble/bass interdependency main part */
358#define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN) 398#define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
359 399
@@ -383,7 +423,7 @@ static void set_prescaled_volume(void)
383 mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]); 423 mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]);
384#elif defined(HAVE_UDA1380) 424#elif defined(HAVE_UDA1380)
385 uda1380_set_mixer_vol(tenthdb2mixer(-prescale), tenthdb2mixer(-prescale)); 425 uda1380_set_mixer_vol(tenthdb2mixer(-prescale), tenthdb2mixer(-prescale));
386#elif defined(HAVE_WM8975) || defined(HAVE_WM8758) 426#elif defined(HAVE_WM8975) || defined(HAVE_WM8758) || defined(HAVE_WM8731)
387 wmcodec_set_mixer_vol(tenthdb2mixer(-prescale), tenthdb2mixer(-prescale)); 427 wmcodec_set_mixer_vol(tenthdb2mixer(-prescale), tenthdb2mixer(-prescale));
388#endif 428#endif
389 429
@@ -409,7 +449,7 @@ static void set_prescaled_volume(void)
409 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); 449 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
410#elif defined(HAVE_UDA1380) 450#elif defined(HAVE_UDA1380)
411 uda1380_set_master_vol(tenthdb2master(l), tenthdb2master(r)); 451 uda1380_set_master_vol(tenthdb2master(l), tenthdb2master(r));
412#elif defined(HAVE_WM8975) || defined(HAVE_WM8758) 452#elif defined(HAVE_WM8975) || defined(HAVE_WM8758) || defined(HAVE_WM8731)
413 wmcodec_set_master_vol(tenthdb2master(l), tenthdb2master(r)); 453 wmcodec_set_master_vol(tenthdb2master(l), tenthdb2master(r));
414#endif 454#endif
415} 455}
@@ -511,7 +551,7 @@ void sound_set_volume(int value)
511 unsigned tmp = ((unsigned)(value + 115) & 0xff) << 8; 551 unsigned tmp = ((unsigned)(value + 115) & 0xff) << 8;
512 mas_codec_writereg(0x10, tmp); 552 mas_codec_writereg(0x10, tmp);
513#elif (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 || \ 553#elif (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 || \
514 defined HAVE_WM8975 || defined HAVE_WM8758 554 defined HAVE_WM8975 || defined HAVE_WM8758 || defined HAVE_WM8731
515 current_volume = value * 10; /* tenth of dB */ 555 current_volume = value * 10; /* tenth of dB */
516 set_prescaled_volume(); 556 set_prescaled_volume();
517#elif CONFIG_CPU == PNX0101 557#elif CONFIG_CPU == PNX0101
@@ -528,7 +568,7 @@ void sound_set_balance(int value)
528 unsigned tmp = ((unsigned)(value * 127 / 100) & 0xff) << 8; 568 unsigned tmp = ((unsigned)(value * 127 / 100) & 0xff) << 8;
529 mas_codec_writereg(0x11, tmp); 569 mas_codec_writereg(0x11, tmp);
530#elif CONFIG_CODEC == MAS3507D || defined HAVE_UDA1380 || \ 570#elif CONFIG_CODEC == MAS3507D || defined HAVE_UDA1380 || \
531 defined HAVE_WM8975 || defined HAVE_WM8758 571 defined HAVE_WM8975 || defined HAVE_WM8758 || defined HAVE_WM8731
532 current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */ 572 current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */
533 set_prescaled_volume(); 573 set_prescaled_volume();
534#elif CONFIG_CPU == PNX0101 574#elif CONFIG_CPU == PNX0101
@@ -552,7 +592,7 @@ void sound_set_bass(int value)
552 uda1380_set_bass(value >> 1); 592 uda1380_set_bass(value >> 1);
553 current_bass = value * 10; 593 current_bass = value * 10;
554 set_prescaled_volume(); 594 set_prescaled_volume();
555#elif defined HAVE_WM8975 || defined HAVE_WM8758 595#elif defined HAVE_WM8975 || defined HAVE_WM8758 || defined HAVE_WM8731
556 current_bass = value * 10; 596 current_bass = value * 10;
557 wmcodec_set_bass(value); 597 wmcodec_set_bass(value);
558 set_prescaled_volume(); 598 set_prescaled_volume();
@@ -577,7 +617,7 @@ void sound_set_treble(int value)
577 uda1380_set_treble(value >> 1); 617 uda1380_set_treble(value >> 1);
578 current_treble = value * 10; 618 current_treble = value * 10;
579 set_prescaled_volume(); 619 set_prescaled_volume();
580#elif defined(HAVE_WM8975) || defined(HAVE_WM8758) 620#elif defined(HAVE_WM8975) || defined(HAVE_WM8758) || defined(HAVE_WM8731)
581 wmcodec_set_treble(value); 621 wmcodec_set_treble(value);
582 current_treble = value * 10; 622 current_treble = value * 10;
583 set_prescaled_volume(); 623 set_prescaled_volume();