2 * Driver for Sound Core PDAudioCF soundcard
4 * Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <sound/core.h>
22 #include "pdaudiocf.h"
23 #include <sound/initval.h>
24 #include <asm/irq_regs.h>
29 irqreturn_t
pdacf_interrupt(int irq
, void *dev
)
31 struct snd_pdacf
*chip
= dev
;
34 if ((chip
->chip_status
& (PDAUDIOCF_STAT_IS_STALE
|
35 PDAUDIOCF_STAT_IS_CONFIGURED
|
36 PDAUDIOCF_STAT_IS_SUSPENDED
)) != PDAUDIOCF_STAT_IS_CONFIGURED
)
37 return IRQ_HANDLED
; /* IRQ_NONE here? */
39 stat
= inw(chip
->port
+ PDAUDIOCF_REG_ISR
);
40 if (stat
& (PDAUDIOCF_IRQLVL
|PDAUDIOCF_IRQOVR
)) {
41 if (stat
& PDAUDIOCF_IRQOVR
) /* should never happen */
42 snd_printk(KERN_ERR
"PDAUDIOCF SRAM buffer overrun detected!\n");
43 if (chip
->pcm_substream
)
44 tasklet_hi_schedule(&chip
->tq
);
45 if (!(stat
& PDAUDIOCF_IRQAKM
))
46 stat
|= PDAUDIOCF_IRQAKM
; /* check rate */
48 if (get_irq_regs() != NULL
)
49 snd_ak4117_check_rate_and_errors(chip
->ak4117
, 0);
53 static inline void pdacf_transfer_mono16(u16
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
56 *dst
++ = inw(rdp_port
) ^ xor;
61 static inline void pdacf_transfer_mono32(u32
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
63 register u16 val1
, val2
;
69 *dst
++ = ((((u32
)val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor;
73 static inline void pdacf_transfer_stereo16(u16
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
76 *dst
++ = inw(rdp_port
) ^ xor;
77 *dst
++ = inw(rdp_port
) ^ xor;
81 static inline void pdacf_transfer_stereo32(u32
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
83 register u16 val1
, val2
, val3
;
89 *dst
++ = ((((u32
)val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor;
90 *dst
++ = (((u32
)val3
<< 16) | (val2
& 0xff00)) ^ xor;
94 static inline void pdacf_transfer_mono16sw(u16
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
97 *dst
++ = swab16(inw(rdp_port
) ^ xor);
102 static inline void pdacf_transfer_mono32sw(u32
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
104 register u16 val1
, val2
;
107 val1
= inw(rdp_port
);
108 val2
= inw(rdp_port
);
110 *dst
++ = swab32((((val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor);
114 static inline void pdacf_transfer_stereo16sw(u16
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
117 *dst
++ = swab16(inw(rdp_port
) ^ xor);
118 *dst
++ = swab16(inw(rdp_port
) ^ xor);
122 static inline void pdacf_transfer_stereo32sw(u32
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
124 register u16 val1
, val2
, val3
;
127 val1
= inw(rdp_port
);
128 val2
= inw(rdp_port
);
129 val3
= inw(rdp_port
);
130 *dst
++ = swab32((((val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor);
131 *dst
++ = swab32((((u32
)val3
<< 16) | (val2
& 0xff00)) ^ xor);
135 static inline void pdacf_transfer_mono24le(u8
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
137 register u16 val1
, val2
;
141 val1
= inw(rdp_port
);
142 val2
= inw(rdp_port
);
144 xval1
= (((val2
& 0xff) << 8) | (val1
<< 16)) ^ xor;
145 *dst
++ = (u8
)(xval1
>> 8);
146 *dst
++ = (u8
)(xval1
>> 16);
147 *dst
++ = (u8
)(xval1
>> 24);
151 static inline void pdacf_transfer_mono24be(u8
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
153 register u16 val1
, val2
;
157 val1
= inw(rdp_port
);
158 val2
= inw(rdp_port
);
160 xval1
= (((val2
& 0xff) << 8) | (val1
<< 16)) ^ xor;
161 *dst
++ = (u8
)(xval1
>> 24);
162 *dst
++ = (u8
)(xval1
>> 16);
163 *dst
++ = (u8
)(xval1
>> 8);
167 static inline void pdacf_transfer_stereo24le(u8
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
169 register u16 val1
, val2
, val3
;
170 register u32 xval1
, xval2
;
173 val1
= inw(rdp_port
);
174 val2
= inw(rdp_port
);
175 val3
= inw(rdp_port
);
176 xval1
= ((((u32
)val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor;
177 xval2
= (((u32
)val3
<< 16) | (val2
& 0xff00)) ^ xor;
178 *dst
++ = (u8
)(xval1
>> 8);
179 *dst
++ = (u8
)(xval1
>> 16);
180 *dst
++ = (u8
)(xval1
>> 24);
181 *dst
++ = (u8
)(xval2
>> 8);
182 *dst
++ = (u8
)(xval2
>> 16);
183 *dst
++ = (u8
)(xval2
>> 24);
187 static inline void pdacf_transfer_stereo24be(u8
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
189 register u16 val1
, val2
, val3
;
190 register u32 xval1
, xval2
;
193 val1
= inw(rdp_port
);
194 val2
= inw(rdp_port
);
195 val3
= inw(rdp_port
);
196 xval1
= ((((u32
)val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor;
197 xval2
= (((u32
)val3
<< 16) | (val2
& 0xff00)) ^ xor;
198 *dst
++ = (u8
)(xval1
>> 24);
199 *dst
++ = (u8
)(xval1
>> 16);
200 *dst
++ = (u8
)(xval1
>> 8);
201 *dst
++ = (u8
)(xval2
>> 24);
202 *dst
++ = (u8
)(xval2
>> 16);
203 *dst
++ = (u8
)(xval2
>> 8);
207 static void pdacf_transfer(struct snd_pdacf
*chip
, unsigned int size
, unsigned int off
)
209 unsigned long rdp_port
= chip
->port
+ PDAUDIOCF_REG_MD
;
210 unsigned int xor = chip
->pcm_xor
;
212 if (chip
->pcm_sample
== 3) {
213 if (chip
->pcm_little
) {
214 if (chip
->pcm_channels
== 1) {
215 pdacf_transfer_mono24le((char *)chip
->pcm_area
+ (off
* 3), xor, size
, rdp_port
);
217 pdacf_transfer_stereo24le((char *)chip
->pcm_area
+ (off
* 6), xor, size
, rdp_port
);
220 if (chip
->pcm_channels
== 1) {
221 pdacf_transfer_mono24be((char *)chip
->pcm_area
+ (off
* 3), xor, size
, rdp_port
);
223 pdacf_transfer_stereo24be((char *)chip
->pcm_area
+ (off
* 6), xor, size
, rdp_port
);
228 if (chip
->pcm_swab
== 0) {
229 if (chip
->pcm_channels
== 1) {
230 if (chip
->pcm_frame
== 2) {
231 pdacf_transfer_mono16((u16
*)chip
->pcm_area
+ off
, xor, size
, rdp_port
);
233 pdacf_transfer_mono32((u32
*)chip
->pcm_area
+ off
, xor, size
, rdp_port
);
236 if (chip
->pcm_frame
== 2) {
237 pdacf_transfer_stereo16((u16
*)chip
->pcm_area
+ (off
* 2), xor, size
, rdp_port
);
239 pdacf_transfer_stereo32((u32
*)chip
->pcm_area
+ (off
* 2), xor, size
, rdp_port
);
243 if (chip
->pcm_channels
== 1) {
244 if (chip
->pcm_frame
== 2) {
245 pdacf_transfer_mono16sw((u16
*)chip
->pcm_area
+ off
, xor, size
, rdp_port
);
247 pdacf_transfer_mono32sw((u32
*)chip
->pcm_area
+ off
, xor, size
, rdp_port
);
250 if (chip
->pcm_frame
== 2) {
251 pdacf_transfer_stereo16sw((u16
*)chip
->pcm_area
+ (off
* 2), xor, size
, rdp_port
);
253 pdacf_transfer_stereo32sw((u32
*)chip
->pcm_area
+ (off
* 2), xor, size
, rdp_port
);
259 void pdacf_tasklet(unsigned long private_data
)
261 struct snd_pdacf
*chip
= (struct snd_pdacf
*) private_data
;
262 int size
, off
, cont
, rdp
, wdp
;
264 if ((chip
->chip_status
& (PDAUDIOCF_STAT_IS_STALE
|PDAUDIOCF_STAT_IS_CONFIGURED
)) != PDAUDIOCF_STAT_IS_CONFIGURED
)
267 if (chip
->pcm_substream
== NULL
|| chip
->pcm_substream
->runtime
== NULL
|| !snd_pcm_running(chip
->pcm_substream
))
270 rdp
= inw(chip
->port
+ PDAUDIOCF_REG_RDP
);
271 wdp
= inw(chip
->port
+ PDAUDIOCF_REG_WDP
);
272 // printk("TASKLET: rdp = %x, wdp = %x\n", rdp, wdp);
278 size
/= chip
->pcm_frame
;
283 chip
->pcm_hwptr
+= size
;
284 chip
->pcm_hwptr
%= chip
->pcm_size
;
285 chip
->pcm_tdone
+= size
;
286 if (chip
->pcm_frame
== 2) {
287 unsigned long rdp_port
= chip
->port
+ PDAUDIOCF_REG_MD
;
293 unsigned long rdp_port
= chip
->port
+ PDAUDIOCF_REG_MD
;
301 off
= chip
->pcm_hwptr
+ chip
->pcm_tdone
;
302 off
%= chip
->pcm_size
;
303 chip
->pcm_tdone
+= size
;
305 cont
= chip
->pcm_size
- off
;
308 pdacf_transfer(chip
, cont
, off
);
310 off
%= chip
->pcm_size
;
314 spin_lock(&chip
->reg_lock
);
315 while (chip
->pcm_tdone
>= chip
->pcm_period
) {
316 chip
->pcm_hwptr
+= chip
->pcm_period
;
317 chip
->pcm_hwptr
%= chip
->pcm_size
;
318 chip
->pcm_tdone
-= chip
->pcm_period
;
319 spin_unlock(&chip
->reg_lock
);
320 snd_pcm_period_elapsed(chip
->pcm_substream
);
321 spin_lock(&chip
->reg_lock
);
323 spin_unlock(&chip
->reg_lock
);
324 // printk("TASKLET: end\n");