baycom_ser_fdx.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*****************************************************************************/
  3. /*
  4. * baycom_ser_fdx.c -- baycom ser12 fullduplex radio modem driver.
  5. *
  6. * Copyright (C) 1996-2000 Thomas Sailer ([email protected])
  7. *
  8. * Please note that the GPL allows you to use the driver, NOT the radio.
  9. * In order to use the radio, you need a license from the communications
  10. * authority of your country.
  11. *
  12. * Supported modems
  13. *
  14. * ser12: This is a very simple 1200 baud AFSK modem. The modem consists only
  15. * of a modulator/demodulator chip, usually a TI TCM3105. The computer
  16. * is responsible for regenerating the receiver bit clock, as well as
  17. * for handling the HDLC protocol. The modem connects to a serial port,
  18. * hence the name. Since the serial port is not used as an async serial
  19. * port, the kernel driver for serial ports cannot be used, and this
  20. * driver only supports standard serial hardware (8250, 16450, 16550A)
  21. *
  22. * This modem usually draws its supply current out of the otherwise unused
  23. * TXD pin of the serial port. Thus a contiguous stream of 0x00-bytes
  24. * is transmitted to achieve a positive supply voltage.
  25. *
  26. * hsk: This is a 4800 baud FSK modem, designed for TNC use. It works fine
  27. * in 'baycom-mode' :-) In contrast to the TCM3105 modem, power is
  28. * externally supplied. So there's no need to provide the 0x00-byte-stream
  29. * when receiving or idle, which drastically reduces interrupt load.
  30. *
  31. * Command line options (insmod command line)
  32. *
  33. * mode ser# hardware DCD
  34. * ser#* software DCD
  35. * ser#+ hardware DCD, inverted signal at DCD pin
  36. * '#' denotes the baud rate / 100, eg. ser12* is '1200 baud, soft DCD'
  37. * iobase base address of the port; common values are 0x3f8, 0x2f8, 0x3e8, 0x2e8
  38. * baud baud rate (between 300 and 4800)
  39. * irq interrupt line of the port; common values are 4,3
  40. *
  41. * History:
  42. * 0.1 26.06.1996 Adapted from baycom.c and made network driver interface
  43. * 18.10.1996 Changed to new user space access routines (copy_{to,from}_user)
  44. * 0.3 26.04.1997 init code/data tagged
  45. * 0.4 08.07.1997 alternative ser12 decoding algorithm (uses delta CTS ints)
  46. * 0.5 11.11.1997 ser12/par96 split into separate files
  47. * 0.6 24.01.1998 Thorsten Kranzkowski, dl8bcu and Thomas Sailer:
  48. * reduced interrupt load in transmit case
  49. * reworked receiver
  50. * 0.7 03.08.1999 adapt to Linus' new __setup/__initcall
  51. * 0.8 10.08.1999 use module_init/module_exit
  52. * 0.9 12.02.2000 adapted to softnet driver interface
  53. * 0.10 03.07.2000 fix interface name handling
  54. */
  55. /*****************************************************************************/
  56. #include <linux/capability.h>
  57. #include <linux/module.h>
  58. #include <linux/ioport.h>
  59. #include <linux/string.h>
  60. #include <linux/init.h>
  61. #include <linux/interrupt.h>
  62. #include <linux/hdlcdrv.h>
  63. #include <linux/baycom.h>
  64. #include <linux/jiffies.h>
  65. #include <linux/time64.h>
  66. #include <linux/uaccess.h>
  67. #include <asm/io.h>
  68. #include <asm/irq.h>
  69. /* --------------------------------------------------------------------- */
  70. #define BAYCOM_DEBUG
  71. /* --------------------------------------------------------------------- */
  72. static const char bc_drvname[] = "baycom_ser_fdx";
  73. static const char bc_drvinfo[] = KERN_INFO "baycom_ser_fdx: (C) 1996-2000 Thomas Sailer, HB9JNX/AE4WA\n"
  74. "baycom_ser_fdx: version 0.10\n";
  75. /* --------------------------------------------------------------------- */
  76. #define NR_PORTS 4
  77. static struct net_device *baycom_device[NR_PORTS];
  78. /* --------------------------------------------------------------------- */
  79. #define RBR(iobase) (iobase+0)
  80. #define THR(iobase) (iobase+0)
  81. #define IER(iobase) (iobase+1)
  82. #define IIR(iobase) (iobase+2)
  83. #define FCR(iobase) (iobase+2)
  84. #define LCR(iobase) (iobase+3)
  85. #define MCR(iobase) (iobase+4)
  86. #define LSR(iobase) (iobase+5)
  87. #define MSR(iobase) (iobase+6)
  88. #define SCR(iobase) (iobase+7)
  89. #define DLL(iobase) (iobase+0)
  90. #define DLM(iobase) (iobase+1)
  91. #define SER12_EXTENT 8
  92. /* ---------------------------------------------------------------------- */
  93. /*
  94. * Information that need to be kept for each board.
  95. */
  96. struct baycom_state {
  97. struct hdlcdrv_state hdrv;
  98. unsigned int baud, baud_us, baud_arbdiv, baud_uartdiv, baud_dcdtimeout;
  99. int opt_dcd;
  100. struct modem_state {
  101. unsigned char flags;
  102. unsigned char ptt;
  103. unsigned int shreg;
  104. struct modem_state_ser12 {
  105. unsigned char tx_bit;
  106. unsigned char last_rxbit;
  107. int dcd_sum0, dcd_sum1, dcd_sum2;
  108. int dcd_time;
  109. unsigned int pll_time;
  110. unsigned int txshreg;
  111. } ser12;
  112. } modem;
  113. #ifdef BAYCOM_DEBUG
  114. struct debug_vals {
  115. unsigned long last_jiffies;
  116. unsigned cur_intcnt;
  117. unsigned last_intcnt;
  118. int cur_pllcorr;
  119. int last_pllcorr;
  120. } debug_vals;
  121. #endif /* BAYCOM_DEBUG */
  122. };
  123. /* --------------------------------------------------------------------- */
  124. static inline void baycom_int_freq(struct baycom_state *bc)
  125. {
  126. #ifdef BAYCOM_DEBUG
  127. unsigned long cur_jiffies = jiffies;
  128. /*
  129. * measure the interrupt frequency
  130. */
  131. bc->debug_vals.cur_intcnt++;
  132. if (time_after_eq(cur_jiffies, bc->debug_vals.last_jiffies + HZ)) {
  133. bc->debug_vals.last_jiffies = cur_jiffies;
  134. bc->debug_vals.last_intcnt = bc->debug_vals.cur_intcnt;
  135. bc->debug_vals.cur_intcnt = 0;
  136. bc->debug_vals.last_pllcorr = bc->debug_vals.cur_pllcorr;
  137. bc->debug_vals.cur_pllcorr = 0;
  138. }
  139. #endif /* BAYCOM_DEBUG */
  140. }
  141. /* --------------------------------------------------------------------- */
  142. /*
  143. * ===================== SER12 specific routines =========================
  144. */
  145. /* --------------------------------------------------------------------- */
  146. static inline void ser12_set_divisor(struct net_device *dev,
  147. unsigned int divisor)
  148. {
  149. outb(0x81, LCR(dev->base_addr)); /* DLAB = 1 */
  150. outb(divisor, DLL(dev->base_addr));
  151. outb(divisor >> 8, DLM(dev->base_addr));
  152. outb(0x01, LCR(dev->base_addr)); /* word length = 6 */
  153. /*
  154. * make sure the next interrupt is generated;
  155. * 0 must be used to power the modem; the modem draws its
  156. * power from the TxD line
  157. */
  158. outb(0x00, THR(dev->base_addr));
  159. /*
  160. * it is important not to set the divider while transmitting;
  161. * this reportedly makes some UARTs generating interrupts
  162. * in the hundredthousands per second region
  163. * Reported by: [email protected] (Ignacio Arenaza Nuno)
  164. */
  165. }
  166. static __inline__ void ser12_rx(struct net_device *dev, struct baycom_state *bc, struct timespec64 *ts, unsigned char curs)
  167. {
  168. int timediff;
  169. int bdus8 = bc->baud_us >> 3;
  170. int bdus4 = bc->baud_us >> 2;
  171. int bdus2 = bc->baud_us >> 1;
  172. timediff = 1000000 + ts->tv_nsec / NSEC_PER_USEC -
  173. bc->modem.ser12.pll_time;
  174. while (timediff >= 500000)
  175. timediff -= 1000000;
  176. while (timediff >= bdus2) {
  177. timediff -= bc->baud_us;
  178. bc->modem.ser12.pll_time += bc->baud_us;
  179. bc->modem.ser12.dcd_time--;
  180. /* first check if there is room to add a bit */
  181. if (bc->modem.shreg & 1) {
  182. hdlcdrv_putbits(&bc->hdrv, (bc->modem.shreg >> 1) ^ 0xffff);
  183. bc->modem.shreg = 0x10000;
  184. }
  185. /* add a one bit */
  186. bc->modem.shreg >>= 1;
  187. }
  188. if (bc->modem.ser12.dcd_time <= 0) {
  189. if (!bc->opt_dcd)
  190. hdlcdrv_setdcd(&bc->hdrv, (bc->modem.ser12.dcd_sum0 +
  191. bc->modem.ser12.dcd_sum1 +
  192. bc->modem.ser12.dcd_sum2) < 0);
  193. bc->modem.ser12.dcd_sum2 = bc->modem.ser12.dcd_sum1;
  194. bc->modem.ser12.dcd_sum1 = bc->modem.ser12.dcd_sum0;
  195. bc->modem.ser12.dcd_sum0 = 2; /* slight bias */
  196. bc->modem.ser12.dcd_time += 120;
  197. }
  198. if (bc->modem.ser12.last_rxbit != curs) {
  199. bc->modem.ser12.last_rxbit = curs;
  200. bc->modem.shreg |= 0x10000;
  201. /* adjust the PLL */
  202. if (timediff > 0)
  203. bc->modem.ser12.pll_time += bdus8;
  204. else
  205. bc->modem.ser12.pll_time += 1000000 - bdus8;
  206. /* update DCD */
  207. if (abs(timediff) > bdus4)
  208. bc->modem.ser12.dcd_sum0 += 4;
  209. else
  210. bc->modem.ser12.dcd_sum0--;
  211. #ifdef BAYCOM_DEBUG
  212. bc->debug_vals.cur_pllcorr = timediff;
  213. #endif /* BAYCOM_DEBUG */
  214. }
  215. while (bc->modem.ser12.pll_time >= 1000000)
  216. bc->modem.ser12.pll_time -= 1000000;
  217. }
  218. /* --------------------------------------------------------------------- */
  219. static irqreturn_t ser12_interrupt(int irq, void *dev_id)
  220. {
  221. struct net_device *dev = (struct net_device *)dev_id;
  222. struct baycom_state *bc = netdev_priv(dev);
  223. struct timespec64 ts;
  224. unsigned char iir, msr;
  225. unsigned int txcount = 0;
  226. if (!bc || bc->hdrv.magic != HDLCDRV_MAGIC)
  227. return IRQ_NONE;
  228. /* fast way out for shared irq */
  229. if ((iir = inb(IIR(dev->base_addr))) & 1)
  230. return IRQ_NONE;
  231. /* get current time */
  232. ktime_get_ts64(&ts);
  233. msr = inb(MSR(dev->base_addr));
  234. /* delta DCD */
  235. if ((msr & 8) && bc->opt_dcd)
  236. hdlcdrv_setdcd(&bc->hdrv, !((msr ^ bc->opt_dcd) & 0x80));
  237. do {
  238. switch (iir & 6) {
  239. case 6:
  240. inb(LSR(dev->base_addr));
  241. break;
  242. case 4:
  243. inb(RBR(dev->base_addr));
  244. break;
  245. case 2:
  246. /*
  247. * make sure the next interrupt is generated;
  248. * 0 must be used to power the modem; the modem draws its
  249. * power from the TxD line
  250. */
  251. outb(0x00, THR(dev->base_addr));
  252. baycom_int_freq(bc);
  253. txcount++;
  254. /*
  255. * first output the last bit (!) then call HDLC transmitter,
  256. * since this may take quite long
  257. */
  258. if (bc->modem.ptt)
  259. outb(0x0e | (!!bc->modem.ser12.tx_bit), MCR(dev->base_addr));
  260. else
  261. outb(0x0d, MCR(dev->base_addr)); /* transmitter off */
  262. break;
  263. default:
  264. msr = inb(MSR(dev->base_addr));
  265. /* delta DCD */
  266. if ((msr & 8) && bc->opt_dcd)
  267. hdlcdrv_setdcd(&bc->hdrv, !((msr ^ bc->opt_dcd) & 0x80));
  268. break;
  269. }
  270. iir = inb(IIR(dev->base_addr));
  271. } while (!(iir & 1));
  272. ser12_rx(dev, bc, &ts, msr & 0x10); /* CTS */
  273. if (bc->modem.ptt && txcount) {
  274. if (bc->modem.ser12.txshreg <= 1) {
  275. bc->modem.ser12.txshreg = 0x10000 | hdlcdrv_getbits(&bc->hdrv);
  276. if (!hdlcdrv_ptt(&bc->hdrv)) {
  277. ser12_set_divisor(dev, 115200/100/8);
  278. bc->modem.ptt = 0;
  279. goto end_transmit;
  280. }
  281. }
  282. bc->modem.ser12.tx_bit = !(bc->modem.ser12.tx_bit ^ (bc->modem.ser12.txshreg & 1));
  283. bc->modem.ser12.txshreg >>= 1;
  284. }
  285. end_transmit:
  286. local_irq_enable();
  287. if (!bc->modem.ptt && txcount) {
  288. hdlcdrv_arbitrate(dev, &bc->hdrv);
  289. if (hdlcdrv_ptt(&bc->hdrv)) {
  290. ser12_set_divisor(dev, bc->baud_uartdiv);
  291. bc->modem.ser12.txshreg = 1;
  292. bc->modem.ptt = 1;
  293. }
  294. }
  295. hdlcdrv_transmitter(dev, &bc->hdrv);
  296. hdlcdrv_receiver(dev, &bc->hdrv);
  297. local_irq_disable();
  298. return IRQ_HANDLED;
  299. }
  300. /* --------------------------------------------------------------------- */
  301. enum uart { c_uart_unknown, c_uart_8250,
  302. c_uart_16450, c_uart_16550, c_uart_16550A};
  303. static const char *uart_str[] = {
  304. "unknown", "8250", "16450", "16550", "16550A"
  305. };
  306. static enum uart ser12_check_uart(unsigned int iobase)
  307. {
  308. unsigned char b1,b2,b3;
  309. enum uart u;
  310. enum uart uart_tab[] =
  311. { c_uart_16450, c_uart_unknown, c_uart_16550, c_uart_16550A };
  312. b1 = inb(MCR(iobase));
  313. outb(b1 | 0x10, MCR(iobase)); /* loopback mode */
  314. b2 = inb(MSR(iobase));
  315. outb(0x1a, MCR(iobase));
  316. b3 = inb(MSR(iobase)) & 0xf0;
  317. outb(b1, MCR(iobase)); /* restore old values */
  318. outb(b2, MSR(iobase));
  319. if (b3 != 0x90)
  320. return c_uart_unknown;
  321. inb(RBR(iobase));
  322. inb(RBR(iobase));
  323. outb(0x01, FCR(iobase)); /* enable FIFOs */
  324. u = uart_tab[(inb(IIR(iobase)) >> 6) & 3];
  325. if (u == c_uart_16450) {
  326. outb(0x5a, SCR(iobase));
  327. b1 = inb(SCR(iobase));
  328. outb(0xa5, SCR(iobase));
  329. b2 = inb(SCR(iobase));
  330. if ((b1 != 0x5a) || (b2 != 0xa5))
  331. u = c_uart_8250;
  332. }
  333. return u;
  334. }
  335. /* --------------------------------------------------------------------- */
  336. static int ser12_open(struct net_device *dev)
  337. {
  338. struct baycom_state *bc = netdev_priv(dev);
  339. enum uart u;
  340. if (!dev || !bc)
  341. return -ENXIO;
  342. if (!dev->base_addr || dev->base_addr > 0xffff-SER12_EXTENT ||
  343. dev->irq < 2 || dev->irq > nr_irqs) {
  344. printk(KERN_INFO "baycom_ser_fdx: invalid portnumber (max %u) "
  345. "or irq (2 <= irq <= %d)\n",
  346. 0xffff-SER12_EXTENT, nr_irqs);
  347. return -ENXIO;
  348. }
  349. if (bc->baud < 300 || bc->baud > 4800) {
  350. printk(KERN_INFO "baycom_ser_fdx: invalid baudrate "
  351. "(300...4800)\n");
  352. return -EINVAL;
  353. }
  354. if (!request_region(dev->base_addr, SER12_EXTENT, "baycom_ser_fdx")) {
  355. printk(KERN_WARNING "BAYCOM_SER_FSX: I/O port 0x%04lx busy\n",
  356. dev->base_addr);
  357. return -EACCES;
  358. }
  359. memset(&bc->modem, 0, sizeof(bc->modem));
  360. bc->hdrv.par.bitrate = bc->baud;
  361. bc->baud_us = 1000000/bc->baud;
  362. bc->baud_uartdiv = (115200/8)/bc->baud;
  363. if ((u = ser12_check_uart(dev->base_addr)) == c_uart_unknown){
  364. release_region(dev->base_addr, SER12_EXTENT);
  365. return -EIO;
  366. }
  367. outb(0, FCR(dev->base_addr)); /* disable FIFOs */
  368. outb(0x0d, MCR(dev->base_addr));
  369. outb(0, IER(dev->base_addr));
  370. if (request_irq(dev->irq, ser12_interrupt, IRQF_SHARED,
  371. "baycom_ser_fdx", dev)) {
  372. release_region(dev->base_addr, SER12_EXTENT);
  373. return -EBUSY;
  374. }
  375. /*
  376. * set the SIO to 6 Bits/character; during receive,
  377. * the baud rate is set to produce 100 ints/sec
  378. * to feed the channel arbitration process,
  379. * during transmit to baud ints/sec to run
  380. * the transmitter
  381. */
  382. ser12_set_divisor(dev, 115200/100/8);
  383. /*
  384. * enable transmitter empty interrupt and modem status interrupt
  385. */
  386. outb(0x0a, IER(dev->base_addr));
  387. /*
  388. * make sure the next interrupt is generated;
  389. * 0 must be used to power the modem; the modem draws its
  390. * power from the TxD line
  391. */
  392. outb(0x00, THR(dev->base_addr));
  393. hdlcdrv_setdcd(&bc->hdrv, 0);
  394. printk(KERN_INFO "%s: ser_fdx at iobase 0x%lx irq %u baud %u uart %s\n",
  395. bc_drvname, dev->base_addr, dev->irq, bc->baud, uart_str[u]);
  396. return 0;
  397. }
  398. /* --------------------------------------------------------------------- */
  399. static int ser12_close(struct net_device *dev)
  400. {
  401. struct baycom_state *bc = netdev_priv(dev);
  402. if (!dev || !bc)
  403. return -EINVAL;
  404. /*
  405. * disable interrupts
  406. */
  407. outb(0, IER(dev->base_addr));
  408. outb(1, MCR(dev->base_addr));
  409. free_irq(dev->irq, dev);
  410. release_region(dev->base_addr, SER12_EXTENT);
  411. printk(KERN_INFO "%s: close ser_fdx at iobase 0x%lx irq %u\n",
  412. bc_drvname, dev->base_addr, dev->irq);
  413. return 0;
  414. }
  415. /* --------------------------------------------------------------------- */
  416. /*
  417. * ===================== hdlcdrv driver interface =========================
  418. */
  419. /* --------------------------------------------------------------------- */
  420. static int baycom_ioctl(struct net_device *dev, void __user *data,
  421. struct hdlcdrv_ioctl *hi, int cmd);
  422. /* --------------------------------------------------------------------- */
  423. static const struct hdlcdrv_ops ser12_ops = {
  424. .drvname = bc_drvname,
  425. .drvinfo = bc_drvinfo,
  426. .open = ser12_open,
  427. .close = ser12_close,
  428. .ioctl = baycom_ioctl,
  429. };
  430. /* --------------------------------------------------------------------- */
  431. static int baycom_setmode(struct baycom_state *bc, const char *modestr)
  432. {
  433. unsigned int baud;
  434. if (!strncmp(modestr, "ser", 3)) {
  435. baud = simple_strtoul(modestr+3, NULL, 10);
  436. if (baud >= 3 && baud <= 48)
  437. bc->baud = baud*100;
  438. }
  439. if (strchr(modestr, '*'))
  440. bc->opt_dcd = 0;
  441. else if (strchr(modestr, '+'))
  442. bc->opt_dcd = -1;
  443. else
  444. bc->opt_dcd = 1;
  445. return 0;
  446. }
  447. /* --------------------------------------------------------------------- */
  448. static int baycom_ioctl(struct net_device *dev, void __user *data,
  449. struct hdlcdrv_ioctl *hi, int cmd)
  450. {
  451. struct baycom_state *bc;
  452. struct baycom_ioctl bi;
  453. if (!dev)
  454. return -EINVAL;
  455. bc = netdev_priv(dev);
  456. BUG_ON(bc->hdrv.magic != HDLCDRV_MAGIC);
  457. if (cmd != SIOCDEVPRIVATE)
  458. return -ENOIOCTLCMD;
  459. switch (hi->cmd) {
  460. default:
  461. break;
  462. case HDLCDRVCTL_GETMODE:
  463. sprintf(hi->data.modename, "ser%u", bc->baud / 100);
  464. if (bc->opt_dcd <= 0)
  465. strcat(hi->data.modename, (!bc->opt_dcd) ? "*" : "+");
  466. if (copy_to_user(data, hi, sizeof(struct hdlcdrv_ioctl)))
  467. return -EFAULT;
  468. return 0;
  469. case HDLCDRVCTL_SETMODE:
  470. if (netif_running(dev) || !capable(CAP_NET_ADMIN))
  471. return -EACCES;
  472. hi->data.modename[sizeof(hi->data.modename)-1] = '\0';
  473. return baycom_setmode(bc, hi->data.modename);
  474. case HDLCDRVCTL_MODELIST:
  475. strcpy(hi->data.modename, "ser12,ser3,ser24");
  476. if (copy_to_user(data, hi, sizeof(struct hdlcdrv_ioctl)))
  477. return -EFAULT;
  478. return 0;
  479. case HDLCDRVCTL_MODEMPARMASK:
  480. return HDLCDRV_PARMASK_IOBASE | HDLCDRV_PARMASK_IRQ;
  481. }
  482. if (copy_from_user(&bi, data, sizeof(bi)))
  483. return -EFAULT;
  484. switch (bi.cmd) {
  485. default:
  486. return -ENOIOCTLCMD;
  487. #ifdef BAYCOM_DEBUG
  488. case BAYCOMCTL_GETDEBUG:
  489. bi.data.dbg.debug1 = bc->hdrv.ptt_keyed;
  490. bi.data.dbg.debug2 = bc->debug_vals.last_intcnt;
  491. bi.data.dbg.debug3 = bc->debug_vals.last_pllcorr;
  492. break;
  493. #endif /* BAYCOM_DEBUG */
  494. }
  495. if (copy_to_user(data, &bi, sizeof(bi)))
  496. return -EFAULT;
  497. return 0;
  498. }
  499. /* --------------------------------------------------------------------- */
  500. /*
  501. * command line settable parameters
  502. */
  503. static char *mode[NR_PORTS] = { "ser12*", };
  504. static int iobase[NR_PORTS] = { 0x3f8, };
  505. static int irq[NR_PORTS] = { 4, };
  506. static int baud[NR_PORTS] = { [0 ... NR_PORTS-1] = 1200 };
  507. module_param_array(mode, charp, NULL, 0);
  508. MODULE_PARM_DESC(mode, "baycom operating mode; * for software DCD");
  509. module_param_hw_array(iobase, int, ioport, NULL, 0);
  510. MODULE_PARM_DESC(iobase, "baycom io base address");
  511. module_param_hw_array(irq, int, irq, NULL, 0);
  512. MODULE_PARM_DESC(irq, "baycom irq number");
  513. module_param_array(baud, int, NULL, 0);
  514. MODULE_PARM_DESC(baud, "baycom baud rate (300 to 4800)");
  515. MODULE_AUTHOR("Thomas M. Sailer, [email protected], [email protected]");
  516. MODULE_DESCRIPTION("Baycom ser12 full duplex amateur radio modem driver");
  517. MODULE_LICENSE("GPL");
  518. /* --------------------------------------------------------------------- */
  519. static int __init init_baycomserfdx(void)
  520. {
  521. int i, found = 0;
  522. char set_hw = 1;
  523. printk(bc_drvinfo);
  524. /*
  525. * register net devices
  526. */
  527. for (i = 0; i < NR_PORTS; i++) {
  528. struct net_device *dev;
  529. struct baycom_state *bc;
  530. char ifname[IFNAMSIZ];
  531. sprintf(ifname, "bcsf%d", i);
  532. if (!mode[i])
  533. set_hw = 0;
  534. if (!set_hw)
  535. iobase[i] = irq[i] = 0;
  536. dev = hdlcdrv_register(&ser12_ops,
  537. sizeof(struct baycom_state),
  538. ifname, iobase[i], irq[i], 0);
  539. if (IS_ERR(dev))
  540. break;
  541. bc = netdev_priv(dev);
  542. if (set_hw && baycom_setmode(bc, mode[i]))
  543. set_hw = 0;
  544. bc->baud = baud[i];
  545. found++;
  546. baycom_device[i] = dev;
  547. }
  548. if (!found)
  549. return -ENXIO;
  550. return 0;
  551. }
  552. static void __exit cleanup_baycomserfdx(void)
  553. {
  554. int i;
  555. for(i = 0; i < NR_PORTS; i++) {
  556. struct net_device *dev = baycom_device[i];
  557. if (dev)
  558. hdlcdrv_unregister(dev);
  559. }
  560. }
  561. module_init(init_baycomserfdx);
  562. module_exit(cleanup_baycomserfdx);
  563. /* --------------------------------------------------------------------- */
  564. #ifndef MODULE
  565. /*
  566. * format: baycom_ser_fdx=io,irq,mode
  567. * mode: ser# hardware DCD
  568. * ser#* software DCD
  569. * ser#+ hardware DCD, inverted signal at DCD pin
  570. * '#' denotes the baud rate / 100, eg. ser12* is '1200 baud, soft DCD'
  571. */
  572. static int __init baycom_ser_fdx_setup(char *str)
  573. {
  574. static unsigned nr_dev;
  575. int ints[4];
  576. if (nr_dev >= NR_PORTS)
  577. return 0;
  578. str = get_options(str, 4, ints);
  579. if (ints[0] < 2)
  580. return 0;
  581. mode[nr_dev] = str;
  582. iobase[nr_dev] = ints[1];
  583. irq[nr_dev] = ints[2];
  584. if (ints[0] >= 3)
  585. baud[nr_dev] = ints[3];
  586. nr_dev++;
  587. return 1;
  588. }
  589. __setup("baycom_ser_fdx=", baycom_ser_fdx_setup);
  590. #endif /* MODULE */
  591. /* --------------------------------------------------------------------- */