4 * sm_sbc.c -- soundcard radio modem driver soundblaster hardware driver
6 * Copyright (C) 1996 Thomas Sailer (sailer@ife.ee.ethz.ch)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Please note that the GPL allows you to use the driver, NOT the radio.
23 * In order to use the radio, you need a license from the communications
24 * authority of your country.
28 #include <linux/ptrace.h>
29 #include <linux/sched.h>
30 #include <linux/interrupt.h>
33 #include <linux/ioport.h>
34 #include <linux/soundmodem.h>
35 #include <linux/delay.h>
39 /* --------------------------------------------------------------------- */
42 * currently this module is supposed to support both module styles, i.e.
43 * the old one present up to about 2.1.9, and the new one functioning
44 * starting with 2.1.21. The reason is I have a kit allowing to compile
45 * this module also under 2.0.x which was requested by several people.
48 #include <linux/version.h>
50 #if LINUX_VERSION_CODE >= 0x20100
51 #include <asm/uaccess.h>
53 #include <asm/segment.h>
59 #define put_user(x,ptr) ({ __put_user((unsigned long)(x),(ptr),sizeof(*(ptr))); 0; })
60 #define get_user(x,ptr) ({ x = ((__typeof__(*(ptr)))__get_user((ptr),sizeof(*(ptr)))); 0; })
62 extern inline int copy_from_user(void *to
, const void *from
, unsigned long n
)
64 int i
= verify_area(VERIFY_READ
, from
, n
);
67 memcpy_fromfs(to
, from
, n
);
71 extern inline int copy_to_user(void *to
, const void *from
, unsigned long n
)
73 int i
= verify_area(VERIFY_WRITE
, to
, n
);
76 memcpy_tofs(to
, from
, n
);
81 /* --------------------------------------------------------------------- */
84 unsigned char revhi
, revlo
;
89 #define SCSTATE ((struct sc_state_sbc *)(&sm->hw))
91 /* --------------------------------------------------------------------- */
93 * the sbc converter's registers
95 #define DSP_RESET(iobase) (iobase+0x6)
96 #define DSP_READ_DATA(iobase) (iobase+0xa)
97 #define DSP_WRITE_DATA(iobase) (iobase+0xc)
98 #define DSP_WRITE_STATUS(iobase) (iobase+0xc)
99 #define DSP_DATA_AVAIL(iobase) (iobase+0xe)
100 #define DSP_MIXER_ADDR(iobase) (iobase+0x4)
101 #define DSP_MIXER_DATA(iobase) (iobase+0x5)
102 #define DSP_INTACK_16BIT(iobase) (iobase+0xf)
103 #define SBC_EXTENT 16
105 /* --------------------------------------------------------------------- */
109 #define SBC_OUTPUT 0x14
110 #define SBC_INPUT 0x24
111 #define SBC_BLOCKSIZE 0x48
112 #define SBC_HI_OUTPUT 0x91
113 #define SBC_HI_INPUT 0x99
114 #define SBC_LO_OUTPUT_AUTOINIT 0x1c
115 #define SBC_LO_INPUT_AUTOINIT 0x2c
116 #define SBC_HI_OUTPUT_AUTOINIT 0x90
117 #define SBC_HI_INPUT_AUTOINIT 0x98
118 #define SBC_IMMED_INT 0xf2
119 #define SBC_GET_REVISION 0xe1
120 #define ESS_GET_REVISION 0xe7
121 #define SBC_SPEAKER_ON 0xd1
122 #define SBC_SPEAKER_OFF 0xd3
123 #define SBC_DMA_ON 0xd0
124 #define SBC_DMA_OFF 0xd4
125 #define SBC_SAMPLE_RATE 0x40
126 #define SBC_SAMPLE_RATE_OUT 0x41
127 #define SBC_SAMPLE_RATE_IN 0x42
128 #define SBC_MONO_8BIT 0xa0
129 #define SBC_MONO_16BIT 0xa4
130 #define SBC_STEREO_8BIT 0xa8
131 #define SBC_STEREO_16BIT 0xac
133 #define SBC4_OUT8_AI 0xc6
134 #define SBC4_IN8_AI 0xce
135 #define SBC4_MODE_UNS_MONO 0x00
136 #define SBC4_MODE_SIGN_MONO 0x10
138 #define SBC4_OUT16_AI 0xb6
139 #define SBC4_IN16_AI 0xbe
141 /* --------------------------------------------------------------------- */
143 static int inline reset_dsp(struct net_device
*dev
)
147 outb(1, DSP_RESET(dev
->base_addr
));
149 outb(0, DSP_RESET(dev
->base_addr
));
150 for (i
= 0; i
< 0xffff; i
++)
151 if (inb(DSP_DATA_AVAIL(dev
->base_addr
)) & 0x80)
152 if (inb(DSP_READ_DATA(dev
->base_addr
)) == 0xaa)
157 /* --------------------------------------------------------------------- */
159 static void inline write_dsp(struct net_device
*dev
, unsigned char data
)
163 for (i
= 0; i
< 0xffff; i
++)
164 if (!(inb(DSP_WRITE_STATUS(dev
->base_addr
)) & 0x80)) {
165 outb(data
, DSP_WRITE_DATA(dev
->base_addr
));
170 /* --------------------------------------------------------------------- */
172 static int inline read_dsp(struct net_device
*dev
, unsigned char *data
)
178 for (i
= 0; i
< 0xffff; i
++)
179 if (inb(DSP_DATA_AVAIL(dev
->base_addr
)) & 0x80) {
180 *data
= inb(DSP_READ_DATA(dev
->base_addr
));
186 /* --------------------------------------------------------------------- */
188 static int config_resources(struct net_device
*dev
, struct sm_state
*sm
, int fdx
)
190 unsigned char irqreg
= 0, dmareg
= 0, realirq
, realdma
;
233 switch (sm
->hdrv
.ptt_out
.dma2
) {
252 outb(0x80, DSP_MIXER_ADDR(dev
->base_addr
));
253 outb(irqreg
, DSP_MIXER_DATA(dev
->base_addr
));
254 realirq
= inb(DSP_MIXER_DATA(dev
->base_addr
));
255 outb(0x81, DSP_MIXER_ADDR(dev
->base_addr
));
256 outb(dmareg
, DSP_MIXER_DATA(dev
->base_addr
));
257 realdma
= inb(DSP_MIXER_DATA(dev
->base_addr
));
258 restore_flags(flags
);
259 if ((~realirq
) & irqreg
|| (~realdma
) & dmareg
) {
260 printk(KERN_ERR
"%s: sbc resource registers cannot be set; PnP device "
261 "and IRQ/DMA specified wrongly?\n", sm_drvname
);
267 /* --------------------------------------------------------------------- */
269 static void inline sbc_int_ack_8bit(struct net_device
*dev
)
271 inb(DSP_DATA_AVAIL(dev
->base_addr
));
274 /* --------------------------------------------------------------------- */
276 static void inline sbc_int_ack_16bit(struct net_device
*dev
)
278 inb(DSP_INTACK_16BIT(dev
->base_addr
));
281 /* --------------------------------------------------------------------- */
283 static void setup_dma_dsp(struct net_device
*dev
, struct sm_state
*sm
, int send
)
286 static const unsigned char sbcmode
[2][2] = {
287 { SBC_LO_INPUT_AUTOINIT
, SBC_LO_OUTPUT_AUTOINIT
},
288 { SBC_HI_INPUT_AUTOINIT
, SBC_HI_OUTPUT_AUTOINIT
}
290 static const unsigned char sbc4mode
[2] = { SBC4_IN8_AI
, SBC4_OUT8_AI
};
291 static const unsigned char sbcskr
[2] = { SBC_SPEAKER_OFF
, SBC_SPEAKER_ON
};
295 if (!reset_dsp(dev
)) {
296 printk(KERN_ERR
"%s: sbc: cannot reset sb dsp\n", sm_drvname
);
301 sbc_int_ack_8bit(dev
);
302 write_dsp(dev
, SBC_SAMPLE_RATE
); /* set sampling rate */
303 write_dsp(dev
, SCSTATE
->fmt
[send
]);
304 write_dsp(dev
, sbcskr
[send
]);
305 nsamps
= dma_setup(sm
, send
, dev
->dma
) - 1;
306 sbc_int_ack_8bit(dev
);
307 if (SCSTATE
->revhi
>= 4) {
308 write_dsp(dev
, sbc4mode
[send
]);
309 write_dsp(dev
, SBC4_MODE_UNS_MONO
);
310 write_dsp(dev
, nsamps
& 0xff);
311 write_dsp(dev
, nsamps
>> 8);
313 write_dsp(dev
, SBC_BLOCKSIZE
);
314 write_dsp(dev
, nsamps
& 0xff);
315 write_dsp(dev
, nsamps
>> 8);
316 write_dsp(dev
, sbcmode
[SCSTATE
->fmt
[send
] >= 180][send
]);
317 /* hispeed mode if sample rate > 13kHz */
319 restore_flags(flags
);
322 /* --------------------------------------------------------------------- */
324 static void sbc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
326 struct net_device
*dev
= (struct net_device
*)dev_id
;
327 struct sm_state
*sm
= (struct sm_state
*)dev
->priv
;
328 unsigned int curfrag
;
330 if (!dev
|| !sm
|| sm
->hdrv
.magic
!= HDLCDRV_MAGIC
)
333 sbc_int_ack_8bit(dev
);
334 disable_dma(dev
->dma
);
335 clear_dma_ff(dev
->dma
);
336 dma_ptr(sm
, sm
->dma
.ptt_cnt
> 0, dev
->dma
, &curfrag
);
337 enable_dma(dev
->dma
);
340 if (sm
->dma
.ptt_cnt
<= 0) {
341 dma_receive(sm
, curfrag
);
342 hdlcdrv_arbitrate(dev
, &sm
->hdrv
);
343 if (hdlcdrv_ptt(&sm
->hdrv
)) {
344 /* starting to transmit */
345 disable_dma(dev
->dma
);
346 hdlcdrv_transmitter(dev
, &sm
->hdrv
); /* prefill HDLC buffer */
347 dma_start_transmit(sm
);
348 setup_dma_dsp(dev
, sm
, 1);
351 } else if (dma_end_transmit(sm
, curfrag
)) {
352 /* stopping transmission */
353 disable_dma(dev
->dma
);
355 dma_init_receive(sm
);
356 setup_dma_dsp(dev
, sm
, 0);
359 sm_output_status(sm
);
360 hdlcdrv_transmitter(dev
, &sm
->hdrv
);
361 hdlcdrv_receiver(dev
, &sm
->hdrv
);
365 /* --------------------------------------------------------------------- */
367 static int sbc_open(struct net_device
*dev
, struct sm_state
*sm
)
370 unsigned int dmasz
, u
;
372 if (sizeof(sm
->m
) < sizeof(struct sc_state_sbc
)) {
373 printk(KERN_ERR
"sm sbc: sbc state too big: %d > %d\n",
374 sizeof(struct sc_state_sbc
), sizeof(sm
->m
));
379 if (dev
->base_addr
<= 0 || dev
->base_addr
> 0x1000-SBC_EXTENT
||
380 dev
->irq
< 2 || dev
->irq
> 15 || dev
->dma
> 3)
382 if (check_region(dev
->base_addr
, SBC_EXTENT
))
385 * check if a card is available
387 if (!reset_dsp(dev
)) {
388 printk(KERN_ERR
"%s: sbc: no card at io address 0x%lx\n",
389 sm_drvname
, dev
->base_addr
);
392 write_dsp(dev
, SBC_GET_REVISION
);
393 if (!read_dsp(dev
, &SCSTATE
->revhi
) ||
394 !read_dsp(dev
, &SCSTATE
->revlo
))
396 printk(KERN_INFO
"%s: SoundBlaster DSP revision %d.%d\n", sm_drvname
,
397 SCSTATE
->revhi
, SCSTATE
->revlo
);
398 if (SCSTATE
->revhi
< 2) {
399 printk(KERN_ERR
"%s: your card is an antiquity, at least DSP "
400 "rev 2.00 required\n", sm_drvname
);
403 if (SCSTATE
->revhi
< 3 &&
404 (SCSTATE
->fmt
[0] >= 180 || SCSTATE
->fmt
[1] >= 180)) {
405 printk(KERN_ERR
"%s: sbc io 0x%lx: DSP rev %d.%02d too "
406 "old, at least 3.00 required\n", sm_drvname
,
407 dev
->base_addr
, SCSTATE
->revhi
, SCSTATE
->revlo
);
410 if (SCSTATE
->revhi
>= 4 &&
411 (err
= config_resources(dev
, sm
, 0))) {
412 printk(KERN_ERR
"%s: invalid IRQ and/or DMA specified\n", sm_drvname
);
416 * initialize some variables
418 dma_init_receive(sm
);
419 dmasz
= (NUM_FRAGMENTS
+ 1) * sm
->dma
.ifragsz
;
420 u
= NUM_FRAGMENTS
* sm
->dma
.ofragsz
;
423 if (!(sm
->dma
.ibuf
= sm
->dma
.obuf
= kmalloc(dmasz
, GFP_KERNEL
| GFP_DMA
)))
425 dma_init_transmit(sm
);
426 dma_init_receive(sm
);
428 memset(&sm
->m
, 0, sizeof(sm
->m
));
429 memset(&sm
->d
, 0, sizeof(sm
->d
));
430 if (sm
->mode_tx
->init
)
431 sm
->mode_tx
->init(sm
);
432 if (sm
->mode_rx
->init
)
433 sm
->mode_rx
->init(sm
);
435 if (request_dma(dev
->dma
, sm
->hwdrv
->hw_name
)) {
436 kfree_s(sm
->dma
.obuf
, dmasz
);
439 if (request_irq(dev
->irq
, sbc_interrupt
, SA_INTERRUPT
,
440 sm
->hwdrv
->hw_name
, dev
)) {
442 kfree_s(sm
->dma
.obuf
, dmasz
);
445 request_region(dev
->base_addr
, SBC_EXTENT
, sm
->hwdrv
->hw_name
);
446 setup_dma_dsp(dev
, sm
, 0);
450 /* --------------------------------------------------------------------- */
452 static int sbc_close(struct net_device
*dev
, struct sm_state
*sm
)
459 disable_dma(dev
->dma
);
461 free_irq(dev
->irq
, dev
);
463 release_region(dev
->base_addr
, SBC_EXTENT
);
468 /* --------------------------------------------------------------------- */
470 static int sbc_sethw(struct net_device
*dev
, struct sm_state
*sm
, char *mode
)
472 char *cp
= strchr(mode
, '.');
473 const struct modem_tx_info
**mtp
= sm_modem_tx_table
;
474 const struct modem_rx_info
**mrp
;
476 if (!strcmp(mode
, "off")) {
485 for (; *mtp
; mtp
++) {
486 if ((*mtp
)->loc_storage
> sizeof(sm
->m
)) {
487 printk(KERN_ERR
"%s: insufficient storage for modulator %s (%d)\n",
488 sm_drvname
, (*mtp
)->name
, (*mtp
)->loc_storage
);
491 if (!(*mtp
)->name
|| strcmp((*mtp
)->name
, mode
))
493 if ((*mtp
)->srate
< 5000 || (*mtp
)->srate
> 44100)
495 if (!(*mtp
)->modulator_u8
)
497 for (mrp
= sm_modem_rx_table
; *mrp
; mrp
++) {
498 if ((*mrp
)->loc_storage
> sizeof(sm
->d
)) {
499 printk(KERN_ERR
"%s: insufficient storage for demodulator %s (%d)\n",
500 sm_drvname
, (*mrp
)->name
, (*mrp
)->loc_storage
);
503 if (!(*mrp
)->demodulator_u8
)
505 if ((*mrp
)->name
&& !strcmp((*mrp
)->name
, cp
) &&
506 (*mrp
)->srate
>= 5000 && (*mrp
)->srate
<= 44100) {
509 SCSTATE
->fmt
[0] = 256-((1000000L+sm
->mode_rx
->srate
/2)/
511 SCSTATE
->fmt
[1] = 256-((1000000L+sm
->mode_tx
->srate
/2)/
513 sm
->dma
.ifragsz
= (sm
->mode_rx
->srate
+ 50)/100;
514 sm
->dma
.ofragsz
= (sm
->mode_tx
->srate
+ 50)/100;
515 if (sm
->dma
.ifragsz
< sm
->mode_rx
->overlap
)
516 sm
->dma
.ifragsz
= sm
->mode_rx
->overlap
;
517 sm
->dma
.i16bit
= sm
->dma
.o16bit
= 0;
525 /* --------------------------------------------------------------------- */
527 static int sbc_ioctl(struct net_device
*dev
, struct sm_state
*sm
, struct ifreq
*ifr
,
528 struct hdlcdrv_ioctl
*hi
, int cmd
)
534 if (cmd
!= SIOCDEVPRIVATE
)
537 if (hi
->cmd
== HDLCDRVCTL_MODEMPARMASK
)
538 return HDLCDRV_PARMASK_IOBASE
| HDLCDRV_PARMASK_IRQ
|
539 HDLCDRV_PARMASK_DMA
| HDLCDRV_PARMASK_SERIOBASE
|
540 HDLCDRV_PARMASK_PARIOBASE
| HDLCDRV_PARMASK_MIDIIOBASE
;
542 if (copy_from_user(&bi
, ifr
->ifr_data
, sizeof(bi
)))
551 bi
.data
.mix
.sample_rate
= sm
->mode_rx
->srate
;
552 bi
.data
.mix
.bit_rate
= sm
->hdrv
.par
.bitrate
;
553 bi
.data
.mix
.mixer_type
= SM_MIXER_INVALID
;
554 switch (SCSTATE
->revhi
) {
556 bi
.data
.mix
.mixer_type
= SM_MIXER_CT1335
;
559 bi
.data
.mix
.mixer_type
= SM_MIXER_CT1345
;
562 bi
.data
.mix
.mixer_type
= SM_MIXER_CT1745
;
565 if (bi
.data
.mix
.mixer_type
!= SM_MIXER_INVALID
&&
566 bi
.data
.mix
.reg
< 0x80) {
569 outb(bi
.data
.mix
.reg
, DSP_MIXER_ADDR(dev
->base_addr
));
570 bi
.data
.mix
.data
= inb(DSP_MIXER_DATA(dev
->base_addr
));
571 restore_flags(flags
);
574 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
579 if (!capable(CAP_SYS_RAWIO
))
581 switch (SCSTATE
->revhi
) {
583 if (bi
.data
.mix
.mixer_type
!= SM_MIXER_CT1335
)
587 if (bi
.data
.mix
.mixer_type
!= SM_MIXER_CT1345
)
591 if (bi
.data
.mix
.mixer_type
!= SM_MIXER_CT1745
)
597 if (bi
.data
.mix
.reg
>= 0x80)
601 outb(bi
.data
.mix
.reg
, DSP_MIXER_ADDR(dev
->base_addr
));
602 outb(bi
.data
.mix
.data
, DSP_MIXER_DATA(dev
->base_addr
));
603 restore_flags(flags
);
607 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
613 /* --------------------------------------------------------------------- */
615 const struct hardware_info sm_hw_sbc
= {
616 "sbc", sizeof(struct sc_state_sbc
),
617 sbc_open
, sbc_close
, sbc_ioctl
, sbc_sethw
620 /* --------------------------------------------------------------------- */
622 static void setup_dma_fdx_dsp(struct net_device
*dev
, struct sm_state
*sm
)
625 unsigned int isamps
, osamps
;
627 if (!reset_dsp(dev
)) {
628 printk(KERN_ERR
"%s: sbc: cannot reset sb dsp\n", sm_drvname
);
633 sbc_int_ack_8bit(dev
);
634 sbc_int_ack_16bit(dev
);
635 /* should eventually change to set rates individually by SBC_SAMPLE_RATE_{IN/OUT} */
636 write_dsp(dev
, SBC_SAMPLE_RATE_IN
);
637 write_dsp(dev
, SCSTATE
->sr
[0] >> 8);
638 write_dsp(dev
, SCSTATE
->sr
[0] & 0xff);
639 write_dsp(dev
, SBC_SAMPLE_RATE_OUT
);
640 write_dsp(dev
, SCSTATE
->sr
[1] >> 8);
641 write_dsp(dev
, SCSTATE
->sr
[1] & 0xff);
642 write_dsp(dev
, SBC_SPEAKER_ON
);
643 if (sm
->dma
.o16bit
) {
645 * DMA channel 1 (8bit) does input (capture),
646 * DMA channel 2 (16bit) does output (playback)
648 isamps
= dma_setup(sm
, 0, dev
->dma
) - 1;
649 osamps
= dma_setup(sm
, 1, sm
->hdrv
.ptt_out
.dma2
) - 1;
650 sbc_int_ack_8bit(dev
);
651 sbc_int_ack_16bit(dev
);
652 write_dsp(dev
, SBC4_IN8_AI
);
653 write_dsp(dev
, SBC4_MODE_UNS_MONO
);
654 write_dsp(dev
, isamps
& 0xff);
655 write_dsp(dev
, isamps
>> 8);
656 write_dsp(dev
, SBC4_OUT16_AI
);
657 write_dsp(dev
, SBC4_MODE_SIGN_MONO
);
658 write_dsp(dev
, osamps
& 0xff);
659 write_dsp(dev
, osamps
>> 8);
662 * DMA channel 1 (8bit) does output (playback),
663 * DMA channel 2 (16bit) does input (capture)
665 isamps
= dma_setup(sm
, 0, sm
->hdrv
.ptt_out
.dma2
) - 1;
666 osamps
= dma_setup(sm
, 1, dev
->dma
) - 1;
667 sbc_int_ack_8bit(dev
);
668 sbc_int_ack_16bit(dev
);
669 write_dsp(dev
, SBC4_OUT8_AI
);
670 write_dsp(dev
, SBC4_MODE_UNS_MONO
);
671 write_dsp(dev
, osamps
& 0xff);
672 write_dsp(dev
, osamps
>> 8);
673 write_dsp(dev
, SBC4_IN16_AI
);
674 write_dsp(dev
, SBC4_MODE_SIGN_MONO
);
675 write_dsp(dev
, isamps
& 0xff);
676 write_dsp(dev
, isamps
>> 8);
678 dma_init_receive(sm
);
679 dma_init_transmit(sm
);
680 restore_flags(flags
);
683 /* --------------------------------------------------------------------- */
685 static void sbcfdx_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
687 struct net_device
*dev
= (struct net_device
*)dev_id
;
688 struct sm_state
*sm
= (struct sm_state
*)dev
->priv
;
689 unsigned char intsrc
, pbint
= 0, captint
= 0;
690 unsigned int ocfrag
, icfrag
;
693 if (!dev
|| !sm
|| sm
->hdrv
.magic
!= HDLCDRV_MAGIC
)
697 outb(0x82, DSP_MIXER_ADDR(dev
->base_addr
));
698 intsrc
= inb(DSP_MIXER_DATA(dev
->base_addr
));
700 sbc_int_ack_8bit(dev
);
701 if (sm
->dma
.o16bit
) {
703 disable_dma(dev
->dma
);
704 clear_dma_ff(dev
->dma
);
705 dma_ptr(sm
, 0, dev
->dma
, &icfrag
);
706 enable_dma(dev
->dma
);
709 disable_dma(dev
->dma
);
710 clear_dma_ff(dev
->dma
);
711 dma_ptr(sm
, 1, dev
->dma
, &ocfrag
);
712 enable_dma(dev
->dma
);
716 sbc_int_ack_16bit(dev
);
717 if (sm
->dma
.o16bit
) {
719 disable_dma(sm
->hdrv
.ptt_out
.dma2
);
720 clear_dma_ff(sm
->hdrv
.ptt_out
.dma2
);
721 dma_ptr(sm
, 1, sm
->hdrv
.ptt_out
.dma2
, &ocfrag
);
722 enable_dma(sm
->hdrv
.ptt_out
.dma2
);
725 disable_dma(sm
->hdrv
.ptt_out
.dma2
);
726 clear_dma_ff(sm
->hdrv
.ptt_out
.dma2
);
727 dma_ptr(sm
, 0, sm
->hdrv
.ptt_out
.dma2
, &icfrag
);
728 enable_dma(sm
->hdrv
.ptt_out
.dma2
);
731 restore_flags(flags
);
735 if (dma_end_transmit(sm
, ocfrag
))
736 dma_clear_transmit(sm
);
740 dma_receive(sm
, icfrag
);
741 hdlcdrv_arbitrate(dev
, &sm
->hdrv
);
743 sm_output_status(sm
);
744 hdlcdrv_transmitter(dev
, &sm
->hdrv
);
745 hdlcdrv_receiver(dev
, &sm
->hdrv
);
748 /* --------------------------------------------------------------------- */
750 static int sbcfdx_open(struct net_device
*dev
, struct sm_state
*sm
)
754 if (sizeof(sm
->m
) < sizeof(struct sc_state_sbc
)) {
755 printk(KERN_ERR
"sm sbc: sbc state too big: %d > %d\n",
756 sizeof(struct sc_state_sbc
), sizeof(sm
->m
));
761 if (dev
->base_addr
<= 0 || dev
->base_addr
> 0x1000-SBC_EXTENT
||
762 dev
->irq
< 2 || dev
->irq
> 15 || dev
->dma
> 3)
764 if (check_region(dev
->base_addr
, SBC_EXTENT
))
767 * check if a card is available
769 if (!reset_dsp(dev
)) {
770 printk(KERN_ERR
"%s: sbc: no card at io address 0x%lx\n",
771 sm_drvname
, dev
->base_addr
);
774 write_dsp(dev
, SBC_GET_REVISION
);
775 if (!read_dsp(dev
, &SCSTATE
->revhi
) ||
776 !read_dsp(dev
, &SCSTATE
->revlo
))
778 printk(KERN_INFO
"%s: SoundBlaster DSP revision %d.%d\n", sm_drvname
,
779 SCSTATE
->revhi
, SCSTATE
->revlo
);
780 if (SCSTATE
->revhi
< 4) {
781 printk(KERN_ERR
"%s: at least DSP rev 4.00 required\n", sm_drvname
);
784 if ((err
= config_resources(dev
, sm
, 1))) {
785 printk(KERN_ERR
"%s: invalid IRQ and/or DMA specified\n", sm_drvname
);
789 * initialize some variables
791 if (!(sm
->dma
.ibuf
= kmalloc(sm
->dma
.ifragsz
* (NUM_FRAGMENTS
+1), GFP_KERNEL
| GFP_DMA
)))
793 if (!(sm
->dma
.obuf
= kmalloc(sm
->dma
.ofragsz
* NUM_FRAGMENTS
, GFP_KERNEL
| GFP_DMA
))) {
797 dma_init_transmit(sm
);
798 dma_init_receive(sm
);
800 memset(&sm
->m
, 0, sizeof(sm
->m
));
801 memset(&sm
->d
, 0, sizeof(sm
->d
));
802 if (sm
->mode_tx
->init
)
803 sm
->mode_tx
->init(sm
);
804 if (sm
->mode_rx
->init
)
805 sm
->mode_rx
->init(sm
);
807 if (request_dma(dev
->dma
, sm
->hwdrv
->hw_name
)) {
812 if (request_dma(sm
->hdrv
.ptt_out
.dma2
, sm
->hwdrv
->hw_name
)) {
818 if (request_irq(dev
->irq
, sbcfdx_interrupt
, SA_INTERRUPT
,
819 sm
->hwdrv
->hw_name
, dev
)) {
823 free_dma(sm
->hdrv
.ptt_out
.dma2
);
826 request_region(dev
->base_addr
, SBC_EXTENT
, sm
->hwdrv
->hw_name
);
827 setup_dma_fdx_dsp(dev
, sm
);
831 /* --------------------------------------------------------------------- */
833 static int sbcfdx_close(struct net_device
*dev
, struct sm_state
*sm
)
840 disable_dma(dev
->dma
);
841 disable_dma(sm
->hdrv
.ptt_out
.dma2
);
843 free_irq(dev
->irq
, dev
);
845 free_dma(sm
->hdrv
.ptt_out
.dma2
);
846 release_region(dev
->base_addr
, SBC_EXTENT
);
852 /* --------------------------------------------------------------------- */
854 static int sbcfdx_sethw(struct net_device
*dev
, struct sm_state
*sm
, char *mode
)
856 char *cp
= strchr(mode
, '.');
857 const struct modem_tx_info
**mtp
= sm_modem_tx_table
;
858 const struct modem_rx_info
**mrp
;
860 if (!strcmp(mode
, "off")) {
869 for (; *mtp
; mtp
++) {
870 if ((*mtp
)->loc_storage
> sizeof(sm
->m
)) {
871 printk(KERN_ERR
"%s: insufficient storage for modulator %s (%d)\n",
872 sm_drvname
, (*mtp
)->name
, (*mtp
)->loc_storage
);
875 if (!(*mtp
)->name
|| strcmp((*mtp
)->name
, mode
))
877 if ((*mtp
)->srate
< 5000 || (*mtp
)->srate
> 44100)
879 for (mrp
= sm_modem_rx_table
; *mrp
; mrp
++) {
880 if ((*mrp
)->loc_storage
> sizeof(sm
->d
)) {
881 printk(KERN_ERR
"%s: insufficient storage for demodulator %s (%d)\n",
882 sm_drvname
, (*mrp
)->name
, (*mrp
)->loc_storage
);
885 if ((*mrp
)->name
&& !strcmp((*mrp
)->name
, cp
) &&
886 (*mtp
)->srate
>= 5000 && (*mtp
)->srate
<= 44100 &&
887 (*mrp
)->srate
== (*mtp
)->srate
) {
890 SCSTATE
->sr
[0] = sm
->mode_rx
->srate
;
891 SCSTATE
->sr
[1] = sm
->mode_tx
->srate
;
892 sm
->dma
.ifragsz
= (sm
->mode_rx
->srate
+ 50)/100;
893 sm
->dma
.ofragsz
= (sm
->mode_tx
->srate
+ 50)/100;
894 if (sm
->dma
.ifragsz
< sm
->mode_rx
->overlap
)
895 sm
->dma
.ifragsz
= sm
->mode_rx
->overlap
;
896 if (sm
->mode_rx
->demodulator_s16
&& sm
->mode_tx
->modulator_u8
) {
899 sm
->dma
.ifragsz
<<= 1;
900 } else if (sm
->mode_rx
->demodulator_u8
&& sm
->mode_tx
->modulator_s16
) {
903 sm
->dma
.ofragsz
<<= 1;
905 printk(KERN_INFO
"%s: mode %s or %s unusable\n", sm_drvname
,
906 sm
->mode_rx
->name
, sm
->mode_tx
->name
);
918 /* --------------------------------------------------------------------- */
920 static int sbcfdx_ioctl(struct net_device
*dev
, struct sm_state
*sm
, struct ifreq
*ifr
,
921 struct hdlcdrv_ioctl
*hi
, int cmd
)
923 if (cmd
!= SIOCDEVPRIVATE
)
926 if (hi
->cmd
== HDLCDRVCTL_MODEMPARMASK
)
927 return HDLCDRV_PARMASK_IOBASE
| HDLCDRV_PARMASK_IRQ
|
928 HDLCDRV_PARMASK_DMA
| HDLCDRV_PARMASK_DMA2
| HDLCDRV_PARMASK_SERIOBASE
|
929 HDLCDRV_PARMASK_PARIOBASE
| HDLCDRV_PARMASK_MIDIIOBASE
;
931 return sbc_ioctl(dev
, sm
, ifr
, hi
, cmd
);
934 /* --------------------------------------------------------------------- */
936 const struct hardware_info sm_hw_sbcfdx
= {
937 "sbcfdx", sizeof(struct sc_state_sbc
),
938 sbcfdx_open
, sbcfdx_close
, sbcfdx_ioctl
, sbcfdx_sethw
941 /* --------------------------------------------------------------------- */