1 /*****************************************************************************/
4 * sm_wss.c -- soundcard radio modem driver, WSS (half duplex) 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>
38 /* --------------------------------------------------------------------- */
41 * currently this module is supposed to support both module styles, i.e.
42 * the old one present up to about 2.1.9, and the new one functioning
43 * starting with 2.1.21. The reason is I have a kit allowing to compile
44 * this module also under 2.0.x which was requested by several people.
47 #include <linux/version.h>
49 #if LINUX_VERSION_CODE >= 0x20100
50 #include <asm/uaccess.h>
52 #include <asm/segment.h>
58 #define put_user(x,ptr) ({ __put_user((unsigned long)(x),(ptr),sizeof(*(ptr))); 0; })
59 #define get_user(x,ptr) ({ x = ((__typeof__(*(ptr)))__get_user((ptr),sizeof(*(ptr)))); 0; })
61 extern inline int copy_from_user(void *to
, const void *from
, unsigned long n
)
63 int i
= verify_area(VERIFY_READ
, from
, n
);
66 memcpy_fromfs(to
, from
, n
);
70 extern inline int copy_to_user(void *to
, const void *from
, unsigned long n
)
72 int i
= verify_area(VERIFY_WRITE
, to
, n
);
75 memcpy_tofs(to
, from
, n
);
80 /* --------------------------------------------------------------------- */
83 unsigned char revwss
, revid
, revv
, revcid
;
85 unsigned char crystal
;
88 #define SCSTATE ((struct sc_state_wss *)(&sm->hw))
90 /* --------------------------------------------------------------------- */
92 #define WSS_CONFIG(iobase) (iobase+0)
93 #define WSS_STATUS(iobase) (iobase+3)
94 #define WSS_CODEC_IA(iobase) (iobase+4)
95 #define WSS_CODEC_ID(iobase) (iobase+5)
96 #define WSS_CODEC_STATUS(iobase) (iobase+6)
97 #define WSS_CODEC_DATA(iobase) (iobase+7)
101 #define CS423X_HOTFIX
103 /* --------------------------------------------------------------------- */
105 static void write_codec(struct net_device
*dev
, unsigned char idx
,
108 int timeout
= 900000;
110 /* wait until codec ready */
111 while (timeout
> 0 && inb(WSS_CODEC_IA(dev
->base_addr
)) & 0x80)
113 outb(idx
, WSS_CODEC_IA(dev
->base_addr
));
114 outb(data
, WSS_CODEC_ID(dev
->base_addr
));
118 /* --------------------------------------------------------------------- */
120 static unsigned char read_codec(struct net_device
*dev
, unsigned char idx
)
122 int timeout
= 900000;
124 /* wait until codec ready */
125 while (timeout
> 0 && inb(WSS_CODEC_IA(dev
->base_addr
)) & 0x80)
127 outb(idx
& 0x1f, WSS_CODEC_IA(dev
->base_addr
));
128 return inb(WSS_CODEC_ID(dev
->base_addr
));
131 /* --------------------------------------------------------------------- */
133 extern void inline wss_ack_int(struct net_device
*dev
)
135 outb(0, WSS_CODEC_STATUS(dev
->base_addr
));
138 /* --------------------------------------------------------------------- */
140 static int wss_srate_tab
[16] = {
141 8000, 5510, 16000, 11025, 27420, 18900, 32000, 22050,
142 -1, 37800, -1, 44100, 48000, 33075, 9600, 6620
145 static int wss_srate_index(int srate
)
149 for (i
= 0; i
< (sizeof(wss_srate_tab
)/sizeof(wss_srate_tab
[0])); i
++)
150 if (srate
== wss_srate_tab
[i
] && wss_srate_tab
[i
] > 0)
155 /* --------------------------------------------------------------------- */
157 static int wss_set_codec_fmt(struct net_device
*dev
, struct sm_state
*sm
, unsigned char fmt
,
158 unsigned char fmt2
, char fdx
, char fullcalib
)
165 /* Clock and data format register */
166 write_codec(dev
, 0x48, fmt
);
167 if (SCSTATE
->crystal
) {
168 write_codec(dev
, 0x5c, fmt2
& 0xf0);
169 /* MCE and interface config reg */
170 write_codec(dev
, 0x49, (fdx
? 0 : 0x4) | (fullcalib
? 0x18 : 0));
172 /* MCE and interface config reg */
173 write_codec(dev
, 0x49, fdx
? 0x8 : 0xc);
174 outb(0xb, WSS_CODEC_IA(dev
->base_addr
)); /* leave MCE */
175 if (SCSTATE
->crystal
&& !fullcalib
)
181 while (!(read_codec(dev
, 0x0b) & 0x20))
183 printk(KERN_WARNING
"%s: ad1848 auto calibration timed out (1)\n",
185 restore_flags(flags
);
192 time
= jiffies
+ HZ
/4;
193 while ((read_codec(dev
, 0x0b) & 0x20) && ((signed)(jiffies
- time
) < 0));
194 restore_flags(flags
);
195 if ((signed)(jiffies
- time
) >= 0) {
196 printk(KERN_WARNING
"%s: ad1848 auto calibration timed out (2)\n",
203 /* --------------------------------------------------------------------- */
205 static int wss_init_codec(struct net_device
*dev
, struct sm_state
*sm
, char fdx
,
206 unsigned char src_l
, unsigned char src_r
,
207 int igain_l
, int igain_r
,
208 int ogain_l
, int ogain_r
)
210 unsigned char tmp
, reg0
, reg1
, reg6
, reg7
;
211 static const signed char irqtab
[16] =
212 { -1, -1, 0x10, -1, -1, -1, -1, 0x08, -1, 0x10, 0x18, 0x20, -1, -1,
214 static const signed char dmatab
[4] = { 1, 2, -1, 3 };
216 tmp
= inb(WSS_STATUS(dev
->base_addr
));
217 if ((tmp
& 0x3f) != 0x04 && (tmp
& 0x3f) != 0x00 &&
218 (tmp
& 0x3f) != 0x0f) {
219 printk(KERN_WARNING
"sm: WSS card id register not found, "
220 "address 0x%lx, ID register 0x%02x\n",
221 dev
->base_addr
, (int)tmp
);
225 if ((tmp
& 0x80) && ((dev
->dma
== 0) ||
226 ((dev
->irq
>= 8) && (dev
->irq
!= 9)))) {
227 printk(KERN_ERR
"%s: WSS: DMA0 and/or IRQ8..IRQ15 "
228 "(except IRQ9) cannot be used on an 8bit "
229 "card\n", sm_drvname
);
232 if (dev
->irq
> 15 || irqtab
[dev
->irq
] == -1) {
233 printk(KERN_ERR
"%s: WSS: invalid interrupt %d\n",
234 sm_drvname
, (int)dev
->irq
);
237 if (dev
->dma
> 3 || dmatab
[dev
->dma
] == -1) {
238 printk(KERN_ERR
"%s: WSS: invalid dma channel %d\n",
239 sm_drvname
, (int)dev
->dma
);
242 tmp
= irqtab
[dev
->irq
] | dmatab
[dev
->dma
];
244 outb((tmp
& 0x38) | 0x40, WSS_CONFIG(dev
->base_addr
));
245 if (!(inb(WSS_STATUS(dev
->base_addr
)) & 0x40)) {
246 outb(0, WSS_CONFIG(dev
->base_addr
));
247 printk(KERN_ERR
"%s: WSS: IRQ%d is not free!\n",
248 sm_drvname
, dev
->irq
);
250 outb(tmp
, WSS_CONFIG(dev
->base_addr
));
251 SCSTATE
->revwss
= inb(WSS_STATUS(dev
->base_addr
)) & 0x3f;
254 * initialize the codec
264 reg0
= (src_l
<< 6) & 0xc0;
265 reg1
= (src_r
<< 6) & 0xc0;
266 if (reg0
== 0x80 && igain_l
>= 20) {
270 if (reg1
== 0x80 && igain_r
>= 20) {
278 reg0
|= igain_l
* 2 / 3;
279 reg1
|= igain_r
* 2 / 3;
280 reg6
= (ogain_l
< -95) ? 0x80 : (ogain_l
* (-2) / 3);
281 reg7
= (ogain_r
< -95) ? 0x80 : (ogain_r
* (-2) / 3);
282 write_codec(dev
, 9, 0);
283 write_codec(dev
, 0, 0x45);
284 if (read_codec(dev
, 0) != 0x45)
286 write_codec(dev
, 0, 0xaa);
287 if (read_codec(dev
, 0) != 0xaa)
289 write_codec(dev
, 12, 0x40); /* enable MODE2 */
290 write_codec(dev
, 16, 0);
291 write_codec(dev
, 0, 0x45);
292 SCSTATE
->crystal
= (read_codec(dev
, 16) != 0x45);
293 write_codec(dev
, 0, 0xaa);
294 SCSTATE
->crystal
&= (read_codec(dev
, 16) != 0xaa);
295 if (SCSTATE
->crystal
) {
296 SCSTATE
->revcid
= read_codec(dev
, 0x19);
297 SCSTATE
->revv
= (SCSTATE
->revcid
>> 5) & 7;
298 SCSTATE
->revcid
&= 7;
299 write_codec(dev
, 0x10, 0x80); /* maximum output level */
300 write_codec(dev
, 0x11, 0x02); /* xtal enable and no HPF */
301 write_codec(dev
, 0x12, 0x80); /* left line input control */
302 write_codec(dev
, 0x13, 0x80); /* right line input control */
303 write_codec(dev
, 0x16, 0); /* disable alternative freq sel */
304 write_codec(dev
, 0x1a, 0xe0); /* mono IO disable */
305 write_codec(dev
, 0x1b, 0x00); /* left out no att */
306 write_codec(dev
, 0x1d, 0x00); /* right out no att */
309 if (wss_set_codec_fmt(dev
, sm
, SCSTATE
->fmt
[0], SCSTATE
->fmt
[0], fdx
, 1))
312 write_codec(dev
, 0, reg0
); /* left input control */
313 write_codec(dev
, 1, reg1
); /* right input control */
314 write_codec(dev
, 2, 0x80); /* left aux#1 input control */
315 write_codec(dev
, 3, 0x80); /* right aux#1 input control */
316 write_codec(dev
, 4, 0x80); /* left aux#2 input control */
317 write_codec(dev
, 5, 0x80); /* right aux#2 input control */
318 write_codec(dev
, 6, reg6
); /* left dac control */
319 write_codec(dev
, 7, reg7
); /* right dac control */
320 write_codec(dev
, 0xa, 0x2); /* pin control register */
321 write_codec(dev
, 0xd, 0x0); /* digital mix control */
322 SCSTATE
->revid
= read_codec(dev
, 0xc) & 0xf;
326 if (SCSTATE
->crystal
)
327 printk(KERN_INFO
"%s: Crystal CODEC ID %d, Chip revision %d, "
328 " Chip ID %d\n", sm_drvname
, (int)SCSTATE
->revid
,
329 (int)SCSTATE
->revv
, (int)SCSTATE
->revcid
);
331 printk(KERN_INFO
"%s: WSS revision %d, CODEC revision %d\n",
332 sm_drvname
, (int)SCSTATE
->revwss
,
333 (int)SCSTATE
->revid
);
336 outb(0, WSS_CONFIG(dev
->base_addr
));
337 printk(KERN_ERR
"%s: no WSS soundcard found at address 0x%lx\n",
338 sm_drvname
, dev
->base_addr
);
342 /* --------------------------------------------------------------------- */
344 static void setup_dma_wss(struct net_device
*dev
, struct sm_state
*sm
, int send
)
347 static const unsigned char codecmode
[2] = { 0x0e, 0x0d };
348 unsigned char oldcodecmode
;
351 unsigned int numsamps
;
354 fmt
= SCSTATE
->fmt
[send
];
358 * perform the final DMA sequence to disable the codec request
360 oldcodecmode
= read_codec(dev
, 9);
361 write_codec(dev
, 9, 0xc); /* disable codec */
363 if (read_codec(dev
, 11) & 0x10) {
364 dma_setup(sm
, oldcodecmode
& 1, dev
->dma
);
366 while ((read_codec(dev
, 11) & 0x10) || ((++abrt
) >= 0x10000));
369 if (read_codec(dev
, 0x8) != fmt
|| SCSTATE
->crystal
)
370 wss_set_codec_fmt(dev
, sm
, fmt
, fmt
, 0, 0);
371 #else /* CS423X_HOTFIX */
372 if (read_codec(dev
, 0x8) != fmt
)
373 wss_set_codec_fmt(dev
, sm
, fmt
, fmt
, 0, 0);
374 #endif /* CS423X_HOTFIX */
375 numsamps
= dma_setup(sm
, send
, dev
->dma
) - 1;
376 write_codec(dev
, 15, numsamps
& 0xff);
377 write_codec(dev
, 14, numsamps
>> 8);
378 write_codec(dev
, 9, codecmode
[send
]);
379 restore_flags(flags
);
382 /* --------------------------------------------------------------------- */
384 static void wss_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
386 struct net_device
*dev
= (struct net_device
*)dev_id
;
387 struct sm_state
*sm
= (struct sm_state
*)dev
->priv
;
388 unsigned int curfrag
;
391 if (!dev
|| !sm
|| !sm
->mode_rx
|| !sm
->mode_tx
||
392 sm
->hdrv
.magic
!= HDLCDRV_MAGIC
)
396 disable_dma(dev
->dma
);
397 clear_dma_ff(dev
->dma
);
398 nums
= dma_ptr(sm
, sm
->dma
.ptt_cnt
> 0, dev
->dma
, &curfrag
) - 1;
399 write_codec(dev
, 15, nums
& 0xff);
400 write_codec(dev
, 14, nums
>> 8);
401 enable_dma(dev
->dma
);
404 if (sm
->dma
.ptt_cnt
<= 0) {
405 dma_receive(sm
, curfrag
);
406 hdlcdrv_arbitrate(dev
, &sm
->hdrv
);
407 if (hdlcdrv_ptt(&sm
->hdrv
)) {
408 /* starting to transmit */
409 disable_dma(dev
->dma
);
410 hdlcdrv_transmitter(dev
, &sm
->hdrv
); /* prefill HDLC buffer */
411 dma_start_transmit(sm
);
412 setup_dma_wss(dev
, sm
, 1);
415 } else if (dma_end_transmit(sm
, curfrag
)) {
416 /* stopping transmission */
417 disable_dma(dev
->dma
);
418 dma_init_receive(sm
);
419 setup_dma_wss(dev
, sm
, 0);
422 sm_output_status(sm
);
423 hdlcdrv_transmitter(dev
, &sm
->hdrv
);
424 hdlcdrv_receiver(dev
, &sm
->hdrv
);
427 /* --------------------------------------------------------------------- */
429 static int wss_open(struct net_device
*dev
, struct sm_state
*sm
)
431 unsigned int dmasz
, u
;
433 if (sizeof(sm
->m
) < sizeof(struct sc_state_wss
)) {
434 printk(KERN_ERR
"sm wss: wss state too big: %d > %d\n",
435 sizeof(struct sc_state_wss
), sizeof(sm
->m
));
438 if (!dev
|| !sm
|| !sm
->mode_rx
|| !sm
->mode_tx
)
440 if (dev
->base_addr
<= 0 || dev
->base_addr
> 0x1000-WSS_EXTENT
||
441 dev
->irq
< 2 || dev
->irq
> 15 || dev
->dma
> 3)
443 if (check_region(dev
->base_addr
, WSS_EXTENT
))
446 * check if a card is available
448 if (wss_init_codec(dev
, sm
, 0, 1, 1, 0, 0, -45, -45))
451 * initialize some variables
453 dma_init_receive(sm
);
454 dmasz
= (NUM_FRAGMENTS
+ 1) * sm
->dma
.ifragsz
;
455 u
= NUM_FRAGMENTS
* sm
->dma
.ofragsz
;
458 if (!(sm
->dma
.ibuf
= sm
->dma
.obuf
= kmalloc(dmasz
, GFP_KERNEL
| GFP_DMA
)))
460 dma_init_transmit(sm
);
461 dma_init_receive(sm
);
463 memset(&sm
->m
, 0, sizeof(sm
->m
));
464 memset(&sm
->d
, 0, sizeof(sm
->d
));
465 if (sm
->mode_tx
->init
)
466 sm
->mode_tx
->init(sm
);
467 if (sm
->mode_rx
->init
)
468 sm
->mode_rx
->init(sm
);
470 if (request_dma(dev
->dma
, sm
->hwdrv
->hw_name
)) {
474 if (request_irq(dev
->irq
, wss_interrupt
, SA_INTERRUPT
,
475 sm
->hwdrv
->hw_name
, dev
)) {
480 request_region(dev
->base_addr
, WSS_EXTENT
, sm
->hwdrv
->hw_name
);
481 setup_dma_wss(dev
, sm
, 0);
485 /* --------------------------------------------------------------------- */
487 static int wss_close(struct net_device
*dev
, struct sm_state
*sm
)
494 disable_dma(dev
->dma
);
495 write_codec(dev
, 9, 0xc); /* disable codec */
496 free_irq(dev
->irq
, dev
);
498 release_region(dev
->base_addr
, WSS_EXTENT
);
503 /* --------------------------------------------------------------------- */
505 static int wss_sethw(struct net_device
*dev
, struct sm_state
*sm
, char *mode
)
507 char *cp
= strchr(mode
, '.');
508 const struct modem_tx_info
**mtp
= sm_modem_tx_table
;
509 const struct modem_rx_info
**mrp
;
512 if (!strcmp(mode
, "off")) {
521 for (; *mtp
; mtp
++) {
522 if ((*mtp
)->loc_storage
> sizeof(sm
->m
)) {
523 printk(KERN_ERR
"%s: insufficient storage for modulator %s (%d)\n",
524 sm_drvname
, (*mtp
)->name
, (*mtp
)->loc_storage
);
527 if (!(*mtp
)->name
|| strcmp((*mtp
)->name
, mode
))
529 if ((i
= wss_srate_index((*mtp
)->srate
)) < 0)
531 for (mrp
= sm_modem_rx_table
; *mrp
; mrp
++) {
532 if ((*mrp
)->loc_storage
> sizeof(sm
->d
)) {
533 printk(KERN_ERR
"%s: insufficient storage for demodulator %s (%d)\n",
534 sm_drvname
, (*mrp
)->name
, (*mrp
)->loc_storage
);
537 if ((*mrp
)->name
&& !strcmp((*mrp
)->name
, cp
) &&
538 ((j
= wss_srate_index((*mrp
)->srate
)) >= 0)) {
543 sm
->dma
.ifragsz
= (sm
->mode_rx
->srate
+ 50)/100;
544 sm
->dma
.ofragsz
= (sm
->mode_tx
->srate
+ 50)/100;
545 if (sm
->dma
.ifragsz
< sm
->mode_rx
->overlap
)
546 sm
->dma
.ifragsz
= sm
->mode_rx
->overlap
;
547 /* prefer same data format if possible to minimize switching times */
548 sm
->dma
.i16bit
= sm
->dma
.o16bit
= 2;
549 if (sm
->mode_rx
->srate
== sm
->mode_tx
->srate
) {
550 if (sm
->mode_rx
->demodulator_s16
&& sm
->mode_tx
->modulator_s16
)
551 sm
->dma
.i16bit
= sm
->dma
.o16bit
= 1;
552 else if (sm
->mode_rx
->demodulator_u8
&& sm
->mode_tx
->modulator_u8
)
553 sm
->dma
.i16bit
= sm
->dma
.o16bit
= 0;
555 if (sm
->dma
.i16bit
== 2) {
556 if (sm
->mode_rx
->demodulator_s16
)
558 else if (sm
->mode_rx
->demodulator_u8
)
561 if (sm
->dma
.o16bit
== 2) {
562 if (sm
->mode_tx
->modulator_s16
)
564 else if (sm
->mode_tx
->modulator_u8
)
567 if (sm
->dma
.i16bit
== 2 || sm
->dma
.o16bit
== 2) {
568 printk(KERN_INFO
"%s: mode %s or %s unusable\n", sm_drvname
,
569 sm
->mode_rx
->name
, sm
->mode_tx
->name
);
575 /* big endian 16bit only works on crystal cards... */
576 if (sm
->dma
.i16bit
) {
577 SCSTATE
->fmt
[0] |= 0xc0;
578 sm
->dma
.ifragsz
<<= 1;
580 if (sm
->dma
.o16bit
) {
581 SCSTATE
->fmt
[1] |= 0xc0;
582 sm
->dma
.ofragsz
<<= 1;
584 #else /* __BIG_ENDIAN */
585 if (sm
->dma
.i16bit
) {
586 SCSTATE
->fmt
[0] |= 0x40;
587 sm
->dma
.ifragsz
<<= 1;
589 if (sm
->dma
.o16bit
) {
590 SCSTATE
->fmt
[1] |= 0x40;
591 sm
->dma
.ofragsz
<<= 1;
593 #endif /* __BIG_ENDIAN */
601 /* --------------------------------------------------------------------- */
603 static int wss_ioctl(struct net_device
*dev
, struct sm_state
*sm
, struct ifreq
*ifr
,
604 struct hdlcdrv_ioctl
*hi
, int cmd
)
609 if (cmd
!= SIOCDEVPRIVATE
)
612 if (hi
->cmd
== HDLCDRVCTL_MODEMPARMASK
)
613 return HDLCDRV_PARMASK_IOBASE
| HDLCDRV_PARMASK_IRQ
|
614 HDLCDRV_PARMASK_DMA
| HDLCDRV_PARMASK_SERIOBASE
|
615 HDLCDRV_PARMASK_PARIOBASE
| HDLCDRV_PARMASK_MIDIIOBASE
;
617 if (copy_from_user(&bi
, ifr
->ifr_data
, sizeof(bi
)))
626 bi
.data
.mix
.sample_rate
= sm
->mode_rx
->srate
;
627 bi
.data
.mix
.bit_rate
= sm
->hdrv
.par
.bitrate
;
628 bi
.data
.mix
.mixer_type
= SCSTATE
->crystal
?
629 SM_MIXER_CRYSTAL
: SM_MIXER_AD1848
;
630 if (((SCSTATE
->crystal
? 0x2c0c20fflu
: 0x20fflu
)
631 >> bi
.data
.mix
.reg
) & 1) {
632 bi
.data
.mix
.data
= read_codec(dev
, bi
.data
.mix
.reg
);
635 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
640 if (!capable(CAP_SYS_RAWIO
))
642 if ((bi
.data
.mix
.mixer_type
!= SM_MIXER_CRYSTAL
||
643 !SCSTATE
->crystal
) &&
644 (bi
.data
.mix
.mixer_type
!= SM_MIXER_AD1848
||
645 bi
.data
.mix
.reg
>= 0x10))
647 if (!((0x2c0c20fflu
>> bi
.data
.mix
.reg
) & 1))
649 write_codec(dev
, bi
.data
.mix
.reg
, bi
.data
.mix
.data
);
653 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
659 /* --------------------------------------------------------------------- */
661 const struct hardware_info sm_hw_wss
= {
662 "wss", sizeof(struct sc_state_wss
),
663 wss_open
, wss_close
, wss_ioctl
, wss_sethw
666 /* --------------------------------------------------------------------- */
668 static void setup_fdx_dma_wss(struct net_device
*dev
, struct sm_state
*sm
)
671 unsigned char oldcodecmode
, codecdma
;
673 unsigned int osamps
, isamps
;
678 * perform the final DMA sequence to disable the codec request
680 oldcodecmode
= read_codec(dev
, 9);
681 write_codec(dev
, 9, 0); /* disable codec DMA */
683 if ((codecdma
= read_codec(dev
, 11)) & 0x10) {
684 dma_setup(sm
, 1, dev
->dma
);
685 dma_setup(sm
, 0, sm
->hdrv
.ptt_out
.dma2
);
687 while (((codecdma
= read_codec(dev
, 11)) & 0x10) || ((++abrt
) >= 0x10000));
689 wss_set_codec_fmt(dev
, sm
, SCSTATE
->fmt
[1], SCSTATE
->fmt
[0], 1, 1);
690 osamps
= dma_setup(sm
, 1, dev
->dma
) - 1;
691 isamps
= dma_setup(sm
, 0, sm
->hdrv
.ptt_out
.dma2
) - 1;
692 write_codec(dev
, 15, osamps
& 0xff);
693 write_codec(dev
, 14, osamps
>> 8);
694 if (SCSTATE
->crystal
) {
695 write_codec(dev
, 31, isamps
& 0xff);
696 write_codec(dev
, 30, isamps
>> 8);
698 write_codec(dev
, 9, 3);
699 restore_flags(flags
);
702 /* --------------------------------------------------------------------- */
704 static void wssfdx_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
706 struct net_device
*dev
= (struct net_device
*)dev_id
;
707 struct sm_state
*sm
= (struct sm_state
*)dev
->priv
;
709 unsigned char cry_int_src
;
710 unsigned icfrag
, ocfrag
, isamps
, osamps
;
712 if (!dev
|| !sm
|| !sm
->mode_rx
|| !sm
->mode_tx
||
713 sm
->hdrv
.magic
!= HDLCDRV_MAGIC
)
717 if (SCSTATE
->crystal
) {
718 /* Crystal has an essentially different interrupt handler! */
719 cry_int_src
= read_codec(dev
, 0x18);
721 if (cry_int_src
& 0x10) { /* playback interrupt */
722 disable_dma(dev
->dma
);
723 clear_dma_ff(dev
->dma
);
724 osamps
= dma_ptr(sm
, 1, dev
->dma
, &ocfrag
)-1;
725 write_codec(dev
, 15, osamps
& 0xff);
726 write_codec(dev
, 14, osamps
>> 8);
727 enable_dma(dev
->dma
);
729 if (cry_int_src
& 0x20) { /* capture interrupt */
730 disable_dma(sm
->hdrv
.ptt_out
.dma2
);
731 clear_dma_ff(sm
->hdrv
.ptt_out
.dma2
);
732 isamps
= dma_ptr(sm
, 0, sm
->hdrv
.ptt_out
.dma2
, &icfrag
)-1;
733 write_codec(dev
, 31, isamps
& 0xff);
734 write_codec(dev
, 30, isamps
>> 8);
735 enable_dma(sm
->hdrv
.ptt_out
.dma2
);
737 restore_flags(flags
);
740 if (cry_int_src
& 0x10) {
741 if (dma_end_transmit(sm
, ocfrag
))
742 dma_clear_transmit(sm
);
745 if (cry_int_src
& 0x20) {
746 dma_receive(sm
, icfrag
);
747 hdlcdrv_arbitrate(dev
, &sm
->hdrv
);
749 sm_output_status(sm
);
750 hdlcdrv_transmitter(dev
, &sm
->hdrv
);
751 hdlcdrv_receiver(dev
, &sm
->hdrv
);
755 disable_dma(dev
->dma
);
756 disable_dma(sm
->hdrv
.ptt_out
.dma2
);
757 clear_dma_ff(dev
->dma
);
758 clear_dma_ff(sm
->hdrv
.ptt_out
.dma2
);
759 osamps
= dma_ptr(sm
, 1, dev
->dma
, &ocfrag
)-1;
760 isamps
= dma_ptr(sm
, 0, sm
->hdrv
.ptt_out
.dma2
, &icfrag
)-1;
761 write_codec(dev
, 15, osamps
& 0xff);
762 write_codec(dev
, 14, osamps
>> 8);
763 if (SCSTATE
->crystal
) {
764 write_codec(dev
, 31, isamps
& 0xff);
765 write_codec(dev
, 30, isamps
>> 8);
767 enable_dma(dev
->dma
);
768 enable_dma(sm
->hdrv
.ptt_out
.dma2
);
769 restore_flags(flags
);
772 if (dma_end_transmit(sm
, ocfrag
))
773 dma_clear_transmit(sm
);
775 dma_receive(sm
, icfrag
);
776 hdlcdrv_arbitrate(dev
, &sm
->hdrv
);
777 sm_output_status(sm
);
778 hdlcdrv_transmitter(dev
, &sm
->hdrv
);
779 hdlcdrv_receiver(dev
, &sm
->hdrv
);
782 /* --------------------------------------------------------------------- */
784 static int wssfdx_open(struct net_device
*dev
, struct sm_state
*sm
)
786 if (!dev
|| !sm
|| !sm
->mode_rx
|| !sm
->mode_tx
)
788 if (dev
->base_addr
<= 0 || dev
->base_addr
> 0x1000-WSS_EXTENT
||
789 dev
->irq
< 2 || dev
->irq
> 15 || dev
->dma
> 3)
791 if (check_region(dev
->base_addr
, WSS_EXTENT
))
794 * check if a card is available
796 if (wss_init_codec(dev
, sm
, 1, 1, 1, 0, 0, -45, -45))
799 * initialize some variables
801 if (!(sm
->dma
.ibuf
= kmalloc(sm
->dma
.ifragsz
* (NUM_FRAGMENTS
+1), GFP_KERNEL
| GFP_DMA
)))
803 if (!(sm
->dma
.obuf
= kmalloc(sm
->dma
.ofragsz
* NUM_FRAGMENTS
, GFP_KERNEL
| GFP_DMA
))) {
807 dma_init_transmit(sm
);
808 dma_init_receive(sm
);
810 memset(&sm
->m
, 0, sizeof(sm
->m
));
811 memset(&sm
->d
, 0, sizeof(sm
->d
));
812 if (sm
->mode_tx
->init
)
813 sm
->mode_tx
->init(sm
);
814 if (sm
->mode_rx
->init
)
815 sm
->mode_rx
->init(sm
);
817 if (request_dma(dev
->dma
, sm
->hwdrv
->hw_name
)) {
822 if (request_dma(sm
->hdrv
.ptt_out
.dma2
, sm
->hwdrv
->hw_name
)) {
828 if (request_irq(dev
->irq
, wssfdx_interrupt
, SA_INTERRUPT
,
829 sm
->hwdrv
->hw_name
, dev
)) {
833 free_dma(sm
->hdrv
.ptt_out
.dma2
);
836 request_region(dev
->base_addr
, WSS_EXTENT
, sm
->hwdrv
->hw_name
);
837 setup_fdx_dma_wss(dev
, sm
);
841 /* --------------------------------------------------------------------- */
843 static int wssfdx_close(struct net_device
*dev
, struct sm_state
*sm
)
850 disable_dma(dev
->dma
);
851 disable_dma(sm
->hdrv
.ptt_out
.dma2
);
852 write_codec(dev
, 9, 0xc); /* disable codec */
853 free_irq(dev
->irq
, dev
);
855 free_dma(sm
->hdrv
.ptt_out
.dma2
);
856 release_region(dev
->base_addr
, WSS_EXTENT
);
862 /* --------------------------------------------------------------------- */
864 static int wssfdx_sethw(struct net_device
*dev
, struct sm_state
*sm
, char *mode
)
866 char *cp
= strchr(mode
, '.');
867 const struct modem_tx_info
**mtp
= sm_modem_tx_table
;
868 const struct modem_rx_info
**mrp
;
871 if (!strcmp(mode
, "off")) {
880 for (; *mtp
; mtp
++) {
881 if ((*mtp
)->loc_storage
> sizeof(sm
->m
)) {
882 printk(KERN_ERR
"%s: insufficient storage for modulator %s (%d)\n",
883 sm_drvname
, (*mtp
)->name
, (*mtp
)->loc_storage
);
886 if (!(*mtp
)->name
|| strcmp((*mtp
)->name
, mode
))
888 if ((i
= wss_srate_index((*mtp
)->srate
)) < 0)
890 for (mrp
= sm_modem_rx_table
; *mrp
; mrp
++) {
891 if ((*mrp
)->loc_storage
> sizeof(sm
->d
)) {
892 printk(KERN_ERR
"%s: insufficient storage for demodulator %s (%d)\n",
893 sm_drvname
, (*mrp
)->name
, (*mrp
)->loc_storage
);
896 if ((*mrp
)->name
&& !strcmp((*mrp
)->name
, cp
) &&
897 (*mtp
)->srate
== (*mrp
)->srate
) {
900 SCSTATE
->fmt
[0] = SCSTATE
->fmt
[1] = i
;
901 sm
->dma
.ifragsz
= sm
->dma
.ofragsz
= (sm
->mode_rx
->srate
+ 50)/100;
902 if (sm
->dma
.ifragsz
< sm
->mode_rx
->overlap
)
903 sm
->dma
.ifragsz
= sm
->mode_rx
->overlap
;
904 sm
->dma
.i16bit
= sm
->dma
.o16bit
= 2;
905 if (sm
->mode_rx
->demodulator_s16
) {
907 sm
->dma
.ifragsz
<<= 1;
908 #ifdef __BIG_ENDIAN /* big endian 16bit only works on crystal cards... */
909 SCSTATE
->fmt
[0] |= 0xc0;
910 #else /* __BIG_ENDIAN */
911 SCSTATE
->fmt
[0] |= 0x40;
912 #endif /* __BIG_ENDIAN */
913 } else if (sm
->mode_rx
->demodulator_u8
)
915 if (sm
->mode_tx
->modulator_s16
) {
917 sm
->dma
.ofragsz
<<= 1;
918 #ifdef __BIG_ENDIAN /* big endian 16bit only works on crystal cards... */
919 SCSTATE
->fmt
[1] |= 0xc0;
920 #else /* __BIG_ENDIAN */
921 SCSTATE
->fmt
[1] |= 0x40;
922 #endif /* __BIG_ENDIAN */
923 } else if (sm
->mode_tx
->modulator_u8
)
925 if (sm
->dma
.i16bit
== 2 || sm
->dma
.o16bit
== 2) {
926 printk(KERN_INFO
"%s: mode %s or %s unusable\n", sm_drvname
,
927 sm
->mode_rx
->name
, sm
->mode_tx
->name
);
939 /* --------------------------------------------------------------------- */
941 static int wssfdx_ioctl(struct net_device
*dev
, struct sm_state
*sm
, struct ifreq
*ifr
,
942 struct hdlcdrv_ioctl
*hi
, int cmd
)
944 if (cmd
!= SIOCDEVPRIVATE
)
947 if (hi
->cmd
== HDLCDRVCTL_MODEMPARMASK
)
948 return HDLCDRV_PARMASK_IOBASE
| HDLCDRV_PARMASK_IRQ
|
949 HDLCDRV_PARMASK_DMA
| HDLCDRV_PARMASK_DMA2
|
950 HDLCDRV_PARMASK_SERIOBASE
| HDLCDRV_PARMASK_PARIOBASE
|
951 HDLCDRV_PARMASK_MIDIIOBASE
;
953 return wss_ioctl(dev
, sm
, ifr
, hi
, cmd
);
956 /* --------------------------------------------------------------------- */
958 const struct hardware_info sm_hw_wssfdx
= {
959 "wssfdx", sizeof(struct sc_state_wss
),
960 wssfdx_open
, wssfdx_close
, wssfdx_ioctl
, wssfdx_sethw
963 /* --------------------------------------------------------------------- */