2007-05-22 15:56:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2009-07-12 09:43:44 +00:00
|
|
|
* $Id$
|
2007-05-22 15:56:05 +00:00
|
|
|
*
|
|
|
|
* Driver for MAS35xx audio codec
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 by Christian Gmeiner
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-05-22 15:56:05 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
2010-10-31 21:09:34 +00:00
|
|
|
#include "system.h" /* MAX MIN macros */
|
2007-05-22 20:39:50 +00:00
|
|
|
#include "audiohw.h"
|
2007-05-22 15:56:05 +00:00
|
|
|
|
|
|
|
const struct sound_settings_info audiohw_settings[] = {
|
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
|
|
|
[SOUND_VOLUME] = {"dB", 0, 1,-100, 12, -25},
|
|
|
|
[SOUND_BASS] = {"dB", 0, 1, -12, 12, 6},
|
|
|
|
[SOUND_TREBLE] = {"dB", 0, 1, -12, 12, 6},
|
2009-10-01 05:25:20 +00:00
|
|
|
#elif CONFIG_CODEC == MAS3507D
|
2007-05-22 15:56:05 +00:00
|
|
|
[SOUND_VOLUME] = {"dB", 0, 1, -78, 18, -18},
|
|
|
|
[SOUND_BASS] = {"dB", 0, 1, -15, 15, 7},
|
|
|
|
[SOUND_TREBLE] = {"dB", 0, 1, -15, 15, 7},
|
|
|
|
#endif
|
2007-12-10 11:14:28 +00:00
|
|
|
[SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
|
2007-05-22 15:56:05 +00:00
|
|
|
[SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0},
|
2007-10-09 21:29:20 +00:00
|
|
|
[SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100},
|
2007-05-22 15:56:05 +00:00
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
|
|
|
[SOUND_LOUDNESS] = {"dB", 0, 1, 0, 17, 0},
|
|
|
|
[SOUND_AVC] = {"", 0, 1, -1, 4, 0},
|
|
|
|
[SOUND_MDB_STRENGTH] = {"dB", 0, 1, 0, 127, 48},
|
|
|
|
[SOUND_MDB_HARMONICS] = {"%", 0, 1, 0, 100, 50},
|
|
|
|
[SOUND_MDB_CENTER] = {"Hz", 0, 10, 20, 300, 60},
|
|
|
|
[SOUND_MDB_SHAPE] = {"Hz", 0, 10, 50, 300, 90},
|
|
|
|
[SOUND_MDB_ENABLE] = {"", 0, 1, 0, 1, 0},
|
|
|
|
[SOUND_SUPERBASS] = {"", 0, 1, 0, 1, 0},
|
|
|
|
#endif
|
2008-05-25 21:19:07 +00:00
|
|
|
#if CONFIG_CODEC == MAS3587F && defined(HAVE_RECORDING)
|
2007-05-22 15:56:05 +00:00
|
|
|
[SOUND_LEFT_GAIN] = {"dB", 1, 1, 0, 15, 8},
|
|
|
|
[SOUND_RIGHT_GAIN] = {"dB", 1, 1, 0, 15, 8},
|
|
|
|
[SOUND_MIC_GAIN] = {"dB", 1, 1, 0, 15, 2},
|
|
|
|
#endif
|
|
|
|
};
|
2008-04-22 13:43:01 +00:00
|
|
|
|
|
|
|
int channel_configuration = SOUND_CHAN_STEREO;
|
|
|
|
int stereo_width = 100;
|
|
|
|
|
2010-10-31 21:09:34 +00:00
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
|
|
|
unsigned long mdb_shape_shadow = 0;
|
|
|
|
unsigned long loudness_shadow = 0;
|
|
|
|
unsigned long shadow_io_control_main;
|
|
|
|
#endif
|
|
|
|
|
2008-04-22 13:43:01 +00:00
|
|
|
|
|
|
|
static void set_channel_config(void)
|
|
|
|
{
|
|
|
|
/* default values: stereo */
|
|
|
|
unsigned long val_ll = 0x80000;
|
|
|
|
unsigned long val_lr = 0;
|
|
|
|
unsigned long val_rl = 0;
|
|
|
|
unsigned long val_rr = 0x80000;
|
2009-10-01 05:25:20 +00:00
|
|
|
int bank;
|
2008-04-22 13:43:01 +00:00
|
|
|
|
|
|
|
switch(channel_configuration)
|
|
|
|
{
|
|
|
|
/* case SOUND_CHAN_STEREO unnecessary */
|
|
|
|
|
|
|
|
case SOUND_CHAN_MONO:
|
|
|
|
val_ll = 0xc0000;
|
|
|
|
val_lr = 0xc0000;
|
|
|
|
val_rl = 0xc0000;
|
|
|
|
val_rr = 0xc0000;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOUND_CHAN_CUSTOM:
|
|
|
|
{
|
|
|
|
/* fixed point variables (matching MAS internal format)
|
|
|
|
integer part: upper 13 bits (inlcuding sign)
|
|
|
|
fractional part: lower 19 bits */
|
|
|
|
long fp_width, fp_straight, fp_cross;
|
|
|
|
|
|
|
|
fp_width = (stereo_width << 19) / 100;
|
|
|
|
if (stereo_width <= 100)
|
|
|
|
{
|
|
|
|
fp_straight = - ((1<<19) + fp_width) / 2;
|
|
|
|
fp_cross = fp_straight + fp_width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* straight = - (1 + width) / (2 * width) */
|
|
|
|
fp_straight = - ((((1<<19) + fp_width) / (fp_width >> 9)) << 9);
|
|
|
|
fp_cross = (1<<19) + fp_straight;
|
|
|
|
}
|
|
|
|
val_ll = val_rr = fp_straight & 0xfffff;
|
|
|
|
val_lr = val_rl = fp_cross & 0xfffff;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOUND_CHAN_MONO_LEFT:
|
|
|
|
val_ll = 0x80000;
|
|
|
|
val_lr = 0x80000;
|
|
|
|
val_rl = 0;
|
|
|
|
val_rr = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOUND_CHAN_MONO_RIGHT:
|
|
|
|
val_ll = 0;
|
|
|
|
val_lr = 0;
|
|
|
|
val_rl = 0x80000;
|
|
|
|
val_rr = 0x80000;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOUND_CHAN_KARAOKE:
|
|
|
|
val_ll = 0xc0000;
|
|
|
|
val_lr = 0x40000;
|
|
|
|
val_rl = 0x40000;
|
|
|
|
val_rr = 0xc0000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
2009-10-01 05:25:20 +00:00
|
|
|
bank = MAS_BANK_D0;
|
2008-04-22 13:43:01 +00:00
|
|
|
#elif CONFIG_CODEC == MAS3507D
|
2009-10-01 05:25:20 +00:00
|
|
|
bank = MAS_BANK_D1;
|
2008-04-22 13:43:01 +00:00
|
|
|
#endif
|
2009-10-01 05:25:20 +00:00
|
|
|
|
|
|
|
mas_writemem(bank, MAS_D0_OUT_LL, &val_ll, 1); /* LL */
|
|
|
|
mas_writemem(bank, MAS_D0_OUT_LR, &val_lr, 1); /* LR */
|
|
|
|
mas_writemem(bank, MAS_D0_OUT_RL, &val_rl, 1); /* RL */
|
|
|
|
mas_writemem(bank, MAS_D0_OUT_RR, &val_rr, 1); /* RR */
|
2008-04-22 13:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_channel(int val)
|
|
|
|
{
|
|
|
|
channel_configuration = val;
|
|
|
|
set_channel_config();
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_stereo_width(int val)
|
|
|
|
{
|
|
|
|
stereo_width = val;
|
|
|
|
if (channel_configuration == SOUND_CHAN_CUSTOM) {
|
|
|
|
set_channel_config();
|
|
|
|
}
|
|
|
|
}
|
2008-04-28 08:37:18 +00:00
|
|
|
|
|
|
|
void audiohw_set_bass(int val)
|
|
|
|
{
|
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
|
|
|
unsigned tmp = ((unsigned)(val * 8) & 0xff) << 8;
|
2009-10-01 05:25:20 +00:00
|
|
|
mas_codec_writereg(MAS_REG_KBASS, tmp);
|
2008-04-28 08:37:18 +00:00
|
|
|
#elif CONFIG_CODEC == MAS3507D
|
|
|
|
mas_writereg(MAS_REG_KBASS, bass_table[val+15]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-05-14 21:35:19 +00:00
|
|
|
#if CONFIG_CODEC == MAS3507D
|
|
|
|
void audiohw_set_prescaler(int val)
|
|
|
|
{
|
|
|
|
mas_writereg(MAS_REG_KPRESCALE, prescale_table[val/10]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-04-28 08:37:18 +00:00
|
|
|
void audiohw_set_treble(int val)
|
|
|
|
{
|
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
|
|
|
unsigned tmp = ((unsigned)(val * 8) & 0xff) << 8;
|
2009-10-01 05:25:20 +00:00
|
|
|
mas_codec_writereg(MAS_REG_KTREBLE, tmp);
|
2008-04-28 08:37:18 +00:00
|
|
|
#elif CONFIG_CODEC == MAS3507D
|
|
|
|
mas_writereg(MAS_REG_KTREBLE, treble_table[val+15]);
|
|
|
|
#endif
|
|
|
|
}
|
2008-05-13 06:19:16 +00:00
|
|
|
|
|
|
|
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
|
2010-10-31 21:09:34 +00:00
|
|
|
void audiohw_set_volume(int val)
|
|
|
|
{
|
2008-05-13 06:19:16 +00:00
|
|
|
unsigned tmp = ((unsigned)(val + 115) & 0xff) << 8;
|
2009-10-01 05:25:20 +00:00
|
|
|
mas_codec_writereg(MAS_REG_VOLUME_CONTROL, tmp);
|
2008-05-13 06:19:16 +00:00
|
|
|
}
|
|
|
|
|
2010-10-31 21:09:34 +00:00
|
|
|
void audiohw_set_loudness(int value)
|
|
|
|
{
|
|
|
|
loudness_shadow = (loudness_shadow & 0x04) |
|
|
|
|
(MAX(MIN(value * 4, 0x44), 0) << 8);
|
|
|
|
mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_avc(int value)
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
static const uint16_t avc_vals[] =
|
|
|
|
{
|
|
|
|
(0x1 << 8) | (0x8 << 12), /* 20ms */
|
|
|
|
(0x2 << 8) | (0x8 << 12), /* 2s */
|
|
|
|
(0x4 << 8) | (0x8 << 12), /* 4s */
|
|
|
|
(0x8 << 8) | (0x8 << 12), /* 8s */
|
|
|
|
};
|
|
|
|
switch (value) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
tmp = avc_vals[value -1];
|
|
|
|
break;
|
|
|
|
case -1: /* turn off and then turn on again to decay quickly */
|
|
|
|
tmp = mas_codec_readreg(MAS_REG_KAVC);
|
|
|
|
mas_codec_writereg(MAS_REG_KAVC, 0);
|
|
|
|
break;
|
|
|
|
default: /* off */
|
|
|
|
tmp = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mas_codec_writereg(MAS_REG_KAVC, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_mdb_strength(int value)
|
|
|
|
{
|
|
|
|
mas_codec_writereg(MAS_REG_KMDB_STR, (value & 0x7f) << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_mdb_harmonics(int value)
|
|
|
|
{
|
|
|
|
int tmp = value * 127 / 100;
|
|
|
|
mas_codec_writereg(MAS_REG_KMDB_HAR, (tmp & 0x7f) << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_mdb_center(int value)
|
|
|
|
{
|
|
|
|
mas_codec_writereg(MAS_REG_KMDB_FC, (value/10) << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_mdb_shape(int value)
|
|
|
|
{
|
|
|
|
mdb_shape_shadow = (mdb_shape_shadow & 0x02) | ((value/10) << 8);
|
|
|
|
mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_mdb_enable(int value)
|
|
|
|
{
|
|
|
|
mdb_shape_shadow = (mdb_shape_shadow & ~0x02) | (value?2:0);
|
|
|
|
mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_superbass(int value)
|
|
|
|
{
|
|
|
|
loudness_shadow = (loudness_shadow & ~0x04) | (value?4:0);
|
|
|
|
mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_balance(int val)
|
|
|
|
{
|
2008-05-13 06:19:16 +00:00
|
|
|
unsigned tmp = ((unsigned)(val * 127 / 100) & 0xff) << 8;
|
2009-10-01 05:25:20 +00:00
|
|
|
mas_codec_writereg(MAS_REG_BALANCE, tmp);
|
2008-05-13 06:19:16 +00:00
|
|
|
}
|
2010-10-31 21:09:34 +00:00
|
|
|
|
|
|
|
void audiohw_set_pitch(unsigned long val)
|
|
|
|
{
|
|
|
|
mas_writemem(MAS_BANK_D0, MAS_D0_OFREQ_CONTROL, &val, 1);
|
|
|
|
|
|
|
|
/* We must tell the MAS that the frequency has changed.
|
|
|
|
* This will unfortunately cause a short silence. */
|
|
|
|
|
|
|
|
mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN, &shadow_io_control_main, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_CODEC == MAS3587F || CONFIG_CODEC == MAS3539F */
|
|
|
|
|