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
;
33 bool wake_thread
= false;
35 if ((chip
->chip_status
& (PDAUDIOCF_STAT_IS_STALE
|
36 PDAUDIOCF_STAT_IS_CONFIGURED
|
37 PDAUDIOCF_STAT_IS_SUSPENDED
)) != PDAUDIOCF_STAT_IS_CONFIGURED
)
38 return IRQ_HANDLED
; /* IRQ_NONE here? */
40 stat
= inw(chip
->port
+ PDAUDIOCF_REG_ISR
);
41 if (stat
& (PDAUDIOCF_IRQLVL
|PDAUDIOCF_IRQOVR
)) {
42 if (stat
& PDAUDIOCF_IRQOVR
) /* should never happen */
43 snd_printk(KERN_ERR
"PDAUDIOCF SRAM buffer overrun detected!\n");
44 if (chip
->pcm_substream
)
46 if (!(stat
& PDAUDIOCF_IRQAKM
))
47 stat
|= PDAUDIOCF_IRQAKM
; /* check rate */
49 if (get_irq_regs() != NULL
)
50 snd_ak4117_check_rate_and_errors(chip
->ak4117
, 0);
51 return wake_thread
? IRQ_WAKE_THREAD
: IRQ_HANDLED
;
54 static inline void pdacf_transfer_mono16(u16
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
57 *dst
++ = inw(rdp_port
) ^ xor;
62 static inline void pdacf_transfer_mono32(u32
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
64 register u16 val1
, val2
;
70 *dst
++ = ((((u32
)val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor;
74 static inline void pdacf_transfer_stereo16(u16
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
77 *dst
++ = inw(rdp_port
) ^ xor;
78 *dst
++ = inw(rdp_port
) ^ xor;
82 static inline void pdacf_transfer_stereo32(u32
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
84 register u16 val1
, val2
, val3
;
90 *dst
++ = ((((u32
)val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor;
91 *dst
++ = (((u32
)val3
<< 16) | (val2
& 0xff00)) ^ xor;
95 static inline void pdacf_transfer_mono16sw(u16
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
98 *dst
++ = swab16(inw(rdp_port
) ^ xor);
103 static inline void pdacf_transfer_mono32sw(u32
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
105 register u16 val1
, val2
;
108 val1
= inw(rdp_port
);
109 val2
= inw(rdp_port
);
111 *dst
++ = swab32((((val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor);
115 static inline void pdacf_transfer_stereo16sw(u16
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
118 *dst
++ = swab16(inw(rdp_port
) ^ xor);
119 *dst
++ = swab16(inw(rdp_port
) ^ xor);
123 static inline void pdacf_transfer_stereo32sw(u32
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
125 register u16 val1
, val2
, val3
;
128 val1
= inw(rdp_port
);
129 val2
= inw(rdp_port
);
130 val3
= inw(rdp_port
);
131 *dst
++ = swab32((((val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor);
132 *dst
++ = swab32((((u32
)val3
<< 16) | (val2
& 0xff00)) ^ xor);
136 static inline void pdacf_transfer_mono24le(u8
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
138 register u16 val1
, val2
;
142 val1
= inw(rdp_port
);
143 val2
= inw(rdp_port
);
145 xval1
= (((val2
& 0xff) << 8) | (val1
<< 16)) ^ xor;
146 *dst
++ = (u8
)(xval1
>> 8);
147 *dst
++ = (u8
)(xval1
>> 16);
148 *dst
++ = (u8
)(xval1
>> 24);
152 static inline void pdacf_transfer_mono24be(u8
*dst
, u16
xor, unsigned int size
, unsigned long rdp_port
)
154 register u16 val1
, val2
;
158 val1
= inw(rdp_port
);
159 val2
= inw(rdp_port
);
161 xval1
= (((val2
& 0xff) << 8) | (val1
<< 16)) ^ xor;
162 *dst
++ = (u8
)(xval1
>> 24);
163 *dst
++ = (u8
)(xval1
>> 16);
164 *dst
++ = (u8
)(xval1
>> 8);
168 static inline void pdacf_transfer_stereo24le(u8
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
170 register u16 val1
, val2
, val3
;
171 register u32 xval1
, xval2
;
174 val1
= inw(rdp_port
);
175 val2
= inw(rdp_port
);
176 val3
= inw(rdp_port
);
177 xval1
= ((((u32
)val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor;
178 xval2
= (((u32
)val3
<< 16) | (val2
& 0xff00)) ^ xor;
179 *dst
++ = (u8
)(xval1
>> 8);
180 *dst
++ = (u8
)(xval1
>> 16);
181 *dst
++ = (u8
)(xval1
>> 24);
182 *dst
++ = (u8
)(xval2
>> 8);
183 *dst
++ = (u8
)(xval2
>> 16);
184 *dst
++ = (u8
)(xval2
>> 24);
188 static inline void pdacf_transfer_stereo24be(u8
*dst
, u32
xor, unsigned int size
, unsigned long rdp_port
)
190 register u16 val1
, val2
, val3
;
191 register u32 xval1
, xval2
;
194 val1
= inw(rdp_port
);
195 val2
= inw(rdp_port
);
196 val3
= inw(rdp_port
);
197 xval1
= ((((u32
)val2
& 0xff) << 24) | ((u32
)val1
<< 8)) ^ xor;
198 xval2
= (((u32
)val3
<< 16) | (val2
& 0xff00)) ^ xor;
199 *dst
++ = (u8
)(xval1
>> 24);
200 *dst
++ = (u8
)(xval1
>> 16);
201 *dst
++ = (u8
)(xval1
>> 8);
202 *dst
++ = (u8
)(xval2
>> 24);
203 *dst
++ = (u8
)(xval2
>> 16);
204 *dst
++ = (u8
)(xval2
>> 8);
208 static void pdacf_transfer(struct snd_pdacf
*chip
, unsigned int size
, unsigned int off
)
210 unsigned long rdp_port
= chip
->port
+ PDAUDIOCF_REG_MD
;
211 unsigned int xor = chip
->pcm_xor
;
213 if (chip
->pcm_sample
== 3) {
214 if (chip
->pcm_little
) {
215 if (chip
->pcm_channels
== 1) {
216 pdacf_transfer_mono24le((char *)chip
->pcm_area
+ (off
* 3), xor, size
, rdp_port
);
218 pdacf_transfer_stereo24le((char *)chip
->pcm_area
+ (off
* 6), xor, size
, rdp_port
);
221 if (chip
->pcm_channels
== 1) {
222 pdacf_transfer_mono24be((char *)chip
->pcm_area
+ (off
* 3), xor, size
, rdp_port
);
224 pdacf_transfer_stereo24be((char *)chip
->pcm_area
+ (off
* 6), xor, size
, rdp_port
);
229 if (chip
->pcm_swab
== 0) {
230 if (chip
->pcm_channels
== 1) {
231 if (chip
->pcm_frame
== 2) {
232 pdacf_transfer_mono16((u16
*)chip
->pcm_area
+ off
, xor, size
, rdp_port
);
234 pdacf_transfer_mono32((u32
*)chip
->pcm_area
+ off
, xor, size
, rdp_port
);
237 if (chip
->pcm_frame
== 2) {
238 pdacf_transfer_stereo16((u16
*)chip
->pcm_area
+ (off
* 2), xor, size
, rdp_port
);
240 pdacf_transfer_stereo32((u32
*)chip
->pcm_area
+ (off
* 2), xor, size
, rdp_port
);
244 if (chip
->pcm_channels
== 1) {
245 if (chip
->pcm_frame
== 2) {
246 pdacf_transfer_mono16sw((u16
*)chip
->pcm_area
+ off
, xor, size
, rdp_port
);
248 pdacf_transfer_mono32sw((u32
*)chip
->pcm_area
+ off
, xor, size
, rdp_port
);
251 if (chip
->pcm_frame
== 2) {
252 pdacf_transfer_stereo16sw((u16
*)chip
->pcm_area
+ (off
* 2), xor, size
, rdp_port
);
254 pdacf_transfer_stereo32sw((u32
*)chip
->pcm_area
+ (off
* 2), xor, size
, rdp_port
);
260 irqreturn_t
pdacf_threaded_irq(int irq
, void *dev
)
262 struct snd_pdacf
*chip
= dev
;
263 int size
, off
, cont
, rdp
, wdp
;
265 if ((chip
->chip_status
& (PDAUDIOCF_STAT_IS_STALE
|PDAUDIOCF_STAT_IS_CONFIGURED
)) != PDAUDIOCF_STAT_IS_CONFIGURED
)
268 if (chip
->pcm_substream
== NULL
|| chip
->pcm_substream
->runtime
== NULL
|| !snd_pcm_running(chip
->pcm_substream
))
271 rdp
= inw(chip
->port
+ PDAUDIOCF_REG_RDP
);
272 wdp
= inw(chip
->port
+ PDAUDIOCF_REG_WDP
);
273 /* printk(KERN_DEBUG "TASKLET: rdp = %x, wdp = %x\n", rdp, wdp); */
279 size
/= chip
->pcm_frame
;
284 chip
->pcm_hwptr
+= size
;
285 chip
->pcm_hwptr
%= chip
->pcm_size
;
286 chip
->pcm_tdone
+= size
;
287 if (chip
->pcm_frame
== 2) {
288 unsigned long rdp_port
= chip
->port
+ PDAUDIOCF_REG_MD
;
294 unsigned long rdp_port
= chip
->port
+ PDAUDIOCF_REG_MD
;
302 off
= chip
->pcm_hwptr
+ chip
->pcm_tdone
;
303 off
%= chip
->pcm_size
;
304 chip
->pcm_tdone
+= size
;
306 cont
= chip
->pcm_size
- off
;
309 pdacf_transfer(chip
, cont
, off
);
311 off
%= chip
->pcm_size
;
315 mutex_lock(&chip
->reg_lock
);
316 while (chip
->pcm_tdone
>= chip
->pcm_period
) {
317 chip
->pcm_hwptr
+= chip
->pcm_period
;
318 chip
->pcm_hwptr
%= chip
->pcm_size
;
319 chip
->pcm_tdone
-= chip
->pcm_period
;
320 mutex_unlock(&chip
->reg_lock
);
321 snd_pcm_period_elapsed(chip
->pcm_substream
);
322 mutex_lock(&chip
->reg_lock
);
324 mutex_unlock(&chip
->reg_lock
);