summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx233')
-rw-r--r--firmware/target/arm/imx233/audioout-imx233.c42
-rw-r--r--firmware/target/arm/imx233/audioout-imx233.h3
-rw-r--r--firmware/target/arm/imx233/sansa-fuzeplus/audio-fuzeplus.c4
3 files changed, 40 insertions, 9 deletions
diff --git a/firmware/target/arm/imx233/audioout-imx233.c b/firmware/target/arm/imx233/audioout-imx233.c
index 0a48a909e8..e03de5c861 100644
--- a/firmware/target/arm/imx233/audioout-imx233.c
+++ b/firmware/target/arm/imx233/audioout-imx233.c
@@ -23,6 +23,8 @@
23#include "rtc-imx233.h" 23#include "rtc-imx233.h"
24#include "pcm_sampr.h" 24#include "pcm_sampr.h"
25 25
26static int hp_vol_l, hp_vol_r;
27
26void imx233_audioout_preinit(void) 28void imx233_audioout_preinit(void)
27{ 29{
28 /* Enable AUDIOOUT block */ 30 /* Enable AUDIOOUT block */
@@ -78,8 +80,10 @@ void imx233_audioout_close(void)
78 /* will also gate off the module */ 80 /* will also gate off the module */
79 __REG_CLR(HW_AUDIOOUT_CTRL) = HW_AUDIOOUT_CTRL__RUN; 81 __REG_CLR(HW_AUDIOOUT_CTRL) = HW_AUDIOOUT_CTRL__RUN;
80} 82}
81/* volume in half dB */ 83
82void imx233_audioout_set_dac_vol(int vol_l, int vol_r) 84/* volume in half dB
85 * don't check input values */
86static void set_dac_vol(int vol_l, int vol_r)
83{ 87{
84 /* minimum is -100dB and max is 0dB */ 88 /* minimum is -100dB and max is 0dB */
85 vol_l = MAX(-200, MIN(vol_l, 0)); 89 vol_l = MAX(-200, MIN(vol_l, 0));
@@ -92,14 +96,16 @@ void imx233_audioout_set_dac_vol(int vol_l, int vol_r)
92 HW_AUDIOOUT_DACVOLUME__EN_ZCD; 96 HW_AUDIOOUT_DACVOLUME__EN_ZCD;
93} 97}
94 98
95void imx233_audioout_set_hp_vol(int vol_l, int vol_r) 99/* volume in half dB
100 * don't check input values */
101static void set_hp_vol(int vol_l, int vol_r)
96{ 102{
97 uint32_t select = (HW_AUDIOOUT_HPVOL & HW_AUDIOOUT_HPVOL__SELECT); 103 uint32_t select = (HW_AUDIOOUT_HPVOL & HW_AUDIOOUT_HPVOL__SELECT);
98 /* minimum is -57.5dB and max is 6dB in DAC mode 104 /* minimum is -57.5dB and max is 6dB in DAC mode
99 * and -51.5dB / 12dB in Line1 mode */ 105 * and -51.5dB / 12dB in Line1 mode */
100 int min = select ? -103 : -115; 106 int min = select ? -103 : -115;
101 int max = select ? 24 : 12; 107 int max = select ? 24 : 12;
102 108
103 vol_l = MAX(min, MIN(vol_l, max)); 109 vol_l = MAX(min, MIN(vol_l, max));
104 vol_r = MAX(min, MIN(vol_r, max)); 110 vol_r = MAX(min, MIN(vol_r, max));
105 /* unmute, enable zero cross and set volume. Keep select value. */ 111 /* unmute, enable zero cross and set volume. Keep select value. */
@@ -110,6 +116,30 @@ void imx233_audioout_set_hp_vol(int vol_l, int vol_r)
110 HW_AUDIOOUT_HPVOL__EN_MSTR_ZCD; 116 HW_AUDIOOUT_HPVOL__EN_MSTR_ZCD;
111} 117}
112 118
119static void apply_volume(void)
120{
121 /* Two cases: line1 and dac */
122 if(HW_AUDIOOUT_HPVOL & HW_AUDIOOUT_HPVOL__SELECT)
123 {
124 /* In line1 mode, the HP is the only way to adjust the volume */
125 set_hp_vol(hp_vol_l, hp_vol_r);
126 }
127 else
128 {
129 /* In DAC mode we can use both the HP and the DAC volume.
130 * Use the DAC for volume <0 and HP for volume >0 */
131 set_dac_vol(MIN(0, hp_vol_l), MIN(0, hp_vol_r));
132 set_hp_vol(MAX(0, hp_vol_l), MAX(0, hp_vol_r));
133 }
134}
135
136void imx233_audioout_set_hp_vol(int vol_l, int vol_r)
137{
138 hp_vol_l = vol_l;
139 hp_vol_r = vol_r;
140 apply_volume();
141}
142
113void imx233_audioout_set_freq(int fsel) 143void imx233_audioout_set_freq(int fsel)
114{ 144{
115 static struct 145 static struct
@@ -170,10 +200,12 @@ void imx233_audioout_set_freq(int fsel)
170} 200}
171 201
172/* select between DAC and Line1 */ 202/* select between DAC and Line1 */
173void imx233_audiout_select_hp_input(bool line1) 203void imx233_audioout_select_hp_input(bool line1)
174{ 204{
175 if(line1) 205 if(line1)
176 __REG_SET(HW_AUDIOOUT_HPVOL) = HW_AUDIOOUT_HPVOL__SELECT; 206 __REG_SET(HW_AUDIOOUT_HPVOL) = HW_AUDIOOUT_HPVOL__SELECT;
177 else 207 else
178 __REG_CLR(HW_AUDIOOUT_HPVOL) = HW_AUDIOOUT_HPVOL__SELECT; 208 __REG_CLR(HW_AUDIOOUT_HPVOL) = HW_AUDIOOUT_HPVOL__SELECT;
209 /* reapply volume setting */
210 apply_volume();
179} 211}
diff --git a/firmware/target/arm/imx233/audioout-imx233.h b/firmware/target/arm/imx233/audioout-imx233.h
index cd997e7d31..acfb56138f 100644
--- a/firmware/target/arm/imx233/audioout-imx233.h
+++ b/firmware/target/arm/imx233/audioout-imx233.h
@@ -112,11 +112,10 @@ void imx233_audioout_preinit(void);
112void imx233_audioout_postinit(void); 112void imx233_audioout_postinit(void);
113void imx233_audioout_close(void); 113void imx233_audioout_close(void);
114/* volume in half dB */ 114/* volume in half dB */
115void imx233_audioout_set_dac_vol(int vol_l, int vol_r);
116void imx233_audioout_set_hp_vol(int vol_l, int vol_r); 115void imx233_audioout_set_hp_vol(int vol_l, int vol_r);
117/* frequency index, NOT the frequency itself */ 116/* frequency index, NOT the frequency itself */
118void imx233_audioout_set_freq(int fsel); 117void imx233_audioout_set_freq(int fsel);
119/* select between DAC and Line1 */ 118/* select between DAC and Line1 */
120void imx233_audiout_select_hp_input(bool line1); 119void imx233_audioout_select_hp_input(bool line1);
121 120
122#endif /* __audioout_imx233__ */ 121#endif /* __audioout_imx233__ */
diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/audio-fuzeplus.c b/firmware/target/arm/imx233/sansa-fuzeplus/audio-fuzeplus.c
index abdcda90cb..57a3efd642 100644
--- a/firmware/target/arm/imx233/sansa-fuzeplus/audio-fuzeplus.c
+++ b/firmware/target/arm/imx233/sansa-fuzeplus/audio-fuzeplus.c
@@ -32,9 +32,9 @@ static int output_source = AUDIO_SRC_PLAYBACK;
32static void select_audio_path(void) 32static void select_audio_path(void)
33{ 33{
34 if(input_source == AUDIO_SRC_PLAYBACK) 34 if(input_source == AUDIO_SRC_PLAYBACK)
35 imx233_audiout_select_hp_input(false); 35 imx233_audioout_select_hp_input(false);
36 else 36 else
37 imx233_audiout_select_hp_input(true); 37 imx233_audioout_select_hp_input(true);
38} 38}
39 39
40void audio_input_mux(int source, unsigned flags) 40void audio_input_mux(int source, unsigned flags)