2008-04-27 13:43:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Driver for TSC2100 audio codec
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Jonathan Gordon
|
|
|
|
*
|
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.
|
2008-04-27 13:43:05 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "audio.h"
|
|
|
|
|
|
|
|
#include "audiohw.h"
|
2011-12-21 18:02:50 +00:00
|
|
|
#include "sound.h"
|
2008-04-27 13:43:05 +00:00
|
|
|
#include "tsc2100.h"
|
|
|
|
|
|
|
|
static bool is_muted = false;
|
2013-04-13 03:35:47 +00:00
|
|
|
/* convert tenth of dB volume to volume register value */
|
|
|
|
static int vol_tenthdb2hw(int db)
|
2008-04-27 13:43:05 +00:00
|
|
|
{
|
|
|
|
/* 0 to -63.0dB in 1dB steps, tsc2100 can goto -63.5 in 0.5dB steps */
|
2013-04-20 08:06:13 +00:00
|
|
|
if (db <= -640) {
|
2009-03-03 18:05:22 +00:00
|
|
|
return 0x7E;
|
2013-04-20 08:06:13 +00:00
|
|
|
} else if (db >= 0) {
|
2009-03-03 18:05:22 +00:00
|
|
|
return 0x00;
|
2008-04-27 13:43:05 +00:00
|
|
|
} else {
|
2013-04-20 08:06:13 +00:00
|
|
|
return(-((db)/5));
|
2008-04-27 13:43:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_init(void)
|
|
|
|
{
|
|
|
|
short val = tsc2100_readreg(TSAC4_PAGE, TSAC4_ADDRESS);
|
|
|
|
/* disable DAC PGA soft-stepping */
|
|
|
|
val |= TSAC4_DASTDP;
|
|
|
|
|
|
|
|
tsc2100_writereg(TSAC4_PAGE, TSAC4_ADDRESS, val);
|
|
|
|
}
|
|
|
|
|
2010-04-27 00:05:02 +00:00
|
|
|
static void audiohw_mute(bool mute)
|
2008-04-27 13:43:05 +00:00
|
|
|
{
|
|
|
|
short vol = tsc2100_readreg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS);
|
|
|
|
/* left mute bit == 1<<15
|
|
|
|
right mute bit == 1<<7
|
|
|
|
*/
|
|
|
|
if (mute)
|
|
|
|
{
|
|
|
|
vol |= (1<<15)|(1<<7);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
vol &= ~((1<<15)|(1<<7));
|
|
|
|
}
|
|
|
|
is_muted = mute;
|
|
|
|
tsc2100_writereg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS, vol);
|
|
|
|
}
|
|
|
|
|
2010-04-27 00:05:02 +00:00
|
|
|
void audiohw_postinit(void)
|
|
|
|
{
|
|
|
|
audiohw_mute(false);
|
|
|
|
}
|
|
|
|
|
2013-04-15 16:39:04 +00:00
|
|
|
void audiohw_set_volume(int vol_l, int vol_r)
|
2010-04-27 00:05:02 +00:00
|
|
|
{
|
2013-04-13 03:35:47 +00:00
|
|
|
vol_l = vol_tenthdb2hw(vol_l);
|
|
|
|
vol_r = vol_tenthdb2hw(vol_r);
|
|
|
|
tsc2100_writereg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS,
|
|
|
|
(short)((vol_l<<8) | vol_r) );
|
2010-04-27 00:05:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-27 13:43:05 +00:00
|
|
|
void audiohw_close(void)
|
|
|
|
{
|
|
|
|
/* mute headphones */
|
|
|
|
audiohw_mute(true);
|
|
|
|
}
|
|
|
|
|
2008-12-12 11:01:07 +00:00
|
|
|
void audiohw_set_frequency(int fsel)
|
2008-12-12 11:20:58 +00:00
|
|
|
{
|
2009-10-11 06:08:14 +00:00
|
|
|
int reg_val;
|
2011-02-06 19:33:40 +00:00
|
|
|
reg_val = tsc2100_readreg(CONTROL_PAGE2, TSAC1_ADDRESS);
|
2009-10-11 06:08:14 +00:00
|
|
|
|
|
|
|
reg_val &= ~(0x07<<3);
|
|
|
|
|
|
|
|
switch(fsel)
|
|
|
|
{
|
|
|
|
case HW_FREQ_8:
|
|
|
|
reg_val |= (0x06<<3);
|
|
|
|
break;
|
|
|
|
case HW_FREQ_11:
|
|
|
|
reg_val |= (0x04<<3);
|
|
|
|
break;
|
2009-10-11 06:10:39 +00:00
|
|
|
case HW_FREQ_22:
|
|
|
|
reg_val |= (0x02<<3);
|
|
|
|
break;
|
2009-10-11 06:08:14 +00:00
|
|
|
case HW_FREQ_44:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-06 19:33:40 +00:00
|
|
|
tsc2100_writereg(CONTROL_PAGE2, TSAC1_ADDRESS, reg_val);
|
2008-04-27 13:43:05 +00:00
|
|
|
}
|