summaryrefslogtreecommitdiff
path: root/firmware/drivers/audio/xduoolinux_codec.c
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2018-11-05 13:01:55 +0100
committerSolomon Peachy <pizza@shaftnet.org>2020-04-06 18:15:41 +0200
commit180cef835bf40d0081895773aaa637ac926bb0ac (patch)
tree48c380d76c0ea40931cb5e863b40fc5dfa1ecba4 /firmware/drivers/audio/xduoolinux_codec.c
parentced3a20aacf26642ccc3ffd136f64247c67e5769 (diff)
downloadrockbox-180cef835bf40d0081895773aaa637ac926bb0ac.tar.gz
rockbox-180cef835bf40d0081895773aaa637ac926bb0ac.zip
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
Diffstat (limited to 'firmware/drivers/audio/xduoolinux_codec.c')
-rw-r--r--firmware/drivers/audio/xduoolinux_codec.c122
1 files changed, 122 insertions, 0 deletions
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 *
11 * Copyright (c) 2018 Marcin Bukat
12 * Copyright (c) 2018 Roman Stolyarov
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#include "config.h"
25#include "audio.h"
26#include "audiohw.h"
27#include "system.h"
28#include "kernel.h"
29#include "panic.h"
30#include "sysfs.h"
31#include "alsa-controls.h"
32
33static int fd_hw;
34
35static void hw_open(void)
36{
37 fd_hw = open("/dev/snd/controlC0", O_RDWR);
38 if(fd_hw < 0)
39 panicf("Cannot open '/dev/snd/controlC0'");
40}
41
42static void hw_close(void)
43{
44 close(fd_hw);
45}
46
47void audiohw_preinit(void)
48{
49 alsa_controls_init();
50 hw_open();
51}
52
53void audiohw_postinit(void)
54{
55 long int ps = 2; // headset
56 int status = 0;
57
58 const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
59 const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
60#ifdef XDUOO_X20
61 const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
62#endif
63
64#if defined(XDUOO_X3II)
65 alsa_controls_set_bool("AK4490 Soft Mute", true);
66#endif
67
68 sysfs_get_int(sysfs_lo_switch, &status);
69 if (status) ps = 1; // lineout
70
71 sysfs_get_int(sysfs_hs_switch, &status);
72 if (status) ps = 2; // headset
73
74#ifdef XDUOO_X20
75 sysfs_get_int(sysfs_bal_switch, &status);
76 if (status) ps = 3; // balance
77#endif
78
79 /* Output port switch */
80 alsa_controls_set_ints("Output Port Switch", 1, &ps);
81
82#if defined(XDUOO_X3II)
83 alsa_controls_set_bool("AK4490 Soft Mute", false);
84#endif
85}
86
87void audiohw_close(void)
88{
89 hw_close();
90 alsa_controls_close();
91}
92
93void audiohw_set_frequency(int fsel)
94{
95 (void)fsel;
96}
97
98void audiohw_set_volume(int vol_l, int vol_r)
99{
100 long int vol_l_hw = -vol_l/5;
101 long int vol_r_hw = -vol_r/5;
102
103 alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw);
104 alsa_controls_set_ints("Right Playback Volume", 1, &vol_r_hw);
105}
106
107void audiohw_set_filter_roll_off(int value)
108{
109 /* 0 = fast (sharp);
110 1 = slow;
111 2 = fast2
112 3 = slow2
113 4 = NOS ? */
114 long int value_hw = value;
115#if defined(XDUOO_X3II)
116 alsa_controls_set_ints("AK4490 Digital Filter", 1, &value_hw);
117#elif defined(XDUOO_X20)
118 alsa_controls_set_ints("ES9018_K2M Digital Filter", 1, &value_hw);
119#else
120 (void)value;
121#endif
122}