2018-11-05 12:01:55 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 Marcin Bukat
|
|
|
|
* Copyright (c) 2018 Roman Stolyarov
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-10-03 04:11:20 +00:00
|
|
|
//#define LOGF_ENABLE
|
|
|
|
|
2018-11-05 12:01:55 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "audiohw.h"
|
2020-10-01 18:06:48 +00:00
|
|
|
#include "button.h"
|
2018-11-05 12:01:55 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "panic.h"
|
|
|
|
#include "sysfs.h"
|
|
|
|
#include "alsa-controls.h"
|
2020-10-01 02:12:35 +00:00
|
|
|
#include "pcm-alsa.h"
|
2018-11-05 12:01:55 +00:00
|
|
|
|
2020-10-03 04:11:20 +00:00
|
|
|
#include "logf.h"
|
|
|
|
|
2020-10-25 04:32:36 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
X3ii:
|
|
|
|
|
|
|
|
PCM device hw:0,0
|
|
|
|
|
|
|
|
ACCESS: MMAP_INTERLEAVED RW_INTERLEAVED
|
|
|
|
FORMAT: S16_LE S24_LE
|
|
|
|
SUBFORMAT: STD
|
|
|
|
SAMPLE_BITS: [16 32]
|
|
|
|
FRAME_BITS: [16 64]
|
|
|
|
CHANNELS: [1 2]
|
|
|
|
RATE: [8000 384000]
|
|
|
|
PERIOD_TIME: (1333 16384000]
|
|
|
|
PERIOD_SIZE: [512 131072]
|
|
|
|
PERIOD_BYTES: [4096 262144]
|
|
|
|
PERIODS: [4 256]
|
|
|
|
BUFFER_TIME: (5333 65536000]
|
|
|
|
BUFFER_SIZE: [2048 524288]
|
|
|
|
BUFFER_BYTES: [4096 1048576]
|
|
|
|
TICK_TIME: ALL
|
|
|
|
|
|
|
|
Mixer controls:
|
|
|
|
|
|
|
|
numid=1,iface=MIXER,name='Left Playback Volume'
|
|
|
|
; type=INTEGER,access=rw------,values=1,min=0,max=255,step=0
|
|
|
|
: values=0
|
|
|
|
numid=2,iface=MIXER,name='Right Playback Volume'
|
|
|
|
; type=INTEGER,access=rw------,values=1,min=0,max=255,step=0
|
|
|
|
: values=0
|
|
|
|
numid=3,iface=MIXER,name='AK4490 Digital Filter'
|
|
|
|
; type=INTEGER,access=rw------,values=1,min=0,max=4,step=0
|
|
|
|
: values=0
|
|
|
|
numid=4,iface=MIXER,name='AK4490 Soft Mute'
|
|
|
|
; type=BOOLEAN,access=rw------,values=1
|
|
|
|
: values=off
|
|
|
|
numid=5,iface=MIXER,name='Output Port Switch'
|
|
|
|
; type=INTEGER,access=rw------,values=1,min=0,max=5,step=0
|
|
|
|
: values=0
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2021-04-14 01:38:14 +00:00
|
|
|
static int hw_init = 0;
|
2018-11-05 12:01:55 +00:00
|
|
|
|
2020-10-01 02:12:35 +00:00
|
|
|
static long int vol_l_hw = 255;
|
|
|
|
static long int vol_r_hw = 255;
|
2020-10-12 15:09:55 +00:00
|
|
|
static long int last_ps = -1;
|
2020-10-01 02:12:35 +00:00
|
|
|
|
2020-10-12 13:29:21 +00:00
|
|
|
static int muted = -1;
|
|
|
|
|
2020-10-01 02:12:35 +00:00
|
|
|
void audiohw_mute(int mute)
|
2018-11-05 12:01:55 +00:00
|
|
|
{
|
2020-10-03 04:11:20 +00:00
|
|
|
logf("mute %d", mute);
|
|
|
|
|
2021-04-14 01:38:14 +00:00
|
|
|
if (!hw_init || muted == mute)
|
2020-10-12 15:09:55 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
muted = mute;
|
|
|
|
|
2020-10-01 02:12:35 +00:00
|
|
|
if(mute)
|
|
|
|
{
|
2020-10-03 04:11:20 +00:00
|
|
|
long int ps0 = 0;
|
2020-10-01 02:12:35 +00:00
|
|
|
alsa_controls_set_ints("Output Port Switch", 1, &ps0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-12 15:46:05 +00:00
|
|
|
last_ps = 0;
|
2020-10-03 04:11:20 +00:00
|
|
|
xduoo_get_outputs();
|
2020-10-01 02:12:35 +00:00
|
|
|
}
|
2018-11-05 12:01:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-01 18:06:48 +00:00
|
|
|
int xduoo_get_outputs(void){
|
2020-10-03 13:08:22 +00:00
|
|
|
long int ps = 0; // Muted, if nothing is plugged in!
|
2020-10-01 02:12:35 +00:00
|
|
|
|
2018-11-05 12:01:55 +00:00
|
|
|
int status = 0;
|
|
|
|
|
2021-04-14 01:38:14 +00:00
|
|
|
if (!hw_init) return ps;
|
2020-10-01 18:06:48 +00:00
|
|
|
|
2018-11-05 12:01:55 +00:00
|
|
|
const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
|
|
|
|
const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
|
2020-10-01 02:12:35 +00:00
|
|
|
#if defined(XDUOO_X20)
|
2018-11-05 12:01:55 +00:00
|
|
|
const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
|
|
|
|
#endif
|
|
|
|
|
2020-10-01 18:06:48 +00:00
|
|
|
sysfs_get_int(sysfs_lo_switch, &status);
|
|
|
|
if (status) ps = 1; // lineout
|
|
|
|
|
2020-10-10 00:51:55 +00:00
|
|
|
sysfs_get_int(sysfs_hs_switch, &status);
|
|
|
|
if (status) ps = 2; // headset
|
|
|
|
|
2020-10-01 02:12:35 +00:00
|
|
|
#if defined(XDUOO_X20)
|
2018-11-05 12:01:55 +00:00
|
|
|
sysfs_get_int(sysfs_bal_switch, &status);
|
2021-03-11 00:03:00 +00:00
|
|
|
if (status) ps = 3; // balanced output
|
2018-11-05 12:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
2020-10-01 18:06:48 +00:00
|
|
|
xduoo_set_output(ps);
|
|
|
|
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xduoo_set_output(int ps)
|
|
|
|
{
|
2021-04-14 01:38:14 +00:00
|
|
|
if (!hw_init || muted) return;
|
2020-10-01 18:06:48 +00:00
|
|
|
|
2020-10-01 02:12:35 +00:00
|
|
|
if (last_ps != ps)
|
|
|
|
{
|
2020-10-03 04:11:20 +00:00
|
|
|
logf("set out %d/%d", ps, last_ps);
|
2020-10-01 02:12:35 +00:00
|
|
|
/* Output port switch */
|
|
|
|
last_ps = ps;
|
|
|
|
alsa_controls_set_ints("Output Port Switch", 1, &last_ps);
|
2021-03-11 00:03:00 +00:00
|
|
|
audiohw_set_volume(vol_l_hw, vol_r_hw);
|
|
|
|
|
|
|
|
#if defined(XDUOO_X3II)
|
|
|
|
/* Enable/disable headphone remote ADC */
|
|
|
|
sysfs_set_string("/sys/devices/platform/earpods_adc.0/earpods_adc/earpods_adc_sw", (ps == 2) ? "on" : "off");
|
|
|
|
#endif
|
2020-10-01 02:12:35 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-05 12:01:55 +00:00
|
|
|
|
2020-10-01 02:12:35 +00:00
|
|
|
void audiohw_preinit(void)
|
|
|
|
{
|
2020-10-03 04:11:20 +00:00
|
|
|
logf("hw preinit");
|
2018-02-19 05:28:11 +00:00
|
|
|
alsa_controls_init("default");
|
2021-04-14 01:38:14 +00:00
|
|
|
hw_init = 1;
|
2020-10-20 21:03:21 +00:00
|
|
|
|
|
|
|
#if defined(XDUOO_X3II)
|
2020-10-03 13:08:22 +00:00
|
|
|
audiohw_mute(true); /* Start muted to avoid the POP */
|
2020-10-20 21:03:21 +00:00
|
|
|
#else
|
|
|
|
audiohw_mute(false); /* No need */
|
|
|
|
#endif
|
|
|
|
|
2020-10-12 15:09:55 +00:00
|
|
|
// const char * const codec_pmdown = "/sys/devices/platform/ingenic-x3ii.0/x3ii-ak4490-i2s/pmdown_time"; // in ms, defaults 5000
|
2020-10-01 02:12:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_postinit(void)
|
|
|
|
{
|
2020-10-03 04:11:20 +00:00
|
|
|
logf("hw postinit");
|
2018-11-05 12:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_close(void)
|
|
|
|
{
|
2020-10-03 04:11:20 +00:00
|
|
|
logf("hw close");
|
2021-04-14 01:38:14 +00:00
|
|
|
hw_init = 0;
|
2018-11-05 12:01:55 +00:00
|
|
|
alsa_controls_close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_frequency(int fsel)
|
|
|
|
{
|
|
|
|
(void)fsel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_volume(int vol_l, int vol_r)
|
|
|
|
{
|
2020-10-03 04:11:20 +00:00
|
|
|
logf("hw vol %d %d", vol_l, vol_r);
|
|
|
|
|
2020-10-01 18:06:48 +00:00
|
|
|
long l,r;
|
|
|
|
|
|
|
|
vol_l_hw = vol_l;
|
|
|
|
vol_r_hw = vol_r;
|
|
|
|
|
|
|
|
if (lineout_inserted()) {
|
|
|
|
l = 0;
|
|
|
|
r = 0;
|
|
|
|
} else {
|
|
|
|
l = -vol_l/5;
|
|
|
|
r = -vol_r/5;
|
|
|
|
}
|
|
|
|
|
2021-04-14 01:38:14 +00:00
|
|
|
if (!hw_init)
|
2020-10-17 00:34:18 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-01 18:06:48 +00:00
|
|
|
alsa_controls_set_ints("Left Playback Volume", 1, &l);
|
|
|
|
alsa_controls_set_ints("Right Playback Volume", 1, &r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_lineout_volume(int vol_l, int vol_r)
|
|
|
|
{
|
|
|
|
long l,r;
|
|
|
|
|
2020-10-03 04:11:20 +00:00
|
|
|
logf("lo vol %d %d", vol_l, vol_r);
|
|
|
|
|
2020-10-01 18:06:48 +00:00
|
|
|
(void)vol_l;
|
|
|
|
(void)vol_r;
|
|
|
|
|
|
|
|
if (lineout_inserted()) {
|
|
|
|
l = 0;
|
|
|
|
r = 0;
|
|
|
|
} else {
|
|
|
|
l = -vol_l_hw/5;
|
|
|
|
r = -vol_r_hw/5;
|
|
|
|
}
|
|
|
|
|
|
|
|
alsa_controls_set_ints("Left Playback Volume", 1, &l);
|
|
|
|
alsa_controls_set_ints("Right Playback Volume", 1, &r);
|
2018-11-05 12:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void audiohw_set_filter_roll_off(int value)
|
|
|
|
{
|
2020-10-03 04:11:20 +00:00
|
|
|
logf("rolloff %d", value);
|
2020-10-01 18:06:48 +00:00
|
|
|
/* 0 = Sharp;
|
2020-10-01 02:12:35 +00:00
|
|
|
1 = Slow;
|
|
|
|
2 = Short Sharp
|
2021-07-10 02:48:19 +00:00
|
|
|
3 = Short Slow
|
|
|
|
4 = Super Slow */
|
2018-11-05 12:01:55 +00:00
|
|
|
#if defined(XDUOO_X3II)
|
2020-10-01 02:12:35 +00:00
|
|
|
long int value_hw = value;
|
2018-11-05 12:01:55 +00:00
|
|
|
alsa_controls_set_ints("AK4490 Digital Filter", 1, &value_hw);
|
|
|
|
#elif defined(XDUOO_X20)
|
2020-10-01 02:12:35 +00:00
|
|
|
long int value_hw = value;
|
2018-11-05 12:01:55 +00:00
|
|
|
alsa_controls_set_ints("ES9018_K2M Digital Filter", 1, &value_hw);
|
|
|
|
#else
|
|
|
|
(void)value;
|
|
|
|
#endif
|
|
|
|
}
|