Linux 2.6.20.7
[linux/fpc-iii.git] / drivers / net / hamradio / baycom_ser_fdx.c
blob59214e74b9cf5bcd05ff614bf2a5bb3553afa41a
1 /*****************************************************************************/
3 /*
4 * baycom_ser_fdx.c -- baycom ser12 fullduplex radio modem driver.
6 * Copyright (C) 1996-2000 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 * Supported modems
29 * ser12: This is a very simple 1200 baud AFSK modem. The modem consists only
30 * of a modulator/demodulator chip, usually a TI TCM3105. The computer
31 * is responsible for regenerating the receiver bit clock, as well as
32 * for handling the HDLC protocol. The modem connects to a serial port,
33 * hence the name. Since the serial port is not used as an async serial
34 * port, the kernel driver for serial ports cannot be used, and this
35 * driver only supports standard serial hardware (8250, 16450, 16550A)
37 * This modem usually draws its supply current out of the otherwise unused
38 * TXD pin of the serial port. Thus a contignuous stream of 0x00-bytes
39 * is transmitted to achieve a positive supply voltage.
41 * hsk: This is a 4800 baud FSK modem, designed for TNC use. It works fine
42 * in 'baycom-mode' :-) In contrast to the TCM3105 modem, power is
43 * externally supplied. So there's no need to provide the 0x00-byte-stream
44 * when receiving or idle, which drastically reduces interrupt load.
46 * Command line options (insmod command line)
48 * mode ser# hardware DCD
49 * ser#* software DCD
50 * ser#+ hardware DCD, inverted signal at DCD pin
51 * '#' denotes the baud rate / 100, eg. ser12* is '1200 baud, soft DCD'
52 * iobase base address of the port; common values are 0x3f8, 0x2f8, 0x3e8, 0x2e8
53 * baud baud rate (between 300 and 4800)
54 * irq interrupt line of the port; common values are 4,3
57 * History:
58 * 0.1 26.06.1996 Adapted from baycom.c and made network driver interface
59 * 18.10.1996 Changed to new user space access routines (copy_{to,from}_user)
60 * 0.3 26.04.1997 init code/data tagged
61 * 0.4 08.07.1997 alternative ser12 decoding algorithm (uses delta CTS ints)
62 * 0.5 11.11.1997 ser12/par96 split into separate files
63 * 0.6 24.01.1998 Thorsten Kranzkowski, dl8bcu and Thomas Sailer:
64 * reduced interrupt load in transmit case
65 * reworked receiver
66 * 0.7 03.08.1999 adapt to Linus' new __setup/__initcall
67 * 0.8 10.08.1999 use module_init/module_exit
68 * 0.9 12.02.2000 adapted to softnet driver interface
69 * 0.10 03.07.2000 fix interface name handling
72 /*****************************************************************************/
74 #include <linux/module.h>
75 #include <linux/ioport.h>
76 #include <linux/string.h>
77 #include <linux/init.h>
78 #include <asm/uaccess.h>
79 #include <asm/io.h>
80 #include <linux/hdlcdrv.h>
81 #include <linux/baycom.h>
82 #include <linux/jiffies.h>
84 /* --------------------------------------------------------------------- */
86 #define BAYCOM_DEBUG
88 /* --------------------------------------------------------------------- */
90 static const char bc_drvname[] = "baycom_ser_fdx";
91 static const char bc_drvinfo[] = KERN_INFO "baycom_ser_fdx: (C) 1996-2000 Thomas Sailer, HB9JNX/AE4WA\n"
92 KERN_INFO "baycom_ser_fdx: version 0.10 compiled " __TIME__ " " __DATE__ "\n";
94 /* --------------------------------------------------------------------- */
96 #define NR_PORTS 4
98 static struct net_device *baycom_device[NR_PORTS];
100 /* --------------------------------------------------------------------- */
102 #define RBR(iobase) (iobase+0)
103 #define THR(iobase) (iobase+0)
104 #define IER(iobase) (iobase+1)
105 #define IIR(iobase) (iobase+2)
106 #define FCR(iobase) (iobase+2)
107 #define LCR(iobase) (iobase+3)
108 #define MCR(iobase) (iobase+4)
109 #define LSR(iobase) (iobase+5)
110 #define MSR(iobase) (iobase+6)
111 #define SCR(iobase) (iobase+7)
112 #define DLL(iobase) (iobase+0)
113 #define DLM(iobase) (iobase+1)
115 #define SER12_EXTENT 8
117 /* ---------------------------------------------------------------------- */
119 * Information that need to be kept for each board.
122 struct baycom_state {
123 struct hdlcdrv_state hdrv;
125 unsigned int baud, baud_us, baud_arbdiv, baud_uartdiv, baud_dcdtimeout;
126 int opt_dcd;
128 struct modem_state {
129 unsigned char flags;
130 unsigned char ptt;
131 unsigned int shreg;
132 struct modem_state_ser12 {
133 unsigned char tx_bit;
134 unsigned char last_rxbit;
135 int dcd_sum0, dcd_sum1, dcd_sum2;
136 int dcd_time;
137 unsigned int pll_time;
138 unsigned int txshreg;
139 } ser12;
140 } modem;
142 #ifdef BAYCOM_DEBUG
143 struct debug_vals {
144 unsigned long last_jiffies;
145 unsigned cur_intcnt;
146 unsigned last_intcnt;
147 int cur_pllcorr;
148 int last_pllcorr;
149 } debug_vals;
150 #endif /* BAYCOM_DEBUG */
153 /* --------------------------------------------------------------------- */
155 static inline void baycom_int_freq(struct baycom_state *bc)
157 #ifdef BAYCOM_DEBUG
158 unsigned long cur_jiffies = jiffies;
160 * measure the interrupt frequency
162 bc->debug_vals.cur_intcnt++;
163 if (time_after_eq(cur_jiffies, bc->debug_vals.last_jiffies + HZ)) {
164 bc->debug_vals.last_jiffies = cur_jiffies;
165 bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt;
166 bc->debug_vals.cur_intcnt = 0;
167 bc->debug_vals.last_pllcorr = bc->debug_vals.cur_pllcorr;
168 bc->debug_vals.cur_pllcorr = 0;
170 #endif /* BAYCOM_DEBUG */
173 /* --------------------------------------------------------------------- */
175 * ===================== SER12 specific routines =========================
178 /* --------------------------------------------------------------------- */
180 static inline void ser12_set_divisor(struct net_device *dev,
181 unsigned int divisor)
183 outb(0x81, LCR(dev->base_addr)); /* DLAB = 1 */
184 outb(divisor, DLL(dev->base_addr));
185 outb(divisor >> 8, DLM(dev->base_addr));
186 outb(0x01, LCR(dev->base_addr)); /* word length = 6 */
188 * make sure the next interrupt is generated;
189 * 0 must be used to power the modem; the modem draws its
190 * power from the TxD line
192 outb(0x00, THR(dev->base_addr));
194 * it is important not to set the divider while transmitting;
195 * this reportedly makes some UARTs generating interrupts
196 * in the hundredthousands per second region
197 * Reported by: Ignacio.Arenaza@studi.epfl.ch (Ignacio Arenaza Nuno)
201 /* --------------------------------------------------------------------- */
203 #if 0
204 static inline unsigned int hweight16(unsigned int w)
205 __attribute__ ((unused));
206 static inline unsigned int hweight8(unsigned int w)
207 __attribute__ ((unused));
209 static inline unsigned int hweight16(unsigned int w)
211 unsigned short res = (w & 0x5555) + ((w >> 1) & 0x5555);
212 res = (res & 0x3333) + ((res >> 2) & 0x3333);
213 res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
214 return (res & 0x00FF) + ((res >> 8) & 0x00FF);
217 static inline unsigned int hweight8(unsigned int w)
219 unsigned short res = (w & 0x55) + ((w >> 1) & 0x55);
220 res = (res & 0x33) + ((res >> 2) & 0x33);
221 return (res & 0x0F) + ((res >> 4) & 0x0F);
223 #endif
225 /* --------------------------------------------------------------------- */
227 static __inline__ void ser12_rx(struct net_device *dev, struct baycom_state *bc, struct timeval *tv, unsigned char curs)
229 int timediff;
230 int bdus8 = bc->baud_us >> 3;
231 int bdus4 = bc->baud_us >> 2;
232 int bdus2 = bc->baud_us >> 1;
234 timediff = 1000000 + tv->tv_usec - bc->modem.ser12.pll_time;
235 while (timediff >= 500000)
236 timediff -= 1000000;
237 while (timediff >= bdus2) {
238 timediff -= bc->baud_us;
239 bc->modem.ser12.pll_time += bc->baud_us;
240 bc->modem.ser12.dcd_time--;
241 /* first check if there is room to add a bit */
242 if (bc->modem.shreg & 1) {
243 hdlcdrv_putbits(&bc->hdrv, (bc->modem.shreg >> 1) ^ 0xffff);
244 bc->modem.shreg = 0x10000;
246 /* add a one bit */
247 bc->modem.shreg >>= 1;
249 if (bc->modem.ser12.dcd_time <= 0) {
250 if (!bc->opt_dcd)
251 hdlcdrv_setdcd(&bc->hdrv, (bc->modem.ser12.dcd_sum0 +
252 bc->modem.ser12.dcd_sum1 +
253 bc->modem.ser12.dcd_sum2) < 0);
254 bc->modem.ser12.dcd_sum2 = bc->modem.ser12.dcd_sum1;
255 bc->modem.ser12.dcd_sum1 = bc->modem.ser12.dcd_sum0;
256 bc->modem.ser12.dcd_sum0 = 2; /* slight bias */
257 bc->modem.ser12.dcd_time += 120;
259 if (bc->modem.ser12.last_rxbit != curs) {
260 bc->modem.ser12.last_rxbit = curs;
261 bc->modem.shreg |= 0x10000;
262 /* adjust the PLL */
263 if (timediff > 0)
264 bc->modem.ser12.pll_time += bdus8;
265 else
266 bc->modem.ser12.pll_time += 1000000 - bdus8;
267 /* update DCD */
268 if (abs(timediff) > bdus4)
269 bc->modem.ser12.dcd_sum0 += 4;
270 else
271 bc->modem.ser12.dcd_sum0--;
272 #ifdef BAYCOM_DEBUG
273 bc->debug_vals.cur_pllcorr = timediff;
274 #endif /* BAYCOM_DEBUG */
276 while (bc->modem.ser12.pll_time >= 1000000)
277 bc->modem.ser12.pll_time -= 1000000;
280 /* --------------------------------------------------------------------- */
282 static irqreturn_t ser12_interrupt(int irq, void *dev_id)
284 struct net_device *dev = (struct net_device *)dev_id;
285 struct baycom_state *bc = netdev_priv(dev);
286 struct timeval tv;
287 unsigned char iir, msr;
288 unsigned int txcount = 0;
290 if (!bc || bc->hdrv.magic != HDLCDRV_MAGIC)
291 return IRQ_NONE;
292 /* fast way out for shared irq */
293 if ((iir = inb(IIR(dev->base_addr))) & 1)
294 return IRQ_NONE;
295 /* get current time */
296 do_gettimeofday(&tv);
297 msr = inb(MSR(dev->base_addr));
298 /* delta DCD */
299 if ((msr & 8) && bc->opt_dcd)
300 hdlcdrv_setdcd(&bc->hdrv, !((msr ^ bc->opt_dcd) & 0x80));
301 do {
302 switch (iir & 6) {
303 case 6:
304 inb(LSR(dev->base_addr));
305 break;
307 case 4:
308 inb(RBR(dev->base_addr));
309 break;
311 case 2:
313 * make sure the next interrupt is generated;
314 * 0 must be used to power the modem; the modem draws its
315 * power from the TxD line
317 outb(0x00, THR(dev->base_addr));
318 baycom_int_freq(bc);
319 txcount++;
321 * first output the last bit (!) then call HDLC transmitter,
322 * since this may take quite long
324 if (bc->modem.ptt)
325 outb(0x0e | (!!bc->modem.ser12.tx_bit), MCR(dev->base_addr));
326 else
327 outb(0x0d, MCR(dev->base_addr)); /* transmitter off */
328 break;
330 default:
331 msr = inb(MSR(dev->base_addr));
332 /* delta DCD */
333 if ((msr & 8) && bc->opt_dcd)
334 hdlcdrv_setdcd(&bc->hdrv, !((msr ^ bc->opt_dcd) & 0x80));
335 break;
337 iir = inb(IIR(dev->base_addr));
338 } while (!(iir & 1));
339 ser12_rx(dev, bc, &tv, msr & 0x10); /* CTS */
340 if (bc->modem.ptt && txcount) {
341 if (bc->modem.ser12.txshreg <= 1) {
342 bc->modem.ser12.txshreg = 0x10000 | hdlcdrv_getbits(&bc->hdrv);
343 if (!hdlcdrv_ptt(&bc->hdrv)) {
344 ser12_set_divisor(dev, 115200/100/8);
345 bc->modem.ptt = 0;
346 goto end_transmit;
349 bc->modem.ser12.tx_bit = !(bc->modem.ser12.tx_bit ^ (bc->modem.ser12.txshreg & 1));
350 bc->modem.ser12.txshreg >>= 1;
352 end_transmit:
353 local_irq_enable();
354 if (!bc->modem.ptt && txcount) {
355 hdlcdrv_arbitrate(dev, &bc->hdrv);
356 if (hdlcdrv_ptt(&bc->hdrv)) {
357 ser12_set_divisor(dev, bc->baud_uartdiv);
358 bc->modem.ser12.txshreg = 1;
359 bc->modem.ptt = 1;
362 hdlcdrv_transmitter(dev, &bc->hdrv);
363 hdlcdrv_receiver(dev, &bc->hdrv);
364 local_irq_disable();
365 return IRQ_HANDLED;
368 /* --------------------------------------------------------------------- */
370 enum uart { c_uart_unknown, c_uart_8250,
371 c_uart_16450, c_uart_16550, c_uart_16550A};
372 static const char *uart_str[] = {
373 "unknown", "8250", "16450", "16550", "16550A"
376 static enum uart ser12_check_uart(unsigned int iobase)
378 unsigned char b1,b2,b3;
379 enum uart u;
380 enum uart uart_tab[] =
381 { c_uart_16450, c_uart_unknown, c_uart_16550, c_uart_16550A };
383 b1 = inb(MCR(iobase));
384 outb(b1 | 0x10, MCR(iobase)); /* loopback mode */
385 b2 = inb(MSR(iobase));
386 outb(0x1a, MCR(iobase));
387 b3 = inb(MSR(iobase)) & 0xf0;
388 outb(b1, MCR(iobase)); /* restore old values */
389 outb(b2, MSR(iobase));
390 if (b3 != 0x90)
391 return c_uart_unknown;
392 inb(RBR(iobase));
393 inb(RBR(iobase));
394 outb(0x01, FCR(iobase)); /* enable FIFOs */
395 u = uart_tab[(inb(IIR(iobase)) >> 6) & 3];
396 if (u == c_uart_16450) {
397 outb(0x5a, SCR(iobase));
398 b1 = inb(SCR(iobase));
399 outb(0xa5, SCR(iobase));
400 b2 = inb(SCR(iobase));
401 if ((b1 != 0x5a) || (b2 != 0xa5))
402 u = c_uart_8250;
404 return u;
407 /* --------------------------------------------------------------------- */
409 static int ser12_open(struct net_device *dev)
411 struct baycom_state *bc = netdev_priv(dev);
412 enum uart u;
414 if (!dev || !bc)
415 return -ENXIO;
416 if (!dev->base_addr || dev->base_addr > 0x1000-SER12_EXTENT ||
417 dev->irq < 2 || dev->irq > 15)
418 return -ENXIO;
419 if (bc->baud < 300 || bc->baud > 4800)
420 return -EINVAL;
421 if (!request_region(dev->base_addr, SER12_EXTENT, "baycom_ser_fdx")) {
422 printk(KERN_WARNING "BAYCOM_SER_FSX: I/O port 0x%04lx busy \n",
423 dev->base_addr);
424 return -EACCES;
426 memset(&bc->modem, 0, sizeof(bc->modem));
427 bc->hdrv.par.bitrate = bc->baud;
428 bc->baud_us = 1000000/bc->baud;
429 bc->baud_uartdiv = (115200/8)/bc->baud;
430 if ((u = ser12_check_uart(dev->base_addr)) == c_uart_unknown){
431 release_region(dev->base_addr, SER12_EXTENT);
432 return -EIO;
434 outb(0, FCR(dev->base_addr)); /* disable FIFOs */
435 outb(0x0d, MCR(dev->base_addr));
436 outb(0, IER(dev->base_addr));
437 if (request_irq(dev->irq, ser12_interrupt, IRQF_DISABLED | IRQF_SHARED,
438 "baycom_ser_fdx", dev)) {
439 release_region(dev->base_addr, SER12_EXTENT);
440 return -EBUSY;
443 * set the SIO to 6 Bits/character; during receive,
444 * the baud rate is set to produce 100 ints/sec
445 * to feed the channel arbitration process,
446 * during transmit to baud ints/sec to run
447 * the transmitter
449 ser12_set_divisor(dev, 115200/100/8);
451 * enable transmitter empty interrupt and modem status interrupt
453 outb(0x0a, IER(dev->base_addr));
455 * make sure the next interrupt is generated;
456 * 0 must be used to power the modem; the modem draws its
457 * power from the TxD line
459 outb(0x00, THR(dev->base_addr));
460 hdlcdrv_setdcd(&bc->hdrv, 0);
461 printk(KERN_INFO "%s: ser_fdx at iobase 0x%lx irq %u baud %u uart %s\n",
462 bc_drvname, dev->base_addr, dev->irq, bc->baud, uart_str[u]);
463 return 0;
466 /* --------------------------------------------------------------------- */
468 static int ser12_close(struct net_device *dev)
470 struct baycom_state *bc = netdev_priv(dev);
472 if (!dev || !bc)
473 return -EINVAL;
475 * disable interrupts
477 outb(0, IER(dev->base_addr));
478 outb(1, MCR(dev->base_addr));
479 free_irq(dev->irq, dev);
480 release_region(dev->base_addr, SER12_EXTENT);
481 printk(KERN_INFO "%s: close ser_fdx at iobase 0x%lx irq %u\n",
482 bc_drvname, dev->base_addr, dev->irq);
483 return 0;
486 /* --------------------------------------------------------------------- */
488 * ===================== hdlcdrv driver interface =========================
491 /* --------------------------------------------------------------------- */
493 static int baycom_ioctl(struct net_device *dev, struct ifreq *ifr,
494 struct hdlcdrv_ioctl *hi, int cmd);
496 /* --------------------------------------------------------------------- */
498 static struct hdlcdrv_ops ser12_ops = {
499 .drvname = bc_drvname,
500 .drvinfo = bc_drvinfo,
501 .open = ser12_open,
502 .close = ser12_close,
503 .ioctl = baycom_ioctl,
506 /* --------------------------------------------------------------------- */
508 static int baycom_setmode(struct baycom_state *bc, const char *modestr)
510 unsigned int baud;
512 if (!strncmp(modestr, "ser", 3)) {
513 baud = simple_strtoul(modestr+3, NULL, 10);
514 if (baud >= 3 && baud <= 48)
515 bc->baud = baud*100;
517 if (strchr(modestr, '*'))
518 bc->opt_dcd = 0;
519 else if (strchr(modestr, '+'))
520 bc->opt_dcd = -1;
521 else
522 bc->opt_dcd = 1;
523 return 0;
526 /* --------------------------------------------------------------------- */
528 static int baycom_ioctl(struct net_device *dev, struct ifreq *ifr,
529 struct hdlcdrv_ioctl *hi, int cmd)
531 struct baycom_state *bc;
532 struct baycom_ioctl bi;
534 if (!dev)
535 return -EINVAL;
537 bc = netdev_priv(dev);
538 BUG_ON(bc->hdrv.magic != HDLCDRV_MAGIC);
540 if (cmd != SIOCDEVPRIVATE)
541 return -ENOIOCTLCMD;
542 switch (hi->cmd) {
543 default:
544 break;
546 case HDLCDRVCTL_GETMODE:
547 sprintf(hi->data.modename, "ser%u", bc->baud / 100);
548 if (bc->opt_dcd <= 0)
549 strcat(hi->data.modename, (!bc->opt_dcd) ? "*" : "+");
550 if (copy_to_user(ifr->ifr_data, hi, sizeof(struct hdlcdrv_ioctl)))
551 return -EFAULT;
552 return 0;
554 case HDLCDRVCTL_SETMODE:
555 if (netif_running(dev) || !capable(CAP_NET_ADMIN))
556 return -EACCES;
557 hi->data.modename[sizeof(hi->data.modename)-1] = '\0';
558 return baycom_setmode(bc, hi->data.modename);
560 case HDLCDRVCTL_MODELIST:
561 strcpy(hi->data.modename, "ser12,ser3,ser24");
562 if (copy_to_user(ifr->ifr_data, hi, sizeof(struct hdlcdrv_ioctl)))
563 return -EFAULT;
564 return 0;
566 case HDLCDRVCTL_MODEMPARMASK:
567 return HDLCDRV_PARMASK_IOBASE | HDLCDRV_PARMASK_IRQ;
571 if (copy_from_user(&bi, ifr->ifr_data, sizeof(bi)))
572 return -EFAULT;
573 switch (bi.cmd) {
574 default:
575 return -ENOIOCTLCMD;
577 #ifdef BAYCOM_DEBUG
578 case BAYCOMCTL_GETDEBUG:
579 bi.data.dbg.debug1 = bc->hdrv.ptt_keyed;
580 bi.data.dbg.debug2 = bc->debug_vals.last_intcnt;
581 bi.data.dbg.debug3 = bc->debug_vals.last_pllcorr;
582 break;
583 #endif /* BAYCOM_DEBUG */
586 if (copy_to_user(ifr->ifr_data, &bi, sizeof(bi)))
587 return -EFAULT;
588 return 0;
592 /* --------------------------------------------------------------------- */
595 * command line settable parameters
597 static char *mode[NR_PORTS] = { "ser12*", };
598 static int iobase[NR_PORTS] = { 0x3f8, };
599 static int irq[NR_PORTS] = { 4, };
600 static int baud[NR_PORTS] = { [0 ... NR_PORTS-1] = 1200 };
602 module_param_array(mode, charp, NULL, 0);
603 MODULE_PARM_DESC(mode, "baycom operating mode; * for software DCD");
604 module_param_array(iobase, int, NULL, 0);
605 MODULE_PARM_DESC(iobase, "baycom io base address");
606 module_param_array(irq, int, NULL, 0);
607 MODULE_PARM_DESC(irq, "baycom irq number");
608 module_param_array(baud, int, NULL, 0);
609 MODULE_PARM_DESC(baud, "baycom baud rate (300 to 4800)");
611 MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
612 MODULE_DESCRIPTION("Baycom ser12 full duplex amateur radio modem driver");
613 MODULE_LICENSE("GPL");
615 /* --------------------------------------------------------------------- */
617 static int __init init_baycomserfdx(void)
619 int i, found = 0;
620 char set_hw = 1;
622 printk(bc_drvinfo);
624 * register net devices
626 for (i = 0; i < NR_PORTS; i++) {
627 struct net_device *dev;
628 struct baycom_state *bc;
629 char ifname[IFNAMSIZ];
631 sprintf(ifname, "bcsf%d", i);
633 if (!mode[i])
634 set_hw = 0;
635 if (!set_hw)
636 iobase[i] = irq[i] = 0;
638 dev = hdlcdrv_register(&ser12_ops,
639 sizeof(struct baycom_state),
640 ifname, iobase[i], irq[i], 0);
641 if (IS_ERR(dev))
642 break;
644 bc = netdev_priv(dev);
645 if (set_hw && baycom_setmode(bc, mode[i]))
646 set_hw = 0;
647 bc->baud = baud[i];
648 found++;
649 baycom_device[i] = dev;
652 if (!found)
653 return -ENXIO;
654 return 0;
657 static void __exit cleanup_baycomserfdx(void)
659 int i;
661 for(i = 0; i < NR_PORTS; i++) {
662 struct net_device *dev = baycom_device[i];
663 if (dev)
664 hdlcdrv_unregister(dev);
668 module_init(init_baycomserfdx);
669 module_exit(cleanup_baycomserfdx);
671 /* --------------------------------------------------------------------- */
673 #ifndef MODULE
676 * format: baycom_ser_fdx=io,irq,mode
677 * mode: ser# hardware DCD
678 * ser#* software DCD
679 * ser#+ hardware DCD, inverted signal at DCD pin
680 * '#' denotes the baud rate / 100, eg. ser12* is '1200 baud, soft DCD'
683 static int __init baycom_ser_fdx_setup(char *str)
685 static unsigned nr_dev;
686 int ints[4];
688 if (nr_dev >= NR_PORTS)
689 return 0;
690 str = get_options(str, 4, ints);
691 if (ints[0] < 2)
692 return 0;
693 mode[nr_dev] = str;
694 iobase[nr_dev] = ints[1];
695 irq[nr_dev] = ints[2];
696 if (ints[0] >= 3)
697 baud[nr_dev] = ints[3];
698 nr_dev++;
699 return 1;
702 __setup("baycom_ser_fdx=", baycom_ser_fdx_setup);
704 #endif /* MODULE */
705 /* --------------------------------------------------------------------- */