2007-09-21 15:51:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-05-03 15:14:52 +00:00
|
|
|
* Copyright (C) 2008 by Michael Sevakis
|
2007-09-21 15:51:53 +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.
|
2007-09-21 15:51:53 +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 "audio.h"
|
|
|
|
#include "sound.h"
|
2009-02-08 22:32:41 +00:00
|
|
|
#include "sdma-imx31.h"
|
|
|
|
#include "mmu-imx31.h"
|
2011-06-29 06:37:04 +00:00
|
|
|
#include "pcm-internal.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2009-02-08 22:32:41 +00:00
|
|
|
#define DMA_PLAY_CH_NUM 2
|
|
|
|
#define DMA_REC_CH_NUM 1
|
2009-03-12 06:31:40 +00:00
|
|
|
#define DMA_PLAY_CH_PRIORITY 6
|
|
|
|
#define DMA_REC_CH_PRIORITY 6
|
2009-02-08 22:32:41 +00:00
|
|
|
|
2010-05-08 07:45:34 +00:00
|
|
|
static struct buffer_descriptor dma_play_bd NOCACHEBSS_ATTR;
|
2010-06-24 08:40:05 +00:00
|
|
|
|
|
|
|
static void play_dma_callback(void);
|
|
|
|
static struct channel_descriptor dma_play_cd =
|
|
|
|
{
|
|
|
|
.bd_count = 1,
|
|
|
|
.callback = play_dma_callback,
|
|
|
|
.shp_addr = SDMA_PER_ADDR_SSI2_TX1,
|
|
|
|
.wml = SDMA_SSI_TXFIFO_WML*2,
|
|
|
|
.per_type = SDMA_PER_SSI_SHP, /* SSI2 shared with SDMA core */
|
|
|
|
.tran_type = SDMA_TRAN_EMI_2_PER,
|
|
|
|
.event_id1 = SDMA_REQ_SSI2_TX1,
|
|
|
|
};
|
2008-05-03 15:14:52 +00:00
|
|
|
|
2010-05-27 23:14:39 +00:00
|
|
|
/* The pcm locking relies on the fact the interrupt handlers run to completion
|
|
|
|
* before lower-priority modes proceed. We don't have to touch hardware
|
|
|
|
* registers. Disabling SDMA interrupt would disable DMA callbacks systemwide
|
|
|
|
* and that is not something that is desireable.
|
|
|
|
*
|
|
|
|
* Lock explanation [++.locked]:
|
|
|
|
* Trivial, just increment .locked.
|
|
|
|
*
|
|
|
|
* Unlock explanation [if (--.locked == 0 && .state != 0)]:
|
|
|
|
* If int occurred and saw .locked as nonzero, we'll get a pending
|
|
|
|
* and it will have taken no action other than to set the flag to the
|
|
|
|
* value of .state. If it saw zero for .locked, it will have proceeded
|
|
|
|
* normally into the pcm callbacks. If cb set the pending flag, it has
|
|
|
|
* to be called to kickstart the callback mechanism and DMA. If the unlock
|
|
|
|
* came after a stop, we won't be in the block and DMA will be off. If
|
|
|
|
* we're still doing transfers, cb will see 0 for .locked and if pending,
|
|
|
|
* it won't be called by DMA again. */
|
2008-05-03 15:14:52 +00:00
|
|
|
struct dma_data
|
|
|
|
{
|
|
|
|
int locked;
|
2009-02-08 22:32:41 +00:00
|
|
|
int callback_pending; /* DMA interrupt happened while locked */
|
2008-05-03 15:14:52 +00:00
|
|
|
int state;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct dma_data dma_play_data =
|
|
|
|
{
|
2010-05-27 23:14:39 +00:00
|
|
|
/* Initialize to an unlocked, stopped state */
|
2008-05-03 15:14:52 +00:00
|
|
|
.locked = 0,
|
2009-02-08 22:32:41 +00:00
|
|
|
.callback_pending = 0,
|
2008-05-03 15:14:52 +00:00
|
|
|
.state = 0
|
|
|
|
};
|
2007-10-06 22:27:27 +00:00
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
static void play_start_dma(const void *addr, size_t size)
|
2007-10-06 22:27:27 +00:00
|
|
|
{
|
2012-02-23 13:14:46 +00:00
|
|
|
commit_dcache_range(addr, size);
|
|
|
|
|
|
|
|
dma_play_bd.buf_addr = (void *)addr_virt_to_phys((unsigned long)addr);
|
|
|
|
dma_play_bd.mode.count = size;
|
|
|
|
dma_play_bd.mode.command = TRANSFER_16BIT;
|
|
|
|
dma_play_bd.mode.status = BD_DONE | BD_WRAP | BD_INTR;
|
|
|
|
|
|
|
|
sdma_channel_run(DMA_PLAY_CH_NUM);
|
|
|
|
}
|
2009-02-08 22:32:41 +00:00
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
static void play_dma_callback(void)
|
|
|
|
{
|
2009-02-09 03:13:04 +00:00
|
|
|
if (dma_play_data.locked != 0)
|
2008-05-03 15:14:52 +00:00
|
|
|
{
|
2009-02-08 22:32:41 +00:00
|
|
|
/* Callback is locked out */
|
2009-02-09 03:13:04 +00:00
|
|
|
dma_play_data.callback_pending = dma_play_data.state;
|
2009-02-08 22:32:41 +00:00
|
|
|
return;
|
2008-05-03 15:14:52 +00:00
|
|
|
}
|
2007-10-06 22:27:27 +00:00
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
/* Inform of status and get new buffer */
|
|
|
|
enum pcm_dma_status status = (dma_play_bd.mode.status & BD_RROR) ?
|
|
|
|
PCM_DMAST_ERR_DMA : PCM_DMAST_OK;
|
|
|
|
const void *addr;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if (pcm_play_dma_complete_callback(status, &addr, &size))
|
|
|
|
{
|
|
|
|
play_start_dma(addr, size);
|
|
|
|
pcm_play_dma_status_callback(PCM_DMAST_STARTED);
|
|
|
|
}
|
2007-10-06 22:27:27 +00:00
|
|
|
}
|
|
|
|
|
2009-02-08 22:32:41 +00:00
|
|
|
void pcm_play_lock(void)
|
2008-05-03 15:14:52 +00:00
|
|
|
{
|
2011-01-07 20:40:36 +00:00
|
|
|
/* Need to prevent DVFS from causing interrupt priority inversion if audio
|
|
|
|
* is locked and a DVFS interrupt fires, blocking reenabling of audio by a
|
|
|
|
* low-priority mode for at least the duration of the lengthy DVFS routine.
|
|
|
|
* Not really an issue with state changes but lockout when playing.
|
|
|
|
*
|
|
|
|
* Keep direct use of DVFS code away from here though. This could provide
|
|
|
|
* more services in the future anyway. */
|
|
|
|
kernel_audio_locking(true);
|
2010-05-27 23:14:39 +00:00
|
|
|
++dma_play_data.locked;
|
2009-02-08 22:32:41 +00:00
|
|
|
}
|
2008-05-03 15:14:52 +00:00
|
|
|
|
2009-02-08 22:32:41 +00:00
|
|
|
void pcm_play_unlock(void)
|
|
|
|
{
|
2011-01-07 20:40:36 +00:00
|
|
|
if (--dma_play_data.locked == 0)
|
2008-05-03 15:14:52 +00:00
|
|
|
{
|
2011-01-07 20:40:36 +00:00
|
|
|
if (dma_play_data.state != 0)
|
|
|
|
{
|
|
|
|
int oldstatus = disable_irq_save();
|
|
|
|
int pending = dma_play_data.callback_pending;
|
|
|
|
dma_play_data.callback_pending = 0;
|
|
|
|
restore_irq(oldstatus);
|
|
|
|
|
|
|
|
if (pending != 0)
|
|
|
|
play_dma_callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
kernel_audio_locking(false);
|
2008-05-03 15:14:52 +00:00
|
|
|
}
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-12 11:01:07 +00:00
|
|
|
void pcm_dma_apply_settings(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-12-12 11:01:07 +00:00
|
|
|
audiohw_set_frequency(pcm_fsel);
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_play_dma_init(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2011-10-17 15:37:14 +00:00
|
|
|
/* Init DMA channel information */
|
2009-02-08 22:32:41 +00:00
|
|
|
sdma_channel_init(DMA_PLAY_CH_NUM, &dma_play_cd, &dma_play_bd);
|
2009-03-12 06:31:40 +00:00
|
|
|
sdma_channel_set_priority(DMA_PLAY_CH_NUM, DMA_PLAY_CH_PRIORITY);
|
2009-02-08 22:32:41 +00:00
|
|
|
|
2011-10-17 15:37:14 +00:00
|
|
|
/* Init audio interfaces */
|
2008-04-27 10:30:54 +00:00
|
|
|
audiohw_init();
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 12:15:43 +00:00
|
|
|
void pcm_play_dma_postinit(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-04-27 10:30:54 +00:00
|
|
|
audiohw_postinit();
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
static void play_start_pcm(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-05-03 15:14:52 +00:00
|
|
|
/* Stop transmission (if in progress) */
|
2009-03-09 04:25:25 +00:00
|
|
|
SSI_SCR2 &= ~SSI_SCR_TE;
|
2008-05-03 15:14:52 +00:00
|
|
|
|
2009-03-09 04:25:25 +00:00
|
|
|
SSI_SCR2 |= SSI_SCR_SSIEN; /* Enable SSI */
|
|
|
|
SSI_STCR2 |= SSI_STCR_TFEN0; /* Enable TX FIFO */
|
2008-11-19 03:12:34 +00:00
|
|
|
|
2010-05-27 23:22:55 +00:00
|
|
|
dma_play_data.state = 1; /* Check callback on unlock */
|
2008-05-03 15:14:52 +00:00
|
|
|
|
2009-02-08 22:32:41 +00:00
|
|
|
/* Do prefill to prevent swapped channels (see TLSbo61214 in MCIMX31CE).
|
|
|
|
* No actual solution was offered but this appears to work. */
|
2009-03-09 04:25:25 +00:00
|
|
|
SSI_STX0_2 = 0;
|
|
|
|
SSI_STX0_2 = 0;
|
|
|
|
SSI_STX0_2 = 0;
|
|
|
|
SSI_STX0_2 = 0;
|
2009-02-08 22:32:41 +00:00
|
|
|
|
2010-05-27 23:14:39 +00:00
|
|
|
SSI_SIER2 |= SSI_SIER_TDMAE; /* Enable DMA req. */
|
|
|
|
SSI_SCR2 |= SSI_SCR_TE; /* Start transmitting */
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
static void play_stop_pcm(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2010-05-27 23:14:39 +00:00
|
|
|
SSI_SIER2 &= ~SSI_SIER_TDMAE; /* Disable DMA req. */
|
|
|
|
|
|
|
|
/* Set state before pending to prevent race with interrupt */
|
|
|
|
dma_play_data.state = 0;
|
|
|
|
|
2008-05-03 15:14:52 +00:00
|
|
|
/* Wait for FIFO to empty */
|
2009-03-22 01:50:48 +00:00
|
|
|
while (SSI_SFCSR_TFCNT0 & SSI_SFCSR2);
|
2008-05-03 15:14:52 +00:00
|
|
|
|
2010-05-27 23:14:39 +00:00
|
|
|
SSI_STCR2 &= ~SSI_STCR_TFEN0; /* Disable TX */
|
|
|
|
SSI_SCR2 &= ~(SSI_SCR_TE | SSI_SCR_SSIEN); /* Disable transmission, SSI */
|
2008-05-03 15:14:52 +00:00
|
|
|
|
2011-01-01 22:35:00 +00:00
|
|
|
if (pcm_playing)
|
|
|
|
{
|
|
|
|
/* Stopping: clear buffer info to ensure 0-size readbacks when
|
|
|
|
* stopped */
|
|
|
|
unsigned long dsa = 0;
|
|
|
|
dma_play_bd.buf_addr = NULL;
|
|
|
|
dma_play_bd.mode.count = 0;
|
2011-12-17 07:27:24 +00:00
|
|
|
discard_dcache_range(&dsa, sizeof(dsa));
|
2011-01-01 22:35:00 +00:00
|
|
|
sdma_write_words(&dsa, CHANNEL_CONTEXT_ADDR(DMA_PLAY_CH_NUM)+0x0b, 1);
|
|
|
|
}
|
|
|
|
|
2010-05-27 23:14:39 +00:00
|
|
|
/* Clear any pending callback */
|
2009-02-08 22:32:41 +00:00
|
|
|
dma_play_data.callback_pending = 0;
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_play_dma_start(const void *addr, size_t size)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2009-02-08 22:32:41 +00:00
|
|
|
sdma_channel_stop(DMA_PLAY_CH_NUM);
|
|
|
|
|
|
|
|
/* Disable transmission */
|
2009-03-09 04:25:25 +00:00
|
|
|
SSI_STCR2 &= ~SSI_STCR_TFEN0;
|
|
|
|
SSI_SCR2 &= ~(SSI_SCR_TE | SSI_SCR_SSIEN);
|
2009-02-08 22:32:41 +00:00
|
|
|
|
2009-02-13 12:59:30 +00:00
|
|
|
if (!sdma_channel_reset(DMA_PLAY_CH_NUM))
|
|
|
|
return;
|
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
/* Begin I2S transmission */
|
2008-05-03 15:14:52 +00:00
|
|
|
play_start_pcm();
|
2012-02-23 13:14:46 +00:00
|
|
|
|
|
|
|
/* Begin DMA transfer */
|
|
|
|
play_start_dma(addr, size);
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_play_dma_stop(void)
|
|
|
|
{
|
2009-02-08 22:32:41 +00:00
|
|
|
sdma_channel_stop(DMA_PLAY_CH_NUM);
|
2008-05-03 15:14:52 +00:00
|
|
|
play_stop_pcm();
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
void pcm_play_dma_pause(bool pause)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-05-03 15:14:52 +00:00
|
|
|
if (pause)
|
|
|
|
{
|
2009-02-08 22:32:41 +00:00
|
|
|
sdma_channel_pause(DMA_PLAY_CH_NUM);
|
2008-05-03 15:14:52 +00:00
|
|
|
play_stop_pcm();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
play_start_pcm();
|
2009-02-08 22:32:41 +00:00
|
|
|
sdma_channel_run(DMA_PLAY_CH_NUM);
|
2008-05-03 15:14:52 +00:00
|
|
|
}
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
/* Return the number of bytes waiting - full L-R sample pairs only */
|
2007-09-21 15:51:53 +00:00
|
|
|
size_t pcm_get_bytes_waiting(void)
|
|
|
|
{
|
2010-05-08 07:45:34 +00:00
|
|
|
static unsigned long dsa NOCACHEBSS_ATTR;
|
2009-02-08 22:32:41 +00:00
|
|
|
long offs, size;
|
|
|
|
int oldstatus;
|
|
|
|
|
|
|
|
/* read burst dma source address register in channel context */
|
|
|
|
sdma_read_words(&dsa, CHANNEL_CONTEXT_ADDR(DMA_PLAY_CH_NUM)+0x0b, 1);
|
|
|
|
|
|
|
|
oldstatus = disable_irq_save();
|
|
|
|
offs = dsa - (unsigned long)dma_play_bd.buf_addr;
|
|
|
|
size = dma_play_bd.mode.count;
|
|
|
|
restore_irq(oldstatus);
|
|
|
|
|
|
|
|
/* Be addresses are coherent (no buffer change during read) */
|
|
|
|
if (offs >= 0 && offs < size)
|
|
|
|
{
|
|
|
|
return (size - offs) & ~3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:27:27 +00:00
|
|
|
/* Return a pointer to the samples and the number of them in *count */
|
|
|
|
const void * pcm_play_dma_get_peak_buffer(int *count)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2010-05-08 07:45:34 +00:00
|
|
|
static unsigned long dsa NOCACHEBSS_ATTR;
|
2009-02-08 22:32:41 +00:00
|
|
|
unsigned long addr;
|
|
|
|
long offs, size;
|
|
|
|
int oldstatus;
|
|
|
|
|
|
|
|
/* read burst dma source address register in channel context */
|
|
|
|
sdma_read_words(&dsa, CHANNEL_CONTEXT_ADDR(DMA_PLAY_CH_NUM)+0x0b, 1);
|
|
|
|
|
|
|
|
oldstatus = disable_irq_save();
|
|
|
|
addr = dsa;
|
|
|
|
offs = addr - (unsigned long)dma_play_bd.buf_addr;
|
|
|
|
size = dma_play_bd.mode.count;
|
|
|
|
restore_irq(oldstatus);
|
|
|
|
|
|
|
|
/* Be addresses are coherent (no buffer change during read) */
|
|
|
|
if (offs >= 0 && offs < size)
|
|
|
|
{
|
|
|
|
*count = (size - offs) >> 2;
|
|
|
|
return (void *)((addr + 2) & ~3);
|
|
|
|
}
|
|
|
|
|
|
|
|
*count = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void * pcm_dma_addr(void *addr)
|
|
|
|
{
|
|
|
|
return (void *)addr_virt_to_phys((unsigned long)addr);
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-31 01:38:44 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2010-05-08 07:45:34 +00:00
|
|
|
static struct buffer_descriptor dma_rec_bd NOCACHEBSS_ATTR;
|
2010-06-24 08:40:05 +00:00
|
|
|
|
|
|
|
static void rec_dma_callback(void);
|
|
|
|
static struct channel_descriptor dma_rec_cd =
|
|
|
|
{
|
|
|
|
.bd_count = 1,
|
|
|
|
.callback = rec_dma_callback,
|
|
|
|
.shp_addr = SDMA_PER_ADDR_SSI1_RX1,
|
|
|
|
.wml = SDMA_SSI_RXFIFO_WML*2,
|
|
|
|
.per_type = SDMA_PER_SSI,
|
|
|
|
.tran_type = SDMA_TRAN_PER_2_EMI,
|
|
|
|
.event_id1 = SDMA_REQ_SSI1_RX1,
|
|
|
|
};
|
2009-02-08 22:32:41 +00:00
|
|
|
|
2008-12-31 01:38:44 +00:00
|
|
|
static struct dma_data dma_rec_data =
|
|
|
|
{
|
2010-05-27 23:14:39 +00:00
|
|
|
/* Initialize to an unlocked, stopped state */
|
2008-12-31 01:38:44 +00:00
|
|
|
.locked = 0,
|
2009-02-09 03:13:04 +00:00
|
|
|
.callback_pending = 0,
|
2008-12-31 01:38:44 +00:00
|
|
|
.state = 0
|
|
|
|
};
|
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
static void rec_start_dma(void *addr, size_t size)
|
2008-12-31 01:38:44 +00:00
|
|
|
{
|
2012-02-23 13:14:46 +00:00
|
|
|
discard_dcache_range(addr, size);
|
|
|
|
|
|
|
|
addr = (void *)addr_virt_to_phys((unsigned long)addr);
|
2008-12-31 01:38:44 +00:00
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
dma_rec_bd.buf_addr = addr;
|
|
|
|
dma_rec_bd.mode.count = size;
|
|
|
|
dma_rec_bd.mode.command = TRANSFER_16BIT;
|
|
|
|
dma_rec_bd.mode.status = BD_DONE | BD_WRAP | BD_INTR;
|
|
|
|
|
|
|
|
sdma_channel_run(DMA_REC_CH_NUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rec_dma_callback(void)
|
|
|
|
{
|
2009-02-09 03:13:04 +00:00
|
|
|
if (dma_rec_data.locked != 0)
|
2008-12-31 01:38:44 +00:00
|
|
|
{
|
2009-02-09 03:13:04 +00:00
|
|
|
dma_rec_data.callback_pending = dma_rec_data.state;
|
2009-02-08 22:32:41 +00:00
|
|
|
return; /* Callback is locked out */
|
2008-12-31 01:38:44 +00:00
|
|
|
}
|
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
/* Inform middle layer */
|
|
|
|
enum pcm_dma_status status = (dma_rec_bd.mode.status & BD_RROR) ?
|
|
|
|
PCM_DMAST_ERR_DMA : PCM_DMAST_OK;
|
|
|
|
void *addr;
|
|
|
|
size_t size;
|
2010-05-24 16:42:32 +00:00
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
if (pcm_rec_dma_complete_callback(status, &addr, &size))
|
|
|
|
{
|
|
|
|
rec_start_dma(addr, size);
|
|
|
|
pcm_rec_dma_status_callback(PCM_DMAST_STARTED);
|
|
|
|
}
|
2008-12-31 01:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_rec_lock(void)
|
|
|
|
{
|
2011-01-07 20:40:36 +00:00
|
|
|
kernel_audio_locking(true);
|
2010-05-27 23:14:39 +00:00
|
|
|
++dma_rec_data.locked;
|
2008-12-31 01:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_rec_unlock(void)
|
|
|
|
{
|
2011-01-07 20:40:36 +00:00
|
|
|
if (--dma_rec_data.locked == 0)
|
2008-12-31 01:38:44 +00:00
|
|
|
{
|
2011-01-07 20:40:36 +00:00
|
|
|
if (dma_rec_data.state != 0)
|
|
|
|
{
|
|
|
|
int oldstatus = disable_irq_save();
|
|
|
|
int pending = dma_rec_data.callback_pending;
|
|
|
|
dma_rec_data.callback_pending = 0;
|
|
|
|
restore_irq(oldstatus);
|
|
|
|
|
|
|
|
if (pending != 0)
|
|
|
|
rec_dma_callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
kernel_audio_locking(false);
|
2008-12-31 01:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_rec_dma_stop(void)
|
|
|
|
{
|
2010-05-27 23:14:39 +00:00
|
|
|
SSI_SIER1 &= ~SSI_SIER_RDMAE; /* Disable DMA req. */
|
|
|
|
|
|
|
|
/* Set state before pending to prevent race with interrupt */
|
|
|
|
dma_rec_data.state = 0;
|
|
|
|
|
2008-12-31 01:38:44 +00:00
|
|
|
/* Stop receiving data */
|
2009-02-08 22:32:41 +00:00
|
|
|
sdma_channel_stop(DMA_REC_CH_NUM);
|
|
|
|
|
2010-06-30 02:02:46 +00:00
|
|
|
bitclr32(&SSI_SIER1, SSI_SIER_RDMAE);
|
2009-02-08 22:32:41 +00:00
|
|
|
|
2009-03-09 04:25:25 +00:00
|
|
|
SSI_SCR1 &= ~SSI_SCR_RE; /* Disable RX */
|
|
|
|
SSI_SRCR1 &= ~SSI_SRCR_RFEN0; /* Disable RX FIFO */
|
2008-12-31 01:38:44 +00:00
|
|
|
|
2011-01-01 22:35:00 +00:00
|
|
|
if (pcm_recording)
|
|
|
|
{
|
|
|
|
/* Stopping: clear buffer info to ensure 0-size readbacks when
|
|
|
|
* stopped */
|
|
|
|
unsigned long pda = 0;
|
|
|
|
dma_rec_bd.buf_addr = NULL;
|
|
|
|
dma_rec_bd.mode.count = 0;
|
2011-12-17 07:27:24 +00:00
|
|
|
discard_dcache_range(&pda, sizeof(pda));
|
2011-01-01 22:35:00 +00:00
|
|
|
sdma_write_words(&pda, CHANNEL_CONTEXT_ADDR(DMA_REC_CH_NUM)+0x0a, 1);
|
|
|
|
}
|
|
|
|
|
2010-05-27 23:14:39 +00:00
|
|
|
/* Clear any pending callback */
|
2009-02-08 22:32:41 +00:00
|
|
|
dma_rec_data.callback_pending = 0;
|
2008-12-31 01:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_rec_dma_start(void *addr, size_t size)
|
|
|
|
{
|
|
|
|
pcm_rec_dma_stop();
|
|
|
|
|
2009-02-13 12:59:30 +00:00
|
|
|
if (!sdma_channel_reset(DMA_REC_CH_NUM))
|
|
|
|
return;
|
2009-02-08 22:32:41 +00:00
|
|
|
|
2012-05-23 14:18:32 +00:00
|
|
|
SSI_SRCR1 |= SSI_SRCR_RFEN0; /* Enable RX FIFO */
|
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
/* Ensure clear FIFO */
|
|
|
|
while (SSI_SFCSR1 & SSI_SFCSR_RFCNT0)
|
|
|
|
SSI_SRX0_1;
|
2008-12-31 01:38:44 +00:00
|
|
|
|
|
|
|
/* Enable receive */
|
2009-03-09 04:25:25 +00:00
|
|
|
SSI_SCR1 |= SSI_SCR_RE;
|
2010-05-27 23:14:39 +00:00
|
|
|
SSI_SIER1 |= SSI_SIER_RDMAE; /* Enable DMA req. */
|
|
|
|
|
2012-02-23 13:14:46 +00:00
|
|
|
/* Begin DMA transfer */
|
|
|
|
rec_start_dma(addr, size);
|
2012-05-23 14:18:32 +00:00
|
|
|
|
|
|
|
dma_rec_data.state = 1; /* Check callback on unlock */
|
2008-12-31 01:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_rec_dma_close(void)
|
|
|
|
{
|
|
|
|
pcm_rec_dma_stop();
|
2009-02-08 22:32:41 +00:00
|
|
|
sdma_channel_close(DMA_REC_CH_NUM);
|
2008-12-31 01:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_rec_dma_init(void)
|
|
|
|
{
|
|
|
|
pcm_rec_dma_stop();
|
2009-02-08 22:32:41 +00:00
|
|
|
|
|
|
|
/* Init channel information */
|
|
|
|
sdma_channel_init(DMA_REC_CH_NUM, &dma_rec_cd, &dma_rec_bd);
|
2009-03-12 06:31:40 +00:00
|
|
|
sdma_channel_set_priority(DMA_REC_CH_NUM, DMA_REC_CH_PRIORITY);
|
2008-12-31 01:38:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-12 14:05:36 +00:00
|
|
|
const void * pcm_rec_dma_get_peak_buffer(void)
|
2008-12-31 01:38:44 +00:00
|
|
|
{
|
2010-05-08 07:45:34 +00:00
|
|
|
static unsigned long pda NOCACHEBSS_ATTR;
|
2010-05-12 14:05:36 +00:00
|
|
|
unsigned long buf, end, bufend;
|
2009-02-08 22:32:41 +00:00
|
|
|
int oldstatus;
|
|
|
|
|
|
|
|
/* read burst dma destination address register in channel context */
|
|
|
|
sdma_read_words(&pda, CHANNEL_CONTEXT_ADDR(DMA_REC_CH_NUM)+0x0a, 1);
|
|
|
|
|
|
|
|
oldstatus = disable_irq_save();
|
|
|
|
end = pda;
|
|
|
|
buf = (unsigned long)dma_rec_bd.buf_addr;
|
|
|
|
bufend = buf + dma_rec_bd.mode.count;
|
|
|
|
restore_irq(oldstatus);
|
|
|
|
|
|
|
|
/* Be addresses are coherent (no buffer change during read) */
|
2010-05-12 14:05:36 +00:00
|
|
|
if (end >= buf && end < bufend)
|
|
|
|
return (void *)(end & ~3);
|
2009-02-08 22:32:41 +00:00
|
|
|
|
|
|
|
return NULL;
|
2008-12-31 01:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_RECORDING */
|