From a3fe07ff128e521051aee8bc91add071724d6538 Mon Sep 17 00:00:00 2001 From: Dana Conrad Date: Tue, 21 Nov 2023 19:28:51 -0600 Subject: ErosQ New Revision HW volume Add HW volume control via ES9018K2M, and reorganize eros_qn_codec.c/.h, audiohw-erosqnative.c. This automatically detects the presence of the new DAC and uses its hardware volume scaling. If not present, use same SWVOL we have been using so far. Add debug menu readout of SWVOL/I2C result. Break out es9018k2m stuff into its own file so that maybe it can be useful to other ports. Note that we may need to get smarter about detecting the DAC type if/when another model emerges. Change-Id: I586a1cf7f150dd6b4e221157859825952840af56 --- firmware/export/audiohw.h | 1 + firmware/export/eros_qn_codec.h | 16 +++++++++-- firmware/export/es9018k2m.h | 64 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 firmware/export/es9018k2m.h (limited to 'firmware/export') diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h index 3f8b48d750..067118000e 100644 --- a/firmware/export/audiohw.h +++ b/firmware/export/audiohw.h @@ -214,6 +214,7 @@ struct sound_settings_info #include "pcm1792.h" #elif defined(HAVE_EROS_QN_CODEC) #include "eros_qn_codec.h" +#include "es9018k2m.h" #elif defined(HAVE_NWZ_LINUX_CODEC) #include "nwzlinux_codec.h" #elif defined(HAVE_CS4398) diff --git a/firmware/export/eros_qn_codec.h b/firmware/export/eros_qn_codec.h index bf108aa1c7..223ef06779 100644 --- a/firmware/export/eros_qn_codec.h +++ b/firmware/export/eros_qn_codec.h @@ -32,13 +32,25 @@ #define PCM5102A_VOLUME_MIN -740 #define PCM5102A_VOLUME_MAX -20 -/* a small DC offset prevents play/pause clicking due to the DAC auto-muting */ +/* a small DC offset prevents play/pause clicking due to the PCM5102A DAC auto-muting */ #define PCM_DC_OFFSET_VALUE -1 AUDIOHW_SETTING(VOLUME, "dB", 0, 2, PCM5102A_VOLUME_MIN/10, PCM5102A_VOLUME_MAX/10, 0) +/* flag indicating whether this is a new revision unit with the ES9018K2M DAC */ +extern int es9018k2m_present_flag; + +/* Switch the output sink. 0 - headphones, 1 - line out */ +void eros_qn_switch_output(int select); + +/* Record last volume setting for switching between headphones/line out */ +void eros_qn_set_last_vol(long int vol_l, long int vol_r); + /* this just calls audiohw_set_volume() with the last (locally) known volume, * used for switching to/from fixed line out volume. */ -void dac_set_outputs(void); +void eros_qn_set_outputs(void); + +/* returns (global_settings.volume_limit * 10) */ +int eros_qn_get_volume_limit(void); #endif diff --git a/firmware/export/es9018k2m.h b/firmware/export/es9018k2m.h new file mode 100644 index 0000000000..035a607030 --- /dev/null +++ b/firmware/export/es9018k2m.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * + * Copyright (c) 2023 Dana Conrad + * + * 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. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _ES9018K2M_H +#define _ES9018K2M_H + +//====================================================================================== +// ES9018K2M support stuff + +#ifndef ES9018K2M_VOLUME_MIN +# define ES9018K2M_VOLUME_MIN -1270 +#endif + +#ifndef ES9018K2M_VOLUME_MAX +# define ES9018K2M_VOLUME_MAX 0 +#endif + +#define ES9018K2M_REG0_SYSTEM_SETTINGS 0 +#define ES9018K2M_REG1_INPUT_CONFIG 1 +#define ES9018K2M_REG4_AUTOMUTE_TIME 4 +#define ES9018K2M_REG5_AUTOMUTE_LEVEL 5 +#define ES9018K2M_REG6_DEEMPHASIS 6 +#define ES9018K2M_REG7_GENERAL_SETTINGS 7 +#define ES9018K2M_REG8_GPIO_CONFIG 8 +#define ES9018K2M_REG10_MASTER_MODE_CTRL 10 +#define ES9018K2M_REG11_CHANNEL_MAPPING 11 +#define ES9018K2M_REG12_DPLL_SETTINGS 12 +#define ES9018K2M_REG13_THD_COMP 13 +#define ES9018K2M_REG14_SOFTSTART_SETTINGS 14 +#define ES9018K2M_REG15_VOLUME_L 15 +#define ES9018K2M_REG16_VOLUME_R 16 +#define ES9018K2M_REG21_GPIO_INPUT_SELECT 21 + +/* writes volume levels to DAC over I2C */ +void es9018k2m_set_volume(int vol_l, int vol_r); + +/* writes a single register */ +/* returns I2C_STATUS_OK upon success, I2C_STATUS_* errors upon error */ +int es9018k2m_write_reg(uint8_t reg, uint8_t val); + +/* reads a single register */ +/* returns register value, or -1 upon error */ +int es9018k2m_read_reg(uint8_t reg); + +#endif \ No newline at end of file -- cgit v1.2.3