1 /*****************************************************************************/
4 * sm.c -- soundcard radio modem 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.
27 * Command line options (insmod command line)
29 * mode mode string; eg. "wss:afsk1200"
30 * iobase base address of the soundcard; common values are 0x220 for sbc,
32 * irq interrupt number; common values are 7 or 5 for sbc, 11 for wss
33 * dma dma number; common values are 0 or 1
37 * 0.1 21.09.96 Started
38 * 18.10.96 Changed to new user space access routines (copy_{to,from}_user)
39 * 0.4 21.01.97 Separately compileable soundcard/modem modules
40 * 0.5 03.03.97 fixed LPT probing (check_lpt result was interpreted the wrong way round)
43 /*****************************************************************************/
45 #include <linux/config.h>
46 #include <linux/module.h>
47 #include <linux/ptrace.h>
48 #include <linux/types.h>
49 #include <linux/fcntl.h>
50 #include <linux/ioport.h>
51 #include <linux/net.h>
53 #include <linux/string.h>
54 #include <asm/system.h>
56 #include <asm/bitops.h>
57 #include <linux/delay.h>
58 #include <linux/errno.h>
59 #include <linux/init.h>
62 /* --------------------------------------------------------------------- */
65 * currently this module is supposed to support both module styles, i.e.
66 * the old one present up to about 2.1.9, and the new one functioning
67 * starting with 2.1.21. The reason is I have a kit allowing to compile
68 * this module also under 2.0.x which was requested by several people.
71 #include <linux/version.h>
73 #if LINUX_VERSION_CODE >= 0x20100
74 #include <asm/uaccess.h>
76 #include <asm/segment.h>
82 #define put_user(x,ptr) ({ __put_user((unsigned long)(x),(ptr),sizeof(*(ptr))); 0; })
83 #define get_user(x,ptr) ({ x = ((__typeof__(*(ptr)))__get_user((ptr),sizeof(*(ptr)))); 0; })
85 extern inline int copy_from_user(void *to
, const void *from
, unsigned long n
)
87 int i
= verify_area(VERIFY_READ
, from
, n
);
90 memcpy_fromfs(to
, from
, n
);
94 extern inline int copy_to_user(void *to
, const void *from
, unsigned long n
)
96 int i
= verify_area(VERIFY_WRITE
, to
, n
);
99 memcpy_tofs(to
, from
, n
);
104 /* --------------------------------------------------------------------- */
106 const char sm_drvname
[] = "soundmodem";
107 static const char sm_drvinfo
[] = KERN_INFO
"soundmodem: (C) 1996 Thomas Sailer, HB9JNX/AE4WA\n"
108 KERN_INFO
"soundmodem: version 0.5 compiled " __TIME__
" " __DATE__
"\n";
110 /* --------------------------------------------------------------------- */
112 const struct modem_tx_info
*sm_modem_tx_table
[] = {
113 #ifdef CONFIG_SOUNDMODEM_AFSK1200
115 #endif /* CONFIG_SOUNDMODEM_AFSK1200 */
116 #ifdef CONFIG_SOUNDMODEM_AFSK2666
118 #endif /* CONFIG_SOUNDMODEM_AFSK2666 */
119 #ifdef CONFIG_SOUNDMODEM_PSK4800
121 #endif /* CONFIG_SOUNDMODEM_PSK4800 */
122 #ifdef CONFIG_SOUNDMODEM_HAPN4800
126 &sm_hapn4800_pm10_tx
,
127 #endif /* CONFIG_SOUNDMODEM_HAPN4800 */
128 #ifdef CONFIG_SOUNDMODEM_FSK9600
131 #endif /* CONFIG_SOUNDMODEM_FSK9600 */
135 const struct modem_rx_info
*sm_modem_rx_table
[] = {
136 #ifdef CONFIG_SOUNDMODEM_AFSK1200
138 #endif /* CONFIG_SOUNDMODEM_AFSK1200 */
139 #ifdef CONFIG_SOUNDMODEM_AFSK2666
141 #endif /* CONFIG_SOUNDMODEM_AFSK2666 */
142 #ifdef CONFIG_SOUNDMODEM_PSK4800
144 #endif /* CONFIG_SOUNDMODEM_PSK4800 */
145 #ifdef CONFIG_SOUNDMODEM_HAPN4800
149 &sm_hapn4800_pm10_rx
,
150 #endif /* CONFIG_SOUNDMODEM_HAPN4800 */
151 #ifdef CONFIG_SOUNDMODEM_FSK9600
154 #endif /* CONFIG_SOUNDMODEM_FSK9600 */
158 static const struct hardware_info
*sm_hardware_table
[] = {
159 #ifdef CONFIG_SOUNDMODEM_SBC
162 #endif /* CONFIG_SOUNDMODEM_SBC */
163 #ifdef CONFIG_SOUNDMODEM_WSS
166 #endif /* CONFIG_SOUNDMODEM_WSS */
170 /* --------------------------------------------------------------------- */
174 /* --------------------------------------------------------------------- */
176 static struct device sm_device
[NR_PORTS
];
180 int iobase
, irq
, dma
, dma2
, seriobase
, pariobase
, midiiobase
;
181 } sm_ports
[NR_PORTS
] = {
182 { NULL
, -1, 0, 0, 0, -1, -1, -1 },
185 /* --------------------------------------------------------------------- */
187 #define UART_RBR(iobase) (iobase+0)
188 #define UART_THR(iobase) (iobase+0)
189 #define UART_IER(iobase) (iobase+1)
190 #define UART_IIR(iobase) (iobase+2)
191 #define UART_FCR(iobase) (iobase+2)
192 #define UART_LCR(iobase) (iobase+3)
193 #define UART_MCR(iobase) (iobase+4)
194 #define UART_LSR(iobase) (iobase+5)
195 #define UART_MSR(iobase) (iobase+6)
196 #define UART_SCR(iobase) (iobase+7)
197 #define UART_DLL(iobase) (iobase+0)
198 #define UART_DLM(iobase) (iobase+1)
202 #define LPT_DATA(iobase) (iobase+0)
203 #define LPT_STATUS(iobase) (iobase+1)
204 #define LPT_CONTROL(iobase) (iobase+2)
205 #define LPT_IRQ_ENABLE 0x10
209 #define MIDI_DATA(iobase) (iobase)
210 #define MIDI_STATUS(iobase) (iobase+1)
211 #define MIDI_READ_FULL 0x80 /* attention: negative logic!! */
212 #define MIDI_WRITE_EMPTY 0x40 /* attention: negative logic!! */
214 #define MIDI_EXTENT 2
216 /* ---------------------------------------------------------------------- */
218 #define PARAM_TXDELAY 1
219 #define PARAM_PERSIST 2
220 #define PARAM_SLOTTIME 3
221 #define PARAM_TXTAIL 4
222 #define PARAM_FULLDUP 5
223 #define PARAM_HARDWARE 6
224 #define PARAM_RETURN 255
230 /* --------------------------------------------------------------------- */
232 * ===================== port checking routines ========================
236 * returns 0 if ok and != 0 on error;
237 * the same behaviour as par96_check_lpt in baycom.c
241 * returns 0 if ok and != 0 on error;
242 * the same behaviour as par96_check_lpt in baycom.c
245 static int check_lpt(unsigned int iobase
)
250 if (iobase
<= 0 || iobase
> 0x1000-LPT_EXTENT
)
252 if (check_region(iobase
, LPT_EXTENT
))
254 b1
= inb(LPT_DATA(iobase
));
255 b2
= inb(LPT_CONTROL(iobase
));
256 outb(0xaa, LPT_DATA(iobase
));
257 i
= inb(LPT_DATA(iobase
)) == 0xaa;
258 outb(0x55, LPT_DATA(iobase
));
259 i
&= inb(LPT_DATA(iobase
)) == 0x55;
260 outb(0x0a, LPT_CONTROL(iobase
));
261 i
&= (inb(LPT_CONTROL(iobase
)) & 0xf) == 0x0a;
262 outb(0x05, LPT_CONTROL(iobase
));
263 i
&= (inb(LPT_CONTROL(iobase
)) & 0xf) == 0x05;
264 outb(b1
, LPT_DATA(iobase
));
265 outb(b2
, LPT_CONTROL(iobase
));
269 /* --------------------------------------------------------------------- */
271 enum uart
{ c_uart_unknown
, c_uart_8250
,
272 c_uart_16450
, c_uart_16550
, c_uart_16550A
};
273 static const char *uart_str
[] =
274 { "unknown", "8250", "16450", "16550", "16550A" };
276 static enum uart
check_uart(unsigned int iobase
)
278 unsigned char b1
,b2
,b3
;
280 enum uart uart_tab
[] =
281 { c_uart_16450
, c_uart_unknown
, c_uart_16550
, c_uart_16550A
};
283 if (iobase
<= 0 || iobase
> 0x1000-SER_EXTENT
)
284 return c_uart_unknown
;
285 if (check_region(iobase
, SER_EXTENT
))
286 return c_uart_unknown
;
287 b1
= inb(UART_MCR(iobase
));
288 outb(b1
| 0x10, UART_MCR(iobase
)); /* loopback mode */
289 b2
= inb(UART_MSR(iobase
));
290 outb(0x1a, UART_MCR(iobase
));
291 b3
= inb(UART_MSR(iobase
)) & 0xf0;
292 outb(b1
, UART_MCR(iobase
)); /* restore old values */
293 outb(b2
, UART_MSR(iobase
));
295 return c_uart_unknown
;
296 inb(UART_RBR(iobase
));
297 inb(UART_RBR(iobase
));
298 outb(0x01, UART_FCR(iobase
)); /* enable FIFOs */
299 u
= uart_tab
[(inb(UART_IIR(iobase
)) >> 6) & 3];
300 if (u
== c_uart_16450
) {
301 outb(0x5a, UART_SCR(iobase
));
302 b1
= inb(UART_SCR(iobase
));
303 outb(0xa5, UART_SCR(iobase
));
304 b2
= inb(UART_SCR(iobase
));
305 if ((b1
!= 0x5a) || (b2
!= 0xa5))
311 /* --------------------------------------------------------------------- */
313 static int check_midi(unsigned int iobase
)
315 unsigned long timeout
;
319 if (iobase
<= 0 || iobase
> 0x1000-MIDI_EXTENT
)
321 if (check_region(iobase
, MIDI_EXTENT
))
323 timeout
= jiffies
+ (HZ
/ 100);
324 while (inb(MIDI_STATUS(iobase
)) & MIDI_WRITE_EMPTY
)
325 if ((signed)(jiffies
- timeout
) > 0)
329 outb(0xff, MIDI_DATA(iobase
));
330 b
= inb(MIDI_STATUS(iobase
));
331 restore_flags(flags
);
332 if (!(b
& MIDI_WRITE_EMPTY
))
334 while (inb(MIDI_STATUS(iobase
)) & MIDI_WRITE_EMPTY
)
335 if ((signed)(jiffies
- timeout
) > 0)
340 /* --------------------------------------------------------------------- */
342 void sm_output_status(struct sm_state
*sm
)
347 int ptt
= hdlcdrv_ptt(&sm
->hdrv
) ^ invert_ptt
;
348 int dcd
= (!!sm
->hdrv
.hdlcrx
.dcd
) ^ invert_dcd
;
350 if (sm
->hdrv
.ptt_out
.flags
& SP_SER
) {
351 outb(dcd
| (ptt
<< 1), UART_MCR(sm
->hdrv
.ptt_out
.seriobase
));
352 outb(0x40 & (-ptt
), UART_LCR(sm
->hdrv
.ptt_out
.seriobase
));
354 if (sm
->hdrv
.ptt_out
.flags
& SP_PAR
) {
355 outb(ptt
| (dcd
<< 1), LPT_DATA(sm
->hdrv
.ptt_out
.pariobase
));
357 if (sm
->hdrv
.ptt_out
.flags
& SP_MIDI
&& hdlcdrv_ptt(&sm
->hdrv
)) {
358 outb(0, MIDI_DATA(sm
->hdrv
.ptt_out
.midiiobase
));
362 /* --------------------------------------------------------------------- */
364 static void sm_output_open(struct sm_state
*sm
)
366 enum uart u
= c_uart_unknown
;
368 sm
->hdrv
.ptt_out
.flags
= 0;
369 if (sm
->hdrv
.ptt_out
.seriobase
> 0 &&
370 sm
->hdrv
.ptt_out
.seriobase
<= 0x1000-SER_EXTENT
&&
371 ((u
= check_uart(sm
->hdrv
.ptt_out
.seriobase
))) != c_uart_unknown
) {
372 sm
->hdrv
.ptt_out
.flags
|= SP_SER
;
373 request_region(sm
->hdrv
.ptt_out
.seriobase
, SER_EXTENT
, "sm ser ptt");
374 outb(0, UART_IER(sm
->hdrv
.ptt_out
.seriobase
));
375 /* 5 bits, 1 stop, no parity, no break, Div latch access */
376 outb(0x80, UART_LCR(sm
->hdrv
.ptt_out
.seriobase
));
377 outb(0, UART_DLM(sm
->hdrv
.ptt_out
.seriobase
));
378 outb(1, UART_DLL(sm
->hdrv
.ptt_out
.seriobase
)); /* as fast as possible */
379 /* LCR and MCR set by output_status */
381 if (sm
->hdrv
.ptt_out
.pariobase
> 0 &&
382 sm
->hdrv
.ptt_out
.pariobase
<= 0x1000-LPT_EXTENT
&&
383 !check_lpt(sm
->hdrv
.ptt_out
.pariobase
)) {
384 sm
->hdrv
.ptt_out
.flags
|= SP_PAR
;
385 request_region(sm
->hdrv
.ptt_out
.pariobase
, LPT_EXTENT
, "sm par ptt");
387 if (sm
->hdrv
.ptt_out
.midiiobase
> 0 &&
388 sm
->hdrv
.ptt_out
.midiiobase
<= 0x1000-MIDI_EXTENT
&&
389 check_midi(sm
->hdrv
.ptt_out
.midiiobase
)) {
390 sm
->hdrv
.ptt_out
.flags
|= SP_MIDI
;
391 request_region(sm
->hdrv
.ptt_out
.midiiobase
, MIDI_EXTENT
,
394 sm_output_status(sm
);
396 printk(KERN_INFO
"%s: ptt output:", sm_drvname
);
397 if (sm
->hdrv
.ptt_out
.flags
& SP_SER
)
398 printk(" serial interface at 0x%x, uart %s", sm
->hdrv
.ptt_out
.seriobase
,
400 if (sm
->hdrv
.ptt_out
.flags
& SP_PAR
)
401 printk(" parallel interface at 0x%x", sm
->hdrv
.ptt_out
.pariobase
);
402 if (sm
->hdrv
.ptt_out
.flags
& SP_MIDI
)
403 printk(" mpu401 (midi) interface at 0x%x", sm
->hdrv
.ptt_out
.midiiobase
);
404 if (!sm
->hdrv
.ptt_out
.flags
)
409 /* --------------------------------------------------------------------- */
411 static void sm_output_close(struct sm_state
*sm
)
413 /* release regions used for PTT output */
414 sm
->hdrv
.hdlctx
.ptt
= sm
->hdrv
.hdlctx
.calibrate
= 0;
415 sm_output_status(sm
);
416 if (sm
->hdrv
.ptt_out
.flags
& SP_SER
)
417 release_region(sm
->hdrv
.ptt_out
.seriobase
, SER_EXTENT
);
418 if (sm
->hdrv
.ptt_out
.flags
& SP_PAR
)
419 release_region(sm
->hdrv
.ptt_out
.pariobase
, LPT_EXTENT
);
420 if (sm
->hdrv
.ptt_out
.flags
& SP_MIDI
)
421 release_region(sm
->hdrv
.ptt_out
.midiiobase
, MIDI_EXTENT
);
422 sm
->hdrv
.ptt_out
.flags
= 0;
425 /* --------------------------------------------------------------------- */
427 static int sm_open(struct device
*dev
);
428 static int sm_close(struct device
*dev
);
429 static int sm_ioctl(struct device
*dev
, struct ifreq
*ifr
,
430 struct hdlcdrv_ioctl
*hi
, int cmd
);
432 /* --------------------------------------------------------------------- */
434 static const struct hdlcdrv_ops sm_ops
= {
435 sm_drvname
, sm_drvinfo
, sm_open
, sm_close
, sm_ioctl
438 /* --------------------------------------------------------------------- */
440 static int sm_open(struct device
*dev
)
445 if (!dev
|| !dev
->priv
||
446 ((struct sm_state
*)dev
->priv
)->hdrv
.magic
!= HDLCDRV_MAGIC
) {
447 printk(KERN_ERR
"sm_open: invalid device struct\n");
450 sm
= (struct sm_state
*)dev
->priv
;
452 if (!sm
->mode_tx
|| !sm
->mode_rx
|| !sm
->hwdrv
|| !sm
->hwdrv
->open
)
454 sm
->hdrv
.par
.bitrate
= sm
->mode_rx
->bitrate
;
455 err
= sm
->hwdrv
->open(dev
, sm
);
460 printk(KERN_INFO
"%s: %s mode %s.%s at iobase 0x%lx irq %u dma %u\n",
461 sm_drvname
, sm
->hwdrv
->hw_name
, sm
->mode_tx
->name
,
462 sm
->mode_rx
->name
, dev
->base_addr
, dev
->irq
, dev
->dma
);
466 /* --------------------------------------------------------------------- */
468 static int sm_close(struct device
*dev
)
473 if (!dev
|| !dev
->priv
||
474 ((struct sm_state
*)dev
->priv
)->hdrv
.magic
!= HDLCDRV_MAGIC
) {
475 printk(KERN_ERR
"sm_close: invalid device struct\n");
478 sm
= (struct sm_state
*)dev
->priv
;
481 if (sm
->hwdrv
&& sm
->hwdrv
->close
)
482 err
= sm
->hwdrv
&& sm
->hwdrv
->close(dev
, sm
);
485 printk(KERN_INFO
"%s: close %s at iobase 0x%lx irq %u dma %u\n",
486 sm_drvname
, sm
->hwdrv
->hw_name
, dev
->base_addr
, dev
->irq
, dev
->dma
);
490 /* --------------------------------------------------------------------- */
492 static int sethw(struct device
*dev
, struct sm_state
*sm
, char *mode
)
494 char *cp
= strchr(mode
, ':');
495 const struct hardware_info
**hwp
= sm_hardware_table
;
501 while (hwp
&& (*hwp
) && (*hwp
)->hw_name
&& strcmp((*hwp
)->hw_name
, mode
))
503 if (!hwp
|| !*hwp
|| !(*hwp
)->hw_name
)
505 if ((*hwp
)->loc_storage
> sizeof(sm
->hw
)) {
506 printk(KERN_ERR
"%s: insufficient storage for hw driver %s (%d)\n",
507 sm_drvname
, (*hwp
)->hw_name
, (*hwp
)->loc_storage
);
514 if (sm
->hwdrv
&& sm
->hwdrv
->sethw
)
515 return sm
->hwdrv
->sethw(dev
, sm
, cp
);
519 /* --------------------------------------------------------------------- */
521 static int sm_ioctl(struct device
*dev
, struct ifreq
*ifr
,
522 struct hdlcdrv_ioctl
*hi
, int cmd
)
527 unsigned int newdiagmode
;
528 unsigned int newdiagflags
;
530 const struct modem_tx_info
**mtp
= sm_modem_tx_table
;
531 const struct modem_rx_info
**mrp
= sm_modem_rx_table
;
532 const struct hardware_info
**hwp
= sm_hardware_table
;
534 if (!dev
|| !dev
->priv
||
535 ((struct sm_state
*)dev
->priv
)->hdrv
.magic
!= HDLCDRV_MAGIC
) {
536 printk(KERN_ERR
"sm_ioctl: invalid device struct\n");
539 sm
= (struct sm_state
*)dev
->priv
;
541 if (cmd
!= SIOCDEVPRIVATE
) {
542 if (!sm
->hwdrv
|| !sm
->hwdrv
->ioctl
)
543 return sm
->hwdrv
->ioctl(dev
, sm
, ifr
, hi
, cmd
);
548 if (sm
->hwdrv
&& sm
->hwdrv
->ioctl
)
549 return sm
->hwdrv
->ioctl(dev
, sm
, ifr
, hi
, cmd
);
552 case HDLCDRVCTL_GETMODE
:
553 cp
= hi
->data
.modename
;
554 if (sm
->hwdrv
&& sm
->hwdrv
->hw_name
)
555 cp
+= sprintf(cp
, "%s:", sm
->hwdrv
->hw_name
);
557 cp
+= sprintf(cp
, "<unspec>:");
558 if (sm
->mode_tx
&& sm
->mode_tx
->name
)
559 cp
+= sprintf(cp
, "%s", sm
->mode_tx
->name
);
561 cp
+= sprintf(cp
, "<unspec>");
562 if (!sm
->mode_rx
|| !sm
->mode_rx
||
563 strcmp(sm
->mode_rx
->name
, sm
->mode_tx
->name
)) {
564 if (sm
->mode_rx
&& sm
->mode_rx
->name
)
565 cp
+= sprintf(cp
, ",%s", sm
->mode_rx
->name
);
567 cp
+= sprintf(cp
, ",<unspec>");
569 if (copy_to_user(ifr
->ifr_data
, hi
, sizeof(*hi
)))
573 case HDLCDRVCTL_SETMODE
:
574 if (!suser() || dev
->start
)
576 hi
->data
.modename
[sizeof(hi
->data
.modename
)-1] = '\0';
577 return sethw(dev
, sm
, hi
->data
.modename
);
579 case HDLCDRVCTL_MODELIST
:
580 cp
= hi
->data
.modename
;
583 cp
+= sprintf("%s:,", (*hwp
)->hw_name
);
588 cp
+= sprintf(">%s,", (*mtp
)->name
);
593 cp
+= sprintf("<%s,", (*mrp
)->name
);
597 if (copy_to_user(ifr
->ifr_data
, hi
, sizeof(*hi
)))
603 if (copy_from_user(&bi
, ifr
->ifr_data
, sizeof(bi
)))
605 bi
.data
.dbg
.int_rate
= sm
->debug_vals
.last_intcnt
;
606 bi
.data
.dbg
.mod_cycles
= sm
->debug_vals
.mod_cyc
;
607 bi
.data
.dbg
.demod_cycles
= sm
->debug_vals
.demod_cyc
;
608 bi
.data
.dbg
.dma_residue
= sm
->debug_vals
.dma_residue
;
609 sm
->debug_vals
.mod_cyc
= sm
->debug_vals
.demod_cyc
=
610 sm
->debug_vals
.dma_residue
= 0;
611 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
614 #endif /* SM_DEBUG */
617 if (copy_from_user(&bi
, ifr
->ifr_data
, sizeof(bi
)))
619 newdiagmode
= bi
.data
.diag
.mode
;
620 newdiagflags
= bi
.data
.diag
.flags
;
621 if (newdiagmode
> SM_DIAGMODE_CONSTELLATION
)
623 bi
.data
.diag
.mode
= sm
->diag
.mode
;
624 bi
.data
.diag
.flags
= sm
->diag
.flags
;
625 bi
.data
.diag
.samplesperbit
= sm
->mode_rx
->sperbit
;
626 if (sm
->diag
.mode
!= newdiagmode
) {
630 sm
->diag
.flags
= newdiagflags
& ~SM_DIAGFLAG_VALID
;
631 sm
->diag
.mode
= newdiagmode
;
632 restore_flags(flags
);
633 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
637 if (sm
->diag
.ptr
< 0 || sm
->diag
.mode
== SM_DIAGMODE_OFF
) {
638 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
642 if (bi
.data
.diag
.datalen
> DIAGDATALEN
)
643 bi
.data
.diag
.datalen
= DIAGDATALEN
;
644 if (sm
->diag
.ptr
< bi
.data
.diag
.datalen
) {
645 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
649 if (copy_to_user(bi
.data
.diag
.data
, sm
->diag
.data
,
650 bi
.data
.diag
.datalen
* sizeof(short)))
652 bi
.data
.diag
.flags
|= SM_DIAGFLAG_VALID
;
656 sm
->diag
.flags
= newdiagflags
& ~SM_DIAGFLAG_VALID
;
657 sm
->diag
.mode
= newdiagmode
;
658 restore_flags(flags
);
659 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
665 /* --------------------------------------------------------------------- */
667 __initfunc(int sm_init(void))
672 char ifname
[HDLCDRV_IFNAMELEN
];
676 * register net devices
678 for (i
= 0; i
< NR_PORTS
; i
++) {
679 struct device
*dev
= sm_device
+i
;
680 sprintf(ifname
, "sm%d", i
);
682 if (!sm_ports
[i
].mode
)
685 sm_ports
[i
].iobase
= sm_ports
[i
].irq
= 0;
686 j
= hdlcdrv_register_hdlcdrv(dev
, &sm_ops
, sizeof(struct sm_state
),
687 ifname
, sm_ports
[i
].iobase
,
688 sm_ports
[i
].irq
, sm_ports
[i
].dma
);
690 sm
= (struct sm_state
*)dev
->priv
;
691 sm
->hdrv
.ptt_out
.dma2
= sm_ports
[i
].dma2
;
692 sm
->hdrv
.ptt_out
.seriobase
= sm_ports
[i
].seriobase
;
693 sm
->hdrv
.ptt_out
.pariobase
= sm_ports
[i
].pariobase
;
694 sm
->hdrv
.ptt_out
.midiiobase
= sm_ports
[i
].midiiobase
;
695 if (set_hw
&& sethw(dev
, sm
, sm_ports
[i
].mode
))
699 printk(KERN_WARNING
"%s: cannot register net device\n",
708 /* --------------------------------------------------------------------- */
713 * command line settable parameters
715 static char *mode
= NULL
;
716 static int iobase
= -1;
719 static int dma2
= -1;
720 static int serio
= 0;
721 static int pario
= 0;
722 static int midiio
= 0;
724 #if LINUX_VERSION_CODE >= 0x20115
726 MODULE_PARM(mode
, "s");
727 MODULE_PARM_DESC(mode
, "soundmodem operating mode; eg. sbc:afsk1200 or wss:fsk9600");
728 MODULE_PARM(iobase
, "i");
729 MODULE_PARM_DESC(iobase
, "soundmodem base address");
730 MODULE_PARM(irq
, "i");
731 MODULE_PARM_DESC(irq
, "soundmodem interrupt");
732 MODULE_PARM(dma
, "i");
733 MODULE_PARM_DESC(dma
, "soundmodem dma channel");
734 MODULE_PARM(dma2
, "i");
735 MODULE_PARM_DESC(dma2
, "soundmodem 2nd dma channel; full duplex only");
736 MODULE_PARM(serio
, "i");
737 MODULE_PARM_DESC(serio
, "soundmodem PTT output on serial port");
738 MODULE_PARM(pario
, "i");
739 MODULE_PARM_DESC(pario
, "soundmodem PTT output on parallel port");
740 MODULE_PARM(midiio
, "i");
741 MODULE_PARM_DESC(midiio
, "soundmodem PTT output on midi port");
743 MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
744 MODULE_DESCRIPTION("Soundcard amateur radio modem driver");
748 int init_module(void)
752 iobase
= (!strncmp(mode
, "sbc", 3)) ? 0x220 : 0x530;
754 irq
= (!strncmp(mode
, "sbc", 3)) ? 5 : 11;
758 sm_ports
[0].mode
= mode
;
759 sm_ports
[0].iobase
= iobase
;
760 sm_ports
[0].irq
= irq
;
761 sm_ports
[0].dma
= dma
;
762 sm_ports
[0].dma2
= dma2
;
763 sm_ports
[0].seriobase
= serio
;
764 sm_ports
[0].pariobase
= pario
;
765 sm_ports
[0].midiiobase
= midiio
;
766 sm_ports
[1].mode
= NULL
;
771 /* --------------------------------------------------------------------- */
773 void cleanup_module(void)
777 printk(KERN_INFO
"sm: cleanup_module called\n");
779 for(i
= 0; i
< NR_PORTS
; i
++) {
780 struct device
*dev
= sm_device
+i
;
781 struct sm_state
*sm
= (struct sm_state
*)dev
->priv
;
784 if (sm
->hdrv
.magic
!= HDLCDRV_MAGIC
)
785 printk(KERN_ERR
"sm: invalid magic in "
788 hdlcdrv_unregister_hdlcdrv(dev
);
794 /* --------------------------------------------------------------------- */
796 * format: sm=io,irq,dma[,dma2[,serio[,pario]]],mode
798 * hw: sbc, wss, wssfdx
799 * modem: afsk1200, fsk9600
802 __initfunc(void sm_setup(char *str
, int *ints
))
806 for (i
= 0; (i
< NR_PORTS
) && (sm_ports
[i
].mode
); i
++);
807 if ((i
>= NR_PORTS
) || (ints
[0] < 3)) {
808 printk(KERN_INFO
"%s: too many or invalid interface "
809 "specifications\n", sm_drvname
);
812 sm_ports
[i
].mode
= str
;
813 sm_ports
[i
].iobase
= ints
[1];
814 sm_ports
[i
].irq
= ints
[2];
815 sm_ports
[i
].dma
= ints
[3];
816 sm_ports
[i
].dma2
= (ints
[0] >= 4) ? ints
[4] : 0;
817 sm_ports
[i
].seriobase
= (ints
[0] >= 5) ? ints
[5] : 0;
818 sm_ports
[i
].pariobase
= (ints
[0] >= 6) ? ints
[6] : 0;
819 sm_ports
[i
].midiiobase
= (ints
[0] >= 7) ? ints
[7] : 0;
821 sm_ports
[i
+1].mode
= NULL
;
825 /* --------------------------------------------------------------------- */