summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/audioout-imx233.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx233/audioout-imx233.c')
-rw-r--r--firmware/target/arm/imx233/audioout-imx233.c42
1 files changed, 37 insertions, 5 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}