summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-02-27 22:08:58 +0000
committerAidan MacDonald <amachronic@protonmail.com>2021-03-28 00:01:37 +0000
commit3ec66893e377b088c1284d2d23adb2aeea6d7965 (patch)
treeb647717f83ad56b15dc42cfdef5d04d68cd9bd6b /firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
parent83fcbedc65f4b9ae7e491ecf6f07c0af4b245f74 (diff)
downloadrockbox-3ec66893e377b088c1284d2d23adb2aeea6d7965.tar.gz
rockbox-3ec66893e377b088c1284d2d23adb2aeea6d7965.zip
New port: FiiO M3K on bare metal
Change-Id: I7517e7d5459e129dcfc9465c6fbd708619888fbe
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
new file mode 100644
index 0000000000..2f43809523
--- /dev/null
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
@@ -0,0 +1,81 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "audiohw.h"
23#include "system.h"
24#include "pcm_sampr.h"
25#include "logf.h"
26#include "aic-x1000.h"
27#include "i2c-x1000.h"
28#include "gpio-x1000.h"
29#include "x1000/aic.h"
30#include "x1000/cpm.h"
31
32void audiohw_init(void)
33{
34 /* Configure AIC for I2S operation */
35 jz_writef(CPM_CLKGR, AIC(0));
36 gpio_config(GPIO_B, 0x1f, GPIO_DEVICE(1));
37 jz_writef(AIC_I2SCR, STPBK(1));
38
39 /* Operate as I2S master, use external codec */
40 jz_writef(AIC_CFG, AUSEL(1), ICDC(0), BCKD(1), SYNCD(1), LSMP(1));
41 jz_writef(AIC_I2SCR, ESCLK(1), AMSL(0));
42
43 /* Stereo audio, packed 16 bit samples */
44 jz_writef(AIC_CCR, PACK16(1), CHANNEL(1), OSS(1));
45
46 /* Initialize DAC */
47 i2c_x1000_set_freq(AK4376_BUS, I2C_FREQ_400K);
48 ak4376_init();
49}
50
51void audiohw_postinit(void)
52{
53}
54
55void audiohw_close(void)
56{
57 ak4376_close();
58}
59
60void ak4376_set_pdn_pin(int level)
61{
62 gpio_config(GPIO_A, 1 << 16, GPIO_OUTPUT(level ? 1 : 0));
63}
64
65int ak4376_set_mclk_freq(int hw_freq, bool enabled)
66{
67 /* Get the multiplier */
68 int freq = hw_freq_sampr[hw_freq];
69 int mult = freq >= SAMPR_176 ? 128 : 256;
70
71 if(enabled) {
72 /* Set the new frequency; clock is enabled afterward */
73 if(aic_i2s_set_mclk(X1000_CLK_SCLK_A, freq, mult))
74 logf("WARNING: unachievable audio rate %d x %d!?", freq, mult);
75 } else {
76 /* Shut off the clock */
77 jz_writef(AIC_I2SCR, STPBK(1));
78 }
79
80 return mult;
81}