Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 10 | * Copyright (C) 2007 and 2009 by Karl Kurbjun |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 21 | #include <stdlib.h> |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 22 | #include "system.h" |
| 23 | #include "kernel.h" |
| 24 | #include "logf.h" |
| 25 | #include "audio.h" |
| 26 | #include "sound.h" |
| 27 | #include "file.h" |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 28 | #include "dsp-target.h" |
| 29 | #include "dsp/ipc.h" |
| 30 | #include "mmu-arm.h" |
Michael Sevakis | a2b6703 | 2011-06-29 06:37:04 +0000 | [diff] [blame^] | 31 | #include "pcm-internal.h" |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 32 | |
Karl Kurbjun | 50c547c | 2011-02-06 19:33:40 +0000 | [diff] [blame] | 33 | /* This is global to save some latency when pcm_play_dma_get_peak_buffer is |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 34 | * called. |
| 35 | */ |
Michael Sevakis | 1f5b943 | 2010-05-24 16:57:48 +0000 | [diff] [blame] | 36 | static void *start; |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 37 | |
Karl Kurbjun | b7a4e10 | 2007-10-13 14:53:34 +0000 | [diff] [blame] | 38 | void pcm_postinit(void) |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 39 | { |
Karl Kurbjun | 50c547c | 2011-02-06 19:33:40 +0000 | [diff] [blame] | 40 | /* Configure clock divider */ |
| 41 | tsc2100_writereg(CONTROL_PAGE2, TSPP1_ADDRESS, 0x1120); |
| 42 | tsc2100_writereg(CONTROL_PAGE2, TSAC3_ADDRESS, 0x0800); |
| 43 | tsc2100_writereg(CONTROL_PAGE2, TSCPC_ADDRESS, 0x3B00); |
| 44 | tsc2100_writereg(CONTROL_PAGE2, TSAC1_ADDRESS, 0x0300); |
| 45 | tsc2100_writereg(CONTROL_PAGE2, TSCSC_ADDRESS, 0xC580); |
Andree Buschmann | bfc129a | 2010-01-03 10:35:31 +0000 | [diff] [blame] | 46 | audiohw_postinit(); |
Karl Kurbjun | b7a4e10 | 2007-10-13 14:53:34 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 49 | /* Return the current location in the SDRAM to SARAM transfer along with the |
| 50 | * number of bytes read in the current buffer (count). There is latency with |
| 51 | * this method equivalent to ~ the size of the SARAM buffer since there is |
| 52 | * another buffer between your ears and this calculation, but this works for |
| 53 | * key clicks and an approximate peak meter. |
| 54 | */ |
Karl Kurbjun | b7a4e10 | 2007-10-13 14:53:34 +0000 | [diff] [blame] | 55 | const void * pcm_play_dma_get_peak_buffer(int *count) |
| 56 | { |
Andree Buschmann | bfc129a | 2010-01-03 10:35:31 +0000 | [diff] [blame] | 57 | int cnt = DSP_(_sdem_level); |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 58 | |
Karl Kurbjun | 50c547c | 2011-02-06 19:33:40 +0000 | [diff] [blame] | 59 | unsigned long addr = (unsigned long) start + cnt; |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 60 | |
| 61 | *count = (cnt & 0xFFFFF) >> 1; |
| 62 | return (void *)((addr + 2) & ~3); |
Karl Kurbjun | b7a4e10 | 2007-10-13 14:53:34 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void pcm_play_dma_init(void) |
| 66 | { |
Karl Kurbjun | 50c547c | 2011-02-06 19:33:40 +0000 | [diff] [blame] | 67 | IO_INTC_IRQ0 = INTR_IRQ0_IMGBUF; |
| 68 | bitset16(&IO_INTC_EINT0, INTR_EINT0_IMGBUF); |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 69 | |
Karl Kurbjun | e087751 | 2009-12-12 18:36:52 +0000 | [diff] [blame] | 70 | /* Set this as a FIQ */ |
Karl Kurbjun | 50c547c | 2011-02-06 19:33:40 +0000 | [diff] [blame] | 71 | bitset16(&IO_INTC_FISEL0, INTR_EINT0_IMGBUF); |
Karl Kurbjun | e087751 | 2009-12-12 18:36:52 +0000 | [diff] [blame] | 72 | |
Karl Kurbjun | 50c547c | 2011-02-06 19:33:40 +0000 | [diff] [blame] | 73 | /* Enable the HPIB clock */ |
| 74 | bitset16(&IO_CLK_MOD0, (CLK_MOD0_HPIB | CLK_MOD0_DSP)); |
| 75 | |
| 76 | IO_SDRAM_SDDMASEL = 0x24; |
| 77 | |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 78 | IO_DSPC_HPIB_CONTROL = 1 << 10 | 1 << 9 | 1 << 8 | 1 << 7 | 1 << 3 | 1 << 0; |
| 79 | |
| 80 | dsp_reset(); |
| 81 | dsp_load(dsp_image); |
Karl Kurbjun | 50c547c | 2011-02-06 19:33:40 +0000 | [diff] [blame] | 82 | |
| 83 | DSP_(_dma0_stopped)=1; |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 84 | dsp_wake(); |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Michael Sevakis | e69d567 | 2008-12-12 11:01:07 +0000 | [diff] [blame] | 87 | void pcm_dma_apply_settings(void) |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 88 | { |
Andree Buschmann | bfc129a | 2010-01-03 10:35:31 +0000 | [diff] [blame] | 89 | audiohw_set_frequency(pcm_fsel); |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 92 | /* Note that size is actually limited to the size of a short right now due to |
| 93 | * the implementation on the DSP side (and the way that we access it) |
| 94 | */ |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 95 | void pcm_play_dma_start(const void *addr, size_t size) |
| 96 | { |
Andree Buschmann | bfc129a | 2010-01-03 10:35:31 +0000 | [diff] [blame] | 97 | unsigned long sdem_addr=(unsigned long)addr - CONFIG_SDRAM_START; |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 98 | /* Initialize codec. */ |
| 99 | DSP_(_sdem_addrl) = sdem_addr & 0xffff; |
| 100 | DSP_(_sdem_addrh) = sdem_addr >> 16; |
| 101 | DSP_(_sdem_dsp_size) = size; |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 102 | DSP_(_dma0_stopped)=0; |
| 103 | |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 104 | dsp_wake(); |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void pcm_play_dma_stop(void) |
| 108 | { |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 109 | DSP_(_dma0_stopped)=1; |
Karl Kurbjun | 30c3382 | 2009-12-02 04:30:08 +0000 | [diff] [blame] | 110 | dsp_wake(); |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Karl Kurbjun | b7a4e10 | 2007-10-13 14:53:34 +0000 | [diff] [blame] | 113 | void pcm_play_lock(void) |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 114 | { |
Karl Kurbjun | b7a4e10 | 2007-10-13 14:53:34 +0000 | [diff] [blame] | 115 | |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Karl Kurbjun | b7a4e10 | 2007-10-13 14:53:34 +0000 | [diff] [blame] | 118 | void pcm_play_unlock(void) |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 119 | { |
Karl Kurbjun | b7a4e10 | 2007-10-13 14:53:34 +0000 | [diff] [blame] | 120 | |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Karl Kurbjun | b7a4e10 | 2007-10-13 14:53:34 +0000 | [diff] [blame] | 123 | void pcm_play_dma_pause(bool pause) |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 124 | { |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 125 | if (pause) |
| 126 | { |
| 127 | DSP_(_dma0_stopped)=2; |
Karl Kurbjun | 30c3382 | 2009-12-02 04:30:08 +0000 | [diff] [blame] | 128 | dsp_wake(); |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 129 | } |
| 130 | else |
| 131 | { |
Andree Buschmann | bfc129a | 2010-01-03 10:35:31 +0000 | [diff] [blame] | 132 | DSP_(_dma0_stopped)=0; |
Karl Kurbjun | 2670e3f | 2009-03-24 16:40:31 +0000 | [diff] [blame] | 133 | dsp_wake(); |
| 134 | } |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | size_t pcm_get_bytes_waiting(void) |
| 138 | { |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 139 | return DSP_(_sdem_dsp_size)-DSP_(_sdem_level); |
Karl Kurbjun | a56b653 | 2007-09-30 16:29:21 +0000 | [diff] [blame] | 140 | } |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 141 | |
Karl Kurbjun | 5ca8bf0 | 2009-08-13 04:20:46 +0000 | [diff] [blame] | 142 | /* Only used when debugging */ |
Bertrik Sikken | 76f4c02 | 2010-07-31 13:41:06 +0000 | [diff] [blame] | 143 | static char buffer[80]; |
Karl Kurbjun | 5ca8bf0 | 2009-08-13 04:20:46 +0000 | [diff] [blame] | 144 | |
| 145 | void DSPHINT(void) __attribute__ ((section(".icode"))); |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 146 | void DSPHINT(void) |
| 147 | { |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 148 | unsigned int i; |
Karl Kurbjun | 50c547c | 2011-02-06 19:33:40 +0000 | [diff] [blame] | 149 | size_t size; |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 150 | |
Karl Kurbjun | 50c547c | 2011-02-06 19:33:40 +0000 | [diff] [blame] | 151 | IO_INTC_FIQ0 = INTR_IRQ0_IMGBUF; |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 152 | |
| 153 | switch (dsp_message.msg) |
| 154 | { |
| 155 | case MSG_DEBUGF: |
| 156 | /* DSP stores one character per word. */ |
| 157 | for (i = 0; i < sizeof(buffer); i++) |
| 158 | { |
| 159 | buffer[i] = dsp_message.payload.debugf.buffer[i]; |
| 160 | } |
| 161 | |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 162 | DEBUGF("DSP: %s", buffer); |
| 163 | break; |
| 164 | |
| 165 | case MSG_REFILL: |
Andree Buschmann | bfc129a | 2010-01-03 10:35:31 +0000 | [diff] [blame] | 166 | /* Buffer empty. Try to get more. */ |
Michael Sevakis | d569998 | 2010-05-24 16:42:32 +0000 | [diff] [blame] | 167 | pcm_play_get_more_callback(&start, &size); |
| 168 | |
| 169 | if (size != 0) |
Andree Buschmann | bfc129a | 2010-01-03 10:35:31 +0000 | [diff] [blame] | 170 | { |
| 171 | unsigned long sdem_addr=(unsigned long)start - CONFIG_SDRAM_START; |
| 172 | /* Flush any pending cache writes */ |
| 173 | clean_dcache_range(start, size); |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 174 | |
Andree Buschmann | bfc129a | 2010-01-03 10:35:31 +0000 | [diff] [blame] | 175 | /* set the new DMA values */ |
| 176 | DSP_(_sdem_addrl) = sdem_addr & 0xffff; |
| 177 | DSP_(_sdem_addrh) = sdem_addr >> 16; |
| 178 | DSP_(_sdem_dsp_size) = size; |
| 179 | |
| 180 | DEBUGF("pcm_sdram at 0x%08lx, sdem_addr 0x%08lx", |
| 181 | (unsigned long)start, (unsigned long)sdem_addr); |
Michael Sevakis | a2b6703 | 2011-06-29 06:37:04 +0000 | [diff] [blame^] | 182 | |
| 183 | pcm_play_dma_started_callback(); |
Andree Buschmann | bfc129a | 2010-01-03 10:35:31 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | break; |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 187 | default: |
Andree Buschmann | bfc129a | 2010-01-03 10:35:31 +0000 | [diff] [blame] | 188 | DEBUGF("DSP: unknown msg 0x%04x", dsp_message.msg); |
| 189 | break; |
Karl Kurbjun | 3c7ada5 | 2009-03-11 01:18:23 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* Re-Activate the channel */ |
| 193 | dsp_wake(); |
| 194 | |
| 195 | DEBUGF("DSP: %s", buffer); |
| 196 | } |
| 197 | |