xduoox3ii/x20: Proper lineout detection and volume mangling.
hotplugging hp and lineout works, without blowing out eardrums. Change-Id: I2df5c7a618bb2d1d77d416548d45dff9cfc619db
This commit is contained in:
parent
6d47dc9a88
commit
b030bf5885
10 changed files with 80 additions and 48 deletions
|
@ -3851,10 +3851,6 @@ static void audio_change_frequency_callback(unsigned short id, void *data)
|
||||||
static bool starting_playback = false;
|
static bool starting_playback = false;
|
||||||
struct mp3entry *id3;
|
struct mp3entry *id3;
|
||||||
|
|
||||||
#ifdef AUDIOHW_HAVE_SET_OUTPUT
|
|
||||||
audiohw_set_output();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case PLAYBACK_EVENT_START_PLAYBACK:
|
case PLAYBACK_EVENT_START_PLAYBACK:
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "audiohw.h"
|
#include "audiohw.h"
|
||||||
|
#include "button.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "panic.h"
|
#include "panic.h"
|
||||||
|
@ -32,6 +33,7 @@
|
||||||
#include "pcm-alsa.h"
|
#include "pcm-alsa.h"
|
||||||
|
|
||||||
static int fd_hw;
|
static int fd_hw;
|
||||||
|
static int inited = 0;
|
||||||
|
|
||||||
static long int vol_l_hw = 255;
|
static long int vol_l_hw = 255;
|
||||||
static long int vol_r_hw = 255;
|
static long int vol_r_hw = 255;
|
||||||
|
@ -72,34 +74,45 @@ void audiohw_mute(int mute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void audiohw_set_output(void)
|
int xduoo_get_outputs(void){
|
||||||
{
|
|
||||||
long int ps = 2; // headset
|
long int ps = 2; // headset
|
||||||
|
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
|
if (!inited) return ps;
|
||||||
|
|
||||||
const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
|
const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
|
||||||
const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
|
const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
|
||||||
#if defined(XDUOO_X20)
|
#if defined(XDUOO_X20)
|
||||||
const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
|
const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sysfs_get_int(sysfs_lo_switch, &status);
|
|
||||||
if (status) ps = 1; // lineout
|
|
||||||
|
|
||||||
sysfs_get_int(sysfs_hs_switch, &status);
|
sysfs_get_int(sysfs_hs_switch, &status);
|
||||||
if (status) ps = 2; // headset
|
if (status) ps = 2; // headset
|
||||||
|
|
||||||
|
sysfs_get_int(sysfs_lo_switch, &status);
|
||||||
|
if (status) ps = 1; // lineout
|
||||||
|
|
||||||
#if defined(XDUOO_X20)
|
#if defined(XDUOO_X20)
|
||||||
sysfs_get_int(sysfs_bal_switch, &status);
|
sysfs_get_int(sysfs_bal_switch, &status);
|
||||||
if (status) ps = 3; // balance
|
if (status) ps = 3; // balance
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
xduoo_set_output(ps);
|
||||||
|
|
||||||
|
return ps;
|
||||||
|
}
|
||||||
|
|
||||||
|
void xduoo_set_output(int ps)
|
||||||
|
{
|
||||||
|
if (!inited) return;
|
||||||
|
|
||||||
if (last_ps != ps)
|
if (last_ps != ps)
|
||||||
{
|
{
|
||||||
/* Output port switch */
|
/* Output port switch */
|
||||||
last_ps = ps;
|
last_ps = ps;
|
||||||
alsa_controls_set_ints("Output Port Switch", 1, &last_ps);
|
alsa_controls_set_ints("Output Port Switch", 1, &last_ps);
|
||||||
|
audiohw_set_volume(vol_l_hw, vol_r_hw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,15 +120,17 @@ void audiohw_preinit(void)
|
||||||
{
|
{
|
||||||
alsa_controls_init();
|
alsa_controls_init();
|
||||||
hw_open();
|
hw_open();
|
||||||
|
inited = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void audiohw_postinit(void)
|
void audiohw_postinit(void)
|
||||||
{
|
{
|
||||||
audiohw_set_output();
|
xduoo_set_output(xduoo_get_outputs());
|
||||||
}
|
}
|
||||||
|
|
||||||
void audiohw_close(void)
|
void audiohw_close(void)
|
||||||
{
|
{
|
||||||
|
inited = 0;
|
||||||
hw_close();
|
hw_close();
|
||||||
alsa_controls_close();
|
alsa_controls_close();
|
||||||
}
|
}
|
||||||
|
@ -127,16 +142,45 @@ void audiohw_set_frequency(int fsel)
|
||||||
|
|
||||||
void audiohw_set_volume(int vol_l, int vol_r)
|
void audiohw_set_volume(int vol_l, int vol_r)
|
||||||
{
|
{
|
||||||
vol_l_hw = -vol_l/5;
|
long l,r;
|
||||||
vol_r_hw = -vol_r/5;
|
|
||||||
|
vol_l_hw = vol_l;
|
||||||
alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw);
|
vol_r_hw = vol_r;
|
||||||
alsa_controls_set_ints("Right Playback Volume", 1, &vol_r_hw);
|
|
||||||
|
if (lineout_inserted()) {
|
||||||
|
l = 0;
|
||||||
|
r = 0;
|
||||||
|
} else {
|
||||||
|
l = -vol_l/5;
|
||||||
|
r = -vol_r/5;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void audiohw_set_filter_roll_off(int value)
|
void audiohw_set_filter_roll_off(int value)
|
||||||
{
|
{
|
||||||
/* 0 = Sharp;
|
/* 0 = Sharp;
|
||||||
1 = Slow;
|
1 = Slow;
|
||||||
2 = Short Sharp
|
2 = Short Sharp
|
||||||
3 = Short Slow */
|
3 = Short Slow */
|
||||||
|
|
|
@ -452,10 +452,6 @@ void audiohw_set_volume(int vol_l, int vol_r);
|
||||||
void audiohw_set_lineout_volume(int vol_l, int vol_r);
|
void audiohw_set_lineout_volume(int vol_l, int vol_r);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef AUDIOHW_HAVE_SET_OUTPUT
|
|
||||||
void audiohw_set_output(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef AUDIOHW_HAVE_CLIPPING
|
#ifndef AUDIOHW_HAVE_CLIPPING
|
||||||
#if defined(AUDIOHW_HAVE_BASS) || defined(AUDIOHW_HAVE_TREBLE) \
|
#if defined(AUDIOHW_HAVE_BASS) || defined(AUDIOHW_HAVE_TREBLE) \
|
||||||
|| defined(AUDIOHW_HAVE_EQ)
|
|| defined(AUDIOHW_HAVE_EQ)
|
||||||
|
|
|
@ -67,6 +67,7 @@
|
||||||
#define PLUGIN_BUFFER_SIZE 0x100000
|
#define PLUGIN_BUFFER_SIZE 0x100000
|
||||||
|
|
||||||
#define HAVE_HEADPHONE_DETECTION
|
#define HAVE_HEADPHONE_DETECTION
|
||||||
|
#define HAVE_LINEOUT_DETECTION
|
||||||
|
|
||||||
/* KeyPad configuration for plugins */
|
/* KeyPad configuration for plugins */
|
||||||
#define CONFIG_KEYPAD XDUOO_X20_PAD
|
#define CONFIG_KEYPAD XDUOO_X20_PAD
|
||||||
|
@ -81,7 +82,6 @@
|
||||||
/* We have usb power and can detect usb but it is handled by Linux */
|
/* We have usb power and can detect usb but it is handled by Linux */
|
||||||
#define HAVE_USB_POWER
|
#define HAVE_USB_POWER
|
||||||
|
|
||||||
#define AUDIOHW_HAVE_SET_OUTPUT
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CONFIG_BATTERY_MEASURE PERCENTAGE_MEASURE
|
#define CONFIG_BATTERY_MEASURE PERCENTAGE_MEASURE
|
||||||
|
|
|
@ -85,9 +85,6 @@
|
||||||
/* Define this if a programmable hotkey is mapped */
|
/* Define this if a programmable hotkey is mapped */
|
||||||
#define HAVE_HOTKEY
|
#define HAVE_HOTKEY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef BOOTLOADER
|
#ifndef BOOTLOADER
|
||||||
/* define this if you have a real-time clock */
|
/* define this if you have a real-time clock */
|
||||||
#define CONFIG_RTC RTC_JZ4760
|
#define CONFIG_RTC RTC_JZ4760
|
||||||
|
|
|
@ -67,6 +67,7 @@
|
||||||
#define PLUGIN_BUFFER_SIZE 0x100000
|
#define PLUGIN_BUFFER_SIZE 0x100000
|
||||||
|
|
||||||
#define HAVE_HEADPHONE_DETECTION
|
#define HAVE_HEADPHONE_DETECTION
|
||||||
|
#define HAVE_LINEOUT_DETECTION
|
||||||
|
|
||||||
/* KeyPad configuration for plugins */
|
/* KeyPad configuration for plugins */
|
||||||
#define CONFIG_KEYPAD XDUOO_X3II_PAD
|
#define CONFIG_KEYPAD XDUOO_X3II_PAD
|
||||||
|
@ -81,7 +82,6 @@
|
||||||
/* We have usb power and can detect usb but it is handled by Linux */
|
/* We have usb power and can detect usb but it is handled by Linux */
|
||||||
#define HAVE_USB_POWER
|
#define HAVE_USB_POWER
|
||||||
|
|
||||||
#define AUDIOHW_HAVE_SET_OUTPUT
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
|
#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#ifndef __XDUOOLINUX_CODEC__
|
#ifndef __XDUOOLINUX_CODEC__
|
||||||
#define __XDUOOLINUX_CODEC__
|
#define __XDUOOLINUX_CODEC__
|
||||||
|
|
||||||
#define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP)
|
#define AUDIOHW_CAPS (LINEOUT_CAP | FILTER_ROLL_OFF_CAP)
|
||||||
AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -127, 0, -30)
|
AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -127, 0, -30)
|
||||||
AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 4, 0)
|
AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 4, 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void audiohw_mute(int mute);
|
void audiohw_mute(int mute);
|
||||||
void audiohw_set_output(void);
|
void xduoo_set_output(int ps);
|
||||||
|
int xduoo_get_outputs(void);
|
||||||
|
|
|
@ -41,6 +41,13 @@ bool dbg_hw_info(void)
|
||||||
line = 0;
|
line = 0;
|
||||||
|
|
||||||
lcd_putsf(0, line++, "pcm srate: %d", pcm_alsa_get_rate());
|
lcd_putsf(0, line++, "pcm srate: %d", pcm_alsa_get_rate());
|
||||||
|
#ifdef HAVE_HEADPHONE_DETECTION
|
||||||
|
lcd_putsf(0, line++, "hp: %d", headphones_inserted());
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_LINEOUT_DETECTION
|
||||||
|
lcd_putsf(0, line++, "lo: %d", lineout_inserted());
|
||||||
|
#endif
|
||||||
|
|
||||||
btn = button_read_device();
|
btn = button_read_device();
|
||||||
|
|
||||||
lcd_update();
|
lcd_update();
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* __________ __ ___.
|
* __________ __ ___.
|
||||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
* \/ \/ \/ \/ \/
|
* \/ \/ \/ \/ \/
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016 Amaury Pouly
|
* Copyright (C) 2016 Amaury Pouly
|
||||||
*
|
*
|
||||||
|
|
|
@ -166,25 +166,16 @@ int button_read_device(void)
|
||||||
|
|
||||||
bool headphones_inserted(void)
|
bool headphones_inserted(void)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int ps = xduoo_get_outputs();
|
||||||
const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
|
|
||||||
const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
|
|
||||||
#ifdef XDUOO_X20
|
|
||||||
const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sysfs_get_int(sysfs_lo_switch, &status);
|
return (ps == 2 || ps == 3);
|
||||||
if (status) return true;
|
}
|
||||||
|
|
||||||
sysfs_get_int(sysfs_hs_switch, &status);
|
bool lineout_inserted(void)
|
||||||
if (status) return true;
|
{
|
||||||
|
int ps = xduoo_get_outputs();
|
||||||
|
|
||||||
#ifdef XDUOO_X20
|
return (ps == 1);
|
||||||
sysfs_get_int(sysfs_bal_switch, &status);
|
|
||||||
if (status) return true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void button_close_device(void)
|
void button_close_device(void)
|
||||||
|
|
Loading…
Reference in a new issue