Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Michael Sevakis |
| 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. |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +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 | ****************************************************************************/ |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 21 | #include <stdlib.h> |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 22 | #include "system.h" |
| 23 | #include "kernel.h" |
| 24 | #include "logf.h" |
| 25 | #include "audio.h" |
Michael Sevakis | c2d2106 | 2007-03-11 06:21:43 +0000 | [diff] [blame] | 26 | #include "sound.h" |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 27 | #include "file.h" |
| 28 | |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 29 | /* All exact rates for 16.9344MHz clock */ |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 30 | #define GIGABEAT_11025HZ (0x19 << 1) |
| 31 | #define GIGABEAT_22050HZ (0x1b << 1) |
| 32 | #define GIGABEAT_44100HZ (0x11 << 1) |
| 33 | #define GIGABEAT_88200HZ (0x1f << 1) |
| 34 | |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 35 | /* PCM interrupt routine lockout */ |
| 36 | static struct |
| 37 | { |
| 38 | int locked; |
| 39 | unsigned long state; |
| 40 | } dma_play_lock = |
| 41 | { |
| 42 | .locked = 0, |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 43 | .state = 0, |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | /* Last samplerate set by pcm_set_frequency */ |
| 47 | static unsigned long pcm_freq = 0; /* 44.1 is default */ |
| 48 | /* Samplerate control for audio codec */ |
Michael Sevakis | d989f19 | 2007-05-03 18:08:00 +0000 | [diff] [blame] | 49 | static int sr_ctrl = 0; |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 50 | |
| 51 | #define FIFO_COUNT ((IISFCON >> 6) & 0x3F) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 52 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 53 | /* Setup for the DMA controller */ |
| 54 | #define DMA_CONTROL_SETUP ((1<<31) | (1<<29) | (1<<23) | (1<<22) | (1<<20)) |
| 55 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 56 | /* DMA count has hit zero - no more data */ |
| 57 | /* Get more data from the callback and top off the FIFO */ |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 58 | void fiq_handler(void) __attribute__((interrupt ("FIQ"))); |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 59 | |
| 60 | static void _pcm_apply_settings(void) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 61 | { |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 62 | if (pcm_freq != pcm_curr_sampr) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 63 | { |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 64 | pcm_curr_sampr = pcm_freq; |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 65 | audiohw_set_frequency(sr_ctrl); |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 66 | } |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 69 | void pcm_apply_settings(void) |
| 70 | { |
Michael Sevakis | af395f4 | 2008-03-26 01:50:41 +0000 | [diff] [blame] | 71 | int status = disable_fiq_save(); |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 72 | _pcm_apply_settings(); |
Michael Sevakis | af395f4 | 2008-03-26 01:50:41 +0000 | [diff] [blame] | 73 | restore_fiq(status); |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 74 | } |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 75 | |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 76 | /* Mask the DMA interrupt */ |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 77 | void pcm_play_lock(void) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 78 | { |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 79 | if (++dma_play_lock.locked == 1) |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 80 | s3c_regset(&INTMSK, DMA2_MASK); |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 81 | } |
Greg White | dd7b75b | 2007-01-04 11:36:25 +0000 | [diff] [blame] | 82 | |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 83 | /* Unmask the DMA interrupt if enabled */ |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 84 | void pcm_play_unlock(void) |
| 85 | { |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 86 | if (--dma_play_lock.locked == 0) |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 87 | s3c_regclr(&INTMSK, dma_play_lock.state); |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void pcm_play_dma_init(void) |
| 91 | { |
Steve Gotthardt | cd05dbc | 2007-01-16 03:36:32 +0000 | [diff] [blame] | 92 | pcm_set_frequency(SAMPR_44); |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 93 | |
Karl Kurbjun | 66010b9 | 2008-05-10 19:43:23 +0000 | [diff] [blame] | 94 | /* There seem to be problems when changing the IIS interface configuration |
| 95 | * when a clock is not present. |
| 96 | */ |
| 97 | s3c_regset(&CLKCON, 1<<17); |
| 98 | /* slave, transmit mode, 16 bit samples - MCLK 384fs - use 16.9344Mhz - |
| 99 | BCLK 32fs */ |
| 100 | IISMOD = (1<<9) | (1<<8) | (2<<6) | (1<<3) | (1<<2) | (1<<0); |
Michael Sevakis | f783617 | 2007-06-24 20:41:27 +0000 | [diff] [blame] | 101 | |
Karl Kurbjun | 66010b9 | 2008-05-10 19:43:23 +0000 | [diff] [blame] | 102 | /* RX,TX off,on */ |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 103 | IISCON |= (1<<3) | (1<<2); |
| 104 | |
Karl Kurbjun | 66010b9 | 2008-05-10 19:43:23 +0000 | [diff] [blame] | 105 | s3c_regclr(&CLKCON, 1<<17); |
| 106 | |
Michael Sevakis | d989f19 | 2007-05-03 18:08:00 +0000 | [diff] [blame] | 107 | audiohw_init(); |
| 108 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 109 | /* init GPIO */ |
| 110 | GPCCON = (GPCCON & ~(3<<14)) | (1<<14); |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 111 | GPCDAT |= (1<<7); |
| 112 | /* GPE4=I2SDO, GPE3=I2SDI, GPE2=CDCLK, GPE1=I2SSCLK, GPE0=I2SLRCK */ |
| 113 | GPECON = (GPECON & ~0x3ff) | 0x2aa; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 114 | |
Steve Gotthardt | cd05dbc | 2007-01-16 03:36:32 +0000 | [diff] [blame] | 115 | /* Do not service DMA requests, yet */ |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 116 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 117 | /* clear any pending int and mask it */ |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 118 | s3c_regset(&INTMSK, DMA2_MASK); |
| 119 | SRCPND = DMA2_MASK; |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 120 | |
| 121 | /* connect to FIQ */ |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 122 | s3c_regset(&INTMOD, DMA2_MASK); |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Michael Sevakis | c2d2106 | 2007-03-11 06:21:43 +0000 | [diff] [blame] | 125 | void pcm_postinit(void) |
| 126 | { |
| 127 | audiohw_postinit(); |
Michael Sevakis | d989f19 | 2007-05-03 18:08:00 +0000 | [diff] [blame] | 128 | pcm_apply_settings(); |
Michael Sevakis | c2d2106 | 2007-03-11 06:21:43 +0000 | [diff] [blame] | 129 | } |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 130 | |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 131 | /* Connect the DMA and start filling the FIFO */ |
| 132 | static void play_start_pcm(void) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 133 | { |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 134 | /* clear pending DMA interrupt */ |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 135 | SRCPND = DMA2_MASK; |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 136 | |
| 137 | _pcm_apply_settings(); |
| 138 | |
Greg White | dd7b75b | 2007-01-04 11:36:25 +0000 | [diff] [blame] | 139 | /* Flush any pending writes */ |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 140 | clean_dcache_range((void*)DISRC2, (DCON2 & 0xFFFFF) * 2); |
| 141 | |
| 142 | /* unmask DMA interrupt when unlocking */ |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 143 | dma_play_lock.state = DMA2_MASK; |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 144 | |
| 145 | /* turn on the request */ |
| 146 | IISCON |= (1<<5); |
Greg White | dd7b75b | 2007-01-04 11:36:25 +0000 | [diff] [blame] | 147 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 148 | /* Activate the channel */ |
| 149 | DMASKTRIG2 = 0x2; |
Greg White | dd7b75b | 2007-01-04 11:36:25 +0000 | [diff] [blame] | 150 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 151 | /* turn off the idle */ |
| 152 | IISCON &= ~(1<<3); |
| 153 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 154 | /* start the IIS */ |
| 155 | IISCON |= (1<<0); |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 158 | /* Disconnect the DMA and wait for the FIFO to clear */ |
| 159 | static void play_stop_pcm(void) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 160 | { |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 161 | /* Mask DMA interrupt */ |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 162 | s3c_regset(&INTMSK, DMA2_MASK); |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 163 | |
| 164 | /* De-Activate the DMA channel */ |
| 165 | DMASKTRIG2 = 0x4; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 166 | |
Steve Gotthardt | cd05dbc | 2007-01-16 03:36:32 +0000 | [diff] [blame] | 167 | /* are we playing? wait for the chunk to finish */ |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 168 | if (dma_play_lock.state != 0) |
Steve Gotthardt | cd05dbc | 2007-01-16 03:36:32 +0000 | [diff] [blame] | 169 | { |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 170 | /* wait for the FIFO to empty and DMA to stop */ |
| 171 | while ((IISCON & (1<<7)) || (DMASKTRIG2 & 0x2)); |
Steve Gotthardt | cd05dbc | 2007-01-16 03:36:32 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 174 | /* Keep interrupt masked when unlocking */ |
| 175 | dma_play_lock.state = 0; |
| 176 | |
| 177 | /* turn off the request */ |
| 178 | IISCON &= ~(1<<5); |
| 179 | |
| 180 | /* turn on the idle */ |
| 181 | IISCON |= (1<<3); |
| 182 | |
| 183 | /* stop the IIS */ |
| 184 | IISCON &= ~(1<<0); |
| 185 | } |
| 186 | |
| 187 | void pcm_play_dma_start(const void *addr, size_t size) |
| 188 | { |
| 189 | /* Enable the IIS clock */ |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 190 | s3c_regset(&CLKCON, 1<<17); |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 191 | |
| 192 | /* stop any DMA in progress - idle IIS */ |
| 193 | play_stop_pcm(); |
| 194 | |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 195 | /* connect DMA to the FIFO and enable the FIFO */ |
| 196 | IISFCON = (1<<15) | (1<<13); |
| 197 | |
| 198 | /* set DMA dest */ |
| 199 | DIDST2 = (unsigned int)&IISFIFO; |
| 200 | |
| 201 | /* IIS is on the APB bus, INT when TC reaches 0, fixed dest addr */ |
| 202 | DIDSTC2 = 0x03; |
| 203 | |
| 204 | /* set DMA source and options */ |
| 205 | DISRC2 = (unsigned int)addr + 0x30000000; |
| 206 | /* How many transfers to make - we transfer half-word at a time = 2 bytes */ |
| 207 | /* DMA control: CURR_TC int, single service mode, I2SSDO int, HW trig */ |
| 208 | /* no auto-reload, half-word (16bit) */ |
| 209 | DCON2 = DMA_CONTROL_SETUP | (size / 2); |
| 210 | DISRCC2 = 0x00; /* memory is on AHB bus, increment addresses */ |
| 211 | |
| 212 | play_start_pcm(); |
| 213 | } |
| 214 | |
| 215 | /* Promptly stop DMA transfers and stop IIS */ |
| 216 | void pcm_play_dma_stop(void) |
| 217 | { |
| 218 | play_stop_pcm(); |
| 219 | |
Steve Gotthardt | cd05dbc | 2007-01-16 03:36:32 +0000 | [diff] [blame] | 220 | /* Disconnect the IIS clock */ |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 221 | s3c_regclr(&CLKCON, 1<<17); |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 222 | } |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 223 | |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 224 | void pcm_play_dma_pause(bool pause) |
| 225 | { |
| 226 | if (pause) |
| 227 | { |
| 228 | /* pause playback on current buffer */ |
| 229 | play_stop_pcm(); |
| 230 | } |
| 231 | else |
| 232 | { |
| 233 | /* restart playback on current buffer */ |
| 234 | /* make sure we're aligned on left channel - skip any right |
| 235 | channel sample left waiting */ |
| 236 | DISRC2 = (DCSRC2 + 2) & ~0x3; |
| 237 | DCON2 = DMA_CONTROL_SETUP | (DSTAT2 & 0xFFFFE); |
| 238 | play_start_pcm(); |
| 239 | } |
| 240 | } |
| 241 | |
Michael Sevakis | f48e0b5 | 2007-05-03 12:39:36 +0000 | [diff] [blame] | 242 | void fiq_handler(void) |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 243 | { |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 244 | static unsigned char *start; |
| 245 | static size_t size; |
Michael Sevakis | f48e0b5 | 2007-05-03 12:39:36 +0000 | [diff] [blame] | 246 | register pcm_more_callback_type get_more; /* No stack for this */ |
Michael Sevakis | f48e0b5 | 2007-05-03 12:39:36 +0000 | [diff] [blame] | 247 | |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 248 | /* clear any pending interrupt */ |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 249 | SRCPND = DMA2_MASK; |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 250 | |
| 251 | /* Buffer empty. Try to get more. */ |
Michael Sevakis | f48e0b5 | 2007-05-03 12:39:36 +0000 | [diff] [blame] | 252 | get_more = pcm_callback_for_more; |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 253 | size = 0; |
| 254 | |
| 255 | if (get_more == NULL || (get_more(&start, &size), size == 0)) |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 256 | { |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 257 | /* Callback missing or no more DMA to do */ |
| 258 | pcm_play_dma_stop(); |
| 259 | pcm_play_dma_stopped_callback(); |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 260 | } |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 261 | else |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 262 | { |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 263 | /* Flush any pending cache writes */ |
| 264 | clean_dcache_range(start, size); |
| 265 | |
| 266 | /* set the new DMA values */ |
| 267 | DCON2 = DMA_CONTROL_SETUP | (size >> 1); |
| 268 | DISRC2 = (unsigned int)start + 0x30000000; |
| 269 | |
| 270 | /* Re-Activate the channel */ |
| 271 | DMASKTRIG2 = 0x2; |
Michael Sevakis | 3c38fe4 | 2007-05-02 22:33:24 +0000 | [diff] [blame] | 272 | } |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 275 | void pcm_set_frequency(unsigned int frequency) |
| 276 | { |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 277 | switch(frequency) |
| 278 | { |
| 279 | case SAMPR_11: |
Marcoen Hirschberg | b01da58 | 2007-01-18 13:48:06 +0000 | [diff] [blame] | 280 | sr_ctrl = GIGABEAT_11025HZ; |
| 281 | break; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 282 | case SAMPR_22: |
Marcoen Hirschberg | b01da58 | 2007-01-18 13:48:06 +0000 | [diff] [blame] | 283 | sr_ctrl = GIGABEAT_22050HZ; |
| 284 | break; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 285 | default: |
Marcoen Hirschberg | b01da58 | 2007-01-18 13:48:06 +0000 | [diff] [blame] | 286 | frequency = SAMPR_44; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 287 | case SAMPR_44: |
Marcoen Hirschberg | b01da58 | 2007-01-18 13:48:06 +0000 | [diff] [blame] | 288 | sr_ctrl = GIGABEAT_44100HZ; |
| 289 | break; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 290 | case SAMPR_88: |
Marcoen Hirschberg | b01da58 | 2007-01-18 13:48:06 +0000 | [diff] [blame] | 291 | sr_ctrl = GIGABEAT_88200HZ; |
| 292 | break; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 293 | } |
Marcoen Hirschberg | b01da58 | 2007-01-18 13:48:06 +0000 | [diff] [blame] | 294 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 295 | pcm_freq = frequency; |
| 296 | } |
| 297 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 298 | size_t pcm_get_bytes_waiting(void) |
| 299 | { |
Michael Sevakis | f783617 | 2007-06-24 20:41:27 +0000 | [diff] [blame] | 300 | /* lie a little and only return full pairs */ |
| 301 | return (DSTAT2 & 0xFFFFE) * 2; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 304 | const void * pcm_play_dma_get_peak_buffer(int *count) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 305 | { |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 306 | unsigned long addr = DCSRC2; |
| 307 | int cnt = DSTAT2; |
| 308 | *count = (cnt & 0xFFFFF) >> 1; |
| 309 | return (void *)((addr + 2) & ~3); |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 310 | } |