From 180cef835bf40d0081895773aaa637ac926bb0ac Mon Sep 17 00:00:00 2001 From: Marcin Bukat Date: Mon, 5 Nov 2018 13:01:55 +0100 Subject: xDuoo X3II and X20 port Provided by Roman Stolyarov Integration, Refactoring, and Upstreaming by Solomon Peachy X3II confirmed working by forum tester, X20 is nearly identical. This includes bootloader, main firmware, and the flash image patcher. Eventual Todo: * Further refactor AGPTek Rocker & xduoo hiby bootloaders * Further refactor AGPTek Rocker & xduoo hosted platform code Change-Id: I34a674051d368efcc75d1d18c725971fe46c3eee --- firmware/drivers/audio/xduoolinux_codec.c | 122 ++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 firmware/drivers/audio/xduoolinux_codec.c (limited to 'firmware/drivers/audio/xduoolinux_codec.c') diff --git a/firmware/drivers/audio/xduoolinux_codec.c b/firmware/drivers/audio/xduoolinux_codec.c new file mode 100644 index 0000000000..5db4902e5f --- /dev/null +++ b/firmware/drivers/audio/xduoolinux_codec.c @@ -0,0 +1,122 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ + +#include "config.h" +#include "audio.h" +#include "audiohw.h" +#include "system.h" +#include "kernel.h" +#include "panic.h" +#include "sysfs.h" +#include "alsa-controls.h" + +static int fd_hw; + +static void hw_open(void) +{ + fd_hw = open("/dev/snd/controlC0", O_RDWR); + if(fd_hw < 0) + panicf("Cannot open '/dev/snd/controlC0'"); +} + +static void hw_close(void) +{ + close(fd_hw); +} + +void audiohw_preinit(void) +{ + alsa_controls_init(); + hw_open(); +} + +void audiohw_postinit(void) +{ + long int ps = 2; // headset + int status = 0; + + 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 + +#if defined(XDUOO_X3II) + alsa_controls_set_bool("AK4490 Soft Mute", true); +#endif + + sysfs_get_int(sysfs_lo_switch, &status); + if (status) ps = 1; // lineout + + sysfs_get_int(sysfs_hs_switch, &status); + if (status) ps = 2; // headset + +#ifdef XDUOO_X20 + sysfs_get_int(sysfs_bal_switch, &status); + if (status) ps = 3; // balance +#endif + + /* Output port switch */ + alsa_controls_set_ints("Output Port Switch", 1, &ps); + +#if defined(XDUOO_X3II) + alsa_controls_set_bool("AK4490 Soft Mute", false); +#endif +} + +void audiohw_close(void) +{ + hw_close(); + alsa_controls_close(); +} + +void audiohw_set_frequency(int fsel) +{ + (void)fsel; +} + +void audiohw_set_volume(int vol_l, int vol_r) +{ + long int vol_l_hw = -vol_l/5; + long int vol_r_hw = -vol_r/5; + + alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw); + alsa_controls_set_ints("Right Playback Volume", 1, &vol_r_hw); +} + +void audiohw_set_filter_roll_off(int value) +{ + /* 0 = fast (sharp); + 1 = slow; + 2 = fast2 + 3 = slow2 + 4 = NOS ? */ + long int value_hw = value; +#if defined(XDUOO_X3II) + alsa_controls_set_ints("AK4490 Digital Filter", 1, &value_hw); +#elif defined(XDUOO_X20) + alsa_controls_set_ints("ES9018_K2M Digital Filter", 1, &value_hw); +#else + (void)value; +#endif +} -- cgit v1.2.3