summaryrefslogtreecommitdiff
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
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
-rw-r--r--apps/plugin.c9
-rw-r--r--apps/plugin.h10
-rw-r--r--apps/recorder/recording.c114
-rw-r--r--apps/recorder/recording.h9
-rw-r--r--firmware/SOURCES3
-rw-r--r--firmware/drivers/uda1380.c9
-rw-r--r--firmware/export/audio.h13
-rw-r--r--firmware/export/pcm_record.h4
-rw-r--r--firmware/pcm_playback.c5
-rw-r--r--firmware/pcm_record.c33
-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
13 files changed, 330 insertions, 263 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index f5e6cebf65..21930ee3a8 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -456,22 +456,25 @@ static const struct plugin_api rockbox_api = {
456#ifdef HAVE_RECORDING 456#ifdef HAVE_RECORDING
457 &rec_freq_sampr[0], 457 &rec_freq_sampr[0],
458#ifndef SIMULATOR 458#ifndef SIMULATOR
459 pcm_set_monitor,
460 pcm_set_rec_source,
461 pcm_init_recording, 459 pcm_init_recording,
462 pcm_close_recording, 460 pcm_close_recording,
463 pcm_record_data, 461 pcm_record_data,
464 pcm_stop_recording, 462 pcm_stop_recording,
465 pcm_calculate_rec_peaks, 463 pcm_calculate_rec_peaks,
464 audio_set_recording_gain,
465 audio_set_output_source,
466 rec_set_source, 466 rec_set_source,
467#endif 467#endif
468#endif /* HAVE_RECORDING */ 468#endif /* HAVE_RECORDING */
469#endif /* CONFIG_CODEC == SWCODEC */ 469#endif /* CONFIG_CODEC == SWCODEC */
470 470
471
472#ifdef IRAM_STEAL 471#ifdef IRAM_STEAL
473 plugin_iram_init, 472 plugin_iram_init,
474#endif 473#endif
474
475#if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) && !defined(SIMULATOR)
476 sound_default,
477#endif
475}; 478};
476 479
477int plugin_load(const char* plugin, void* parameter) 480int plugin_load(const char* plugin, void* parameter)
diff --git a/apps/plugin.h b/apps/plugin.h
index 339afe93a8..ba0fdf0c29 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -568,25 +568,27 @@ struct plugin_api {
568#ifdef HAVE_RECORDING 568#ifdef HAVE_RECORDING
569 const unsigned long *rec_freq_sampr; 569 const unsigned long *rec_freq_sampr;
570#ifndef SIMULATOR 570#ifndef SIMULATOR
571 void (*pcm_set_monitor)(int monitor);
572 void (*pcm_set_rec_source)(int source);
573 void (*pcm_init_recording)(void); 571 void (*pcm_init_recording)(void);
574 void (*pcm_close_recording)(void); 572 void (*pcm_close_recording)(void);
575 void (*pcm_record_data)(pcm_more_callback_type more_ready, 573 void (*pcm_record_data)(pcm_more_callback_type more_ready,
576 unsigned char *start, size_t size); 574 unsigned char *start, size_t size);
577 void (*pcm_stop_recording)(void); 575 void (*pcm_stop_recording)(void);
578 void (*pcm_calculate_rec_peaks)(int *left, int *right); 576 void (*pcm_calculate_rec_peaks)(int *left, int *right);
577 void (*audio_set_recording_gain)(int left, int right, int type);
578 void (*audio_set_output_source)(int monitor);
579 void (*rec_set_source)(int source, unsigned flags); 579 void (*rec_set_source)(int source, unsigned flags);
580#endif 580#endif
581#endif /* HAVE_RECORDING */ 581#endif /* HAVE_RECORDING */
582#endif /* CONFIG_CODEC == SWCODEC */ 582#endif /* CONFIG_CODEC == SWCODEC */
583 583
584
585
586#ifdef IRAM_STEAL 584#ifdef IRAM_STEAL
587 void (*plugin_iram_init)(char *iramstart, char *iramcopy, size_t iram_size, 585 void (*plugin_iram_init)(char *iramstart, char *iramcopy, size_t iram_size,
588 char *iedata, size_t iedata_size); 586 char *iedata, size_t iedata_size);
589#endif 587#endif
588
589#if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) && !defined(SIMULATOR)
590 int (*sound_default)(int setting);
591#endif
590}; 592};
591 593
592/* plugin header */ 594/* plugin header */
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index 73d0425f24..6750acc691 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -38,12 +38,6 @@
38#include "spdif.h" 38#include "spdif.h"
39#endif 39#endif
40#endif /* CONFIG_CODEC == SWCODEC */ 40#endif /* CONFIG_CODEC == SWCODEC */
41#ifdef HAVE_UDA1380
42#include "uda1380.h"
43#endif
44#ifdef HAVE_TLV320
45#include "tlv320.h"
46#endif
47#include "recording.h" 41#include "recording.h"
48#include "mp3_playback.h" 42#include "mp3_playback.h"
49#include "mas.h" 43#include "mas.h"
@@ -580,36 +574,14 @@ static void rec_boost(bool state)
580 * The order of setting monitoring may need tweaking dependent upon the 574 * The order of setting monitoring may need tweaking dependent upon the
581 * selected source to get the smoothest transition. 575 * selected source to get the smoothest transition.
582 */ 576 */
583#if defined(HAVE_UDA1380)
584#define ac_disable_recording uda1380_disable_recording
585#define ac_enable_recording uda1380_enable_recording
586#define ac_set_monitor uda1380_set_monitor
587#elif defined(HAVE_TLV320)
588#define ac_disable_recording tlv320_disable_recording
589#define ac_enable_recording tlv320_enable_recording
590#define ac_set_monitor tlv320_set_monitor
591#endif
592
593void rec_set_source(int source, unsigned flags) 577void rec_set_source(int source, unsigned flags)
594{ 578{
595 /* Prevent pops from unneeded switching */
596 static int last_source = AUDIO_SRC_PLAYBACK;
597#ifdef HAVE_TLV320
598 static bool last_recording = false;
599#endif
600
601 bool recording = flags & SRCF_RECORDING;
602 /* Default to peakmeter record. */
603 bool pm_playback = false;
604 bool pm_enabled = true;
605
606 /** Do power up/down of associated device(s) **/ 579 /** Do power up/down of associated device(s) **/
607 580
608 /** SPDIF **/ 581 /** SPDIF **/
609#ifdef HAVE_SPDIF_IN 582#ifdef HAVE_SPDIF_IN
610 /* Always boost for SPDIF */ 583 /* Always boost for SPDIF */
611 if ((source == AUDIO_SRC_SPDIF) != (source == last_source)) 584 rec_boost(source == AUDIO_SRC_SPDIF);
612 rec_boost(source == AUDIO_SRC_SPDIF);
613#endif /* HAVE_SPDIF_IN */ 585#endif /* HAVE_SPDIF_IN */
614 586
615#ifdef HAVE_SPDIF_POWER 587#ifdef HAVE_SPDIF_POWER
@@ -639,87 +611,11 @@ void rec_set_source(int source, unsigned flags)
639 radio_start(); 611 radio_start();
640#endif 612#endif
641 613
642 switch (source) 614 /* set hardware inputs */
643 { 615 audio_set_source(source, flags);
644 default: /* playback - no recording */
645 source = AUDIO_SRC_PLAYBACK;
646 case AUDIO_SRC_PLAYBACK:
647 pm_playback = true;
648 if (source == last_source)
649 break;
650 ac_disable_recording();
651 ac_set_monitor(false);
652 pcm_rec_mux(0); /* line in */
653 break;
654
655 case AUDIO_SRC_MIC: /* recording only */
656 if (source == last_source)
657 break;
658 ac_enable_recording(true); /* source mic */
659 pcm_rec_mux(0); /* line in */
660 break;
661
662 case AUDIO_SRC_LINEIN: /* recording only */
663 if (source == last_source)
664 break;
665 pcm_rec_mux(0); /* line in */
666 ac_enable_recording(false); /* source line */
667 break;
668 616
669#ifdef HAVE_SPDIF_IN 617 peak_meter_playback((flags & SRCF_RECORDING) == 0);
670 case AUDIO_SRC_SPDIF: /* recording only */ 618 peak_meter_enabled = true;
671 if (source == last_source)
672 break;
673 ac_disable_recording();
674 break;
675#endif /* HAVE_SPDIF_IN */
676
677#ifdef HAVE_FMRADIO_IN
678 case AUDIO_SRC_FMRADIO: /* recording and playback */
679 if (!recording)
680 {
681 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
682 sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN);
683 pm_playback = true;
684 pm_enabled = false;
685 }
686
687 pcm_rec_mux(1); /* fm radio */
688
689#ifdef HAVE_UDA1380
690 if (source == last_source)
691 break;
692 /* I2S recording and playback */
693 uda1380_enable_recording(false); /* source line */
694 uda1380_set_monitor(true);
695#endif
696#ifdef HAVE_TLV320
697 /* I2S recording and analog playback */
698 if (source == last_source && recording == last_recording)
699 break;
700
701 last_recording = recording;
702
703 if (recording)
704 tlv320_enable_recording(false); /* source line */
705 else
706 {
707 tlv320_disable_recording();
708 tlv320_set_monitor(true); /* analog bypass */
709 }
710#endif
711 break;
712/* #elif defined(CONFIG_TUNER) */
713/* Have radio but cannot record it */
714/* case AUDIO_SRC_FMRADIO: */
715/* break; */
716#endif /* HAVE_FMRADIO_IN */
717 } /* end switch */
718
719 peak_meter_playback(pm_playback);
720 peak_meter_enabled = pm_enabled;
721
722 last_source = source;
723} /* rec_set_source */ 619} /* rec_set_source */
724#endif /* CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) */ 620#endif /* CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) */
725 621
diff --git a/apps/recorder/recording.h b/apps/recorder/recording.h
index a977efa749..a67337b9b6 100644
--- a/apps/recorder/recording.h
+++ b/apps/recorder/recording.h
@@ -24,14 +24,7 @@ char *rec_create_filename(char *buf);
24int rec_create_directory(void); 24int rec_create_directory(void);
25 25
26#if CONFIG_CODEC == SWCODEC 26#if CONFIG_CODEC == SWCODEC
27/* selects an audio source for recording or playback */ 27/* handles device powerup and sets audio source */
28#define SRCF_PLAYBACK 0x0000 /* default */
29#define SRCF_RECORDING 0x1000
30#ifdef CONFIG_TUNER
31/* for AUDIO_SRC_FMRADIO */
32#define SRCF_FMRADIO_PLAYING 0x0000 /* default */
33#define SRCF_FMRADIO_PAUSED 0x2000
34#endif
35void rec_set_source(int source, unsigned flags); 28void rec_set_source(int source, unsigned flags);
36#endif /* CONFIG_CODEC == SW_CODEC */ 29#endif /* CONFIG_CODEC == SW_CODEC */
37 30
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 167bea2c4c..d9f92d14ca 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -324,6 +324,7 @@ target/coldfire/iaudio/x5/power-x5.c
324target/coldfire/pcf50606-coldfire.c 324target/coldfire/pcf50606-coldfire.c
325target/coldfire/iaudio/x5/adc-x5.c 325target/coldfire/iaudio/x5/adc-x5.c
326target/coldfire/iaudio/x5/ata-x5.c 326target/coldfire/iaudio/x5/ata-x5.c
327target/coldfire/iaudio/x5/audio-x5.c
327target/coldfire/iaudio/x5/backlight-x5.c 328target/coldfire/iaudio/x5/backlight-x5.c
328target/coldfire/iaudio/x5/button-x5.c 329target/coldfire/iaudio/x5/button-x5.c
329target/coldfire/iaudio/x5/lcd-as-x5.S 330target/coldfire/iaudio/x5/lcd-as-x5.S
@@ -348,6 +349,7 @@ target/coldfire/iriver/h300/power-h300.c
348#ifndef SIMULATOR 349#ifndef SIMULATOR
349target/coldfire/pcf50606-coldfire.c 350target/coldfire/pcf50606-coldfire.c
350target/coldfire/iriver/ata-iriver.c 351target/coldfire/iriver/ata-iriver.c
352target/coldfire/iriver/audio-iriver.c
351target/coldfire/iriver/system-iriver.c 353target/coldfire/iriver/system-iriver.c
352target/coldfire/iriver/h300/adc-h300.c 354target/coldfire/iriver/h300/adc-h300.c
353target/coldfire/iriver/h300/backlight-h300.c 355target/coldfire/iriver/h300/backlight-h300.c
@@ -363,6 +365,7 @@ target/coldfire/iriver/h300/usb-h300.c
363target/coldfire/iriver/h100/power-h100.c 365target/coldfire/iriver/h100/power-h100.c
364#ifndef SIMULATOR 366#ifndef SIMULATOR
365target/coldfire/iriver/ata-iriver.c 367target/coldfire/iriver/ata-iriver.c
368target/coldfire/iriver/audio-iriver.c
366target/coldfire/iriver/system-iriver.c 369target/coldfire/iriver/system-iriver.c
367target/coldfire/iriver/h100/adc-h100.c 370target/coldfire/iriver/h100/adc-h100.c
368target/coldfire/iriver/h100/backlight-h100.c 371target/coldfire/iriver/h100/backlight-h100.c
diff --git a/firmware/drivers/uda1380.c b/firmware/drivers/uda1380.c
index d6dfe6623b..82bf6d1ae1 100644
--- a/firmware/drivers/uda1380.c
+++ b/firmware/drivers/uda1380.c
@@ -272,7 +272,7 @@ void uda1380_enable_recording(bool source_mic)
272 { 272 {
273 /* VGA_GAIN: 0=0 dB, F=30dB */ 273 /* VGA_GAIN: 0=0 dB, F=30dB */
274 /* Output of left ADC is fed into right bitstream */ 274 /* Output of left ADC is fed into right bitstream */
275 uda1380_regs[REG_PWR] &= ~(PON_PLL | PON_PGAR | PON_ADCR); 275 uda1380_regs[REG_PWR] &= ~(PON_PGAR | PON_ADCR);
276 uda1380_write_reg(REG_PWR, uda1380_regs[REG_PWR] | PON_LNA | PON_ADCL); 276 uda1380_write_reg(REG_PWR, uda1380_regs[REG_PWR] | PON_LNA | PON_ADCL);
277 uda1380_regs[REG_ADC] &= ~SKIP_DCFIL; 277 uda1380_regs[REG_ADC] &= ~SKIP_DCFIL;
278 uda1380_write_reg(REG_ADC, (uda1380_regs[REG_ADC] & VGA_GAIN_MASK) 278 uda1380_write_reg(REG_ADC, (uda1380_regs[REG_ADC] & VGA_GAIN_MASK)
@@ -282,7 +282,7 @@ void uda1380_enable_recording(bool source_mic)
282 else 282 else
283 { 283 {
284 /* PGA_GAIN: 0=0 dB, F=24dB */ 284 /* PGA_GAIN: 0=0 dB, F=24dB */
285 uda1380_regs[REG_PWR] &= ~(PON_PLL | PON_LNA); 285 uda1380_regs[REG_PWR] &= ~PON_LNA;
286 uda1380_write_reg(REG_PWR, uda1380_regs[REG_PWR] | PON_PGAL | PON_ADCL 286 uda1380_write_reg(REG_PWR, uda1380_regs[REG_PWR] | PON_PGAL | PON_ADCL
287 | PON_PGAR | PON_ADCR); 287 | PON_PGAR | PON_ADCR);
288 uda1380_write_reg(REG_ADC, EN_DCFIL); 288 uda1380_write_reg(REG_ADC, EN_DCFIL);
@@ -305,8 +305,9 @@ void uda1380_disable_recording(void)
305 305
306 uda1380_write_reg(REG_I2S, I2S_IFMT_IIS); 306 uda1380_write_reg(REG_I2S, I2S_IFMT_IIS);
307 307
308 uda1380_regs[REG_PWR] &= ~(PON_LNA | PON_ADCL | PON_ADCR | PON_PGAL | PON_PGAR); 308 uda1380_regs[REG_PWR] &= ~(PON_LNA | PON_ADCL | PON_ADCR |
309 uda1380_write_reg(REG_PWR, uda1380_regs[REG_PWR] | PON_PLL); 309 PON_PGAL | PON_PGAR);
310 uda1380_write_reg(REG_PWR, uda1380_regs[REG_PWR]);
310 311
311 uda1380_regs[REG_0] &= ~EN_ADC; 312 uda1380_regs[REG_0] &= ~EN_ADC;
312 uda1380_write_reg(REG_0, uda1380_regs[REG_0] | ADC_CLK | DAC_CLK); 313 uda1380_write_reg(REG_0, uda1380_regs[REG_0] | ADC_CLK | DAC_CLK);
diff --git a/firmware/export/audio.h b/firmware/export/audio.h
index 4875d621f0..3edbfe155d 100644
--- a/firmware/export/audio.h
+++ b/firmware/export/audio.h
@@ -150,6 +150,17 @@ enum audio_sources
150 AUDIO_SRC_MAX = AUDIO_NUM_SOURCES-1 150 AUDIO_SRC_MAX = AUDIO_NUM_SOURCES-1
151}; 151};
152 152
153#if CONFIG_CODEC == SWCODEC
154/* selects an audio source for recording or playback */
155#define SRCF_PLAYBACK 0x0000 /* default */
156#define SRCF_RECORDING 0x1000
157#ifdef CONFIG_TUNER
158/* for AUDIO_SRC_FMRADIO */
159#define SRCF_FMRADIO_PLAYING 0x0000 /* default */
160#define SRCF_FMRADIO_PAUSED 0x2000
161#endif
162#endif
163
153#ifdef HAVE_RECORDING 164#ifdef HAVE_RECORDING
154/* parameters for audio_set_recording_options */ 165/* parameters for audio_set_recording_options */
155struct audio_recording_options 166struct audio_recording_options
@@ -186,6 +197,8 @@ unsigned long audio_num_recorded_bytes(void);
186bool audio_load_encoder(int afmt); 197bool audio_load_encoder(int afmt);
187void audio_remove_encoder(void); 198void audio_remove_encoder(void);
188unsigned char *audio_get_recording_buffer(size_t *buffer_size); 199unsigned char *audio_get_recording_buffer(size_t *buffer_size);
200void audio_set_source(int source, unsigned flags);
201void audio_set_output_source(int source);
189#endif /* CONFIG_CODEC == SWCODEC */ 202#endif /* CONFIG_CODEC == SWCODEC */
190#endif /* HAVE_RECORDING */ 203#endif /* HAVE_RECORDING */
191 204
diff --git a/firmware/export/pcm_record.h b/firmware/export/pcm_record.h
index 639ad7c97d..84db80680d 100644
--- a/firmware/export/pcm_record.h
+++ b/firmware/export/pcm_record.h
@@ -24,9 +24,6 @@
24#ifdef HAVE_SPDIF_IN 24#ifdef HAVE_SPDIF_IN
25#define DMA_REC_ERROR_SPDIF ((size_t)-2) 25#define DMA_REC_ERROR_SPDIF ((size_t)-2)
26#endif 26#endif
27/* Use AUDIO_SRC_* enumeration values */
28void pcm_set_monitor(int monitor);
29void pcm_set_rec_source(int source);
30 27
31/** 28/**
32 * RAW pcm data recording 29 * RAW pcm data recording
@@ -55,7 +52,6 @@ void pcm_calculate_rec_peaks(int *left, int *right);
55 results for consistency with the hardware codec version */ 52 results for consistency with the hardware codec version */
56/* unsigned long pcm_rec_status(void); */ 53/* unsigned long pcm_rec_status(void); */
57void pcm_rec_init(void); 54void pcm_rec_init(void);
58void pcm_rec_mux(int source);
59int pcm_rec_current_bitrate(void); 55int pcm_rec_current_bitrate(void);
60int pcm_rec_encoder_afmt(void); /* AFMT_* value, AFMT_UNKNOWN if none */ 56int pcm_rec_encoder_afmt(void); /* AFMT_* value, AFMT_UNKNOWN if none */
61int pcm_rec_rec_format(void); /* Format index or -1 otherwise */ 57int pcm_rec_rec_format(void); /* Format index or -1 otherwise */
diff --git a/firmware/pcm_playback.c b/firmware/pcm_playback.c
index 8b5479cae9..99a495ca10 100644
--- a/firmware/pcm_playback.c
+++ b/firmware/pcm_playback.c
@@ -597,11 +597,6 @@ void pcm_apply_settings(bool reset)
597{ 597{
598 (void)reset; 598 (void)reset;
599} 599}
600
601void pcm_set_monitor(int monitor)
602{
603 (void)monitor;
604}
605/** **/ 600/** **/
606 601
607void pcm_mute(bool mute) 602void pcm_mute(bool mute)
diff --git a/firmware/pcm_record.c b/firmware/pcm_record.c
index a1b2afd1bf..f7059dc40b 100644
--- a/firmware/pcm_record.c
+++ b/firmware/pcm_record.c
@@ -323,13 +323,9 @@ void audio_close_recording(void)
323 pcm_thread_wait_for_stop(); 323 pcm_thread_wait_for_stop();
324 pcm_thread_sync_post(PCMREC_CLOSE, NULL); 324 pcm_thread_sync_post(PCMREC_CLOSE, NULL);
325 /* reset pcm to defaults (playback only) */ 325 /* reset pcm to defaults (playback only) */
326 pcm_set_frequency(-1); 326 pcm_set_frequency(HW_SAMPR_DEFAULT);
327 pcm_set_monitor(-1); 327 audio_set_output_source(AUDIO_SRC_PLAYBACK);
328 pcm_set_rec_source(-1);
329#ifdef HAVE_TLV320
330 /* tlv320 screeches if left at 88.2 with no inputs */
331 pcm_apply_settings(true); 328 pcm_apply_settings(true);
332#endif
333 audio_remove_encoder(); 329 audio_remove_encoder();
334} /* audio_close_recording */ 330} /* audio_close_recording */
335 331
@@ -408,12 +404,12 @@ void audio_set_recording_options(struct audio_recording_options *options)
408 pcm_set_frequency(sample_rate); 404 pcm_set_frequency(sample_rate);
409 } 405 }
410 406
411 pcm_set_monitor(rec_source); 407 /* set monitoring */
412 pcm_set_rec_source(rec_source); 408 audio_set_output_source(rec_source);
413 409
414 /* apply pcm settings to hardware */ 410 /* apply pcm settings to hardware */
415 pcm_apply_settings(true); 411 pcm_apply_settings(true);
416 412
417 if (audio_load_encoder(enc_config.afmt)) 413 if (audio_load_encoder(enc_config.afmt))
418 { 414 {
419 /* start DMA transfer */ 415 /* start DMA transfer */
@@ -425,27 +421,10 @@ void audio_set_recording_options(struct audio_recording_options *options)
425 { 421 {
426 logf("set rec opt: enc load failed"); 422 logf("set rec opt: enc load failed");
427 is_error = true; 423 is_error = true;
428} 424 }
429} /* audio_set_recording_options */ 425} /* audio_set_recording_options */
430 426
431/** 427/**
432 * Note that microphone is mono, only left value is used
433 * See {uda1380,tlv320}_set_recvol() for exact ranges.
434 *
435 * @param type 0=line-in (radio), 1=mic
436 *
437 */
438void audio_set_recording_gain(int left, int right, int type)
439{
440 //logf("rcmrec: t=%d l=%d r=%d", type, left, right);
441#if defined(HAVE_UDA1380)
442 uda1380_set_recvol(left, right, type);
443#elif defined (HAVE_TLV320)
444 tlv320_set_recvol(left, right, type);
445#endif
446} /* audio_set_recording_gain */
447
448/**
449 * Start recording 428 * Start recording
450 * 429 *
451 * Use audio_set_recording_options first to select recording options 430 * Use audio_set_recording_options first to select recording options
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 */