2006-02-13 13:48:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2006-12-18 01:52:21 +00:00
|
|
|
* Driver for WM8758 audio codec - based on datasheet for WM8983
|
2006-02-13 13:48:08 +00:00
|
|
|
*
|
|
|
|
* Based on code from the ipodlinux project - http://ipodlinux.org/
|
|
|
|
* Adapted for Rockbox in December 2005
|
|
|
|
*
|
|
|
|
* Original file: linux/arch/armnommu/mach-ipod/audio.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
|
|
|
|
*
|
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.
|
2006-02-13 13:48:08 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "system.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "audio.h"
|
|
|
|
|
2006-10-20 17:12:42 +00:00
|
|
|
#include "wmcodec.h"
|
2007-05-22 20:39:50 +00:00
|
|
|
#include "audiohw.h"
|
2006-12-09 19:18:18 +00:00
|
|
|
#include "i2s.h"
|
2006-02-13 13:48:08 +00:00
|
|
|
|
2007-05-22 15:56:05 +00:00
|
|
|
const struct sound_settings_info audiohw_settings[] = {
|
|
|
|
[SOUND_VOLUME] = {"dB", 0, 1, -58, 6, -25},
|
2007-11-24 07:51:00 +00:00
|
|
|
[SOUND_BASS] = {"dB", 0, 1, -12, 12, 0},
|
|
|
|
[SOUND_TREBLE] = {"dB", 0, 1, -12, 12, 0},
|
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},
|
2008-05-25 21:19:07 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2008-09-13 19:34:16 +00:00
|
|
|
[SOUND_LEFT_GAIN] = {"dB", 1, 1, 0, 63, 16},
|
|
|
|
[SOUND_RIGHT_GAIN] = {"dB", 1, 1, 0, 63, 16},
|
|
|
|
[SOUND_MIC_GAIN] = {"dB", 1, 1, 0, 63, 16},
|
2008-05-25 21:19:07 +00:00
|
|
|
#endif
|
2007-11-24 07:51:00 +00:00
|
|
|
[SOUND_BASS_CUTOFF] = {"", 0, 1, 1, 4, 1},
|
|
|
|
[SOUND_TREBLE_CUTOFF] = {"", 0, 1, 1, 4, 1},
|
2007-05-22 15:56:05 +00:00
|
|
|
};
|
|
|
|
|
2007-11-24 07:51:00 +00:00
|
|
|
/* shadow registers */
|
2008-09-13 19:34:16 +00:00
|
|
|
static unsigned short eq1_reg = EQ1_EQ3DMODE | EQ_GAIN_VALUE(0);
|
|
|
|
static unsigned short eq5_reg = EQ_GAIN_VALUE(0);
|
2007-11-24 07:51:00 +00:00
|
|
|
|
2006-12-06 13:34:15 +00:00
|
|
|
/* convert tenth of dB volume (-57..6) to master volume register value */
|
|
|
|
int tenthdb2master(int db)
|
|
|
|
{
|
|
|
|
if (db < VOLUME_MIN) {
|
|
|
|
return 0x40;
|
|
|
|
} else {
|
2008-09-13 19:34:16 +00:00
|
|
|
return (db/10)+57;
|
2006-12-06 13:34:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
int sound_val2phys(int setting, int value)
|
2006-12-06 13:34:15 +00:00
|
|
|
{
|
2008-09-13 19:34:16 +00:00
|
|
|
int result;
|
2006-12-06 13:34:15 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
switch(setting)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
case SOUND_LEFT_GAIN:
|
|
|
|
case SOUND_RIGHT_GAIN:
|
|
|
|
case SOUND_MIC_GAIN:
|
|
|
|
result = ((value - 16) * 15) / 2;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
result = value;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-13 13:48:08 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
return result;
|
|
|
|
}
|
2006-02-13 13:48:08 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
void audiohw_mute(bool mute)
|
2006-02-13 13:48:08 +00:00
|
|
|
{
|
2008-09-13 19:34:16 +00:00
|
|
|
if (mute) {
|
|
|
|
wmcodec_write(DACCTRL, DACCTRL_SOFTMUTE);
|
|
|
|
} else {
|
|
|
|
wmcodec_write(DACCTRL, 0);
|
|
|
|
}
|
|
|
|
}
|
2006-02-20 22:46:58 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
void audiohw_preinit(void)
|
|
|
|
{
|
|
|
|
i2s_reset();
|
2006-02-13 13:48:08 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(RESET, RESET_RESET);
|
2006-02-13 13:48:08 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(PWRMGMT1, PWRMGMT1_PLLEN | PWRMGMT1_BIASEN
|
|
|
|
| PWRMGMT1_VMIDSEL_5K);
|
|
|
|
wmcodec_write(PWRMGMT2, PWRMGMT2_ROUT1EN | PWRMGMT2_LOUT1EN);
|
|
|
|
wmcodec_write(PWRMGMT3, PWRMGMT3_LOUT2EN | PWRMGMT3_ROUT2EN
|
|
|
|
| PWRMGMT3_RMIXEN | PWRMGMT3_LMIXEN
|
|
|
|
| PWRMGMT3_DACENR | PWRMGMT3_DACENL);
|
|
|
|
|
|
|
|
wmcodec_write(AINTFCE, AINTFCE_IWL_16BIT | AINTFCE_FORMAT_I2S);
|
|
|
|
wmcodec_write(OUTCTRL, OUTCTRL_VROI);
|
|
|
|
wmcodec_write(CLKCTRL, CLKCTRL_MS); /* WM8758 is clock master */
|
2006-02-13 13:48:08 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
audiohw_set_sample_rate(WM8758_44100HZ);
|
2006-02-13 13:48:08 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(LOUTMIX, LOUTMIX_DACL2LMIX);
|
|
|
|
wmcodec_write(ROUTMIX, ROUTMIX_DACR2RMIX);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_postinit(void)
|
|
|
|
{
|
|
|
|
wmcodec_write(PWRMGMT1, PWRMGMT1_PLLEN | PWRMGMT1_BIASEN
|
|
|
|
| PWRMGMT1_VMIDSEL_75K);
|
|
|
|
/* lower the VMID power consumption */
|
|
|
|
audiohw_mute(false);
|
2006-02-13 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 11:19:23 +00:00
|
|
|
void audiohw_set_master_vol(int vol_l, int vol_r)
|
2006-02-13 13:48:08 +00:00
|
|
|
{
|
|
|
|
/* OUT1 */
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(LOUT1VOL, LOUT1VOL_LOUT1ZC | vol_l);
|
|
|
|
wmcodec_write(ROUT1VOL, ROUT1VOL_OUT1VU | ROUT1VOL_ROUT1ZC | vol_r);
|
2006-03-22 13:04:49 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 11:19:23 +00:00
|
|
|
void audiohw_set_lineout_vol(int vol_l, int vol_r)
|
2006-03-22 13:04:49 +00:00
|
|
|
{
|
2006-02-13 13:48:08 +00:00
|
|
|
/* OUT2 */
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(LOUT2VOL, LOUT2VOL_LOUT2ZC | vol_l);
|
|
|
|
wmcodec_write(ROUT2VOL, ROUT2VOL_OUT2VU | ROUT2VOL_ROUT2ZC | vol_r);
|
2006-02-13 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 10:24:59 +00:00
|
|
|
void audiohw_set_bass(int value)
|
2006-02-13 13:48:08 +00:00
|
|
|
{
|
2007-11-24 07:51:00 +00:00
|
|
|
eq1_reg = (eq1_reg & ~EQ_GAIN_MASK) | EQ_GAIN_VALUE(value);
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(EQ1, eq1_reg);
|
2007-11-24 07:51:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_bass_cutoff(int value)
|
|
|
|
{
|
|
|
|
eq1_reg = (eq1_reg & ~EQ_CUTOFF_MASK) | EQ_CUTOFF_VALUE(value);
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(EQ1, eq1_reg);
|
2006-02-13 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 10:24:59 +00:00
|
|
|
void audiohw_set_treble(int value)
|
2006-02-13 13:48:08 +00:00
|
|
|
{
|
2007-11-24 07:51:00 +00:00
|
|
|
eq5_reg = (eq5_reg & ~EQ_GAIN_MASK) | EQ_GAIN_VALUE(value);
|
|
|
|
wmcodec_write(EQ5, eq5_reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_treble_cutoff(int value)
|
|
|
|
{
|
|
|
|
eq5_reg = (eq5_reg & ~EQ_CUTOFF_MASK) | EQ_CUTOFF_VALUE(value);
|
|
|
|
wmcodec_write(EQ5, eq5_reg);
|
2006-02-13 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Nice shutdown of WM8758 codec */
|
2006-12-06 10:24:59 +00:00
|
|
|
void audiohw_close(void)
|
2006-02-13 13:48:08 +00:00
|
|
|
{
|
2008-09-13 19:34:16 +00:00
|
|
|
audiohw_mute(true);
|
2006-02-13 13:48:08 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(PWRMGMT3, 0);
|
|
|
|
wmcodec_write(PWRMGMT1, 0);
|
|
|
|
wmcodec_write(PWRMGMT2, PWRMGMT2_SLEEP);
|
2006-02-13 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: Disable output before calling this function */
|
2006-12-06 10:24:59 +00:00
|
|
|
void audiohw_set_sample_rate(int sampling_control)
|
2006-02-13 13:48:08 +00:00
|
|
|
{
|
|
|
|
/**** We force 44.1KHz for now. ****/
|
|
|
|
(void)sampling_control;
|
|
|
|
|
|
|
|
/* setup PLL for MHZ=11.2896 */
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(PLLN, PLLN_PLLPRESCALE | 0x7);
|
2006-10-20 17:12:42 +00:00
|
|
|
wmcodec_write(PLLK1, 0x21);
|
|
|
|
wmcodec_write(PLLK2, 0x161);
|
|
|
|
wmcodec_write(PLLK3, 0x26);
|
2006-02-13 13:48:08 +00:00
|
|
|
|
|
|
|
/* set clock div */
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(CLKCTRL, CLKCTRL_CLKSEL | CLKCTRL_MCLKDIV_2
|
|
|
|
| CLKCTRL_BCLKDIV_2 | CLKCTRL_MS);
|
2006-02-13 13:48:08 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(ADDCTRL, ADDCTRL_SR_48kHz | ADDCTRL_SLOWCLKEN);
|
|
|
|
/* SLOWCLK enabled for zero cross timeout to work */
|
2006-02-13 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 10:24:59 +00:00
|
|
|
void audiohw_enable_recording(bool source_mic)
|
2006-02-13 13:48:08 +00:00
|
|
|
{
|
2006-12-18 01:52:21 +00:00
|
|
|
(void)source_mic; /* We only have a line-in (I think) */
|
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(PWRMGMT2, PWRMGMT2_ROUT1EN | PWRMGMT2_LOUT1EN
|
|
|
|
| PWRMGMT2_INPGAENR | PWRMGMT2_INPGAENL
|
|
|
|
| PWRMGMT2_ADCENR | PWRMGMT2_ADCENL);
|
2006-12-18 01:52:21 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(INCTRL, INCTRL_R2_2INPGA | INCTRL_L2_2INPGA);
|
2006-12-18 01:52:21 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(LADCBOOST, LADCBOOST_L2_2BOOST(5));
|
|
|
|
wmcodec_write(RADCBOOST, RADCBOOST_R2_2BOOST(5));
|
2006-12-18 01:52:21 +00:00
|
|
|
|
|
|
|
/* Enable monitoring */
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(LOUTMIX, LOUTMIX_BYP2LMIXVOL(5)
|
|
|
|
| LOUTMIX_BYPL2LMIX | LOUTMIX_DACL2LMIX);
|
|
|
|
wmcodec_write(ROUTMIX, ROUTMIX_BYP2RMIXVOL(5)
|
|
|
|
| ROUTMIX_BYPR2RMIX | ROUTMIX_DACR2RMIX);
|
2006-02-13 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
void audiohw_disable_recording(void)
|
|
|
|
{
|
|
|
|
wmcodec_write(LOUTMIX, LOUTMIX_DACL2LMIX);
|
|
|
|
wmcodec_write(ROUTMIX, ROUTMIX_DACR2RMIX);
|
2006-02-13 13:48:08 +00:00
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
wmcodec_write(PWRMGMT2, PWRMGMT2_ROUT1EN | PWRMGMT2_LOUT1EN);
|
2006-02-13 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
void audiohw_set_recvol(int left, int right, int type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case AUDIO_GAIN_MIC:
|
|
|
|
right = left;
|
|
|
|
/* fall through */
|
|
|
|
case AUDIO_GAIN_LINEIN:
|
|
|
|
wmcodec_write(LINPGAVOL, LINPGAVOL_INPGAZCL
|
|
|
|
| (left & LINPGAVOL_INPGAVOL_MASK));
|
|
|
|
wmcodec_write(RINPGAVOL, RINPGAVOL_INPGAVU | RINPGAVOL_INPGAZCR
|
|
|
|
| (right & RINPGAVOL_INPGAVOL_MASK));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2006-02-13 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-13 19:34:16 +00:00
|
|
|
void audiohw_set_monitor(bool enable)
|
|
|
|
{
|
2006-02-13 13:48:08 +00:00
|
|
|
(void)enable;
|
|
|
|
}
|
2006-08-14 10:52:05 +00:00
|
|
|
|