2007-03-11 17:38:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2010-03-20 17:09:44 +00:00
|
|
|
* Driver for AS3514 and compatible audio codec
|
2007-03-11 17:38:08 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Daniel Ankers
|
2007-04-14 00:49:35 +00:00
|
|
|
* Copyright (c) 2007 Christian Gmeiner
|
2007-03-11 17:38:08 +00:00
|
|
|
*
|
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-03-11 17:38:08 +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"
|
2007-06-05 07:03:30 +00:00
|
|
|
#include "audio.h"
|
2008-05-03 08:35:14 +00:00
|
|
|
#include "sound.h"
|
2007-03-11 17:38:08 +00:00
|
|
|
|
2007-05-22 20:39:50 +00:00
|
|
|
#include "audiohw.h"
|
2007-03-11 17:38:08 +00:00
|
|
|
#include "i2s.h"
|
2008-10-31 00:16:42 +00:00
|
|
|
#include "ascodec.h"
|
2007-03-11 17:38:08 +00:00
|
|
|
|
2013-04-20 08:06:13 +00:00
|
|
|
#if CONFIG_CPU == AS3525v2
|
|
|
|
/* Headphone volume goes from -81.0 ... +6dB */
|
|
|
|
#define VOLUME_MIN -820
|
|
|
|
#define VOLUME_MAX 60
|
|
|
|
#else
|
|
|
|
/* Headphone volume goes from -73.5 ... +6dB */
|
|
|
|
#define VOLUME_MIN -740
|
|
|
|
#define VOLUME_MAX 60
|
|
|
|
#endif
|
|
|
|
|
2010-03-20 17:09:44 +00:00
|
|
|
/*
|
|
|
|
* This drivers supports:
|
|
|
|
* as3514 , as used in the PP targets
|
2010-05-16 09:22:02 +00:00
|
|
|
* as3515 , as used in the as3525 targets
|
2010-03-20 17:09:44 +00:00
|
|
|
* as3543 , as used in the as3525v2 targets
|
|
|
|
*/
|
|
|
|
|
2010-03-29 22:26:58 +00:00
|
|
|
#if CONFIG_CPU == AS3525
|
2009-02-05 19:57:18 +00:00
|
|
|
/* AMS Sansas based on the AS3525 use the LINE2 input for the analog radio
|
|
|
|
signal instead of LINE1 */
|
2010-03-29 22:26:58 +00:00
|
|
|
#define AS3514_LINE_IN_R AS3514_LINE_IN2_R
|
|
|
|
#define AS3514_LINE_IN_L AS3514_LINE_IN2_L
|
|
|
|
#define ADC_R_ADCMUX_LINE_IN ADC_R_ADCMUX_LINE_IN2
|
|
|
|
#define AUDIOSET1_LIN_on AUDIOSET1_LIN2_on
|
|
|
|
|
|
|
|
#elif CONFIG_CPU == AS3525v2
|
|
|
|
/* There is only 1 pair of registers on AS3543, the line input is selectable in
|
|
|
|
LINE_IN_R register */
|
|
|
|
#define AS3514_LINE_IN_R AS3514_LINE_IN1_R
|
|
|
|
#define AS3514_LINE_IN_L AS3514_LINE_IN1_L
|
|
|
|
#define ADC_R_ADCMUX_LINE_IN ADC_R_ADCMUX_LINE_IN2
|
|
|
|
#define AUDIOSET1_LIN_on AUDIOSET1_LIN1_on
|
|
|
|
|
|
|
|
#else /* PP use line1 */
|
|
|
|
|
|
|
|
#define AS3514_LINE_IN_R AS3514_LINE_IN1_R
|
|
|
|
#define AS3514_LINE_IN_L AS3514_LINE_IN1_L
|
|
|
|
#define ADC_R_ADCMUX_LINE_IN ADC_R_ADCMUX_LINE_IN1
|
|
|
|
#define AUDIOSET1_LIN_on AUDIOSET1_LIN1_on
|
|
|
|
|
2009-02-05 19:57:18 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-14 00:49:35 +00:00
|
|
|
/* Shadow registers */
|
2010-04-26 23:14:31 +00:00
|
|
|
static uint8_t as3514_regs[AS3514_NUM_AUDIO_REGS]; /* 8-bit registers */
|
2007-06-05 07:03:30 +00:00
|
|
|
|
2007-04-14 00:49:35 +00:00
|
|
|
/*
|
|
|
|
* little helper method to set register values.
|
2011-12-24 17:59:43 +00:00
|
|
|
* With the help of as3514_regs, we minimize i2c/syscall
|
2007-04-14 00:49:35 +00:00
|
|
|
* traffic.
|
|
|
|
*/
|
2007-06-05 07:03:30 +00:00
|
|
|
static void as3514_write(unsigned int reg, unsigned int value)
|
2007-04-14 00:49:35 +00:00
|
|
|
{
|
2010-05-19 17:30:38 +00:00
|
|
|
ascodec_write(reg, value);
|
2007-05-04 10:28:07 +00:00
|
|
|
|
2010-05-19 17:30:38 +00:00
|
|
|
if (reg < AS3514_NUM_AUDIO_REGS)
|
2010-04-26 23:14:31 +00:00
|
|
|
as3514_regs[reg] = value;
|
2007-04-14 00:49:35 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 07:03:30 +00:00
|
|
|
/* Helpers to set/clear bits */
|
2008-11-25 16:16:06 +00:00
|
|
|
static void as3514_set(unsigned int reg, unsigned int bits)
|
2007-06-05 07:03:30 +00:00
|
|
|
{
|
2010-04-26 23:14:31 +00:00
|
|
|
as3514_write(reg, as3514_regs[reg] | bits);
|
2007-06-05 07:03:30 +00:00
|
|
|
}
|
|
|
|
|
2008-11-25 16:16:06 +00:00
|
|
|
static void as3514_clear(unsigned int reg, unsigned int bits)
|
2007-06-05 07:03:30 +00:00
|
|
|
{
|
2010-04-26 23:14:31 +00:00
|
|
|
as3514_write(reg, as3514_regs[reg] & ~bits);
|
2008-11-25 16:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void as3514_write_masked(unsigned int reg, unsigned int bits,
|
|
|
|
unsigned int mask)
|
|
|
|
{
|
2010-04-26 23:14:31 +00:00
|
|
|
as3514_write(reg, (as3514_regs[reg] & ~mask) | (bits & mask));
|
2007-06-05 07:03:30 +00:00
|
|
|
}
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
|
2007-03-11 17:38:08 +00:00
|
|
|
/* convert tenth of dB volume to master volume register value */
|
2013-04-13 03:35:47 +00:00
|
|
|
static int vol_tenthdb2hw(int db)
|
2007-03-11 17:38:08 +00:00
|
|
|
{
|
2013-04-20 08:06:13 +00:00
|
|
|
if (db <= VOLUME_MIN) {
|
2007-03-11 17:38:08 +00:00
|
|
|
return 0x0;
|
2010-06-24 01:11:51 +00:00
|
|
|
} else if (db > VOLUME_MAX) {
|
2013-04-20 08:06:13 +00:00
|
|
|
return (VOLUME_MAX - VOLUME_MIN) / 15;
|
2007-03-11 17:38:08 +00:00
|
|
|
} else {
|
2013-04-20 08:06:13 +00:00
|
|
|
return (db - VOLUME_MIN) / 15;
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise the PP I2C and I2S.
|
|
|
|
*/
|
2008-10-31 00:16:42 +00:00
|
|
|
void audiohw_preinit(void)
|
2007-04-14 00:49:35 +00:00
|
|
|
{
|
2008-11-25 16:16:06 +00:00
|
|
|
/* read all reg values */
|
2010-05-19 17:30:38 +00:00
|
|
|
ascodec_readbytes(0x0, AS3514_NUM_AUDIO_REGS, as3514_regs);
|
2008-11-25 16:16:06 +00:00
|
|
|
|
2010-05-19 17:30:38 +00:00
|
|
|
#ifdef HAVE_AS3543
|
|
|
|
|
|
|
|
as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_DAC_GAIN_on);
|
2011-07-24 21:56:24 +00:00
|
|
|
as3514_write(AS3514_AUDIOSET2, AUDIOSET2_AGC_off | AUDIOSET2_HPH_QUALITY_LOW_POWER);
|
2010-05-19 17:30:38 +00:00
|
|
|
/* common ground on, delay playback unmuting when inserting headphones */
|
|
|
|
as3514_write(AS3514_AUDIOSET3, AUDIOSET3_HPCM_on | AUDIOSET3_HP_LONGSTART);
|
|
|
|
|
|
|
|
as3514_write(AS3543_DAC_IF, AS3543_DAC_INT_PLL);
|
2012-04-07 08:30:23 +00:00
|
|
|
#ifdef SAMSUNG_YPR0
|
|
|
|
/* Select Line 1 for FM radio */
|
|
|
|
as3514_clear(AS3514_LINE_IN1_R, LINE_IN_R_LINE_SELECT);
|
|
|
|
#else
|
2010-05-19 17:30:38 +00:00
|
|
|
/* Select Line 2 for FM radio */
|
|
|
|
as3514_set(AS3514_LINE_IN1_R, LINE_IN_R_LINE_SELECT);
|
2012-04-07 08:30:23 +00:00
|
|
|
#endif
|
2010-05-19 17:30:38 +00:00
|
|
|
/* Output SUM of microphone/line/DAC */
|
|
|
|
as3514_write(AS3514_HPH_OUT_R, HPH_OUT_R_HEADPHONES | HPH_OUT_R_HP_OUT_SUM);
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* as3514/as3515 */
|
2007-06-05 07:03:30 +00:00
|
|
|
|
2010-10-27 21:30:04 +00:00
|
|
|
#if defined(SANSA_E200V2) || defined(SANSA_FUZE) || defined(SANSA_C200)
|
2010-06-27 23:27:54 +00:00
|
|
|
/* Set ADC off, mixer on, DAC on, line out on, line in off, mic off */
|
|
|
|
/* Turn on SUM, DAC */
|
|
|
|
as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_LOUT_on |
|
|
|
|
AUDIOSET1_SUM_on);
|
|
|
|
#else
|
2010-05-19 17:30:38 +00:00
|
|
|
/* Set ADC off, mixer on, DAC on, line out off, line in off, mic off */
|
2007-06-05 07:03:30 +00:00
|
|
|
/* Turn on SUM, DAC */
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_SUM_on);
|
2010-10-27 21:30:04 +00:00
|
|
|
#endif /* SANSA_E200V2 || SANSA_FUZE || SANSA_C200 */
|
2007-06-05 07:03:30 +00:00
|
|
|
|
2010-05-05 04:47:20 +00:00
|
|
|
/* Set BIAS on, DITH off, AGC off, IBR_DAC max reduction, LSP_LP on,
|
|
|
|
IBR_LSP max reduction (50%), taken from c200v2 OF
|
|
|
|
*/
|
|
|
|
as3514_write(AS3514_AUDIOSET2, AUDIOSET2_IBR_LSP_50 | AUDIOSET2_LSP_LP |
|
2010-05-05 15:38:56 +00:00
|
|
|
AUDIOSET2_IBR_DAC_50 | AUDIOSET2_AGC_off | AUDIOSET2_DITH_off );
|
2010-05-19 17:30:38 +00:00
|
|
|
|
|
|
|
/* Mute and disable speaker */
|
|
|
|
as3514_write(AS3514_LSP_OUT_R, LSP_OUT_R_SP_OVC_TO_256MS | 0x00);
|
|
|
|
as3514_write(AS3514_LSP_OUT_L, LSP_OUT_L_SP_MUTE | 0x00);
|
|
|
|
|
|
|
|
#ifdef PHILIPS_SA9200
|
|
|
|
/* LRCK 8-23kHz (there are audible clicks while reading the ADC otherwise) */
|
|
|
|
as3514_write(AS3514_PLLMODE, PLLMODE_LRCK_8_23);
|
|
|
|
#else
|
|
|
|
/* LRCK 24-48kHz */
|
|
|
|
as3514_write(AS3514_PLLMODE, PLLMODE_LRCK_24_48);
|
|
|
|
#endif /* PHILIPS_SA9200 */
|
|
|
|
|
|
|
|
/* Set headphone over-current to 0, Min volume */
|
|
|
|
as3514_write(AS3514_HPH_OUT_R, HPH_OUT_R_HP_OVC_TO_0MS | 0x00);
|
2007-10-25 09:15:31 +00:00
|
|
|
|
2008-12-16 22:16:55 +00:00
|
|
|
/* AMS Sansas based on the AS3525 need HPCM enabled, otherwise they output the
|
|
|
|
L-R signal on both L and R headphone outputs instead of normal stereo.
|
|
|
|
Turning it off saves a little power on targets that don't need it. */
|
|
|
|
#if (CONFIG_CPU == AS3525)
|
2010-05-05 04:47:20 +00:00
|
|
|
/* Set HPCM on, ZCU off, reduce bias current, settings taken from c200v2 OF
|
|
|
|
*/
|
|
|
|
as3514_write(AS3514_AUDIOSET3, AUDIOSET3_IBR_HPH | AUDIOSET3_ZCU_off);
|
2008-12-16 22:16:55 +00:00
|
|
|
#else
|
2010-05-05 04:47:20 +00:00
|
|
|
/* TODO: check if AS3525 settings save power on e200v1 or as3525v2 */
|
2008-12-16 22:16:55 +00:00
|
|
|
/* Set HPCM off, ZCU on */
|
|
|
|
as3514_write(AS3514_AUDIOSET3, AUDIOSET3_HPCM_off);
|
2010-05-19 17:30:38 +00:00
|
|
|
#endif /* CONFIG_CPU == AS3525 */
|
2007-06-05 07:03:30 +00:00
|
|
|
|
2010-05-19 17:30:38 +00:00
|
|
|
/* M2_Sup_off */
|
|
|
|
as3514_set(AS3514_MIC2_L, MIC2_L_M2_SUP_off);
|
2007-06-05 07:03:30 +00:00
|
|
|
|
2010-05-19 17:30:38 +00:00
|
|
|
#endif /* HAVE_AS3543 */
|
2007-04-14 00:49:35 +00:00
|
|
|
|
2010-05-19 17:30:38 +00:00
|
|
|
/* registers identical on as3514/as3515 and as3543 */
|
2007-06-05 07:03:30 +00:00
|
|
|
|
|
|
|
/* M1_Sup_off */
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_set(AS3514_MIC1_L, MIC1_L_M1_SUP_off);
|
2010-05-19 17:30:38 +00:00
|
|
|
|
|
|
|
/* Headphone ON, MUTE, Min volume */
|
|
|
|
as3514_write(AS3514_HPH_OUT_L, HPH_OUT_L_HP_ON | HPH_OUT_L_HP_MUTE | 0x00);
|
|
|
|
|
2010-10-27 21:30:04 +00:00
|
|
|
#if defined(SANSA_E200V2) || defined(SANSA_FUZE) || defined(SANSA_C200)
|
2010-06-27 23:27:54 +00:00
|
|
|
/* Line Out Stereo, MUTE, Min volume */
|
|
|
|
as3514_write(AS3514_LINE_OUT_L, LINE_OUT_L_LO_SES_DM_SE_ST |
|
|
|
|
LINE_OUT_L_LO_SES_DM_MUTE | 0x00);
|
|
|
|
#endif /* SANSA_E200V2 || SANSA_FUZE */
|
|
|
|
|
2010-05-19 17:30:38 +00:00
|
|
|
/* DAC_Mute_off */
|
|
|
|
as3514_set(AS3514_DAC_L, DAC_L_DAC_MUTE_off);
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 00:05:02 +00:00
|
|
|
static void audiohw_mute(bool mute)
|
|
|
|
{
|
|
|
|
if (mute) {
|
|
|
|
as3514_set(AS3514_HPH_OUT_L, HPH_OUT_L_HP_MUTE);
|
2010-10-27 21:30:04 +00:00
|
|
|
#if defined(SANSA_E200V2) || defined(SANSA_FUZE) || defined(SANSA_C200)
|
2010-06-27 23:27:54 +00:00
|
|
|
as3514_set(AS3514_LINE_OUT_L, LINE_OUT_L_LO_SES_DM_MUTE);
|
2010-10-27 21:30:04 +00:00
|
|
|
#endif /* SANSA_E200V2 || SANSA_FUZE || SANSA_C200 */
|
2010-04-27 00:05:02 +00:00
|
|
|
} else {
|
|
|
|
as3514_clear(AS3514_HPH_OUT_L, HPH_OUT_L_HP_MUTE);
|
2010-10-27 21:30:04 +00:00
|
|
|
#if defined(SANSA_E200V2) || defined(SANSA_FUZE) || defined(SANSA_C200)
|
2010-06-27 23:27:54 +00:00
|
|
|
as3514_clear(AS3514_LINE_OUT_L, LINE_OUT_L_LO_SES_DM_MUTE);
|
2010-10-27 21:30:04 +00:00
|
|
|
#endif /* SANSA_E200V2 || SANSA_FUZE || SANSA_C200 */
|
2010-04-27 00:05:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-25 16:16:06 +00:00
|
|
|
void audiohw_postinit(void)
|
2007-03-11 17:38:08 +00:00
|
|
|
{
|
2008-11-25 16:16:06 +00:00
|
|
|
/* wait until outputs have stabilized */
|
|
|
|
sleep(HZ/4);
|
2007-03-11 17:38:08 +00:00
|
|
|
|
2012-01-08 01:43:16 +00:00
|
|
|
#ifdef SANSA_E200 /* check C200 */
|
|
|
|
/* Release pop prevention */
|
|
|
|
GPIO_CLEAR_BITWISE(GPIOG_OUTPUT_VAL, 0x08);
|
2008-11-25 16:16:06 +00:00
|
|
|
#endif
|
|
|
|
|
2010-10-27 21:30:04 +00:00
|
|
|
#if defined(SANSA_E200V2) || defined(SANSA_FUZE) || defined(SANSA_C200)
|
2010-06-27 23:27:54 +00:00
|
|
|
/* Set line out volume to 0dB */
|
|
|
|
as3514_write_masked(AS3514_LINE_OUT_R, 0x1b, AS3514_VOL_MASK);
|
|
|
|
as3514_write_masked(AS3514_LINE_OUT_L, 0x1b, AS3514_VOL_MASK);
|
2010-10-27 21:30:04 +00:00
|
|
|
#endif /* SANSA_E200V2 || SANSA_FUZE || SANSA_C200 */
|
2010-06-27 23:27:54 +00:00
|
|
|
|
2008-11-25 16:16:06 +00:00
|
|
|
audiohw_mute(false);
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 16:39:04 +00:00
|
|
|
void audiohw_set_volume(int vol_l, int vol_r)
|
2007-03-11 17:38:08 +00:00
|
|
|
{
|
2008-11-25 16:16:06 +00:00
|
|
|
unsigned int hph_r, hph_l;
|
2007-06-05 07:03:30 +00:00
|
|
|
unsigned int mix_l, mix_r;
|
|
|
|
|
2013-04-13 03:35:47 +00:00
|
|
|
vol_l = vol_tenthdb2hw(vol_l);
|
|
|
|
vol_r = vol_tenthdb2hw(vol_r);
|
|
|
|
|
2010-05-19 17:30:38 +00:00
|
|
|
if (vol_l == 0 && vol_r == 0) {
|
2010-05-14 08:35:53 +00:00
|
|
|
audiohw_mute(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-24 01:11:51 +00:00
|
|
|
/* We combine the mixer/DAC channel volume range with the headphone volume
|
2008-11-25 16:16:06 +00:00
|
|
|
range - keep first stage as loud as possible */
|
2010-06-24 01:11:51 +00:00
|
|
|
|
|
|
|
/*AS3543 mixer can go a little louder then the as3514, although
|
|
|
|
* it might be possible to go louder on the as3514 as well */
|
|
|
|
|
|
|
|
#if CONFIG_CPU == AS3525v2
|
|
|
|
#define MIXER_MAX_VOLUME 0x1b
|
|
|
|
#else /* lets leave the AS3514 alone until its better tested*/
|
|
|
|
#define MIXER_MAX_VOLUME 0x16
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (vol_r <= MIXER_MAX_VOLUME) {
|
2008-11-25 16:16:06 +00:00
|
|
|
mix_r = vol_r;
|
|
|
|
hph_r = 0;
|
2007-06-05 07:03:30 +00:00
|
|
|
} else {
|
2010-06-24 01:11:51 +00:00
|
|
|
mix_r = MIXER_MAX_VOLUME;
|
|
|
|
hph_r = vol_r - MIXER_MAX_VOLUME;
|
2007-05-20 19:09:15 +00:00
|
|
|
}
|
2007-06-05 07:03:30 +00:00
|
|
|
|
2010-06-24 01:11:51 +00:00
|
|
|
if (vol_l <= MIXER_MAX_VOLUME) {
|
2008-11-25 16:16:06 +00:00
|
|
|
mix_l = vol_l;
|
|
|
|
hph_l = 0;
|
2007-06-05 07:03:30 +00:00
|
|
|
} else {
|
2010-06-24 01:11:51 +00:00
|
|
|
mix_l = MIXER_MAX_VOLUME;
|
|
|
|
hph_l = vol_l - MIXER_MAX_VOLUME;
|
|
|
|
}
|
2007-03-11 17:38:08 +00:00
|
|
|
|
2009-01-08 04:21:24 +00:00
|
|
|
as3514_write_masked(AS3514_DAC_R, mix_r, AS3514_VOL_MASK);
|
|
|
|
as3514_write_masked(AS3514_DAC_L, mix_l, AS3514_VOL_MASK);
|
2009-02-05 19:57:18 +00:00
|
|
|
#if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
|
2010-03-29 22:26:58 +00:00
|
|
|
as3514_write_masked(AS3514_LINE_IN_R, mix_r, AS3514_VOL_MASK);
|
|
|
|
as3514_write_masked(AS3514_LINE_IN_L, mix_l, AS3514_VOL_MASK);
|
2009-01-08 04:21:24 +00:00
|
|
|
#endif
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_write_masked(AS3514_HPH_OUT_R, hph_r, AS3514_VOL_MASK);
|
|
|
|
as3514_write_masked(AS3514_HPH_OUT_L, hph_l, AS3514_VOL_MASK);
|
2010-05-14 08:35:53 +00:00
|
|
|
|
|
|
|
audiohw_mute(false);
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 17:30:38 +00:00
|
|
|
#if 0 /* unused */
|
2013-04-13 03:35:47 +00:00
|
|
|
void audiohw_set_lineout_volume(int vol_l, int vol_r)
|
2007-03-11 17:38:08 +00:00
|
|
|
{
|
2010-05-19 17:30:38 +00:00
|
|
|
#ifdef HAVE_AS3543
|
|
|
|
/* line out volume is set in the same registers */
|
2013-04-15 16:39:04 +00:00
|
|
|
audiohw_set_volume(vol_l, vol_r);
|
2010-05-19 17:30:38 +00:00
|
|
|
#else
|
2013-04-13 03:35:47 +00:00
|
|
|
vol_l = vol_tenthdb2hw(vol_l);
|
|
|
|
vol_r = vol_tenthdb2hw(vol_r);
|
2009-02-05 19:57:18 +00:00
|
|
|
as3514_write_masked(AS3514_LINE_OUT_R, vol_r, AS3514_VOL_MASK);
|
|
|
|
as3514_write_masked(AS3514_LINE_OUT_L, vol_l, AS3514_VOL_MASK);
|
2010-05-19 17:30:38 +00:00
|
|
|
#endif
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
2010-05-19 17:30:38 +00:00
|
|
|
#endif
|
2007-03-11 17:38:08 +00:00
|
|
|
|
2008-05-14 00:39:24 +00:00
|
|
|
/* Nice shutdown of AS3514 audio codec */
|
2007-03-11 17:38:08 +00:00
|
|
|
void audiohw_close(void)
|
|
|
|
{
|
2007-04-14 00:49:35 +00:00
|
|
|
/* mute headphones */
|
2007-06-05 07:03:30 +00:00
|
|
|
audiohw_mute(true);
|
2007-03-11 17:38:08 +00:00
|
|
|
|
2012-01-08 01:43:16 +00:00
|
|
|
#ifdef SANSA_E200 /* check C200 */
|
|
|
|
/* Set pop prevention */
|
|
|
|
GPIO_SET_BITWISE(GPIOG_OUTPUT_VAL, 0x08);
|
2008-11-25 16:16:06 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* turn on common */
|
|
|
|
as3514_clear(AS3514_AUDIOSET3, AUDIOSET3_HPCM_off);
|
|
|
|
|
2007-04-14 00:49:35 +00:00
|
|
|
/* turn off everything */
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_clear(AS3514_HPH_OUT_L, HPH_OUT_L_HP_ON);
|
2008-04-15 21:33:32 +00:00
|
|
|
as3514_write(AS3514_AUDIOSET1, 0x0);
|
2008-11-25 16:16:06 +00:00
|
|
|
|
|
|
|
/* Allow caps to discharge */
|
|
|
|
sleep(HZ/4);
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2008-12-12 11:01:07 +00:00
|
|
|
void audiohw_set_frequency(int fsel)
|
2007-03-11 17:38:08 +00:00
|
|
|
{
|
2010-06-26 10:07:17 +00:00
|
|
|
#if defined(SANSA_E200) || defined(SANSA_C200)
|
|
|
|
if ((unsigned)fsel >= HW_NUM_FREQ)
|
|
|
|
fsel = HW_FREQ_DEFAULT;
|
|
|
|
|
|
|
|
as3514_write(AS3514_PLLMODE, hw_freq_sampr[fsel] < 24000 ?
|
|
|
|
PLLMODE_LRCK_8_23 : PLLMODE_LRCK_24_48);
|
|
|
|
|
|
|
|
audiohw_set_sampr_dividers(fsel);
|
|
|
|
#endif
|
2008-12-12 11:01:07 +00:00
|
|
|
(void)fsel;
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-21 03:55:17 +00:00
|
|
|
#if defined(HAVE_RECORDING)
|
2007-03-11 17:38:08 +00:00
|
|
|
void audiohw_enable_recording(bool source_mic)
|
|
|
|
{
|
2007-06-05 07:03:30 +00:00
|
|
|
if (source_mic) {
|
|
|
|
/* ADCmux = Stereo Microphone */
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_write_masked(AS3514_ADC_R, ADC_R_ADCMUX_ST_MIC,
|
|
|
|
ADC_R_ADCMUX);
|
|
|
|
|
2009-02-05 19:57:18 +00:00
|
|
|
/* MIC1_on, others off */
|
|
|
|
as3514_write_masked(AS3514_AUDIOSET1, AUDIOSET1_MIC1_on,
|
|
|
|
AUDIOSET1_INPUT_MASK);
|
|
|
|
|
2010-03-29 22:52:19 +00:00
|
|
|
#if CONFIG_CPU == AS3525v2
|
2010-05-19 17:30:38 +00:00
|
|
|
/* XXX: why is the microphone supply not needed on other models ?? */
|
2010-03-29 22:52:19 +00:00
|
|
|
/* Enable supply */
|
|
|
|
as3514_clear(AS3514_MIC1_L, MIC1_L_M1_SUP_off);
|
|
|
|
#endif
|
|
|
|
|
2007-06-05 07:03:30 +00:00
|
|
|
/* M1_AGC_off */
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_clear(AS3514_MIC1_R, MIC1_R_M1_AGC_off);
|
2007-06-05 07:03:30 +00:00
|
|
|
} else {
|
2009-02-05 19:57:18 +00:00
|
|
|
/* ADCmux = Line_IN1 or Line_IN2 */
|
2010-03-29 22:26:58 +00:00
|
|
|
as3514_write_masked(AS3514_ADC_R, ADC_R_ADCMUX_LINE_IN,
|
2008-11-25 16:16:06 +00:00
|
|
|
ADC_R_ADCMUX);
|
|
|
|
|
2009-02-05 19:57:18 +00:00
|
|
|
/* LIN1_or LIN2 on, rest off */
|
2010-03-29 22:26:58 +00:00
|
|
|
as3514_write_masked(AS3514_AUDIOSET1, AUDIOSET1_LIN_on,
|
2009-02-05 19:57:18 +00:00
|
|
|
AUDIOSET1_INPUT_MASK);
|
2010-03-29 22:52:19 +00:00
|
|
|
|
|
|
|
#if CONFIG_CPU == AS3525v2
|
|
|
|
/* Disable supply */
|
|
|
|
as3514_set(AS3514_MIC1_L, MIC1_L_M1_SUP_off);
|
|
|
|
#endif
|
2007-06-05 07:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ADC_Mute_off */
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_set(AS3514_ADC_L, ADC_L_ADC_MUTE_off);
|
2007-06-05 07:03:30 +00:00
|
|
|
/* ADC_on */
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_set(AS3514_AUDIOSET1, AUDIOSET1_ADC_on);
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2007-04-14 00:49:35 +00:00
|
|
|
void audiohw_disable_recording(void)
|
|
|
|
{
|
2007-06-05 07:03:30 +00:00
|
|
|
/* ADC_Mute_on */
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_clear(AS3514_ADC_L, ADC_L_ADC_MUTE_off);
|
2007-06-05 07:03:30 +00:00
|
|
|
|
2009-02-05 19:57:18 +00:00
|
|
|
/* ADC_off, all input sources off */
|
|
|
|
as3514_clear(AS3514_AUDIOSET1, AUDIOSET1_ADC_on | AUDIOSET1_INPUT_MASK);
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 07:03:30 +00:00
|
|
|
/**
|
|
|
|
* Set recording volume
|
|
|
|
*
|
|
|
|
* Line in : 0 .. 23 .. 31 =>
|
|
|
|
Volume -34.5 .. +00.0 .. +12.0 dB
|
|
|
|
* Mic (left): 0 .. 23 .. 39 =>
|
|
|
|
* Volume -34.5 .. +00.0 .. +24.0 dB
|
|
|
|
*
|
|
|
|
*/
|
2007-04-14 00:49:35 +00:00
|
|
|
void audiohw_set_recvol(int left, int right, int type)
|
|
|
|
{
|
2007-06-05 07:03:30 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case AUDIO_GAIN_MIC:
|
|
|
|
{
|
|
|
|
/* Combine MIC gains seamlessly with ADC levels */
|
2008-11-25 16:16:06 +00:00
|
|
|
unsigned int mic1_r;
|
2007-06-05 07:03:30 +00:00
|
|
|
|
|
|
|
if (left >= 36) {
|
|
|
|
/* M1_Gain = +40db, ADR_Vol = +7.5dB .. +12.0 dB =>
|
|
|
|
+19.5 dB .. +24.0 dB */
|
|
|
|
left -= 8;
|
2008-11-25 16:16:06 +00:00
|
|
|
mic1_r = MIC1_R_M1_GAIN_40DB;
|
2007-06-05 07:03:30 +00:00
|
|
|
} else if (left >= 32) {
|
|
|
|
/* M1_Gain = +34db, ADR_Vol = +7.5dB .. +12.0 dB =>
|
|
|
|
+13.5 dB .. +18.0 dB */
|
|
|
|
left -= 4;
|
2008-11-25 16:16:06 +00:00
|
|
|
mic1_r = MIC1_R_M1_GAIN_34DB;
|
|
|
|
} else {
|
2007-06-05 07:03:30 +00:00
|
|
|
/* M1_Gain = +28db, ADR_Vol = -34.5dB .. +12.0 dB =>
|
|
|
|
-34.5 dB .. +12.0 dB */
|
2008-11-25 16:16:06 +00:00
|
|
|
mic1_r = MIC1_R_M1_GAIN_28DB;
|
|
|
|
}
|
2007-06-05 07:03:30 +00:00
|
|
|
|
|
|
|
right = left;
|
|
|
|
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_write_masked(AS3514_MIC1_R, mic1_r, MIC1_R_M1_GAIN);
|
2007-06-05 07:03:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AUDIO_GAIN_LINEIN:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_write_masked(AS3514_ADC_R, right, AS3514_VOL_MASK);
|
|
|
|
as3514_write_masked(AS3514_ADC_L, left, AS3514_VOL_MASK);
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
2009-02-05 19:57:18 +00:00
|
|
|
#endif /* HAVE_RECORDING */
|
2007-03-11 17:38:08 +00:00
|
|
|
|
2009-02-05 19:57:18 +00:00
|
|
|
#if defined(HAVE_RECORDING) || defined(HAVE_FMRADIO_IN)
|
2007-06-05 07:03:30 +00:00
|
|
|
/**
|
2009-02-05 19:57:18 +00:00
|
|
|
* Enable line in analog monitoring
|
2007-06-05 07:03:30 +00:00
|
|
|
*
|
|
|
|
*/
|
2007-11-19 15:50:52 +00:00
|
|
|
void audiohw_set_monitor(bool enable)
|
2007-03-11 17:38:08 +00:00
|
|
|
{
|
2007-06-05 07:03:30 +00:00
|
|
|
if (enable) {
|
2009-02-05 19:57:18 +00:00
|
|
|
/* select either LIN1 or LIN2 */
|
2010-03-29 22:26:58 +00:00
|
|
|
as3514_write_masked(AS3514_AUDIOSET1, AUDIOSET1_LIN_on,
|
2009-02-05 19:57:18 +00:00
|
|
|
AUDIOSET1_LIN1_on | AUDIOSET1_LIN2_on);
|
2010-03-29 22:26:58 +00:00
|
|
|
as3514_set(AS3514_LINE_IN_R, LINE_IN1_R_LI1R_MUTE_off);
|
|
|
|
as3514_set(AS3514_LINE_IN_L, LINE_IN1_L_LI1L_MUTE_off);
|
2008-11-25 16:16:06 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-05-15 09:19:30 +00:00
|
|
|
/* turn off both LIN1 and LIN2 (if present) */
|
2008-11-25 16:16:06 +00:00
|
|
|
as3514_clear(AS3514_LINE_IN1_R, LINE_IN1_R_LI1R_MUTE_off);
|
|
|
|
as3514_clear(AS3514_LINE_IN1_L, LINE_IN1_L_LI1L_MUTE_off);
|
2010-05-15 09:19:30 +00:00
|
|
|
#ifndef HAVE_AS3543
|
2010-03-29 22:26:58 +00:00
|
|
|
as3514_clear(AS3514_LINE_IN2_R, LINE_IN2_R_LI2R_MUTE_off);
|
|
|
|
as3514_clear(AS3514_LINE_IN2_L, LINE_IN2_L_LI2L_MUTE_off);
|
2010-03-29 19:48:18 +00:00
|
|
|
#endif
|
2009-02-05 19:57:18 +00:00
|
|
|
as3514_clear(AS3514_AUDIOSET1, AUDIOSET1_LIN1_on | AUDIOSET1_LIN2_on);
|
2007-06-05 07:03:30 +00:00
|
|
|
}
|
2007-03-11 17:38:08 +00:00
|
|
|
}
|
2009-02-05 19:57:18 +00:00
|
|
|
#endif /* HAVE_RECORDING || HAVE_FMRADIO_IN */
|