summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2006-11-23 19:21:15 +0000
committerMichael Sevakis <jethead71@rockbox.org>2006-11-23 19:21:15 +0000
commitab1861a3c2c06cf3edff7c42348d117f21235e48 (patch)
treee41eddf45f5348a2d954ac97984fbf7a7c61bd6c /firmware/target/coldfire
parent069c54d5d87378ccd73d84be2606ec2ab654bc21 (diff)
downloadrockbox-ab1861a3c2c06cf3edff7c42348d117f21235e48.tar.gz
rockbox-ab1861a3c2c06cf3edff7c42348d117f21235e48.zip
iRiver/iAudio: Added audio_set_recording gain and sound_default to plugin API. Simplified plugin recording by target/-ing some audio functions. UDA1380 records with WSPLL as a result.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11577 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/coldfire')
-rw-r--r--firmware/target/coldfire/iaudio/x5/audio-x5.c126
-rw-r--r--firmware/target/coldfire/iriver/audio-iriver.c148
-rw-r--r--firmware/target/coldfire/pcm-coldfire.c110
3 files changed, 285 insertions, 99 deletions
diff --git a/firmware/target/coldfire/iaudio/x5/audio-x5.c b/firmware/target/coldfire/iaudio/x5/audio-x5.c
new file mode 100644
index 0000000000..70ef78ff22
--- /dev/null
+++ b/firmware/target/coldfire/iaudio/x5/audio-x5.c
@@ -0,0 +1,126 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Michael Sevakis
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "system.h"
20#include "cpu.h"
21#include "audio.h"
22#include "tlv320.h"
23
24/**
25 * Note that microphone is mono, only left value is used
26 * See tlv320_set_recvol() for exact ranges.
27 *
28 * @param type 0=line-in (radio), 1=mic
29 *
30 */
31void audio_set_recording_gain(int left, int right, int type)
32{
33 //logf("rcmrec: t=%d l=%d r=%d", type, left, right);
34 tlv320_set_recvol(left, right, type);
35} /* audio_set_recording_gain */
36
37void audio_set_output_source(int source)
38{
39 unsigned long txsrc;
40
41 if ((unsigned)source >= AUDIO_NUM_SOURCES)
42 txsrc = (3 << 8); /* playback, PDOR3 */
43 else
44 txsrc = (4 << 8); /* recording, iis1RcvData */
45
46 IIS1CONFIG = (IIS1CONFIG & ~(7 << 8)) | txsrc;
47} /* audio_set_output_source */
48
49void audio_set_source(int source, unsigned flags)
50{
51 /* Prevent pops from unneeded switching */
52 static int last_source = AUDIO_SRC_PLAYBACK;
53 static bool last_recording = false;
54
55 bool recording = flags & SRCF_RECORDING;
56
57 switch (source)
58 {
59 default: /* playback - no recording */
60 source = AUDIO_SRC_PLAYBACK;
61 case AUDIO_SRC_PLAYBACK:
62 if (source != last_source)
63 {
64 tlv320_disable_recording();
65 tlv320_set_monitor(false);
66 /* Reset PDIR2 data flow */
67 DATAINCONTROL = (1 << 9);
68 }
69 break;
70
71 case AUDIO_SRC_MIC: /* recording only */
72 if (source != last_source)
73 {
74 tlv320_enable_recording(true); /* source mic */
75 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
76 DATAINCONTROL = (3 << 14) | (4 << 3);
77 }
78 break;
79
80 case AUDIO_SRC_LINEIN: /* recording only */
81 if (source != last_source)
82 {
83 tlv320_enable_recording(false); /* source line */
84 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
85 DATAINCONTROL = (3 << 14) | (4 << 3);
86 }
87 break;
88
89 case AUDIO_SRC_FMRADIO: /* recording and playback */
90 if (!recording)
91 tlv320_set_recvol(23, 23, AUDIO_GAIN_LINEIN);
92
93 /* I2S recording and analog playback */
94 if (source == last_source && recording == last_recording)
95 break;
96
97 last_recording = recording;
98
99 if (recording)
100 {
101 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
102 DATAINCONTROL = (3 << 14) | (4 << 3);
103 tlv320_enable_recording(false); /* source line */
104 }
105 else
106 {
107 tlv320_disable_recording();
108 tlv320_set_monitor(true); /* analog bypass */
109 /* Reset PDIR2 data flow */
110 DATAINCONTROL = (1 << 9);
111 }
112 break;
113 } /* end switch */
114
115 /* set line multiplexer */
116 if (source == AUDIO_SRC_FMRADIO)
117 and_l(~(1 << 29), &GPIO_OUT); /* FM radio */
118 else
119 or_l((1 << 29), &GPIO_OUT); /* Line In */
120
121 or_l((1 << 29), &GPIO_ENABLE);
122 or_l((1 << 29), &GPIO_FUNCTION);
123
124 last_source = source;
125} /* audio_set_source */
126
diff --git a/firmware/target/coldfire/iriver/audio-iriver.c b/firmware/target/coldfire/iriver/audio-iriver.c
new file mode 100644
index 0000000000..7a52ce1ff0
--- /dev/null
+++ b/firmware/target/coldfire/iriver/audio-iriver.c
@@ -0,0 +1,148 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Michael Sevakis
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "system.h"
20#include "cpu.h"
21#include "audio.h"
22#include "uda1380.h"
23
24/**
25 * Note that microphone is mono, only left value is used
26 * See uda1380_set_recvol() for exact ranges.
27 *
28 * @param type AUDIO_GAIN_MIC, AUDIO_GAIN_LINEIN
29 *
30 */
31void audio_set_recording_gain(int left, int right, int type)
32{
33 //logf("rcmrec: t=%d l=%d r=%d", type, left, right);
34 uda1380_set_recvol(left, right, type);
35} /* audio_set_recording_gain */
36
37void audio_set_output_source(int source)
38{
39 static const unsigned char txsrc_select[AUDIO_NUM_SOURCES+1] =
40 {
41 [AUDIO_SRC_PLAYBACK+1] = 3, /* PDOR3 */
42 [AUDIO_SRC_MIC+1] = 4, /* IIS1 RcvData */
43 [AUDIO_SRC_LINEIN+1] = 4, /* IIS1 RcvData */
44 [AUDIO_SRC_FMRADIO+1] = 4, /* IIS1 RcvData */
45 #ifdef HAVE_SPDIF_IN
46 [AUDIO_SRC_SPDIF+1] = 7, /* EBU1 RcvData */
47 #endif
48 };
49
50 if ((unsigned)source >= AUDIO_NUM_SOURCES)
51 source = AUDIO_SRC_PLAYBACK;
52
53 IIS2CONFIG = (IIS2CONFIG & ~(7 << 8)) | (txsrc_select[source+1] << 8);
54} /* audio_set_output_source */
55
56void audio_set_source(int source, unsigned flags)
57{
58 /* Prevent pops from unneeded switching */
59 static int last_source = AUDIO_SRC_PLAYBACK;
60 bool recording = flags & SRCF_RECORDING;
61
62 switch (source)
63 {
64 default: /* playback - no recording */
65 source = AUDIO_SRC_PLAYBACK;
66 case AUDIO_SRC_PLAYBACK:
67 if (source != last_source)
68 {
69 uda1380_disable_recording();
70 uda1380_set_monitor(false);
71 /* Reset PDIR2 data flow */
72 DATAINCONTROL = (1 << 9);
73 }
74 break;
75
76 case AUDIO_SRC_MIC: /* recording only */
77 if (source != last_source)
78 {
79 uda1380_enable_recording(true); /* source mic */
80 uda1380_set_monitor(true);
81 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
82 DATAINCONTROL = (3 << 14) | (4 << 3);
83 }
84 break;
85
86 case AUDIO_SRC_LINEIN: /* recording only */
87 if (source != last_source)
88 {
89 uda1380_enable_recording(false); /* source line */
90 uda1380_set_monitor(true);
91 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
92 DATAINCONTROL = (3 << 14) | (4 << 3);
93 }
94 break;
95
96#ifdef HAVE_SPDIF_IN
97 case AUDIO_SRC_SPDIF: /* recording only */
98 if (source != last_source)
99 {
100 uda1380_disable_recording();
101 uda1380_set_monitor(false);
102 /* Int. when 6 samples in FIFO, PDIR2 src = ebu1RcvData */
103 DATAINCONTROL = (3 << 14) | (7 << 3);
104 }
105 break;
106#endif /* HAVE_SPDIF_IN */
107
108 case AUDIO_SRC_FMRADIO: /* recording and playback */
109 if (recording)
110 {
111 /* Int. when 6 samples in FIFO, PDIR2 src = iis1RcvData */
112 DATAINCONTROL = (3 << 14) | (4 << 3);
113 }
114 else
115 {
116 uda1380_set_recvol(0, 0, AUDIO_GAIN_LINEIN);
117 /* Reset PDIR2 data flow */
118 DATAINCONTROL = (1 << 9);
119 }
120
121 if (source != last_source)
122 {
123 /* I2S recording and playback */
124 uda1380_enable_recording(false); /* source line */
125 uda1380_set_monitor(true);
126 }
127 break;
128 } /* end switch */
129
130 /* set line multiplexer */
131#if defined(IRIVER_H100_SERIES)
132 #define MUX_BIT (1 << 23)
133#elif defined(IRIVER_H300_SERIES)
134 #define MUX_BIT (1 << 30)
135#endif
136
137 if (source == AUDIO_SRC_FMRADIO)
138 or_l(MUX_BIT, &GPIO_OUT); /* FM radio */
139 else
140 and_l(~MUX_BIT, &GPIO_OUT); /* Line In */
141
142 or_l(MUX_BIT, &GPIO_ENABLE);
143 or_l(MUX_BIT, &GPIO_FUNCTION);
144
145 last_source = source;
146} /* audio_set_source */
147
148
diff --git a/firmware/target/coldfire/pcm-coldfire.c b/firmware/target/coldfire/pcm-coldfire.c
index a0d3b67f58..2936cf5621 100644
--- a/firmware/target/coldfire/pcm-coldfire.c
+++ b/firmware/target/coldfire/pcm-coldfire.c
@@ -57,9 +57,9 @@ static int play_peak_left, play_peak_right;
57static unsigned long *rec_peak_addr; 57static unsigned long *rec_peak_addr;
58static int rec_peak_left, rec_peak_right; 58static int rec_peak_left, rec_peak_right;
59 59
60#define IIS_DEFPARM ( (freq_ent[FPARM_CLOCKSEL] << 12) | \ 60#define IIS_DEFPARM(output) ( (freq_ent[FPARM_CLOCKSEL] << 12) | \
61 (pcm_txsrc_select[pcm_monitor+1] << 8) | \ 61 (output) | \
62 (4 << 2) ) /* 64 bit clocks / word clock */ 62 (4 << 2) ) /* 64 bit clocks / word clock */
63#define IIS_RESET 0x800 63#define IIS_RESET 0x800
64 64
65#ifdef IAUDIO_X5 65#ifdef IAUDIO_X5
@@ -128,80 +128,22 @@ void pcm_set_frequency(unsigned int frequency)
128 pcm_freq = hw_freq_sampr[index]; 128 pcm_freq = hw_freq_sampr[index];
129} /* pcm_set_frequency */ 129} /* pcm_set_frequency */
130 130
131/** monitoring/source selection **/
132static int pcm_monitor = AUDIO_SRC_PLAYBACK;
133
134static const unsigned char pcm_txsrc_select[AUDIO_NUM_SOURCES+1] =
135{
136 [AUDIO_SRC_PLAYBACK+1] = 3, /* PDOR3 */
137 [AUDIO_SRC_MIC+1] = 4, /* IIS1 RcvData */
138 [AUDIO_SRC_LINEIN+1] = 4, /* IIS1 RcvData */
139#ifdef HAVE_FMRADIO_IN
140 [AUDIO_SRC_FMRADIO+1] = 4, /* IIS1 RcvData */
141#endif
142#ifdef HAVE_SPDIF_IN
143 [AUDIO_SRC_SPDIF+1] = 7, /* EBU1 RcvData */
144#endif
145};
146
147static const unsigned short pcm_dataincontrol[AUDIO_NUM_SOURCES+1] =
148{
149 [AUDIO_SRC_PLAYBACK+1] = 0x0200, /* Reset PDIR2 data flow */
150 [AUDIO_SRC_MIC+1] = 0xc020, /* Int. when 6 samples in FIFO,
151 PDIR2 src = ebu1RcvData */
152 [AUDIO_SRC_LINEIN+1] = 0xc020, /* Int. when 6 samples in FIFO,
153 PDIR2 src = ebu1RcvData */
154#ifdef HAVE_FMRADIO_IN
155 [AUDIO_SRC_FMRADIO+1] = 0xc020, /* Int. when 6 samples in FIFO,
156 PDIR2 src = ebu1RcvData */
157#endif
158#ifdef HAVE_SPDIF_IN
159 [AUDIO_SRC_SPDIF+1] = 0xc038, /* Int. when 6 samples in FIFO,
160 PDIR2 src = ebu1RcvData */
161#endif
162};
163
164static int pcm_rec_src = AUDIO_SRC_PLAYBACK;
165
166void pcm_set_monitor(int monitor)
167{
168 if ((unsigned)monitor >= AUDIO_NUM_SOURCES)
169 monitor = AUDIO_SRC_PLAYBACK;
170 pcm_monitor = monitor;
171} /* pcm_set_monitor */
172
173void pcm_set_rec_source(int source)
174{
175 if ((unsigned)source >= AUDIO_NUM_SOURCES)
176 source = AUDIO_SRC_PLAYBACK;
177 pcm_rec_src = source;
178} /* pcm_set_rec_source */
179
180/* apply audio settings */ 131/* apply audio settings */
181void pcm_apply_settings(bool reset) 132void pcm_apply_settings(bool reset)
182{ 133{
183 static int last_pcm_freq = HW_SAMPR_DEFAULT; 134 static int last_pcm_freq = HW_SAMPR_DEFAULT;
184#if 0 135 unsigned long output = IIS_CONFIG & (7 << 8);
185 static int last_pcm_monitor = AUDIO_SRC_PLAYBACK;
186#endif
187 static int last_pcm_rec_src = AUDIO_SRC_PLAYBACK;
188 136
189 /* Playback must prevent pops and record monitoring won't work at all 137 /* Playback must prevent pops and record monitoring won't work at all if
190 adding IIS_RESET when setting IIS_CONFIG. Use a different method for 138 adding IIS_RESET when setting IIS_CONFIG. Use a different method for
191 each. */ 139 each. */
192 if (reset && (pcm_monitor != AUDIO_SRC_PLAYBACK)) 140 if (reset && output != (3 << 8))
193 { 141 {
194 /* Not playback - reset first */ 142 /* Not playback - reset first */
195 SET_IIS_CONFIG(IIS_RESET); 143 SET_IIS_CONFIG(IIS_RESET);
196 reset = false; 144 reset = false;
197 } 145 }
198 146
199 if (pcm_rec_src != last_pcm_rec_src)
200 {
201 last_pcm_rec_src = pcm_rec_src;
202 DATAINCONTROL = pcm_dataincontrol[pcm_rec_src+1];
203 }
204
205 if (pcm_freq != last_pcm_freq) 147 if (pcm_freq != last_pcm_freq)
206 { 148 {
207 last_pcm_freq = pcm_freq; 149 last_pcm_freq = pcm_freq;
@@ -209,7 +151,7 @@ void pcm_apply_settings(bool reset)
209 coldfire_set_pllcr_audio_bits(PLLCR_SET_AUDIO_BITS_DEFPARM); 151 coldfire_set_pllcr_audio_bits(PLLCR_SET_AUDIO_BITS_DEFPARM);
210 } 152 }
211 153
212 SET_IIS_CONFIG(IIS_DEFPARM | (reset ? IIS_RESET : 0)); 154 SET_IIS_CONFIG(IIS_DEFPARM(output) | (reset ? IIS_RESET : 0));
213} /* pcm_apply_settings */ 155} /* pcm_apply_settings */
214 156
215/** DMA **/ 157/** DMA **/
@@ -270,11 +212,10 @@ void pcm_init(void)
270 /* Reset the audio FIFO */ 212 /* Reset the audio FIFO */
271 SET_IIS_CONFIG(IIS_RESET); 213 SET_IIS_CONFIG(IIS_RESET);
272 214
273 pcm_set_frequency(-1); 215 pcm_set_frequency(HW_FREQ_DEFAULT);
274 pcm_set_monitor(-1);
275 216
276 /* Prevent pops (resets DAC to zero point) */ 217 /* Prevent pops (resets DAC to zero point) */
277 SET_IIS_CONFIG(IIS_DEFPARM | IIS_RESET); 218 SET_IIS_CONFIG(IIS_DEFPARM(3 << 8) | IIS_RESET);
278 219
279#if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT) 220#if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
280 spdif_init(); 221 spdif_init();
@@ -443,7 +384,7 @@ void DMA1(void)
443 logf("DMA1 err: 0x%x", res); 384 logf("DMA1 err: 0x%x", res);
444 } 385 }
445#ifdef HAVE_SPDIF_IN 386#ifdef HAVE_SPDIF_IN
446 else if (pcm_rec_src == AUDIO_SRC_SPDIF && 387 else if (DATAINCONTROL == 0xc038 &&
447 (INTERRUPTSTAT & 0x01c00000)) /* valnogood, symbolerr, parityerr */ 388 (INTERRUPTSTAT & 0x01c00000)) /* valnogood, symbolerr, parityerr */
448 { 389 {
449 INTERRUPTCLEAR = 0x03c00000; 390 INTERRUPTCLEAR = 0x03c00000;
@@ -685,32 +626,3 @@ peak_done:
685 if (right) 626 if (right)
686 *right = rec_peak_right; 627 *right = rec_peak_right;
687} /* pcm_calculate_rec_peaks */ 628} /* pcm_calculate_rec_peaks */
688
689/**
690 * Select VINL & VINR source: 0=Line-in, 1=FM Radio
691 */
692/* All use GPIO */
693#if defined(IAUDIO_X5)
694 #define REC_MUX_BIT (1 << 29)
695 #define REC_MUX_SET_LINE() or_l(REC_MUX_BIT, &GPIO_OUT)
696 #define REC_MUX_SET_FM() and_l(~REC_MUX_BIT, &GPIO_OUT)
697#else
698#if defined(IRIVER_H100_SERIES)
699 #define REC_MUX_BIT (1 << 23)
700#elif defined(IRIVER_H300_SERIES)
701 #define REC_MUX_BIT (1 << 30)
702#endif
703 #define REC_MUX_SET_LINE() and_l(~REC_MUX_BIT, &GPIO_OUT)
704 #define REC_MUX_SET_FM() or_l(REC_MUX_BIT, &GPIO_OUT)
705#endif
706
707void pcm_rec_mux(int source)
708{
709 if (source == 0)
710 REC_MUX_SET_LINE(); /* Line In */
711 else
712 REC_MUX_SET_FM(); /* FM radio */
713
714 or_l(REC_MUX_BIT, &GPIO_ENABLE);
715 or_l(REC_MUX_BIT, &GPIO_FUNCTION);
716} /* pcm_rec_mux */