diff options
Diffstat (limited to 'firmware/export/ak4376.h')
-rw-r--r-- | firmware/export/ak4376.h | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/firmware/export/ak4376.h b/firmware/export/ak4376.h new file mode 100644 index 0000000000..eb06755e92 --- /dev/null +++ b/firmware/export/ak4376.h | |||
@@ -0,0 +1,152 @@ | |||
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 | #ifndef __AK4376_H__ | ||
23 | #define __AK4376_H__ | ||
24 | |||
25 | #define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP|POWER_MODE_CAP) | ||
26 | #define AUDIOHW_HAVE_SHORT2_ROLL_OFF | ||
27 | |||
28 | #define AK4376_MIN_VOLUME (-890) | ||
29 | #define AK4376_MAX_VOLUME 150 | ||
30 | |||
31 | AUDIOHW_SETTING(VOLUME, "dB", 1, 5, AK4376_MIN_VOLUME, AK4376_MAX_VOLUME, -200) | ||
32 | AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 3, 0) | ||
33 | AUDIOHW_SETTING(POWER_MODE, "", 0, 1, 0, 1, 0) | ||
34 | |||
35 | /* Register addresses */ | ||
36 | #define AK4376_REG_PWR1 0x00 | ||
37 | #define AK4376_REG_PWR2 0x01 | ||
38 | #define AK4376_REG_PWR3 0x02 | ||
39 | #define AK4376_REG_PWR4 0x03 | ||
40 | #define AK4376_REG_OUTPUT_MODE 0x04 | ||
41 | #define AK4376_REG_CLOCK_MODE 0x05 | ||
42 | #define AK4376_REG_FILTER 0x06 | ||
43 | #define AK4376_REG_MIXER 0x07 | ||
44 | #define AK4376_REG_LCH_VOLUME 0x0b | ||
45 | #define AK4376_REG_RCH_VOLUME 0x0c | ||
46 | #define AK4376_REG_AMP_VOLUME 0x0d | ||
47 | #define AK4376_REG_PLL_CLK_SRC 0x0e | ||
48 | #define AK4376_REG_PLL_REF_DIV1 0x0f | ||
49 | #define AK4376_REG_PLL_REF_DIV2 0x10 | ||
50 | #define AK4376_REG_PLL_FB_DIV1 0x11 | ||
51 | #define AK4376_REG_PLL_FB_DIV2 0x12 | ||
52 | #define AK4376_REG_DAC_CLK_SRC 0x13 | ||
53 | #define AK4376_REG_DAC_CLK_DIV 0x14 | ||
54 | #define AK4376_REG_AUDIO_IF_FMT 0x15 | ||
55 | #define AK4376_REG_CHIP_ID 0x21 | ||
56 | #define AK4376_REG_MODE_CTRL 0x24 | ||
57 | #define AK4376_REG_ADJUST1 0x26 | ||
58 | #define AK4376_REG_ADJUST2 0x2a | ||
59 | #define AK4376_NUM_REGS 0x2b | ||
60 | |||
61 | /* Mixer controls, simply OR them together. | ||
62 | * LCH = add LCH signal to output | ||
63 | * RCH = add RCH signal to output | ||
64 | * HALF = multiply output by 1/2 | ||
65 | * INVERT = invert the output after everything else | ||
66 | */ | ||
67 | #define AK4376_MIX_MUTE 0 | ||
68 | #define AK4376_MIX_LCH 1 | ||
69 | #define AK4376_MIX_RCH 2 | ||
70 | #define AK4376_MIX_HALF 4 | ||
71 | #define AK4376_MIX_INVERT 8 | ||
72 | |||
73 | /* Min/max digital volumes in units of dB/10 */ | ||
74 | #define AK4376_DIG_VOLUME_MIN (-120) | ||
75 | #define AK4376_DIG_VOLUME_MAX 30 | ||
76 | #define AK4376_DIG_VOLUME_STEP 5 | ||
77 | #define AK4376_DIG_VOLUME_MUTE (AK4376_DIG_VOLUME_MIN - 1) | ||
78 | |||
79 | /* Min/max headphone amp volumes in units of dB/10 */ | ||
80 | #define AK4376_AMP_VOLUME_MIN (-200) | ||
81 | #define AK4376_AMP_VOLUME_MAX 60 | ||
82 | #define AK4376_AMP_VOLUME_STEP 20 | ||
83 | #define AK4376_AMP_VOLUME_MUTE (AK4376_AMP_VOLUME_MIN - 1) | ||
84 | |||
85 | /* Digital filters */ | ||
86 | #define AK4376_FILTER_SHARP 0 | ||
87 | #define AK4376_FILTER_SLOW 1 | ||
88 | #define AK4376_FILTER_SHORT_SHARP 2 | ||
89 | #define AK4376_FILTER_SHORT_SLOW 3 | ||
90 | |||
91 | /* Frequency selection */ | ||
92 | #define AK4376_FS_8 0 | ||
93 | #define AK4376_FS_11 1 | ||
94 | #define AK4376_FS_12 2 | ||
95 | #define AK4376_FS_16 4 | ||
96 | #define AK4376_FS_22 5 | ||
97 | #define AK4376_FS_24 6 | ||
98 | #define AK4376_FS_32 8 | ||
99 | #define AK4376_FS_44 9 | ||
100 | #define AK4376_FS_48 10 | ||
101 | #define AK4376_FS_64 12 | ||
102 | #define AK4376_FS_88 13 | ||
103 | #define AK4376_FS_96 14 | ||
104 | #define AK4376_FS_176 17 | ||
105 | #define AK4376_FS_192 18 | ||
106 | |||
107 | /* Functions to power on / off the DAC which should be called from | ||
108 | * the target's audiohw_init() / audiohw_close() implementation. | ||
109 | */ | ||
110 | extern void ak4376_init(void); | ||
111 | extern void ak4376_close(void); | ||
112 | |||
113 | /* Register read/write. Cached to avoid redundant reads/writes. */ | ||
114 | extern void ak4376_write(int reg, int value); | ||
115 | extern int ak4376_read(int reg); | ||
116 | |||
117 | /* Target-specific function to set the PDN pin level. */ | ||
118 | extern void ak4376_set_pdn_pin(int level); | ||
119 | |||
120 | /* Target-specific function to control the external master clock frequency. | ||
121 | * This is called by the ak4376's audiohw implementation when switching to | ||
122 | * or from a frequency that is configured to use this clock source. | ||
123 | * | ||
124 | * - hw_freq is the new sample rate -- one of the HW_FREQ_XX constants. | ||
125 | * - enabled is true if clock should be output, false if not. | ||
126 | * | ||
127 | * The return value is the master clock rate as a multiple of the sampling | ||
128 | * frequency. The allowed multiples depend on the sampling frequency, shown | ||
129 | * in the table below. | ||
130 | * | ||
131 | * +-----------+------------------------+ | ||
132 | * | frequency | master clock rate | | ||
133 | * +-----------+------------------------+ | ||
134 | * | 8 - 24 | 256fs / 512fs / 1024fs | | ||
135 | * | 32 - 48 | 256fs / 512fs | | ||
136 | * | 64 - 96 | 256fs | | ||
137 | * | 128 - 192 | 128fs | | ||
138 | * +-----------+------------------------+ | ||
139 | * | ||
140 | * For example, at 48 KHz you could return either 256 or 512 depending on | ||
141 | * the rate you decided to actually use. | ||
142 | * | ||
143 | * You need to return a valid master multiplier for supported frequencies | ||
144 | * even when enabled = false, since the driver needs to know the multiplier | ||
145 | * _before_ enabling the clock. | ||
146 | * | ||
147 | * For unsupported frequencies you don't need to return a valid master | ||
148 | * multiplier, because the DAC doesn't need the return value in such cases. | ||
149 | */ | ||
150 | extern int ak4376_set_mclk_freq(int hw_freq, bool enabled); | ||
151 | |||
152 | #endif /* __AK4376_H__ */ | ||