FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / firmware / target / arm / pnx0101 / pcm-pnx0101.c
blobfe1e05b79a72cab2f1c5120b17c63097c26453bb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Tomek Malesinski
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "system.h"
22 #include "audio.h"
23 #include "string.h"
25 #define DMA_BUF_SAMPLES 0x100
27 short __attribute__((section(".dmabuf"))) dma_buf_left[DMA_BUF_SAMPLES];
28 short __attribute__((section(".dmabuf"))) dma_buf_right[DMA_BUF_SAMPLES];
30 unsigned short* p IBSS_ATTR;
31 size_t p_size IBSS_ATTR;
33 void pcm_play_lock(void)
37 void pcm_play_unlock(void)
41 void pcm_play_dma_start(const void *addr, size_t size)
43 p = (unsigned short*)addr;
44 p_size = size;
47 void pcm_play_dma_stop(void)
51 void pcm_play_dma_pause(bool pause)
53 (void)pause;
56 static inline void fill_dma_buf(int offset)
58 short *l, *r, *lend;
60 l = dma_buf_left + offset;
61 lend = l + DMA_BUF_SAMPLES / 2;
62 r = dma_buf_right + offset;
64 if (pcm_playing && !pcm_paused)
68 int count;
69 unsigned short *tmp_p;
70 count = MIN(p_size / 4, (size_t)(lend - l));
71 tmp_p = p;
72 p_size -= count * 4;
74 if ((int)l & 3)
76 *l++ = *tmp_p++;
77 *r++ = *tmp_p++;
78 count--;
80 while (count >= 4)
82 asm("ldmia %0!, {r0, r1, r2, r3}\n\t"
83 "and r4, r0, %3\n\t"
84 "orr r4, r4, r1, lsl #16\n\t"
85 "and r5, r2, %3\n\t"
86 "orr r5, r5, r3, lsl #16\n\t"
87 "stmia %1!, {r4, r5}\n\t"
88 "bic r4, r1, %3\n\t"
89 "orr r4, r4, r0, lsr #16\n\t"
90 "bic r5, r3, %3\n\t"
91 "orr r5, r5, r2, lsr #16\n\t"
92 "stmia %2!, {r4, r5}"
93 : "+r" (tmp_p), "+r" (l), "+r" (r)
94 : "r" (0xffff)
95 : "r0", "r1", "r2", "r3", "r4", "r5", "memory");
96 count -= 4;
98 while (count > 0)
100 *l++ = *tmp_p++;
101 *r++ = *tmp_p++;
102 count--;
104 p = tmp_p;
105 if (l >= lend)
106 return;
107 else if (pcm_callback_for_more)
108 pcm_callback_for_more((unsigned char**)&p,
109 &p_size);
111 while (p_size);
113 pcm_play_dma_stopped_callback();
116 if (l < lend)
118 memset(l, 0, sizeof(short) * (lend - l));
119 memset(r, 0, sizeof(short) * (lend - l));
123 static void audio_irq(void)
125 unsigned long st = DMAINTSTAT & ~DMAINTEN;
126 int i;
127 for (i = 0; i < 2; i++)
128 if (st & (1 << i))
130 fill_dma_buf((i == 1) ? 0 : DMA_BUF_SAMPLES / 2);
131 DMAINTSTAT = 1 << i;
135 unsigned long physical_address(void *p)
137 unsigned long adr = (unsigned long)p;
138 return (MMUBLOCK((adr >> 21) & 0xf) << 21) | (adr & ((1 << 21) - 1));
141 void pcm_init(void)
143 int i;
145 memset(dma_buf_left, 0, sizeof(dma_buf_left));
146 memset(dma_buf_right, 0, sizeof(dma_buf_right));
148 for (i = 0; i < 8; i++)
150 DMASRC(i) = 0;
151 DMADEST(i) = 0;
152 DMALEN(i) = 0x1ffff;
153 DMAR0C(i) = 0;
154 DMAR10(i) = 0;
155 DMAR1C(i) = 0;
158 DMAINTSTAT = 0xc000ffff;
159 DMAINTEN = 0xc000ffff;
161 DMASRC(0) = physical_address(dma_buf_left);
162 DMADEST(0) = 0x80200280;
163 DMALEN(0) = 0xff;
164 DMAR1C(0) = 0;
165 DMAR0C(0) = 0x40408;
167 DMASRC(1) = physical_address(dma_buf_right);
168 DMADEST(1) = 0x80200284;
169 DMALEN(1) = 0xff;
170 DMAR1C(1) = 0;
171 DMAR0C(1) = 0x40409;
173 irq_set_int_handler(0x1b, audio_irq);
174 irq_enable_int(0x1b);
176 DMAINTSTAT = 1;
177 DMAINTSTAT = 2;
178 DMAINTEN &= ~3;
179 DMAR10(0) |= 1;
180 DMAR10(1) |= 1;
183 void pcm_postinit(void)
185 audiohw_postinit();
188 void pcm_dma_apply_settings(void)
192 size_t pcm_get_bytes_waiting(void)
194 return p_size & ~3;
197 const void * pcm_play_dma_get_peak_buffer(int *count)
199 unsigned long addr = (unsigned long)p;
200 size_t cnt = p_size;
201 *count = cnt >> 2;
202 return (void *)((addr + 2) & ~3);