2009-07-05 13:41:16 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright © 2009 Bertrik Sikken
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "s5l8700.h"
|
|
|
|
#include "panic.h"
|
|
|
|
#include "audiohw.h"
|
|
|
|
#include "pcm.h"
|
2011-06-29 06:37:04 +00:00
|
|
|
#include "pcm-internal.h"
|
2009-07-05 13:41:16 +00:00
|
|
|
#include "pcm_sampr.h"
|
2009-11-11 20:30:53 +00:00
|
|
|
#include "dma-target.h"
|
2010-04-13 16:05:11 +00:00
|
|
|
#include "mmu-arm.h"
|
2009-07-05 13:41:16 +00:00
|
|
|
|
|
|
|
/* Driver for the IIS/PCM part of the s5l8700 using DMA
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
- pcm_play_dma_pause is untested, not sure if implemented the right way
|
|
|
|
- pcm_play_dma_stop is untested, not sure if implemented the right way
|
|
|
|
- recording is not implemented
|
|
|
|
*/
|
|
|
|
|
2009-10-23 23:47:38 +00:00
|
|
|
static volatile int locked = 0;
|
2010-11-13 21:08:15 +00:00
|
|
|
static const int zerosample = 0;
|
2010-11-14 19:49:20 +00:00
|
|
|
static unsigned char dblbuf[1024] IBSS_ATTR;
|
2010-11-13 21:08:15 +00:00
|
|
|
static const unsigned char* queuedbuf;
|
|
|
|
static size_t queuedsize;
|
|
|
|
static const unsigned char* nextbuf;
|
2010-08-08 10:49:32 +00:00
|
|
|
static size_t nextsize;
|
2009-07-05 13:41:16 +00:00
|
|
|
|
|
|
|
static const struct div_entry {
|
|
|
|
int pdiv, mdiv, sdiv, cdiv;
|
|
|
|
} div_table[HW_NUM_FREQ] = {
|
2009-07-25 00:49:13 +00:00
|
|
|
#ifdef IPOD_NANO2G
|
2010-11-14 04:46:38 +00:00
|
|
|
[HW_FREQ_11] = { 0, 41, 3, 8},
|
|
|
|
[HW_FREQ_22] = { 0, 41, 3, 4},
|
|
|
|
[HW_FREQ_44] = { 0, 41, 3, 2},
|
|
|
|
[HW_FREQ_88] = { 0, 41, 3, 1},
|
|
|
|
[HW_FREQ_8 ] = { 0, 2, 1, 9},
|
|
|
|
[HW_FREQ_16] = { 0, 2, 0, 9},
|
|
|
|
[HW_FREQ_32] = { 2, 2, 0, 9},
|
|
|
|
[HW_FREQ_64] = { 6, 2, 0, 9},
|
|
|
|
[HW_FREQ_12] = { 0, 2, 2, 3},
|
|
|
|
[HW_FREQ_24] = { 0, 2, 1, 3},
|
|
|
|
[HW_FREQ_48] = { 0, 2, 0, 3},
|
|
|
|
[HW_FREQ_96] = { 2, 2, 0, 3},
|
2009-07-25 00:49:13 +00:00
|
|
|
#else
|
2010-11-13 21:08:15 +00:00
|
|
|
/* table of recommended PLL/MCLK dividers for mode 256Fs from the datasheet */
|
2009-10-05 12:29:21 +00:00
|
|
|
[HW_FREQ_11] = { 26, 189, 3, 8},
|
2009-07-05 13:41:16 +00:00
|
|
|
[HW_FREQ_22] = { 50, 98, 2, 8},
|
|
|
|
[HW_FREQ_44] = { 37, 151, 1, 9},
|
|
|
|
[HW_FREQ_88] = { 50, 98, 1, 4},
|
|
|
|
#if 0 /* disabled because the codec driver does not support it (yet) */
|
2009-10-23 23:47:38 +00:00
|
|
|
[HW_FREQ_8 ] = { 28, 192, 3, 12},
|
2009-07-05 13:41:16 +00:00
|
|
|
[HW_FREQ_16] = { 28, 192, 3, 6},
|
|
|
|
[HW_FREQ_32] = { 28, 192, 2, 6},
|
|
|
|
[HW_FREQ_12] = { 28, 192, 3, 8},
|
|
|
|
[HW_FREQ_24] = { 28, 192, 2, 8},
|
|
|
|
[HW_FREQ_48] = { 28, 192, 2, 4},
|
|
|
|
[HW_FREQ_96] = { 28, 192, 1, 4},
|
|
|
|
#endif
|
2009-10-05 12:29:21 +00:00
|
|
|
#endif
|
2009-07-05 13:41:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Mask the DMA interrupt */
|
|
|
|
void pcm_play_lock(void)
|
|
|
|
{
|
|
|
|
if (locked++ == 0) {
|
|
|
|
INTMSK &= ~(1 << 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unmask the DMA interrupt if enabled */
|
|
|
|
void pcm_play_unlock(void)
|
|
|
|
{
|
|
|
|
if (--locked == 0) {
|
2009-07-18 11:54:01 +00:00
|
|
|
INTMSK |= (1 << 10);
|
2009-07-05 13:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 21:08:15 +00:00
|
|
|
void INT_DMA(void) ICODE_ATTR;
|
|
|
|
void INT_DMA(void)
|
2009-07-05 13:41:16 +00:00
|
|
|
{
|
2011-06-29 06:37:04 +00:00
|
|
|
bool new_buffer = false;
|
2010-11-13 21:08:15 +00:00
|
|
|
DMACOM0 = 7;
|
|
|
|
while (!(DMACON0 & (1 << 18)))
|
2009-10-23 23:47:38 +00:00
|
|
|
{
|
2010-11-13 21:08:15 +00:00
|
|
|
if (queuedsize)
|
2009-10-23 23:47:38 +00:00
|
|
|
{
|
2010-11-13 21:08:15 +00:00
|
|
|
memcpy(dblbuf, queuedbuf, queuedsize);
|
|
|
|
DMABASE0 = (unsigned int)dblbuf;
|
|
|
|
DMATCNT0 = queuedsize / 2 - 1;
|
|
|
|
queuedsize = 0;
|
2009-07-05 13:41:16 +00:00
|
|
|
}
|
2009-10-23 23:47:38 +00:00
|
|
|
else
|
|
|
|
{
|
2011-06-29 06:37:04 +00:00
|
|
|
if (!nextsize)
|
|
|
|
{
|
|
|
|
pcm_play_get_more_callback((void**)&nextbuf, &nextsize);
|
|
|
|
if (!nextsize) break;
|
|
|
|
new_buffer = true;
|
|
|
|
}
|
2010-11-13 21:08:15 +00:00
|
|
|
queuedsize = MIN(sizeof(dblbuf), nextsize / 2);
|
|
|
|
nextsize -= queuedsize;
|
|
|
|
queuedbuf = nextbuf + nextsize;
|
|
|
|
DMABASE0 = (unsigned int)nextbuf;
|
|
|
|
DMATCNT0 = nextsize / 2 - 1;
|
|
|
|
nextsize = 0;
|
2009-07-05 13:41:16 +00:00
|
|
|
}
|
2011-12-17 07:54:00 +00:00
|
|
|
commit_dcache();
|
2010-11-13 21:08:15 +00:00
|
|
|
DMACOM0 = 4;
|
|
|
|
DMACOM0 = 7;
|
2011-06-29 06:37:04 +00:00
|
|
|
|
|
|
|
if (new_buffer)
|
|
|
|
{
|
|
|
|
pcm_play_dma_started_callback();
|
|
|
|
new_buffer = false;
|
|
|
|
}
|
2009-07-05 13:41:16 +00:00
|
|
|
}
|
2011-06-29 06:37:04 +00:00
|
|
|
|
2009-07-05 13:41:16 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 21:08:15 +00:00
|
|
|
void pcm_play_dma_start(const void* addr, size_t size)
|
2009-07-05 13:41:16 +00:00
|
|
|
{
|
2010-11-13 21:08:15 +00:00
|
|
|
/* DMA channel on */
|
|
|
|
nextbuf = (const unsigned char*)addr;
|
|
|
|
nextsize = size;
|
|
|
|
queuedsize = 0;
|
|
|
|
DMABASE0 = (unsigned int)(&zerosample);
|
|
|
|
DMATCNT0 = 0;
|
|
|
|
DMACOM0 = 4;
|
|
|
|
|
|
|
|
/* IIS Tx clock on */
|
2009-07-05 13:41:16 +00:00
|
|
|
I2SCLKCON = (1 << 0); /* 1 = power on */
|
|
|
|
|
2010-11-13 21:08:15 +00:00
|
|
|
/* IIS Tx on */
|
2009-07-05 13:41:16 +00:00
|
|
|
I2STXCOM = (1 << 3) | /* 1 = transmit mode on */
|
|
|
|
(1 << 2) | /* 1 = I2S interface enable */
|
|
|
|
(1 << 1) | /* 1 = DMA request enable */
|
|
|
|
(0 << 0); /* 0 = LRCK on */
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_play_dma_stop(void)
|
|
|
|
{
|
|
|
|
/* DMA channel off */
|
2009-10-23 23:47:38 +00:00
|
|
|
DMACOM0 = 5;
|
2009-07-05 13:41:16 +00:00
|
|
|
|
|
|
|
/* IIS Tx off */
|
|
|
|
I2STXCOM = (1 << 3) | /* 1 = transmit mode on */
|
|
|
|
(0 << 2) | /* 1 = I2S interface enable */
|
|
|
|
(1 << 1) | /* 1 = DMA request enable */
|
|
|
|
(0 << 0); /* 0 = LRCK on */
|
|
|
|
}
|
|
|
|
|
2009-10-21 18:52:09 +00:00
|
|
|
/* pause playback by disabling the I2S interface */
|
2009-07-05 13:41:16 +00:00
|
|
|
void pcm_play_dma_pause(bool pause)
|
|
|
|
{
|
|
|
|
if (pause) {
|
2009-10-21 18:52:09 +00:00
|
|
|
I2STXCOM |= (1 << 0); /* LRCK off */
|
2009-07-05 13:41:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-10-21 18:52:09 +00:00
|
|
|
I2STXCOM &= ~(1 << 0); /* LRCK on */
|
2009-07-05 13:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 21:08:15 +00:00
|
|
|
static void pcm_dma_set_freq(enum hw_freq_indexes idx)
|
2009-07-05 13:41:16 +00:00
|
|
|
{
|
2010-11-13 21:08:15 +00:00
|
|
|
struct div_entry div = div_table[idx];
|
2009-07-25 00:49:13 +00:00
|
|
|
|
2009-07-05 13:41:16 +00:00
|
|
|
/* configure PLL1 and MCLK for the desired sample rate */
|
|
|
|
PLL1PMS = (div.pdiv << 16) |
|
|
|
|
(div.mdiv << 8) |
|
|
|
|
(div.sdiv << 0);
|
2010-11-14 04:46:38 +00:00
|
|
|
PLL1LCNT = 280; /* 150 microseconds */
|
2009-07-25 00:49:13 +00:00
|
|
|
|
2009-07-05 13:41:16 +00:00
|
|
|
/* enable PLL1 and wait for lock */
|
2010-11-14 04:46:38 +00:00
|
|
|
PLLCON |= 1 << 1;
|
2009-07-05 13:41:16 +00:00
|
|
|
while ((PLLLOCK & (1 << 1)) == 0);
|
|
|
|
|
|
|
|
/* configure MCLK */
|
2009-07-25 00:49:13 +00:00
|
|
|
CLKCON = (CLKCON & ~(0xFF)) |
|
2009-07-05 13:41:16 +00:00
|
|
|
(0 << 7) | /* MCLK_MASK */
|
2009-10-23 23:47:38 +00:00
|
|
|
(2 << 5) | /* MCLK_SEL = PLL1 */
|
2009-07-05 13:41:16 +00:00
|
|
|
(1 << 4) | /* MCLK_DIV_ON */
|
|
|
|
(div.cdiv - 1); /* MCLK_DIV_VAL */
|
|
|
|
}
|
|
|
|
|
2010-11-13 21:08:15 +00:00
|
|
|
void pcm_play_dma_init(void)
|
|
|
|
{
|
|
|
|
/* configure IIS pins */
|
|
|
|
#ifdef IPOD_NANO2G
|
|
|
|
PCON5 = (PCON5 & ~(0xFFFF0000)) | 0x77720000;
|
|
|
|
PCON6 = (PCON6 & ~(0x0F000000)) | 0x02000000;
|
|
|
|
#else
|
|
|
|
PCON7 = (PCON7 & ~(0x0FFFFF00)) | 0x02222200;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* configure DMA channel */
|
|
|
|
DMACON0 = (0 << 30) | /* DEVSEL */
|
|
|
|
(1 << 29) | /* DIR */
|
|
|
|
(0 << 24) | /* SCHCNT */
|
|
|
|
(1 << 22) | /* DSIZE */
|
|
|
|
(0 << 19) | /* BLEN */
|
|
|
|
(0 << 18) | /* RELOAD */
|
|
|
|
(0 << 17) | /* HCOMINT */
|
|
|
|
(1 << 16) | /* WCOMINT */
|
|
|
|
(0 << 0); /* OFFSET */
|
|
|
|
|
|
|
|
/* Enable the DMA IRQ */
|
|
|
|
INTMSK |= (1 << 10);
|
|
|
|
|
|
|
|
/* setup PLL */
|
|
|
|
pcm_dma_set_freq(HW_FREQ_44);
|
|
|
|
|
|
|
|
/* enable clock to the IIS module */
|
|
|
|
PWRCON &= ~(1 << 6);
|
|
|
|
|
|
|
|
/* configure IIS core */
|
|
|
|
#ifdef IPOD_NANO2G
|
|
|
|
I2STXCON = (1 << 20) | /* undocumented */
|
|
|
|
(0 << 16) | /* burst length */
|
|
|
|
(0 << 15) | /* 0 = falling edge */
|
|
|
|
(0 << 13) | /* 0 = basic I2S format */
|
|
|
|
(0 << 12) | /* 0 = MSB first */
|
|
|
|
(0 << 11) | /* 0 = left channel for low polarity */
|
2010-11-14 04:46:38 +00:00
|
|
|
(3 << 8) | /* MCLK divider */
|
2010-11-13 21:08:15 +00:00
|
|
|
(0 << 5) | /* 0 = 16-bit */
|
|
|
|
(2 << 3) | /* bit clock per frame */
|
|
|
|
(1 << 0); /* channel index */
|
|
|
|
#else
|
|
|
|
I2STXCON = (DMA_IISOUT_BLEN << 16) | /* burst length */
|
|
|
|
(0 << 15) | /* 0 = falling edge */
|
|
|
|
(0 << 13) | /* 0 = basic I2S format */
|
|
|
|
(0 << 12) | /* 0 = MSB first */
|
|
|
|
(0 << 11) | /* 0 = left channel for low polarity */
|
|
|
|
(3 << 8) | /* MCLK divider */
|
|
|
|
(0 << 5) | /* 0 = 16-bit */
|
|
|
|
(0 << 3) | /* bit clock per frame */
|
|
|
|
(1 << 0); /* channel index */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
audiohw_preinit();
|
|
|
|
}
|
|
|
|
|
2011-09-01 12:15:43 +00:00
|
|
|
void pcm_play_dma_postinit(void)
|
2010-11-13 21:08:15 +00:00
|
|
|
{
|
|
|
|
audiohw_postinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the configured PCM frequency */
|
|
|
|
void pcm_dma_apply_settings(void)
|
|
|
|
{
|
|
|
|
pcm_dma_set_freq(pcm_fsel);
|
|
|
|
}
|
|
|
|
|
2009-07-05 13:41:16 +00:00
|
|
|
size_t pcm_get_bytes_waiting(void)
|
|
|
|
{
|
2009-11-09 15:50:13 +00:00
|
|
|
return (nextsize + DMACTCNT0 + 2) << 1;
|
2009-07-05 13:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const void * pcm_play_dma_get_peak_buffer(int *count)
|
|
|
|
{
|
2009-10-12 11:58:36 +00:00
|
|
|
*count = DMACTCNT0 >> 1;
|
2009-10-23 23:47:38 +00:00
|
|
|
return (void *)(((DMACADDR0 + 2) & ~3) | 0x40000000);
|
2009-07-05 13:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_PCM_DMA_ADDRESS
|
|
|
|
void * pcm_dma_addr(void *addr)
|
|
|
|
{
|
|
|
|
if (addr != NULL)
|
2009-10-21 18:52:09 +00:00
|
|
|
addr = (void*)((uintptr_t)addr | 0x40000000);
|
2009-07-05 13:41:16 +00:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
** Recording DMA transfer
|
|
|
|
**/
|
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
void pcm_rec_lock(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_rec_unlock(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_rec_dma_stop(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_rec_dma_start(void *addr, size_t size)
|
|
|
|
{
|
|
|
|
(void)addr;
|
|
|
|
(void)size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_rec_dma_close(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void pcm_rec_dma_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-12 14:05:36 +00:00
|
|
|
const void * pcm_rec_dma_get_peak_buffer(void)
|
2009-07-05 13:41:16 +00:00
|
|
|
{
|
2010-05-12 14:05:36 +00:00
|
|
|
return NULL;
|
2009-07-05 13:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_RECORDING */
|