2006-11-06 18:18:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Michael Sevakis
|
2009-02-12 21:32:14 +00:00
|
|
|
* Copyright (C) 2005 by Linus Nielsen Feltzing
|
2006-11-06 18:18:05 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-11-06 18:18:05 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "system.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "logf.h"
|
|
|
|
#include "audio.h"
|
2007-03-11 06:21:43 +00:00
|
|
|
#include "sound.h"
|
2007-05-20 20:26:36 +00:00
|
|
|
#if defined(HAVE_SPDIF_REC) || defined(HAVE_SPDIF_OUT)
|
2006-11-13 23:21:54 +00:00
|
|
|
#include "spdif.h"
|
|
|
|
#endif
|
2011-06-29 06:37:04 +00:00
|
|
|
#include "pcm-internal.h"
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
#define IIS_PLAY_DEFPARM ( (freq_ent[FPARM_CLOCKSEL] << 12) | \
|
|
|
|
(IIS_PLAY & (7 << 8)) | \
|
|
|
|
(4 << 2) ) /* 64 bit clocks / word clock */
|
|
|
|
#define IIS_FIFO_RESET (1 << 11)
|
|
|
|
#define PDIR2_FIFO_RESET (1 << 9)
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2008-03-15 21:55:14 +00:00
|
|
|
#if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
|
2009-02-12 21:32:14 +00:00
|
|
|
#define IIS_PLAY IIS1CONFIG
|
2006-11-06 18:18:05 +00:00
|
|
|
#else
|
2009-02-12 21:32:14 +00:00
|
|
|
#define IIS_PLAY IIS2CONFIG
|
2006-11-06 18:18:05 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
#ifdef HAVE_SPDIF_OUT
|
|
|
|
/* EBU TX auto sync, PDIR2 fifo auto sync, IIS1 fifo auto sync */
|
|
|
|
#define AUDIOGLOB_DEFPARM ((1 << 10) | (1 << 8) | (1 << 7))
|
|
|
|
#else
|
|
|
|
/* PDIR2 fifo auto sync, IIS1 fifo auto sync */
|
|
|
|
#define AUDIOGLOB_DEFPARM ((1 << 8) | (1 << 7))
|
|
|
|
#endif
|
2007-03-07 06:23:02 +00:00
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
/** Sample rates **/
|
2007-03-05 08:14:27 +00:00
|
|
|
#define PLLCR_SET_AUDIO_BITS_DEFPARM \
|
|
|
|
((freq_ent[FPARM_CLSEL] << 28) | (1 << 22))
|
|
|
|
|
2006-11-06 18:18:05 +00:00
|
|
|
#define FPARM_CLOCKSEL 0
|
|
|
|
#define FPARM_CLSEL 1
|
2010-04-26 21:40:00 +00:00
|
|
|
|
|
|
|
/* SCLK = Fs * bit clocks per word
|
|
|
|
* so SCLK should be Fs * 64
|
|
|
|
*
|
|
|
|
* CLOCKSEL sets SCLK freq based on Audio CLK
|
|
|
|
* 0x0c SCLK = Audio CLK/2 88200 * 64 = 5644800 Hz
|
|
|
|
* 0x06 SCLK = Audio CLK/4 44100 * 64 = 2822400 Hz
|
|
|
|
* 0x04 SCLK = Audio CLK/8 22050 * 64 = 1411200 Hz
|
|
|
|
* 0x02 SCLK = Audio CLK/16 11025 * 64 = 705600 Hz
|
|
|
|
*
|
|
|
|
* CLSEL sets MCLK1/2 DAC freq based on XTAL freq
|
|
|
|
* 0x01 MCLK1/2 = XTAL freq
|
|
|
|
* 0x02 MCLK1/2 = XTAL/2 freq
|
|
|
|
*
|
|
|
|
* Audio CLK can be XTAL freq or XTAL/2 freq (bit22 in PLLCR)
|
|
|
|
* we always set bit22 so Audio CLK is always XTAL freq
|
|
|
|
*/
|
|
|
|
|
2006-11-06 18:18:05 +00:00
|
|
|
#if CONFIG_CPU == MCF5249 && defined(HAVE_UDA1380)
|
2008-12-12 11:01:07 +00:00
|
|
|
static const unsigned char pcm_freq_parms[HW_NUM_FREQ][2] =
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2008-12-12 11:01:07 +00:00
|
|
|
[HW_FREQ_88] = { 0x0c, 0x01 },
|
|
|
|
[HW_FREQ_44] = { 0x06, 0x01 },
|
|
|
|
[HW_FREQ_22] = { 0x04, 0x02 },
|
|
|
|
[HW_FREQ_11] = { 0x02, 0x02 },
|
2006-11-06 18:18:05 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-04-26 21:40:00 +00:00
|
|
|
#if CONFIG_CPU == MCF5249 && defined(HAVE_WM8750)
|
2010-07-02 21:09:28 +00:00
|
|
|
/* We run codec in master mode.
|
|
|
|
* Codec can reconstruct all frequencies
|
|
|
|
* from single 11.2896 MHz master clock
|
|
|
|
*/
|
2010-04-26 21:40:00 +00:00
|
|
|
static const unsigned char pcm_freq_parms[HW_NUM_FREQ][2] =
|
|
|
|
{
|
2010-07-02 21:09:28 +00:00
|
|
|
[HW_FREQ_88] = { 0x00, 0x01 },
|
|
|
|
[HW_FREQ_44] = { 0x00, 0x01 },
|
|
|
|
[HW_FREQ_22] = { 0x00, 0x01 },
|
|
|
|
[HW_FREQ_11] = { 0x00, 0x01 },
|
2010-04-26 21:40:00 +00:00
|
|
|
};
|
2010-07-02 21:09:28 +00:00
|
|
|
|
2010-04-26 21:40:00 +00:00
|
|
|
#endif
|
|
|
|
|
2008-03-14 08:54:54 +00:00
|
|
|
#if (CONFIG_CPU == MCF5250 || CONFIG_CPU == MCF5249) && defined(HAVE_TLV320)
|
2008-12-12 11:01:07 +00:00
|
|
|
static const unsigned char pcm_freq_parms[HW_NUM_FREQ][2] =
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2008-12-12 11:01:07 +00:00
|
|
|
[HW_FREQ_88] = { 0x0c, 0x01 },
|
|
|
|
[HW_FREQ_44] = { 0x06, 0x01 },
|
|
|
|
[HW_FREQ_22] = { 0x04, 0x01 },
|
|
|
|
[HW_FREQ_11] = { 0x02, 0x02 },
|
2006-11-06 18:18:05 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2008-12-12 11:01:07 +00:00
|
|
|
static const unsigned char *freq_ent;
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
/* Lock status struct for playback and recording */
|
|
|
|
struct dma_lock
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2009-02-12 21:32:14 +00:00
|
|
|
int locked;
|
|
|
|
unsigned long state;
|
|
|
|
};
|
2008-12-12 11:01:07 +00:00
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
static void iis_play_reset(void)
|
|
|
|
{
|
|
|
|
or_l(IIS_FIFO_RESET, &IIS_PLAY);
|
|
|
|
and_l(~IIS_FIFO_RESET, &IIS_PLAY);
|
|
|
|
PDOR3 = 0;
|
|
|
|
}
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
static bool is_playback_monitoring(void)
|
|
|
|
{
|
|
|
|
return (IIS_PLAY & (7 << 8)) == (3 << 8);
|
|
|
|
}
|
2008-12-12 11:01:07 +00:00
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
static void iis_play_reset_if_playback(bool if_playback)
|
|
|
|
{
|
|
|
|
int level = set_irq_level(DMA_IRQ_LEVEL);
|
|
|
|
if (is_playback_monitoring() == if_playback)
|
|
|
|
iis_play_reset();
|
2008-12-12 11:01:07 +00:00
|
|
|
restore_irq(level);
|
2009-02-12 21:32:14 +00:00
|
|
|
}
|
2008-12-12 11:01:07 +00:00
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
/* apply audio settings */
|
2007-03-07 06:23:02 +00:00
|
|
|
/* This clears the reset bit to enable monitoring immediately if monitoring
|
|
|
|
recording sources or always if playback is in progress - we might be
|
|
|
|
switching samplerates on the fly */
|
2008-12-12 11:01:07 +00:00
|
|
|
void pcm_dma_apply_settings(void)
|
2007-03-05 08:14:27 +00:00
|
|
|
{
|
2007-03-07 06:23:02 +00:00
|
|
|
int level = set_irq_level(DMA_IRQ_LEVEL);
|
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
/* remember table entry */
|
|
|
|
freq_ent = pcm_freq_parms[pcm_fsel];
|
|
|
|
|
|
|
|
/* Reprogramming bits 15-12 requires FIFO to be in a reset
|
|
|
|
condition - Users Manual 17-8, Note 11 */
|
|
|
|
or_l(IIS_FIFO_RESET, &IIS_PLAY);
|
|
|
|
/* Important for TLV320 - this must happen in the correct order
|
|
|
|
or starting recording will sound absolutely awful once in
|
|
|
|
awhile - audiohw_set_frequency then coldfire_set_pllcr_audio_bits
|
|
|
|
*/
|
|
|
|
IIS_PLAY = IIS_PLAY_DEFPARM | IIS_FIFO_RESET;
|
|
|
|
restore_irq(level);
|
|
|
|
|
|
|
|
audiohw_set_frequency(pcm_fsel);
|
|
|
|
coldfire_set_pllcr_audio_bits(PLLCR_SET_AUDIO_BITS_DEFPARM);
|
|
|
|
|
|
|
|
level = set_irq_level(DMA_IRQ_LEVEL);
|
|
|
|
|
|
|
|
IIS_PLAY = IIS_PLAY_DEFPARM;
|
|
|
|
|
|
|
|
if ((DCR0 & DMA_EEXT) != 0 && is_playback_monitoring())
|
2007-03-07 06:23:02 +00:00
|
|
|
PDOR3 = 0; /* Kick FIFO out of reset by writing to it */
|
|
|
|
|
2008-03-26 01:50:41 +00:00
|
|
|
restore_irq(level);
|
2008-12-12 11:01:07 +00:00
|
|
|
} /* pcm_dma_apply_settings */
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_play_dma_init(void)
|
2007-03-07 06:23:02 +00:00
|
|
|
{
|
2008-12-12 11:01:07 +00:00
|
|
|
freq_ent = pcm_freq_parms[pcm_fsel];
|
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
AUDIOGLOB = AUDIOGLOB_DEFPARM;
|
|
|
|
DIVR0 = 54; /* DMA0 is mapped into vector 54 in system.c */
|
2007-03-05 08:14:27 +00:00
|
|
|
and_l(0xffffff00, &DMAROUTE);
|
|
|
|
or_l(DMA0_REQ_AUDIO_1, &DMAROUTE);
|
2009-02-12 21:32:14 +00:00
|
|
|
DMACONFIG = 1; /* DMA0Req = PDOR3, DMA1Req = PDIR2 */
|
|
|
|
BCR0 = 0; /* No bytes waiting */
|
|
|
|
ICR6 = (6 << 2); /* Enable interrupt at level 6, priority 0 */
|
2007-03-11 05:04:48 +00:00
|
|
|
|
2007-03-13 15:05:46 +00:00
|
|
|
/* Setup Coldfire I2S before initializing hardware or changing
|
|
|
|
other settings. */
|
|
|
|
or_l(IIS_FIFO_RESET, &IIS_PLAY);
|
2009-02-12 21:32:14 +00:00
|
|
|
IIS_PLAY = IIS_PLAY_DEFPARM | IIS_FIFO_RESET;
|
2007-03-13 15:05:46 +00:00
|
|
|
audio_set_output_source(AUDIO_SRC_PLAYBACK);
|
|
|
|
|
2007-03-11 05:04:48 +00:00
|
|
|
/* Initialize default register values. */
|
|
|
|
audiohw_init();
|
|
|
|
|
2007-06-08 23:42:04 +00:00
|
|
|
audio_input_mux(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2008-12-12 11:01:07 +00:00
|
|
|
audiohw_set_frequency(pcm_fsel);
|
2007-03-13 15:05:46 +00:00
|
|
|
coldfire_set_pllcr_audio_bits(PLLCR_SET_AUDIO_BITS_DEFPARM);
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2007-05-20 20:26:36 +00:00
|
|
|
#if defined(HAVE_SPDIF_REC) || defined(HAVE_SPDIF_OUT)
|
2006-11-13 23:21:54 +00:00
|
|
|
spdif_init();
|
|
|
|
#endif
|
2007-10-06 22:27:27 +00:00
|
|
|
} /* pcm_play_dma_init */
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2011-09-01 12:15:43 +00:00
|
|
|
void pcm_play_dma_postinit(void)
|
2007-03-11 06:21:43 +00:00
|
|
|
{
|
|
|
|
audiohw_postinit();
|
2009-02-12 21:32:14 +00:00
|
|
|
iis_play_reset();
|
2007-03-11 06:21:43 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
/** DMA **/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
** Playback DMA transfer
|
|
|
|
**/
|
|
|
|
/* For the locks, DMA interrupt must be disabled when manipulating the lock
|
|
|
|
if the handler ever calls these - right now things are arranged so it
|
|
|
|
doesn't */
|
|
|
|
static struct dma_lock dma_play_lock =
|
|
|
|
{
|
|
|
|
.locked = 0,
|
2011-06-17 03:09:47 +00:00
|
|
|
.state = (1 << 14) /* bit 14 is DMA0 */
|
2007-10-06 22:27:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void pcm_play_lock(void)
|
|
|
|
{
|
|
|
|
if (++dma_play_lock.locked == 1)
|
2011-06-17 03:09:47 +00:00
|
|
|
coldfire_imr_mod(1 << 14, 1 << 14);
|
2007-10-06 22:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_play_unlock(void)
|
|
|
|
{
|
|
|
|
if (--dma_play_lock.locked == 0)
|
2011-06-17 03:09:47 +00:00
|
|
|
coldfire_imr_mod(dma_play_lock.state, 1 << 14);
|
2007-10-06 22:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the DMA transfer that kicks in when the audio FIFO gets empty */
|
|
|
|
void pcm_play_dma_start(const void *addr, size_t size)
|
|
|
|
{
|
2009-02-12 21:32:14 +00:00
|
|
|
/* Stop any DMA in progress */
|
|
|
|
pcm_play_dma_stop();
|
2007-10-06 22:27:27 +00:00
|
|
|
|
|
|
|
/* Set up DMA transfer */
|
|
|
|
SAR0 = (unsigned long)addr; /* Source address */
|
|
|
|
DAR0 = (unsigned long)&PDOR3; /* Destination address */
|
|
|
|
BCR0 = (unsigned long)size; /* Bytes to transfer */
|
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
DCR0 = DMA_INT | DMA_EEXT | DMA_CS | DMA_AA | DMA_SINC |
|
|
|
|
DMA_SSIZE(DMA_SIZE_LINE) | DMA_START;
|
2007-10-06 22:27:27 +00:00
|
|
|
|
2011-06-17 03:09:47 +00:00
|
|
|
dma_play_lock.state = (0 << 14);
|
2007-10-06 22:27:27 +00:00
|
|
|
} /* pcm_play_dma_start */
|
|
|
|
|
|
|
|
/* Stops the DMA transfer and interrupt */
|
|
|
|
void pcm_play_dma_stop(void)
|
|
|
|
{
|
2009-02-12 21:32:14 +00:00
|
|
|
and_l(~(DMA_EEXT | DMA_INT), &DCR0); /* per request and int OFF */
|
|
|
|
BCR0 = 0; /* No bytes remaining */
|
|
|
|
DSR0 = 1; /* Clear interrupt, errors, stop transfer */
|
2007-10-06 22:27:27 +00:00
|
|
|
|
|
|
|
iis_play_reset_if_playback(true);
|
|
|
|
|
2011-06-17 03:09:47 +00:00
|
|
|
dma_play_lock.state = (1 << 14);
|
2007-10-06 22:27:27 +00:00
|
|
|
} /* pcm_play_dma_stop */
|
|
|
|
|
|
|
|
void pcm_play_dma_pause(bool pause)
|
|
|
|
{
|
|
|
|
if (pause)
|
|
|
|
{
|
|
|
|
/* pause playback on current buffer */
|
2009-02-12 21:32:14 +00:00
|
|
|
and_l(~(DMA_EEXT | DMA_INT), &DCR0); /* per request and int OFF */
|
|
|
|
DSR0 = 1; /* stop channel */
|
2007-10-06 22:27:27 +00:00
|
|
|
iis_play_reset_if_playback(true);
|
2011-06-17 03:09:47 +00:00
|
|
|
dma_play_lock.state = (1 << 14);
|
2007-10-06 22:27:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* restart playback on current buffer */
|
2009-02-12 21:32:14 +00:00
|
|
|
iis_play_reset_if_playback(true);
|
|
|
|
or_l(DMA_INT | DMA_EEXT | DMA_START, &DCR0); /* everything ON */
|
2011-06-17 03:09:47 +00:00
|
|
|
dma_play_lock.state = (0 << 14);
|
2007-10-06 22:27:27 +00:00
|
|
|
}
|
|
|
|
} /* pcm_play_dma_pause */
|
|
|
|
|
2006-11-06 18:18:05 +00:00
|
|
|
size_t pcm_get_bytes_waiting(void)
|
|
|
|
{
|
|
|
|
return BCR0 & 0xffffff;
|
|
|
|
} /* pcm_get_bytes_waiting */
|
|
|
|
|
|
|
|
/* DMA0 Interrupt is called when the DMA has finished transfering a chunk
|
|
|
|
from the caller's buffer */
|
|
|
|
void DMA0(void) __attribute__ ((interrupt_handler, section(".icode")));
|
|
|
|
void DMA0(void)
|
|
|
|
{
|
2009-02-12 21:32:14 +00:00
|
|
|
unsigned long res = DSR0;
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
and_l(~(DMA_EEXT | DMA_INT), &DCR0); /* per request and int OFF */
|
|
|
|
DSR0 = 1; /* Clear interrupt and errors */
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
if (res & 0x70)
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2007-03-05 08:14:27 +00:00
|
|
|
logf("DMA0 err: %02x", res);
|
|
|
|
#if 0
|
|
|
|
logf(" SAR0: %08x", SAR0);
|
|
|
|
logf(" DAR0: %08x", DAR0);
|
|
|
|
logf(" BCR0: %08x", BCR0);
|
|
|
|
logf(" DCR0: %08x", DCR0);
|
|
|
|
#endif
|
2006-11-06 18:18:05 +00:00
|
|
|
}
|
2010-05-24 16:42:32 +00:00
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
const void *addr;
|
|
|
|
size_t size;
|
2010-05-24 16:42:32 +00:00
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
if (pcm_play_dma_complete_callback((res & 0x70) ?
|
|
|
|
PCM_DMAST_ERR_DMA : PCM_DMAST_OK,
|
|
|
|
&addr, &size))
|
2009-02-12 21:32:14 +00:00
|
|
|
{
|
2012-02-23 13:14:46 +00:00
|
|
|
SAR0 = (unsigned long)addr; /* Source address */
|
|
|
|
BCR0 = (unsigned long)size; /* Bytes to transfer */
|
2010-05-24 16:42:32 +00:00
|
|
|
or_l(DMA_EEXT | DMA_INT, &DCR0); /* per request and int ON */
|
2011-06-29 06:37:04 +00:00
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
pcm_play_dma_status_callback(PCM_DMAST_STARTED);
|
2009-02-12 21:32:14 +00:00
|
|
|
}
|
2010-05-24 16:42:32 +00:00
|
|
|
/* else inished playing */
|
2006-11-06 18:18:05 +00:00
|
|
|
} /* DMA0 */
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
const void * pcm_play_dma_get_peak_buffer(int *count)
|
|
|
|
{
|
2009-02-12 21:32:14 +00:00
|
|
|
unsigned long addr, cnt;
|
|
|
|
|
|
|
|
/* Make sure interrupt doesn't change the second value after we read the
|
|
|
|
* first value. */
|
|
|
|
int level = set_irq_level(DMA_IRQ_LEVEL);
|
|
|
|
addr = SAR0;
|
|
|
|
cnt = BCR0;
|
|
|
|
restore_irq(level);
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
*count = (cnt & 0xffffff) >> 2;
|
|
|
|
return (void *)((addr + 2) & ~3);
|
|
|
|
} /* pcm_play_dma_get_peak_buffer */
|
|
|
|
|
2010-04-26 21:40:00 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2006-11-06 18:18:05 +00:00
|
|
|
/****************************************************************************
|
|
|
|
** Recording DMA transfer
|
|
|
|
**/
|
2007-10-06 22:27:27 +00:00
|
|
|
static struct dma_lock dma_rec_lock =
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2007-10-06 22:27:27 +00:00
|
|
|
.locked = 0,
|
2011-06-17 03:09:47 +00:00
|
|
|
.state = (1 << 15) /* bit 15 is DMA1 */
|
2007-10-06 22:27:27 +00:00
|
|
|
};
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
/* For the locks, DMA interrupt must be disabled when manipulating the lock
|
|
|
|
if the handler ever calls these - right now things are arranged so it
|
|
|
|
doesn't */
|
|
|
|
void pcm_rec_lock(void)
|
|
|
|
{
|
|
|
|
if (++dma_rec_lock.locked == 1)
|
2011-06-17 03:09:47 +00:00
|
|
|
coldfire_imr_mod(1 << 15, 1 << 15);
|
2007-10-06 22:27:27 +00:00
|
|
|
}
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_rec_unlock(void)
|
|
|
|
{
|
|
|
|
if (--dma_rec_lock.locked == 0)
|
2011-06-17 03:09:47 +00:00
|
|
|
coldfire_imr_mod(dma_rec_lock.state, 1 << 15);
|
2007-10-06 22:27:27 +00:00
|
|
|
}
|
2007-03-07 06:23:02 +00:00
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_rec_dma_start(void *addr, size_t size)
|
|
|
|
{
|
2012-02-23 13:14:46 +00:00
|
|
|
/* Stop any DMA in progress */
|
2009-02-12 21:32:14 +00:00
|
|
|
pcm_rec_dma_stop();
|
|
|
|
|
2007-03-05 08:14:27 +00:00
|
|
|
and_l(~PDIR2_FIFO_RESET, &DATAINCONTROL);
|
2006-11-06 18:18:05 +00:00
|
|
|
|
|
|
|
/* Start the DMA transfer.. */
|
2007-05-20 20:26:36 +00:00
|
|
|
#ifdef HAVE_SPDIF_REC
|
2007-04-18 02:07:56 +00:00
|
|
|
/* clear: ebu1cnew, valnogood, symbolerr, parityerr */
|
|
|
|
INTERRUPTCLEAR = (1 << 25) | (1 << 24) | (1 << 23) | (1 << 22);
|
2006-11-06 18:18:05 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
SAR1 = (unsigned long)&PDIR2; /* Source address */
|
|
|
|
DAR1 = (unsigned long)addr; /* Destination address */
|
|
|
|
BCR1 = (unsigned long)size; /* Bytes to transfer */
|
2006-12-06 08:34:55 +00:00
|
|
|
|
2006-12-12 04:25:52 +00:00
|
|
|
DCR1 = DMA_INT | DMA_EEXT | DMA_CS | DMA_AA | DMA_DINC |
|
2007-10-06 22:27:27 +00:00
|
|
|
DMA_DSIZE(DMA_SIZE_LINE) | DMA_START;
|
2007-03-07 06:23:02 +00:00
|
|
|
|
2011-06-17 03:09:47 +00:00
|
|
|
dma_rec_lock.state = (0 << 15);
|
2007-10-06 22:27:27 +00:00
|
|
|
} /* pcm_rec_dma_start */
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_rec_dma_stop(void)
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2009-02-12 21:32:14 +00:00
|
|
|
and_l(~(DMA_EEXT | DMA_INT), &DCR1); /* per request and int OFF */
|
|
|
|
DSR1 = 1; /* Clear interrupt, errors, stop transfer */
|
|
|
|
BCR1 = 0; /* No bytes received */
|
|
|
|
|
2007-03-05 08:14:27 +00:00
|
|
|
or_l(PDIR2_FIFO_RESET, &DATAINCONTROL);
|
2007-03-07 06:23:02 +00:00
|
|
|
|
|
|
|
iis_play_reset_if_playback(false);
|
|
|
|
|
2011-06-17 03:09:47 +00:00
|
|
|
dma_rec_lock.state = (1 << 15);
|
2007-03-07 06:23:02 +00:00
|
|
|
} /* pcm_rec_dma_stop */
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_rec_dma_init(void)
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2007-10-06 22:27:27 +00:00
|
|
|
DIVR1 = 55; /* DMA1 is mapped into vector 55 in system.c */
|
|
|
|
DMACONFIG = 1; /* DMA0Req = PDOR3, DMA1Req = PDIR2 */
|
2007-03-05 08:14:27 +00:00
|
|
|
and_l(0xffff00ff, &DMAROUTE);
|
|
|
|
or_l(DMA1_REQ_AUDIO_2, &DMAROUTE);
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
pcm_rec_dma_stop();
|
2007-03-07 06:23:02 +00:00
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
/* Enable interrupt at level 6, priority 1 */
|
|
|
|
ICR7 = (6 << 2) | (1 << 0);
|
2006-11-06 18:18:05 +00:00
|
|
|
} /* pcm_init_recording */
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_rec_dma_close(void)
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2009-02-12 21:32:14 +00:00
|
|
|
pcm_rec_dma_stop();
|
|
|
|
|
2007-03-05 08:14:27 +00:00
|
|
|
and_l(0xffff00ff, &DMAROUTE);
|
2007-10-06 22:27:27 +00:00
|
|
|
ICR7 = 0x00; /* Disable interrupt */
|
|
|
|
dma_rec_lock.state = (0 << 15);
|
|
|
|
} /* pcm_rec_dma_close */
|
2006-11-06 18:18:05 +00:00
|
|
|
|
|
|
|
/* DMA1 Interrupt is called when the DMA has finished transfering a chunk
|
|
|
|
into the caller's buffer */
|
|
|
|
void DMA1(void) __attribute__ ((interrupt_handler, section(".icode")));
|
|
|
|
void DMA1(void)
|
|
|
|
{
|
2009-02-12 21:32:14 +00:00
|
|
|
unsigned long res = DSR1;
|
2012-02-23 13:14:46 +00:00
|
|
|
enum pcm_dma_status status = PCM_DMAST_OK;
|
2006-11-06 18:18:05 +00:00
|
|
|
|
2009-02-12 21:32:14 +00:00
|
|
|
and_l(~(DMA_EEXT | DMA_INT), &DCR1); /* per request and int OFF */
|
|
|
|
DSR1 = 1; /* Clear interrupt and errors */
|
2006-11-06 18:18:05 +00:00
|
|
|
|
|
|
|
if (res & 0x70)
|
|
|
|
{
|
2012-02-23 13:14:46 +00:00
|
|
|
status = PCM_DMAST_ERR_DMA;
|
2007-03-05 08:14:27 +00:00
|
|
|
logf("DMA1 err: %02x", res);
|
|
|
|
#if 0
|
|
|
|
logf(" SAR1: %08x", SAR1);
|
|
|
|
logf(" DAR1: %08x", DAR1);
|
|
|
|
logf(" BCR1: %08x", BCR1);
|
|
|
|
logf(" DCR1: %08x", DCR1);
|
|
|
|
#endif
|
2006-11-06 18:18:05 +00:00
|
|
|
}
|
2007-05-20 20:26:36 +00:00
|
|
|
#ifdef HAVE_SPDIF_REC
|
2006-11-23 19:21:15 +00:00
|
|
|
else if (DATAINCONTROL == 0xc038 &&
|
2008-08-19 23:07:54 +00:00
|
|
|
(INTERRUPTSTAT & ((1 << 23) | (1 << 22))))
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2008-08-19 23:07:54 +00:00
|
|
|
/* reason: symbolerr, parityerr.
|
|
|
|
* Ignore valnogood since several sources don't set it properly. */
|
|
|
|
/* clear: ebu1cnew, symbolerr, parityerr */
|
|
|
|
INTERRUPTCLEAR = (1 << 25) | (1 << 23) | (1 << 22);
|
2012-02-23 13:14:46 +00:00
|
|
|
status = PCM_DMAST_ERR_SPDIF;
|
2006-11-06 18:18:05 +00:00
|
|
|
logf("spdif err");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-24 16:42:32 +00:00
|
|
|
/* Inform PCM we have more data (or error) */
|
2012-02-23 13:14:46 +00:00
|
|
|
void *addr;
|
|
|
|
size_t size;
|
2006-12-06 08:34:55 +00:00
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
if (pcm_rec_dma_complete_callback(status, &addr, &size))
|
2010-05-24 16:42:32 +00:00
|
|
|
{
|
2012-02-23 13:14:46 +00:00
|
|
|
DAR1 = (unsigned long)addr; /* Destination address */
|
2010-05-24 16:42:32 +00:00
|
|
|
BCR1 = (unsigned long)size; /* Bytes to transfer */
|
|
|
|
or_l(DMA_EEXT | DMA_INT, &DCR1); /* per request and int ON */
|
2012-02-23 13:14:46 +00:00
|
|
|
|
|
|
|
pcm_rec_dma_status_callback(PCM_DMAST_STARTED);
|
2010-05-24 16:42:32 +00:00
|
|
|
}
|
2006-11-06 18:18:05 +00:00
|
|
|
} /* DMA1 */
|
|
|
|
|
2010-05-12 14:05:36 +00:00
|
|
|
const void * pcm_rec_dma_get_peak_buffer(void)
|
2006-11-06 18:18:05 +00:00
|
|
|
{
|
2010-05-12 14:05:36 +00:00
|
|
|
return (void *)(DAR1 & ~3);
|
2007-10-06 22:27:27 +00:00
|
|
|
} /* pcm_rec_dma_get_peak_buffer */
|
2010-04-26 21:40:00 +00:00
|
|
|
#endif
|