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