1 /*****************************************************************************/ 2 3 /* 4 * baycom_ser_fdx.c -- baycom ser12 fullduplex radio modem driver. 5 * 6 * Copyright (C) 1996-2000 Thomas Sailer (sailer@ife.ee.ethz.ch) 7 * 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. 12 * 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. 17 * 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. 21 * 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. 25 * 26 * 27 * Supported modems 28 * 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) 36 * 37 * This modem usually draws its supply current out of the otherwise unused 38 * TXD pin of the serial port. Thus a contiguous stream of 0x00-bytes 39 * is transmitted to achieve a positive supply voltage. 40 * 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. 45 * 46 * Command line options (insmod command line) 47 * 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 55 * 56 * 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 70 */ 71 72 /*****************************************************************************/ 73 74 #include <linux/capability.h> 75 #include <linux/module.h> 76 #include <linux/ioport.h> 77 #include <linux/string.h> 78 #include <linux/init.h> 79 #include <linux/interrupt.h> 80 #include <linux/hdlcdrv.h> 81 #include <linux/baycom.h> 82 #include <linux/jiffies.h> 83 #include <linux/time64.h> 84 85 #include <linux/uaccess.h> 86 #include <asm/io.h> 87 #include <asm/irq.h> 88 89 /* --------------------------------------------------------------------- */ 90 91 #define BAYCOM_DEBUG 92 93 /* --------------------------------------------------------------------- */ 94 95 static const char bc_drvname[] = "baycom_ser_fdx"; 96 static const char bc_drvinfo[] = KERN_INFO "baycom_ser_fdx: (C) 1996-2000 Thomas Sailer, HB9JNX/AE4WA\n" 97 "baycom_ser_fdx: version 0.10\n"; 98 99 /* --------------------------------------------------------------------- */ 100 101 #define NR_PORTS 4 102 103 static struct net_device *baycom_device[NR_PORTS]; 104 105 /* --------------------------------------------------------------------- */ 106 107 #define RBR(iobase) (iobase+0) 108 #define THR(iobase) (iobase+0) 109 #define IER(iobase) (iobase+1) 110 #define IIR(iobase) (iobase+2) 111 #define FCR(iobase) (iobase+2) 112 #define LCR(iobase) (iobase+3) 113 #define MCR(iobase) (iobase+4) 114 #define LSR(iobase) (iobase+5) 115 #define MSR(iobase) (iobase+6) 116 #define SCR(iobase) (iobase+7) 117 #define DLL(iobase) (iobase+0) 118 #define DLM(iobase) (iobase+1) 119 120 #define SER12_EXTENT 8 121 122 /* ---------------------------------------------------------------------- */ 123 /* 124 * Information that need to be kept for each board. 125 */ 126 127 struct baycom_state { 128 struct hdlcdrv_state hdrv; 129 130 unsigned int baud, baud_us, baud_arbdiv, baud_uartdiv, baud_dcdtimeout; 131 int opt_dcd; 132 133 struct modem_state { 134 unsigned char flags; 135 unsigned char ptt; 136 unsigned int shreg; 137 struct modem_state_ser12 { 138 unsigned char tx_bit; 139 unsigned char last_rxbit; 140 int dcd_sum0, dcd_sum1, dcd_sum2; 141 int dcd_time; 142 unsigned int pll_time; 143 unsigned int txshreg; 144 } ser12; 145 } modem; 146 147 #ifdef BAYCOM_DEBUG 148 struct debug_vals { 149 unsigned long last_jiffies; 150 unsigned cur_intcnt; 151 unsigned last_intcnt; 152 int cur_pllcorr; 153 int last_pllcorr; 154 } debug_vals; 155 #endif /* BAYCOM_DEBUG */ 156 }; 157 158 /* --------------------------------------------------------------------- */ 159 160 static inline void baycom_int_freq(struct baycom_state *bc) 161 { 162 #ifdef BAYCOM_DEBUG 163 unsigned long cur_jiffies = jiffies; 164 /* 165 * measure the interrupt frequency 166 */ 167 bc->debug_vals.cur_intcnt++; 168 if (time_after_eq(cur_jiffies, bc->debug_vals.last_jiffies + HZ)) { 169 bc->debug_vals.last_jiffies = cur_jiffies; 170 bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt; 171 bc->debug_vals.cur_intcnt = 0; 172 bc->debug_vals.last_pllcorr = bc->debug_vals.cur_pllcorr; 173 bc->debug_vals.cur_pllcorr = 0; 174 } 175 #endif /* BAYCOM_DEBUG */ 176 } 177 178 /* --------------------------------------------------------------------- */ 179 /* 180 * ===================== SER12 specific routines ========================= 181 */ 182 183 /* --------------------------------------------------------------------- */ 184 185 static inline void ser12_set_divisor(struct net_device *dev, 186 unsigned int divisor) 187 { 188 outb(0x81, LCR(dev->base_addr)); /* DLAB = 1 */ 189 outb(divisor, DLL(dev->base_addr)); 190 outb(divisor >> 8, DLM(dev->base_addr)); 191 outb(0x01, LCR(dev->base_addr)); /* word length = 6 */ 192 /* 193 * make sure the next interrupt is generated; 194 * 0 must be used to power the modem; the modem draws its 195 * power from the TxD line 196 */ 197 outb(0x00, THR(dev->base_addr)); 198 /* 199 * it is important not to set the divider while transmitting; 200 * this reportedly makes some UARTs generating interrupts 201 * in the hundredthousands per second region 202 * Reported by: Ignacio.Arenaza@studi.epfl.ch (Ignacio Arenaza Nuno) 203 */ 204 } 205 206 static __inline__ void ser12_rx(struct net_device *dev, struct baycom_state *bc, struct timespec64 *ts, unsigned char curs) 207 { 208 int timediff; 209 int bdus8 = bc->baud_us >> 3; 210 int bdus4 = bc->baud_us >> 2; 211 int bdus2 = bc->baud_us >> 1; 212 213 timediff = 1000000 + ts->tv_nsec / NSEC_PER_USEC - 214 bc->modem.ser12.pll_time; 215 while (timediff >= 500000) 216 timediff -= 1000000; 217 while (timediff >= bdus2) { 218 timediff -= bc->baud_us; 219 bc->modem.ser12.pll_time += bc->baud_us; 220 bc->modem.ser12.dcd_time--; 221 /* first check if there is room to add a bit */ 222 if (bc->modem.shreg & 1) { 223 hdlcdrv_putbits(&bc->hdrv, (bc->modem.shreg >> 1) ^ 0xffff); 224 bc->modem.shreg = 0x10000; 225 } 226 /* add a one bit */ 227 bc->modem.shreg >>= 1; 228 } 229 if (bc->modem.ser12.dcd_time <= 0) { 230 if (!bc->opt_dcd) 231 hdlcdrv_setdcd(&bc->hdrv, (bc->modem.ser12.dcd_sum0 + 232 bc->modem.ser12.dcd_sum1 + 233 bc->modem.ser12.dcd_sum2) < 0); 234 bc->modem.ser12.dcd_sum2 = bc->modem.ser12.dcd_sum1; 235 bc->modem.ser12.dcd_sum1 = bc->modem.ser12.dcd_sum0; 236 bc->modem.ser12.dcd_sum0 = 2; /* slight bias */ 237 bc->modem.ser12.dcd_time += 120; 238 } 239 if (bc->modem.ser12.last_rxbit != curs) { 240 bc->modem.ser12.last_rxbit = curs; 241 bc->modem.shreg |= 0x10000; 242 /* adjust the PLL */ 243 if (timediff > 0) 244 bc->modem.ser12.pll_time += bdus8; 245 else 246 bc->modem.ser12.pll_time += 1000000 - bdus8; 247 /* update DCD */ 248 if (abs(timediff) > bdus4) 249 bc->modem.ser12.dcd_sum0 += 4; 250 else 251 bc->modem.ser12.dcd_sum0--; 252 #ifdef BAYCOM_DEBUG 253 bc->debug_vals.cur_pllcorr = timediff; 254 #endif /* BAYCOM_DEBUG */ 255 } 256 while (bc->modem.ser12.pll_time >= 1000000) 257 bc->modem.ser12.pll_time -= 1000000; 258 } 259 260 /* --------------------------------------------------------------------- */ 261 262 static irqreturn_t ser12_interrupt(int irq, void *dev_id) 263 { 264 struct net_device *dev = (struct net_device *)dev_id; 265 struct baycom_state *bc = netdev_priv(dev); 266 struct timespec64 ts; 267 unsigned char iir, msr; 268 unsigned int txcount = 0; 269 270 if (!bc || bc->hdrv.magic != HDLCDRV_MAGIC) 271 return IRQ_NONE; 272 /* fast way out for shared irq */ 273 if ((iir = inb(IIR(dev->base_addr))) & 1) 274 return IRQ_NONE; 275 /* get current time */ 276 ktime_get_ts64(&ts); 277 msr = inb(MSR(dev->base_addr)); 278 /* delta DCD */ 279 if ((msr & 8) && bc->opt_dcd) 280 hdlcdrv_setdcd(&bc->hdrv, !((msr ^ bc->opt_dcd) & 0x80)); 281 do { 282 switch (iir & 6) { 283 case 6: 284 inb(LSR(dev->base_addr)); 285 break; 286 287 case 4: 288 inb(RBR(dev->base_addr)); 289 break; 290 291 case 2: 292 /* 293 * make sure the next interrupt is generated; 294 * 0 must be used to power the modem; the modem draws its 295 * power from the TxD line 296 */ 297 outb(0x00, THR(dev->base_addr)); 298 baycom_int_freq(bc); 299 txcount++; 300 /* 301 * first output the last bit (!) then call HDLC transmitter, 302 * since this may take quite long 303 */ 304 if (bc->modem.ptt) 305 outb(0x0e | (!!bc->modem.ser12.tx_bit), MCR(dev->base_addr)); 306 else 307 outb(0x0d, MCR(dev->base_addr)); /* transmitter off */ 308 break; 309 310 default: 311 msr = inb(MSR(dev->base_addr)); 312 /* delta DCD */ 313 if ((msr & 8) && bc->opt_dcd) 314 hdlcdrv_setdcd(&bc->hdrv, !((msr ^ bc->opt_dcd) & 0x80)); 315 break; 316 } 317 iir = inb(IIR(dev->base_addr)); 318 } while (!(iir & 1)); 319 ser12_rx(dev, bc, &ts, msr & 0x10); /* CTS */ 320 if (bc->modem.ptt && txcount) { 321 if (bc->modem.ser12.txshreg <= 1) { 322 bc->modem.ser12.txshreg = 0x10000 | hdlcdrv_getbits(&bc->hdrv); 323 if (!hdlcdrv_ptt(&bc->hdrv)) { 324 ser12_set_divisor(dev, 115200/100/8); 325 bc->modem.ptt = 0; 326 goto end_transmit; 327 } 328 } 329 bc->modem.ser12.tx_bit = !(bc->modem.ser12.tx_bit ^ (bc->modem.ser12.txshreg & 1)); 330 bc->modem.ser12.txshreg >>= 1; 331 } 332 end_transmit: 333 local_irq_enable(); 334 if (!bc->modem.ptt && txcount) { 335 hdlcdrv_arbitrate(dev, &bc->hdrv); 336 if (hdlcdrv_ptt(&bc->hdrv)) { 337 ser12_set_divisor(dev, bc->baud_uartdiv); 338 bc->modem.ser12.txshreg = 1; 339 bc->modem.ptt = 1; 340 } 341 } 342 hdlcdrv_transmitter(dev, &bc->hdrv); 343 hdlcdrv_receiver(dev, &bc->hdrv); 344 local_irq_disable(); 345 return IRQ_HANDLED; 346 } 347 348 /* --------------------------------------------------------------------- */ 349 350 enum uart { c_uart_unknown, c_uart_8250, 351 c_uart_16450, c_uart_16550, c_uart_16550A}; 352 static const char *uart_str[] = { 353 "unknown", "8250", "16450", "16550", "16550A" 354 }; 355 356 static enum uart ser12_check_uart(unsigned int iobase) 357 { 358 unsigned char b1,b2,b3; 359 enum uart u; 360 enum uart uart_tab[] = 361 { c_uart_16450, c_uart_unknown, c_uart_16550, c_uart_16550A }; 362 363 b1 = inb(MCR(iobase)); 364 outb(b1 | 0x10, MCR(iobase)); /* loopback mode */ 365 b2 = inb(MSR(iobase)); 366 outb(0x1a, MCR(iobase)); 367 b3 = inb(MSR(iobase)) & 0xf0; 368 outb(b1, MCR(iobase)); /* restore old values */ 369 outb(b2, MSR(iobase)); 370 if (b3 != 0x90) 371 return c_uart_unknown; 372 inb(RBR(iobase)); 373 inb(RBR(iobase)); 374 outb(0x01, FCR(iobase)); /* enable FIFOs */ 375 u = uart_tab[(inb(IIR(iobase)) >> 6) & 3]; 376 if (u == c_uart_16450) { 377 outb(0x5a, SCR(iobase)); 378 b1 = inb(SCR(iobase)); 379 outb(0xa5, SCR(iobase)); 380 b2 = inb(SCR(iobase)); 381 if ((b1 != 0x5a) || (b2 != 0xa5)) 382 u = c_uart_8250; 383 } 384 return u; 385 } 386 387 /* --------------------------------------------------------------------- */ 388 389 static int ser12_open(struct net_device *dev) 390 { 391 struct baycom_state *bc = netdev_priv(dev); 392 enum uart u; 393 394 if (!dev || !bc) 395 return -ENXIO; 396 if (!dev->base_addr || dev->base_addr > 0xffff-SER12_EXTENT || 397 dev->irq < 2 || dev->irq > nr_irqs) { 398 printk(KERN_INFO "baycom_ser_fdx: invalid portnumber (max %u) " 399 "or irq (2 <= irq <= %d)\n", 400 0xffff-SER12_EXTENT, nr_irqs); 401 return -ENXIO; 402 } 403 if (bc->baud < 300 || bc->baud > 4800) { 404 printk(KERN_INFO "baycom_ser_fdx: invalid baudrate " 405 "(300...4800)\n"); 406 return -EINVAL; 407 } 408 if (!request_region(dev->base_addr, SER12_EXTENT, "baycom_ser_fdx")) { 409 printk(KERN_WARNING "BAYCOM_SER_FSX: I/O port 0x%04lx busy\n", 410 dev->base_addr); 411 return -EACCES; 412 } 413 memset(&bc->modem, 0, sizeof(bc->modem)); 414 bc->hdrv.par.bitrate = bc->baud; 415 bc->baud_us = 1000000/bc->baud; 416 bc->baud_uartdiv = (115200/8)/bc->baud; 417 if ((u = ser12_check_uart(dev->base_addr)) == c_uart_unknown){ 418 release_region(dev->base_addr, SER12_EXTENT); 419 return -EIO; 420 } 421 outb(0, FCR(dev->base_addr)); /* disable FIFOs */ 422 outb(0x0d, MCR(dev->base_addr)); 423 outb(0, IER(dev->base_addr)); 424 if (request_irq(dev->irq, ser12_interrupt, IRQF_SHARED, 425 "baycom_ser_fdx", dev)) { 426 release_region(dev->base_addr, SER12_EXTENT); 427 return -EBUSY; 428 } 429 /* 430 * set the SIO to 6 Bits/character; during receive, 431 * the baud rate is set to produce 100 ints/sec 432 * to feed the channel arbitration process, 433 * during transmit to baud ints/sec to run 434 * the transmitter 435 */ 436 ser12_set_divisor(dev, 115200/100/8); 437 /* 438 * enable transmitter empty interrupt and modem status interrupt 439 */ 440 outb(0x0a, IER(dev->base_addr)); 441 /* 442 * make sure the next interrupt is generated; 443 * 0 must be used to power the modem; the modem draws its 444 * power from the TxD line 445 */ 446 outb(0x00, THR(dev->base_addr)); 447 hdlcdrv_setdcd(&bc->hdrv, 0); 448 printk(KERN_INFO "%s: ser_fdx at iobase 0x%lx irq %u baud %u uart %s\n", 449 bc_drvname, dev->base_addr, dev->irq, bc->baud, uart_str[u]); 450 return 0; 451 } 452 453 /* --------------------------------------------------------------------- */ 454 455 static int ser12_close(struct net_device *dev) 456 { 457 struct baycom_state *bc = netdev_priv(dev); 458 459 if (!dev || !bc) 460 return -EINVAL; 461 /* 462 * disable interrupts 463 */ 464 outb(0, IER(dev->base_addr)); 465 outb(1, MCR(dev->base_addr)); 466 free_irq(dev->irq, dev); 467 release_region(dev->base_addr, SER12_EXTENT); 468 printk(KERN_INFO "%s: close ser_fdx at iobase 0x%lx irq %u\n", 469 bc_drvname, dev->base_addr, dev->irq); 470 return 0; 471 } 472 473 /* --------------------------------------------------------------------- */ 474 /* 475 * ===================== hdlcdrv driver interface ========================= 476 */ 477 478 /* --------------------------------------------------------------------- */ 479 480 static int baycom_ioctl(struct net_device *dev, struct ifreq *ifr, 481 struct hdlcdrv_ioctl *hi, int cmd); 482 483 /* --------------------------------------------------------------------- */ 484 485 static const struct hdlcdrv_ops ser12_ops = { 486 .drvname = bc_drvname, 487 .drvinfo = bc_drvinfo, 488 .open = ser12_open, 489 .close = ser12_close, 490 .ioctl = baycom_ioctl, 491 }; 492 493 /* --------------------------------------------------------------------- */ 494 495 static int baycom_setmode(struct baycom_state *bc, const char *modestr) 496 { 497 unsigned int baud; 498 499 if (!strncmp(modestr, "ser", 3)) { 500 baud = simple_strtoul(modestr+3, NULL, 10); 501 if (baud >= 3 && baud <= 48) 502 bc->baud = baud*100; 503 } 504 if (strchr(modestr, '*')) 505 bc->opt_dcd = 0; 506 else if (strchr(modestr, '+')) 507 bc->opt_dcd = -1; 508 else 509 bc->opt_dcd = 1; 510 return 0; 511 } 512 513 /* --------------------------------------------------------------------- */ 514 515 static int baycom_ioctl(struct net_device *dev, struct ifreq *ifr, 516 struct hdlcdrv_ioctl *hi, int cmd) 517 { 518 struct baycom_state *bc; 519 struct baycom_ioctl bi; 520 521 if (!dev) 522 return -EINVAL; 523 524 bc = netdev_priv(dev); 525 BUG_ON(bc->hdrv.magic != HDLCDRV_MAGIC); 526 527 if (cmd != SIOCDEVPRIVATE) 528 return -ENOIOCTLCMD; 529 switch (hi->cmd) { 530 default: 531 break; 532 533 case HDLCDRVCTL_GETMODE: 534 sprintf(hi->data.modename, "ser%u", bc->baud / 100); 535 if (bc->opt_dcd <= 0) 536 strcat(hi->data.modename, (!bc->opt_dcd) ? "*" : "+"); 537 if (copy_to_user(ifr->ifr_data, hi, sizeof(struct hdlcdrv_ioctl))) 538 return -EFAULT; 539 return 0; 540 541 case HDLCDRVCTL_SETMODE: 542 if (netif_running(dev) || !capable(CAP_NET_ADMIN)) 543 return -EACCES; 544 hi->data.modename[sizeof(hi->data.modename)-1] = '\0'; 545 return baycom_setmode(bc, hi->data.modename); 546 547 case HDLCDRVCTL_MODELIST: 548 strcpy(hi->data.modename, "ser12,ser3,ser24"); 549 if (copy_to_user(ifr->ifr_data, hi, sizeof(struct hdlcdrv_ioctl))) 550 return -EFAULT; 551 return 0; 552 553 case HDLCDRVCTL_MODEMPARMASK: 554 return HDLCDRV_PARMASK_IOBASE | HDLCDRV_PARMASK_IRQ; 555 556 } 557 558 if (copy_from_user(&bi, ifr->ifr_data, sizeof(bi))) 559 return -EFAULT; 560 switch (bi.cmd) { 561 default: 562 return -ENOIOCTLCMD; 563 564 #ifdef BAYCOM_DEBUG 565 case BAYCOMCTL_GETDEBUG: 566 bi.data.dbg.debug1 = bc->hdrv.ptt_keyed; 567 bi.data.dbg.debug2 = bc->debug_vals.last_intcnt; 568 bi.data.dbg.debug3 = bc->debug_vals.last_pllcorr; 569 break; 570 #endif /* BAYCOM_DEBUG */ 571 572 } 573 if (copy_to_user(ifr->ifr_data, &bi, sizeof(bi))) 574 return -EFAULT; 575 return 0; 576 577 } 578 579 /* --------------------------------------------------------------------- */ 580 581 /* 582 * command line settable parameters 583 */ 584 static char *mode[NR_PORTS] = { "ser12*", }; 585 static int iobase[NR_PORTS] = { 0x3f8, }; 586 static int irq[NR_PORTS] = { 4, }; 587 static int baud[NR_PORTS] = { [0 ... NR_PORTS-1] = 1200 }; 588 589 module_param_array(mode, charp, NULL, 0); 590 MODULE_PARM_DESC(mode, "baycom operating mode; * for software DCD"); 591 module_param_hw_array(iobase, int, ioport, NULL, 0); 592 MODULE_PARM_DESC(iobase, "baycom io base address"); 593 module_param_hw_array(irq, int, irq, NULL, 0); 594 MODULE_PARM_DESC(irq, "baycom irq number"); 595 module_param_array(baud, int, NULL, 0); 596 MODULE_PARM_DESC(baud, "baycom baud rate (300 to 4800)"); 597 598 MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu"); 599 MODULE_DESCRIPTION("Baycom ser12 full duplex amateur radio modem driver"); 600 MODULE_LICENSE("GPL"); 601 602 /* --------------------------------------------------------------------- */ 603 604 static int __init init_baycomserfdx(void) 605 { 606 int i, found = 0; 607 char set_hw = 1; 608 609 printk(bc_drvinfo); 610 /* 611 * register net devices 612 */ 613 for (i = 0; i < NR_PORTS; i++) { 614 struct net_device *dev; 615 struct baycom_state *bc; 616 char ifname[IFNAMSIZ]; 617 618 sprintf(ifname, "bcsf%d", i); 619 620 if (!mode[i]) 621 set_hw = 0; 622 if (!set_hw) 623 iobase[i] = irq[i] = 0; 624 625 dev = hdlcdrv_register(&ser12_ops, 626 sizeof(struct baycom_state), 627 ifname, iobase[i], irq[i], 0); 628 if (IS_ERR(dev)) 629 break; 630 631 bc = netdev_priv(dev); 632 if (set_hw && baycom_setmode(bc, mode[i])) 633 set_hw = 0; 634 bc->baud = baud[i]; 635 found++; 636 baycom_device[i] = dev; 637 } 638 639 if (!found) 640 return -ENXIO; 641 return 0; 642 } 643 644 static void __exit cleanup_baycomserfdx(void) 645 { 646 int i; 647 648 for(i = 0; i < NR_PORTS; i++) { 649 struct net_device *dev = baycom_device[i]; 650 if (dev) 651 hdlcdrv_unregister(dev); 652 } 653 } 654 655 module_init(init_baycomserfdx); 656 module_exit(cleanup_baycomserfdx); 657 658 /* --------------------------------------------------------------------- */ 659 660 #ifndef MODULE 661 662 /* 663 * format: baycom_ser_fdx=io,irq,mode 664 * mode: ser# hardware DCD 665 * ser#* software DCD 666 * ser#+ hardware DCD, inverted signal at DCD pin 667 * '#' denotes the baud rate / 100, eg. ser12* is '1200 baud, soft DCD' 668 */ 669 670 static int __init baycom_ser_fdx_setup(char *str) 671 { 672 static unsigned nr_dev; 673 int ints[4]; 674 675 if (nr_dev >= NR_PORTS) 676 return 0; 677 str = get_options(str, 4, ints); 678 if (ints[0] < 2) 679 return 0; 680 mode[nr_dev] = str; 681 iobase[nr_dev] = ints[1]; 682 irq[nr_dev] = ints[2]; 683 if (ints[0] >= 3) 684 baud[nr_dev] = ints[3]; 685 nr_dev++; 686 return 1; 687 } 688 689 __setup("baycom_ser_fdx=", baycom_ser_fdx_setup); 690 691 #endif /* MODULE */ 692 /* --------------------------------------------------------------------- */ 693