stallion.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:136k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1.  * Scan through all the boards in the configuration and see what we
  2.  * can find. Handle EIO and the ECH boards a little differently here
  3.  * since the initial search and setup is very different.
  4.  */
  5. static int __init stl_brdinit(stlbrd_t *brdp)
  6. {
  7. int i;
  8. #if DEBUG
  9. printk("stl_brdinit(brdp=%x)n", (int) brdp);
  10. #endif
  11. switch (brdp->brdtype) {
  12. case BRD_EASYIO:
  13. case BRD_EASYIOPCI:
  14. stl_initeio(brdp);
  15. break;
  16. case BRD_ECH:
  17. case BRD_ECHMC:
  18. case BRD_ECHPCI:
  19. case BRD_ECH64PCI:
  20. stl_initech(brdp);
  21. break;
  22. default:
  23. printk("STALLION: board=%d is unknown board type=%dn",
  24. brdp->brdnr, brdp->brdtype);
  25. return(ENODEV);
  26. }
  27. stl_brds[brdp->brdnr] = brdp;
  28. if ((brdp->state & BRD_FOUND) == 0) {
  29. printk("STALLION: %s board not found, board=%d io=%x irq=%dn",
  30. stl_brdnames[brdp->brdtype], brdp->brdnr,
  31. brdp->ioaddr1, brdp->irq);
  32. return(ENODEV);
  33. }
  34. for (i = 0; (i < STL_MAXPANELS); i++)
  35. if (brdp->panels[i] != (stlpanel_t *) NULL)
  36. stl_initports(brdp, brdp->panels[i]);
  37. printk("STALLION: %s found, board=%d io=%x irq=%d "
  38. "nrpanels=%d nrports=%dn", stl_brdnames[brdp->brdtype],
  39. brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
  40. brdp->nrports);
  41. return(0);
  42. }
  43. /*****************************************************************************/
  44. /*
  45.  * Find the next available board number that is free.
  46.  */
  47. static inline int stl_getbrdnr()
  48. {
  49. int i;
  50. for (i = 0; (i < STL_MAXBRDS); i++) {
  51. if (stl_brds[i] == (stlbrd_t *) NULL) {
  52. if (i >= stl_nrbrds)
  53. stl_nrbrds = i + 1;
  54. return(i);
  55. }
  56. }
  57. return(-1);
  58. }
  59. /*****************************************************************************/
  60. #ifdef CONFIG_PCI
  61. /*
  62.  * We have a Stallion board. Allocate a board structure and
  63.  * initialize it. Read its IO and IRQ resources from PCI
  64.  * configuration space.
  65.  */
  66. static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
  67. {
  68. stlbrd_t *brdp;
  69. #if DEBUG
  70. printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)n", brdtype,
  71. devp->bus->number, devp->devfn);
  72. #endif
  73. if (pci_enable_device(devp))
  74. return(-EIO);
  75. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  76. return(-ENOMEM);
  77. if ((brdp->brdnr = stl_getbrdnr()) < 0) {
  78. printk("STALLION: too many boards found, "
  79. "maximum supported %dn", STL_MAXBRDS);
  80. return(0);
  81. }
  82. brdp->brdtype = brdtype;
  83. /*
  84.  * Different Stallion boards use the BAR registers in different ways,
  85.  * so set up io addresses based on board type.
  86.  */
  87. #if DEBUG
  88. printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%xn", __FILE__, __LINE__,
  89. pci_resource_start(devp, 0), pci_resource_start(devp, 1),
  90. pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
  91. #endif
  92. /*
  93.  * We have all resources from the board, so let's setup the actual
  94.  * board structure now.
  95.  */
  96. switch (brdtype) {
  97. case BRD_ECHPCI:
  98. brdp->ioaddr2 = pci_resource_start(devp, 0);
  99. brdp->ioaddr1 = pci_resource_start(devp, 1);
  100. break;
  101. case BRD_ECH64PCI:
  102. brdp->ioaddr2 = pci_resource_start(devp, 2);
  103. brdp->ioaddr1 = pci_resource_start(devp, 1);
  104. break;
  105. case BRD_EASYIOPCI:
  106. brdp->ioaddr1 = pci_resource_start(devp, 2);
  107. brdp->ioaddr2 = pci_resource_start(devp, 1);
  108. break;
  109. default:
  110. printk("STALLION: unknown PCI board type=%dn", brdtype);
  111. break;
  112. }
  113. brdp->irq = devp->irq;
  114. stl_brdinit(brdp);
  115. return(0);
  116. }
  117. /*****************************************************************************/
  118. /*
  119.  * Find all Stallion PCI boards that might be installed. Initialize each
  120.  * one as it is found.
  121.  */
  122. static inline int stl_findpcibrds()
  123. {
  124. struct pci_dev *dev = NULL;
  125. int i, rc;
  126. #if DEBUG
  127. printk("stl_findpcibrds()n");
  128. #endif
  129. if (! pci_present())
  130. return(0);
  131. for (i = 0; (i < stl_nrpcibrds); i++)
  132. while ((dev = pci_find_device(stl_pcibrds[i].vendid,
  133.     stl_pcibrds[i].devid, dev))) {
  134. /*
  135.  * Found a device on the PCI bus that has our vendor and
  136.  * device ID. Need to check now that it is really us.
  137.  */
  138. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  139. continue;
  140. rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
  141. if (rc)
  142. return(rc);
  143. }
  144. return(0);
  145. }
  146. #endif
  147. /*****************************************************************************/
  148. /*
  149.  * Scan through all the boards in the configuration and see what we
  150.  * can find. Handle EIO and the ECH boards a little differently here
  151.  * since the initial search and setup is too different.
  152.  */
  153. static inline int stl_initbrds()
  154. {
  155. stlbrd_t *brdp;
  156. stlconf_t *confp;
  157. int i;
  158. #if DEBUG
  159. printk("stl_initbrds()n");
  160. #endif
  161. if (stl_nrbrds > STL_MAXBRDS) {
  162. printk("STALLION: too many boards in configuration table, "
  163. "truncating to %dn", STL_MAXBRDS);
  164. stl_nrbrds = STL_MAXBRDS;
  165. }
  166. /*
  167.  * Firstly scan the list of static boards configured. Allocate
  168.  * resources and initialize the boards as found.
  169.  */
  170. for (i = 0; (i < stl_nrbrds); i++) {
  171. confp = &stl_brdconf[i];
  172. #ifdef MODULE
  173. stl_parsebrd(confp, stl_brdsp[i]);
  174. #endif
  175. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  176. return(-ENOMEM);
  177. brdp->brdnr = i;
  178. brdp->brdtype = confp->brdtype;
  179. brdp->ioaddr1 = confp->ioaddr1;
  180. brdp->ioaddr2 = confp->ioaddr2;
  181. brdp->irq = confp->irq;
  182. brdp->irqtype = confp->irqtype;
  183. stl_brdinit(brdp);
  184. }
  185. /*
  186.  * Find any dynamically supported boards. That is via module load
  187.  * line options or auto-detected on the PCI bus.
  188.  */
  189. #ifdef MODULE
  190. stl_argbrds();
  191. #endif
  192. #ifdef CONFIG_PCI
  193. stl_findpcibrds();
  194. #endif
  195. return(0);
  196. }
  197. /*****************************************************************************/
  198. /*
  199.  * Return the board stats structure to user app.
  200.  */
  201. static int stl_getbrdstats(combrd_t *bp)
  202. {
  203. stlbrd_t *brdp;
  204. stlpanel_t *panelp;
  205. int i;
  206. if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
  207. return -EFAULT;
  208. if (stl_brdstats.brd >= STL_MAXBRDS)
  209. return(-ENODEV);
  210. brdp = stl_brds[stl_brdstats.brd];
  211. if (brdp == (stlbrd_t *) NULL)
  212. return(-ENODEV);
  213. memset(&stl_brdstats, 0, sizeof(combrd_t));
  214. stl_brdstats.brd = brdp->brdnr;
  215. stl_brdstats.type = brdp->brdtype;
  216. stl_brdstats.hwid = brdp->hwid;
  217. stl_brdstats.state = brdp->state;
  218. stl_brdstats.ioaddr = brdp->ioaddr1;
  219. stl_brdstats.ioaddr2 = brdp->ioaddr2;
  220. stl_brdstats.irq = brdp->irq;
  221. stl_brdstats.nrpanels = brdp->nrpanels;
  222. stl_brdstats.nrports = brdp->nrports;
  223. for (i = 0; (i < brdp->nrpanels); i++) {
  224. panelp = brdp->panels[i];
  225. stl_brdstats.panels[i].panel = i;
  226. stl_brdstats.panels[i].hwid = panelp->hwid;
  227. stl_brdstats.panels[i].nrports = panelp->nrports;
  228. }
  229. return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
  230. }
  231. /*****************************************************************************/
  232. /*
  233.  * Resolve the referenced port number into a port struct pointer.
  234.  */
  235. static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
  236. {
  237. stlbrd_t *brdp;
  238. stlpanel_t *panelp;
  239. if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
  240. return((stlport_t *) NULL);
  241. brdp = stl_brds[brdnr];
  242. if (brdp == (stlbrd_t *) NULL)
  243. return((stlport_t *) NULL);
  244. if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
  245. return((stlport_t *) NULL);
  246. panelp = brdp->panels[panelnr];
  247. if (panelp == (stlpanel_t *) NULL)
  248. return((stlport_t *) NULL);
  249. if ((portnr < 0) || (portnr >= panelp->nrports))
  250. return((stlport_t *) NULL);
  251. return(panelp->ports[portnr]);
  252. }
  253. /*****************************************************************************/
  254. /*
  255.  * Return the port stats structure to user app. A NULL port struct
  256.  * pointer passed in means that we need to find out from the app
  257.  * what port to get stats for (used through board control device).
  258.  */
  259. static int stl_getportstats(stlport_t *portp, comstats_t *cp)
  260. {
  261. unsigned char *head, *tail;
  262. unsigned long flags;
  263. if (portp == (stlport_t *) NULL) {
  264. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  265. return -EFAULT;
  266. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  267. stl_comstats.port);
  268. if (portp == (stlport_t *) NULL)
  269. return(-ENODEV);
  270. }
  271. portp->stats.state = portp->istate;
  272. portp->stats.flags = portp->flags;
  273. portp->stats.hwid = portp->hwid;
  274. portp->stats.ttystate = 0;
  275. portp->stats.cflags = 0;
  276. portp->stats.iflags = 0;
  277. portp->stats.oflags = 0;
  278. portp->stats.lflags = 0;
  279. portp->stats.rxbuffered = 0;
  280. save_flags(flags);
  281. cli();
  282. if (portp->tty != (struct tty_struct *) NULL) {
  283. if (portp->tty->driver_data == portp) {
  284. portp->stats.ttystate = portp->tty->flags;
  285. portp->stats.rxbuffered = portp->tty->flip.count;
  286. if (portp->tty->termios != (struct termios *) NULL) {
  287. portp->stats.cflags = portp->tty->termios->c_cflag;
  288. portp->stats.iflags = portp->tty->termios->c_iflag;
  289. portp->stats.oflags = portp->tty->termios->c_oflag;
  290. portp->stats.lflags = portp->tty->termios->c_lflag;
  291. }
  292. }
  293. }
  294. restore_flags(flags);
  295. head = portp->tx.head;
  296. tail = portp->tx.tail;
  297. portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
  298. (STL_TXBUFSIZE - (tail - head)));
  299. portp->stats.signals = (unsigned long) stl_getsignals(portp);
  300. return copy_to_user(cp, &portp->stats,
  301.     sizeof(comstats_t)) ? -EFAULT : 0;
  302. }
  303. /*****************************************************************************/
  304. /*
  305.  * Clear the port stats structure. We also return it zeroed out...
  306.  */
  307. static int stl_clrportstats(stlport_t *portp, comstats_t *cp)
  308. {
  309. if (portp == (stlport_t *) NULL) {
  310. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  311. return -EFAULT;
  312. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  313. stl_comstats.port);
  314. if (portp == (stlport_t *) NULL)
  315. return(-ENODEV);
  316. }
  317. memset(&portp->stats, 0, sizeof(comstats_t));
  318. portp->stats.brd = portp->brdnr;
  319. portp->stats.panel = portp->panelnr;
  320. portp->stats.port = portp->portnr;
  321. return copy_to_user(cp, &portp->stats,
  322.     sizeof(comstats_t)) ? -EFAULT : 0;
  323. }
  324. /*****************************************************************************/
  325. /*
  326.  * Return the entire driver ports structure to a user app.
  327.  */
  328. static int stl_getportstruct(unsigned long arg)
  329. {
  330. stlport_t *portp;
  331. if (copy_from_user(&stl_dummyport, (void *) arg, sizeof(stlport_t)))
  332. return -EFAULT;
  333. portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
  334.  stl_dummyport.portnr);
  335. if (portp == (stlport_t *) NULL)
  336. return(-ENODEV);
  337. return copy_to_user((void *)arg, portp,
  338.     sizeof(stlport_t)) ? -EFAULT : 0;
  339. }
  340. /*****************************************************************************/
  341. /*
  342.  * Return the entire driver board structure to a user app.
  343.  */
  344. static int stl_getbrdstruct(unsigned long arg)
  345. {
  346. stlbrd_t *brdp;
  347. if (copy_from_user(&stl_dummybrd, (void *) arg, sizeof(stlbrd_t)))
  348. return -EFAULT;
  349. if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
  350. return(-ENODEV);
  351. brdp = stl_brds[stl_dummybrd.brdnr];
  352. if (brdp == (stlbrd_t *) NULL)
  353. return(-ENODEV);
  354. return copy_to_user((void *)arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
  355. }
  356. /*****************************************************************************/
  357. /*
  358.  * The "staliomem" device is also required to do some special operations
  359.  * on the board and/or ports. In this driver it is mostly used for stats
  360.  * collection.
  361.  */
  362. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  363. {
  364. int brdnr, rc;
  365. #if DEBUG
  366. printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)n", (int) ip,
  367. (int) fp, cmd, (int) arg);
  368. #endif
  369. brdnr = MINOR(ip->i_rdev);
  370. if (brdnr >= STL_MAXBRDS)
  371. return(-ENODEV);
  372. rc = 0;
  373. switch (cmd) {
  374. case COM_GETPORTSTATS:
  375. if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
  376.     sizeof(comstats_t))) == 0)
  377. rc = stl_getportstats((stlport_t *) NULL,
  378. (comstats_t *) arg);
  379. break;
  380. case COM_CLRPORTSTATS:
  381. if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
  382.     sizeof(comstats_t))) == 0)
  383. rc = stl_clrportstats((stlport_t *) NULL,
  384. (comstats_t *) arg);
  385. break;
  386. case COM_GETBRDSTATS:
  387. if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
  388.     sizeof(combrd_t))) == 0)
  389. rc = stl_getbrdstats((combrd_t *) arg);
  390. break;
  391. case COM_READPORT:
  392. if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
  393.     sizeof(stlport_t))) == 0)
  394. rc = stl_getportstruct(arg);
  395. break;
  396. case COM_READBOARD:
  397. if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
  398.     sizeof(stlbrd_t))) == 0)
  399. rc = stl_getbrdstruct(arg);
  400. break;
  401. default:
  402. rc = -ENOIOCTLCMD;
  403. break;
  404. }
  405. return(rc);
  406. }
  407. /*****************************************************************************/
  408. int __init stl_init(void)
  409. {
  410. printk(KERN_INFO "%s: version %sn", stl_drvtitle, stl_drvversion);
  411. stl_initbrds();
  412. /*
  413.  * Allocate a temporary write buffer.
  414.  */
  415. stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
  416. if (stl_tmpwritebuf == (char *) NULL)
  417. printk("STALLION: failed to allocate memory (size=%d)n",
  418. STL_TXBUFSIZE);
  419. /*
  420.  * Set up a character driver for per board stuff. This is mainly used
  421.  * to do stats ioctls on the ports.
  422.  */
  423. if (devfs_register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
  424. printk("STALLION: failed to register serial board devicen");
  425. devfs_handle = devfs_mk_dir (NULL, "staliomem", NULL);
  426. devfs_register_series (devfs_handle, "%u", 4, DEVFS_FL_DEFAULT,
  427.        STL_SIOMEMMAJOR, 0,
  428.        S_IFCHR | S_IRUSR | S_IWUSR,
  429.        &stl_fsiomem, NULL);
  430. /*
  431.  * Set up the tty driver structure and register us as a driver.
  432.  * Also setup the callout tty device.
  433.  */
  434. memset(&stl_serial, 0, sizeof(struct tty_driver));
  435. stl_serial.magic = TTY_DRIVER_MAGIC;
  436. stl_serial.driver_name = stl_drvname;
  437. stl_serial.name = stl_serialname;
  438. stl_serial.major = STL_SERIALMAJOR;
  439. stl_serial.minor_start = 0;
  440. stl_serial.num = STL_MAXBRDS * STL_MAXPORTS;
  441. stl_serial.type = TTY_DRIVER_TYPE_SERIAL;
  442. stl_serial.subtype = STL_DRVTYPSERIAL;
  443. stl_serial.init_termios = stl_deftermios;
  444. stl_serial.flags = TTY_DRIVER_REAL_RAW;
  445. stl_serial.refcount = &stl_refcount;
  446. stl_serial.table = stl_ttys;
  447. stl_serial.termios = stl_termios;
  448. stl_serial.termios_locked = stl_termioslocked;
  449. stl_serial.open = stl_open;
  450. stl_serial.close = stl_close;
  451. stl_serial.write = stl_write;
  452. stl_serial.put_char = stl_putchar;
  453. stl_serial.flush_chars = stl_flushchars;
  454. stl_serial.write_room = stl_writeroom;
  455. stl_serial.chars_in_buffer = stl_charsinbuffer;
  456. stl_serial.ioctl = stl_ioctl;
  457. stl_serial.set_termios = stl_settermios;
  458. stl_serial.throttle = stl_throttle;
  459. stl_serial.unthrottle = stl_unthrottle;
  460. stl_serial.stop = stl_stop;
  461. stl_serial.start = stl_start;
  462. stl_serial.hangup = stl_hangup;
  463. stl_serial.flush_buffer = stl_flushbuffer;
  464. stl_serial.break_ctl = stl_breakctl;
  465. stl_serial.wait_until_sent = stl_waituntilsent;
  466. stl_serial.send_xchar = stl_sendxchar;
  467. stl_serial.read_proc = stl_readproc;
  468. stl_callout = stl_serial;
  469. stl_callout.name = stl_calloutname;
  470. stl_callout.major = STL_CALLOUTMAJOR;
  471. stl_callout.subtype = STL_DRVTYPCALLOUT;
  472. stl_callout.read_proc = 0;
  473. if (tty_register_driver(&stl_serial))
  474. printk("STALLION: failed to register serial drivern");
  475. if (tty_register_driver(&stl_callout))
  476. printk("STALLION: failed to register callout drivern");
  477. return(0);
  478. }
  479. /*****************************************************************************/
  480. /*                       CD1400 HARDWARE FUNCTIONS                           */
  481. /*****************************************************************************/
  482. /*
  483.  * These functions get/set/update the registers of the cd1400 UARTs.
  484.  * Access to the cd1400 registers is via an address/data io port pair.
  485.  * (Maybe should make this inline...)
  486.  */
  487. static int stl_cd1400getreg(stlport_t *portp, int regnr)
  488. {
  489. outb((regnr + portp->uartaddr), portp->ioaddr);
  490. return(inb(portp->ioaddr + EREG_DATA));
  491. }
  492. static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
  493. {
  494. outb((regnr + portp->uartaddr), portp->ioaddr);
  495. outb(value, portp->ioaddr + EREG_DATA);
  496. }
  497. static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
  498. {
  499. outb((regnr + portp->uartaddr), portp->ioaddr);
  500. if (inb(portp->ioaddr + EREG_DATA) != value) {
  501. outb(value, portp->ioaddr + EREG_DATA);
  502. return(1);
  503. }
  504. return(0);
  505. }
  506. /*****************************************************************************/
  507. /*
  508.  * Inbitialize the UARTs in a panel. We don't care what sort of board
  509.  * these ports are on - since the port io registers are almost
  510.  * identical when dealing with ports.
  511.  */
  512. static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
  513. {
  514. unsigned int gfrcr;
  515. int chipmask, i, j;
  516. int nrchips, uartaddr, ioaddr;
  517. #if DEBUG
  518. printk("stl_panelinit(brdp=%x,panelp=%x)n", (int) brdp, (int) panelp);
  519. #endif
  520. BRDENABLE(panelp->brdnr, panelp->pagenr);
  521. /*
  522.  * Check that each chip is present and started up OK.
  523.  */
  524. chipmask = 0;
  525. nrchips = panelp->nrports / CD1400_PORTS;
  526. for (i = 0; (i < nrchips); i++) {
  527. if (brdp->brdtype == BRD_ECHPCI) {
  528. outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
  529. ioaddr = panelp->iobase;
  530. } else {
  531. ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
  532. }
  533. uartaddr = (i & 0x01) ? 0x080 : 0;
  534. outb((GFRCR + uartaddr), ioaddr);
  535. outb(0, (ioaddr + EREG_DATA));
  536. outb((CCR + uartaddr), ioaddr);
  537. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  538. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  539. outb((GFRCR + uartaddr), ioaddr);
  540. for (j = 0; (j < CCR_MAXWAIT); j++) {
  541. if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
  542. break;
  543. }
  544. if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
  545. printk("STALLION: cd1400 not responding, "
  546. "brd=%d panel=%d chip=%dn",
  547. panelp->brdnr, panelp->panelnr, i);
  548. continue;
  549. }
  550. chipmask |= (0x1 << i);
  551. outb((PPR + uartaddr), ioaddr);
  552. outb(PPR_SCALAR, (ioaddr + EREG_DATA));
  553. }
  554. BRDDISABLE(panelp->brdnr);
  555. return(chipmask);
  556. }
  557. /*****************************************************************************/
  558. /*
  559.  * Initialize hardware specific port registers.
  560.  */
  561. static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
  562. {
  563. #if DEBUG
  564. printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)n",
  565. (int) brdp, (int) panelp, (int) portp);
  566. #endif
  567. if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
  568.     (portp == (stlport_t *) NULL))
  569. return;
  570. portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
  571. (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
  572. portp->uartaddr = (portp->portnr & 0x04) << 5;
  573. portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
  574. BRDENABLE(portp->brdnr, portp->pagenr);
  575. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  576. stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
  577. portp->hwid = stl_cd1400getreg(portp, GFRCR);
  578. BRDDISABLE(portp->brdnr);
  579. }
  580. /*****************************************************************************/
  581. /*
  582.  * Wait for the command register to be ready. We will poll this,
  583.  * since it won't usually take too long to be ready.
  584.  */
  585. static void stl_cd1400ccrwait(stlport_t *portp)
  586. {
  587. int i;
  588. for (i = 0; (i < CCR_MAXWAIT); i++) {
  589. if (stl_cd1400getreg(portp, CCR) == 0) {
  590. return;
  591. }
  592. }
  593. printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%dn",
  594. portp->portnr, portp->panelnr, portp->brdnr);
  595. }
  596. /*****************************************************************************/
  597. /*
  598.  * Set up the cd1400 registers for a port based on the termios port
  599.  * settings.
  600.  */
  601. static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
  602. {
  603. stlbrd_t *brdp;
  604. unsigned long flags;
  605. unsigned int clkdiv, baudrate;
  606. unsigned char cor1, cor2, cor3;
  607. unsigned char cor4, cor5, ccr;
  608. unsigned char srer, sreron, sreroff;
  609. unsigned char mcor1, mcor2, rtpr;
  610. unsigned char clk, div;
  611. cor1 = 0;
  612. cor2 = 0;
  613. cor3 = 0;
  614. cor4 = 0;
  615. cor5 = 0;
  616. ccr = 0;
  617. rtpr = 0;
  618. clk = 0;
  619. div = 0;
  620. mcor1 = 0;
  621. mcor2 = 0;
  622. sreron = 0;
  623. sreroff = 0;
  624. brdp = stl_brds[portp->brdnr];
  625. if (brdp == (stlbrd_t *) NULL)
  626. return;
  627. /*
  628.  * Set up the RX char ignore mask with those RX error types we
  629.  * can ignore. We can get the cd1400 to help us out a little here,
  630.  * it will ignore parity errors and breaks for us.
  631.  */
  632. portp->rxignoremsk = 0;
  633. if (tiosp->c_iflag & IGNPAR) {
  634. portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
  635. cor1 |= COR1_PARIGNORE;
  636. }
  637. if (tiosp->c_iflag & IGNBRK) {
  638. portp->rxignoremsk |= ST_BREAK;
  639. cor4 |= COR4_IGNBRK;
  640. }
  641. portp->rxmarkmsk = ST_OVERRUN;
  642. if (tiosp->c_iflag & (INPCK | PARMRK))
  643. portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
  644. if (tiosp->c_iflag & BRKINT)
  645. portp->rxmarkmsk |= ST_BREAK;
  646. /*
  647.  * Go through the char size, parity and stop bits and set all the
  648.  * option register appropriately.
  649.  */
  650. switch (tiosp->c_cflag & CSIZE) {
  651. case CS5:
  652. cor1 |= COR1_CHL5;
  653. break;
  654. case CS6:
  655. cor1 |= COR1_CHL6;
  656. break;
  657. case CS7:
  658. cor1 |= COR1_CHL7;
  659. break;
  660. default:
  661. cor1 |= COR1_CHL8;
  662. break;
  663. }
  664. if (tiosp->c_cflag & CSTOPB)
  665. cor1 |= COR1_STOP2;
  666. else
  667. cor1 |= COR1_STOP1;
  668. if (tiosp->c_cflag & PARENB) {
  669. if (tiosp->c_cflag & PARODD)
  670. cor1 |= (COR1_PARENB | COR1_PARODD);
  671. else
  672. cor1 |= (COR1_PARENB | COR1_PAREVEN);
  673. } else {
  674. cor1 |= COR1_PARNONE;
  675. }
  676. /*
  677.  * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
  678.  * space for hardware flow control and the like. This should be set to
  679.  * VMIN. Also here we will set the RX data timeout to 10ms - this should
  680.  * really be based on VTIME.
  681.  */
  682. cor3 |= FIFO_RXTHRESHOLD;
  683. rtpr = 2;
  684. /*
  685.  * Calculate the baud rate timers. For now we will just assume that
  686.  * the input and output baud are the same. Could have used a baud
  687.  * table here, but this way we can generate virtually any baud rate
  688.  * we like!
  689.  */
  690. baudrate = tiosp->c_cflag & CBAUD;
  691. if (baudrate & CBAUDEX) {
  692. baudrate &= ~CBAUDEX;
  693. if ((baudrate < 1) || (baudrate > 4))
  694. tiosp->c_cflag &= ~CBAUDEX;
  695. else
  696. baudrate += 15;
  697. }
  698. baudrate = stl_baudrates[baudrate];
  699. if ((tiosp->c_cflag & CBAUD) == B38400) {
  700. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  701. baudrate = 57600;
  702. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  703. baudrate = 115200;
  704. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  705. baudrate = 230400;
  706. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  707. baudrate = 460800;
  708. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  709. baudrate = (portp->baud_base / portp->custom_divisor);
  710. }
  711. if (baudrate > STL_CD1400MAXBAUD)
  712. baudrate = STL_CD1400MAXBAUD;
  713. if (baudrate > 0) {
  714. for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
  715. clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
  716. if (clkdiv < 0x100)
  717. break;
  718. }
  719. div = (unsigned char) clkdiv;
  720. }
  721. /*
  722.  * Check what form of modem signaling is required and set it up.
  723.  */
  724. if ((tiosp->c_cflag & CLOCAL) == 0) {
  725. mcor1 |= MCOR1_DCD;
  726. mcor2 |= MCOR2_DCD;
  727. sreron |= SRER_MODEM;
  728. portp->flags |= ASYNC_CHECK_CD;
  729. } else {
  730. portp->flags &= ~ASYNC_CHECK_CD;
  731. }
  732. /*
  733.  * Setup cd1400 enhanced modes if we can. In particular we want to
  734.  * handle as much of the flow control as possible automatically. As
  735.  * well as saving a few CPU cycles it will also greatly improve flow
  736.  * control reliability.
  737.  */
  738. if (tiosp->c_iflag & IXON) {
  739. cor2 |= COR2_TXIBE;
  740. cor3 |= COR3_SCD12;
  741. if (tiosp->c_iflag & IXANY)
  742. cor2 |= COR2_IXM;
  743. }
  744. if (tiosp->c_cflag & CRTSCTS) {
  745. cor2 |= COR2_CTSAE;
  746. mcor1 |= FIFO_RTSTHRESHOLD;
  747. }
  748. /*
  749.  * All cd1400 register values calculated so go through and set
  750.  * them all up.
  751.  */
  752. #if DEBUG
  753. printk("SETPORT: portnr=%d panelnr=%d brdnr=%dn",
  754. portp->portnr, portp->panelnr, portp->brdnr);
  755. printk("    cor1=%x cor2=%x cor3=%x cor4=%x cor5=%xn",
  756. cor1, cor2, cor3, cor4, cor5);
  757. printk("    mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%xn",
  758. mcor1, mcor2, rtpr, sreron, sreroff);
  759. printk("    tcor=%x tbpr=%x rcor=%x rbpr=%xn", clk, div, clk, div);
  760. printk("    schr1=%x schr2=%x schr3=%x schr4=%xn",
  761. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  762. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  763. #endif
  764. save_flags(flags);
  765. cli();
  766. BRDENABLE(portp->brdnr, portp->pagenr);
  767. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
  768. srer = stl_cd1400getreg(portp, SRER);
  769. stl_cd1400setreg(portp, SRER, 0);
  770. if (stl_cd1400updatereg(portp, COR1, cor1))
  771. ccr = 1;
  772. if (stl_cd1400updatereg(portp, COR2, cor2))
  773. ccr = 1;
  774. if (stl_cd1400updatereg(portp, COR3, cor3))
  775. ccr = 1;
  776. if (ccr) {
  777. stl_cd1400ccrwait(portp);
  778. stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
  779. }
  780. stl_cd1400setreg(portp, COR4, cor4);
  781. stl_cd1400setreg(portp, COR5, cor5);
  782. stl_cd1400setreg(portp, MCOR1, mcor1);
  783. stl_cd1400setreg(portp, MCOR2, mcor2);
  784. if (baudrate > 0) {
  785. stl_cd1400setreg(portp, TCOR, clk);
  786. stl_cd1400setreg(portp, TBPR, div);
  787. stl_cd1400setreg(portp, RCOR, clk);
  788. stl_cd1400setreg(portp, RBPR, div);
  789. }
  790. stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
  791. stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
  792. stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
  793. stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
  794. stl_cd1400setreg(portp, RTPR, rtpr);
  795. mcor1 = stl_cd1400getreg(portp, MSVR1);
  796. if (mcor1 & MSVR1_DCD)
  797. portp->sigs |= TIOCM_CD;
  798. else
  799. portp->sigs &= ~TIOCM_CD;
  800. stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
  801. BRDDISABLE(portp->brdnr);
  802. restore_flags(flags);
  803. }
  804. /*****************************************************************************/
  805. /*
  806.  * Set the state of the DTR and RTS signals.
  807.  */
  808. static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
  809. {
  810. unsigned char msvr1, msvr2;
  811. unsigned long flags;
  812. #if DEBUG
  813. printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)n",
  814. (int) portp, dtr, rts);
  815. #endif
  816. msvr1 = 0;
  817. msvr2 = 0;
  818. if (dtr > 0)
  819. msvr1 = MSVR1_DTR;
  820. if (rts > 0)
  821. msvr2 = MSVR2_RTS;
  822. save_flags(flags);
  823. cli();
  824. BRDENABLE(portp->brdnr, portp->pagenr);
  825. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  826. if (rts >= 0)
  827. stl_cd1400setreg(portp, MSVR2, msvr2);
  828. if (dtr >= 0)
  829. stl_cd1400setreg(portp, MSVR1, msvr1);
  830. BRDDISABLE(portp->brdnr);
  831. restore_flags(flags);
  832. }
  833. /*****************************************************************************/
  834. /*
  835.  * Return the state of the signals.
  836.  */
  837. static int stl_cd1400getsignals(stlport_t *portp)
  838. {
  839. unsigned char msvr1, msvr2;
  840. unsigned long flags;
  841. int sigs;
  842. #if DEBUG
  843. printk("stl_cd1400getsignals(portp=%x)n", (int) portp);
  844. #endif
  845. save_flags(flags);
  846. cli();
  847. BRDENABLE(portp->brdnr, portp->pagenr);
  848. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  849. msvr1 = stl_cd1400getreg(portp, MSVR1);
  850. msvr2 = stl_cd1400getreg(portp, MSVR2);
  851. BRDDISABLE(portp->brdnr);
  852. restore_flags(flags);
  853. sigs = 0;
  854. sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
  855. sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
  856. sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
  857. sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
  858. #if 0
  859. sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
  860. sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
  861. #else
  862. sigs |= TIOCM_DSR;
  863. #endif
  864. return(sigs);
  865. }
  866. /*****************************************************************************/
  867. /*
  868.  * Enable/Disable the Transmitter and/or Receiver.
  869.  */
  870. static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
  871. {
  872. unsigned char ccr;
  873. unsigned long flags;
  874. #if DEBUG
  875. printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)n",
  876. (int) portp, rx, tx);
  877. #endif
  878. ccr = 0;
  879. if (tx == 0)
  880. ccr |= CCR_TXDISABLE;
  881. else if (tx > 0)
  882. ccr |= CCR_TXENABLE;
  883. if (rx == 0)
  884. ccr |= CCR_RXDISABLE;
  885. else if (rx > 0)
  886. ccr |= CCR_RXENABLE;
  887. save_flags(flags);
  888. cli();
  889. BRDENABLE(portp->brdnr, portp->pagenr);
  890. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  891. stl_cd1400ccrwait(portp);
  892. stl_cd1400setreg(portp, CCR, ccr);
  893. stl_cd1400ccrwait(portp);
  894. BRDDISABLE(portp->brdnr);
  895. restore_flags(flags);
  896. }
  897. /*****************************************************************************/
  898. /*
  899.  * Start/stop the Transmitter and/or Receiver.
  900.  */
  901. static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
  902. {
  903. unsigned char sreron, sreroff;
  904. unsigned long flags;
  905. #if DEBUG
  906. printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)n",
  907. (int) portp, rx, tx);
  908. #endif
  909. sreron = 0;
  910. sreroff = 0;
  911. if (tx == 0)
  912. sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
  913. else if (tx == 1)
  914. sreron |= SRER_TXDATA;
  915. else if (tx >= 2)
  916. sreron |= SRER_TXEMPTY;
  917. if (rx == 0)
  918. sreroff |= SRER_RXDATA;
  919. else if (rx > 0)
  920. sreron |= SRER_RXDATA;
  921. save_flags(flags);
  922. cli();
  923. BRDENABLE(portp->brdnr, portp->pagenr);
  924. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  925. stl_cd1400setreg(portp, SRER,
  926. ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
  927. BRDDISABLE(portp->brdnr);
  928. if (tx > 0)
  929. set_bit(ASYI_TXBUSY, &portp->istate);
  930. restore_flags(flags);
  931. }
  932. /*****************************************************************************/
  933. /*
  934.  * Disable all interrupts from this port.
  935.  */
  936. static void stl_cd1400disableintrs(stlport_t *portp)
  937. {
  938. unsigned long flags;
  939. #if DEBUG
  940. printk("stl_cd1400disableintrs(portp=%x)n", (int) portp);
  941. #endif
  942. save_flags(flags);
  943. cli();
  944. BRDENABLE(portp->brdnr, portp->pagenr);
  945. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  946. stl_cd1400setreg(portp, SRER, 0);
  947. BRDDISABLE(portp->brdnr);
  948. restore_flags(flags);
  949. }
  950. /*****************************************************************************/
  951. static void stl_cd1400sendbreak(stlport_t *portp, int len)
  952. {
  953. unsigned long flags;
  954. #if DEBUG
  955. printk("stl_cd1400sendbreak(portp=%x,len=%d)n", (int) portp, len);
  956. #endif
  957. save_flags(flags);
  958. cli();
  959. BRDENABLE(portp->brdnr, portp->pagenr);
  960. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  961. stl_cd1400setreg(portp, SRER,
  962. ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
  963. SRER_TXEMPTY));
  964. BRDDISABLE(portp->brdnr);
  965. portp->brklen = len;
  966. if (len == 1)
  967. portp->stats.txbreaks++;
  968. restore_flags(flags);
  969. }
  970. /*****************************************************************************/
  971. /*
  972.  * Take flow control actions...
  973.  */
  974. static void stl_cd1400flowctrl(stlport_t *portp, int state)
  975. {
  976. struct tty_struct *tty;
  977. unsigned long flags;
  978. #if DEBUG
  979. printk("stl_cd1400flowctrl(portp=%x,state=%x)n", (int) portp, state);
  980. #endif
  981. if (portp == (stlport_t *) NULL)
  982. return;
  983. tty = portp->tty;
  984. if (tty == (struct tty_struct *) NULL)
  985. return;
  986. save_flags(flags);
  987. cli();
  988. BRDENABLE(portp->brdnr, portp->pagenr);
  989. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  990. if (state) {
  991. if (tty->termios->c_iflag & IXOFF) {
  992. stl_cd1400ccrwait(portp);
  993. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  994. portp->stats.rxxon++;
  995. stl_cd1400ccrwait(portp);
  996. }
  997. /*
  998.  * Question: should we return RTS to what it was before? It may
  999.  * have been set by an ioctl... Suppose not, since if you have
  1000.  * hardware flow control set then it is pretty silly to go and
  1001.  * set the RTS line by hand.
  1002.  */
  1003. if (tty->termios->c_cflag & CRTSCTS) {
  1004. stl_cd1400setreg(portp, MCOR1,
  1005. (stl_cd1400getreg(portp, MCOR1) |
  1006. FIFO_RTSTHRESHOLD));
  1007. stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
  1008. portp->stats.rxrtson++;
  1009. }
  1010. } else {
  1011. if (tty->termios->c_iflag & IXOFF) {
  1012. stl_cd1400ccrwait(portp);
  1013. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  1014. portp->stats.rxxoff++;
  1015. stl_cd1400ccrwait(portp);
  1016. }
  1017. if (tty->termios->c_cflag & CRTSCTS) {
  1018. stl_cd1400setreg(portp, MCOR1,
  1019. (stl_cd1400getreg(portp, MCOR1) & 0xf0));
  1020. stl_cd1400setreg(portp, MSVR2, 0);
  1021. portp->stats.rxrtsoff++;
  1022. }
  1023. }
  1024. BRDDISABLE(portp->brdnr);
  1025. restore_flags(flags);
  1026. }
  1027. /*****************************************************************************/
  1028. /*
  1029.  * Send a flow control character...
  1030.  */
  1031. static void stl_cd1400sendflow(stlport_t *portp, int state)
  1032. {
  1033. struct tty_struct *tty;
  1034. unsigned long flags;
  1035. #if DEBUG
  1036. printk("stl_cd1400sendflow(portp=%x,state=%x)n", (int) portp, state);
  1037. #endif
  1038. if (portp == (stlport_t *) NULL)
  1039. return;
  1040. tty = portp->tty;
  1041. if (tty == (struct tty_struct *) NULL)
  1042. return;
  1043. save_flags(flags);
  1044. cli();
  1045. BRDENABLE(portp->brdnr, portp->pagenr);
  1046. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  1047. if (state) {
  1048. stl_cd1400ccrwait(portp);
  1049. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  1050. portp->stats.rxxon++;
  1051. stl_cd1400ccrwait(portp);
  1052. } else {
  1053. stl_cd1400ccrwait(portp);
  1054. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  1055. portp->stats.rxxoff++;
  1056. stl_cd1400ccrwait(portp);
  1057. }
  1058. BRDDISABLE(portp->brdnr);
  1059. restore_flags(flags);
  1060. }
  1061. /*****************************************************************************/
  1062. static void stl_cd1400flush(stlport_t *portp)
  1063. {
  1064. unsigned long flags;
  1065. #if DEBUG
  1066. printk("stl_cd1400flush(portp=%x)n", (int) portp);
  1067. #endif
  1068. if (portp == (stlport_t *) NULL)
  1069. return;
  1070. save_flags(flags);
  1071. cli();
  1072. BRDENABLE(portp->brdnr, portp->pagenr);
  1073. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  1074. stl_cd1400ccrwait(portp);
  1075. stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
  1076. stl_cd1400ccrwait(portp);
  1077. portp->tx.tail = portp->tx.head;
  1078. BRDDISABLE(portp->brdnr);
  1079. restore_flags(flags);
  1080. }
  1081. /*****************************************************************************/
  1082. /*
  1083.  * Return the current state of data flow on this port. This is only
  1084.  * really interresting when determining if data has fully completed
  1085.  * transmission or not... This is easy for the cd1400, it accurately
  1086.  * maintains the busy port flag.
  1087.  */
  1088. static int stl_cd1400datastate(stlport_t *portp)
  1089. {
  1090. #if DEBUG
  1091. printk("stl_cd1400datastate(portp=%x)n", (int) portp);
  1092. #endif
  1093. if (portp == (stlport_t *) NULL)
  1094. return(0);
  1095. return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
  1096. }
  1097. /*****************************************************************************/
  1098. /*
  1099.  * Interrupt service routine for cd1400 EasyIO boards.
  1100.  */
  1101. static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
  1102. {
  1103. unsigned char svrtype;
  1104. #if DEBUG
  1105. printk("stl_cd1400eiointr(panelp=%x,iobase=%x)n",
  1106. (int) panelp, iobase);
  1107. #endif
  1108. outb(SVRR, iobase);
  1109. svrtype = inb(iobase + EREG_DATA);
  1110. if (panelp->nrports > 4) {
  1111. outb((SVRR + 0x80), iobase);
  1112. svrtype |= inb(iobase + EREG_DATA);
  1113. }
  1114. if (svrtype & SVRR_RX)
  1115. stl_cd1400rxisr(panelp, iobase);
  1116. else if (svrtype & SVRR_TX)
  1117. stl_cd1400txisr(panelp, iobase);
  1118. else if (svrtype & SVRR_MDM)
  1119. stl_cd1400mdmisr(panelp, iobase);
  1120. }
  1121. /*****************************************************************************/
  1122. /*
  1123.  * Interrupt service routine for cd1400 panels.
  1124.  */
  1125. static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
  1126. {
  1127. unsigned char svrtype;
  1128. #if DEBUG
  1129. printk("stl_cd1400echintr(panelp=%x,iobase=%x)n", (int) panelp,
  1130. iobase);
  1131. #endif
  1132. outb(SVRR, iobase);
  1133. svrtype = inb(iobase + EREG_DATA);
  1134. outb((SVRR + 0x80), iobase);
  1135. svrtype |= inb(iobase + EREG_DATA);
  1136. if (svrtype & SVRR_RX)
  1137. stl_cd1400rxisr(panelp, iobase);
  1138. else if (svrtype & SVRR_TX)
  1139. stl_cd1400txisr(panelp, iobase);
  1140. else if (svrtype & SVRR_MDM)
  1141. stl_cd1400mdmisr(panelp, iobase);
  1142. }
  1143. /*****************************************************************************/
  1144. /*
  1145.  * Unfortunately we need to handle breaks in the TX data stream, since
  1146.  * this is the only way to generate them on the cd1400.
  1147.  */
  1148. static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
  1149. {
  1150. if (portp->brklen == 1) {
  1151. outb((COR2 + portp->uartaddr), ioaddr);
  1152. outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
  1153. (ioaddr + EREG_DATA));
  1154. outb((TDR + portp->uartaddr), ioaddr);
  1155. outb(ETC_CMD, (ioaddr + EREG_DATA));
  1156. outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
  1157. outb((SRER + portp->uartaddr), ioaddr);
  1158. outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
  1159. (ioaddr + EREG_DATA));
  1160. return(1);
  1161. } else if (portp->brklen > 1) {
  1162. outb((TDR + portp->uartaddr), ioaddr);
  1163. outb(ETC_CMD, (ioaddr + EREG_DATA));
  1164. outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
  1165. portp->brklen = -1;
  1166. return(1);
  1167. } else {
  1168. outb((COR2 + portp->uartaddr), ioaddr);
  1169. outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
  1170. (ioaddr + EREG_DATA));
  1171. portp->brklen = 0;
  1172. }
  1173. return(0);
  1174. }
  1175. /*****************************************************************************/
  1176. /*
  1177.  * Transmit interrupt handler. This has gotta be fast!  Handling TX
  1178.  * chars is pretty simple, stuff as many as possible from the TX buffer
  1179.  * into the cd1400 FIFO. Must also handle TX breaks here, since they
  1180.  * are embedded as commands in the data stream. Oh no, had to use a goto!
  1181.  * This could be optimized more, will do when I get time...
  1182.  * In practice it is possible that interrupts are enabled but that the
  1183.  * port has been hung up. Need to handle not having any TX buffer here,
  1184.  * this is done by using the side effect that head and tail will also
  1185.  * be NULL if the buffer has been freed.
  1186.  */
  1187. static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
  1188. {
  1189. stlport_t *portp;
  1190. int len, stlen;
  1191. char *head, *tail;
  1192. unsigned char ioack, srer;
  1193. #if DEBUG
  1194. printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)n", (int) panelp, ioaddr);
  1195. #endif
  1196. ioack = inb(ioaddr + EREG_TXACK);
  1197. if (((ioack & panelp->ackmask) != 0) ||
  1198.     ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
  1199. printk("STALLION: bad TX interrupt ack value=%xn", ioack);
  1200. return;
  1201. }
  1202. portp = panelp->ports[(ioack >> 3)];
  1203. /*
  1204.  * Unfortunately we need to handle breaks in the data stream, since
  1205.  * this is the only way to generate them on the cd1400. Do it now if
  1206.  * a break is to be sent.
  1207.  */
  1208. if (portp->brklen != 0)
  1209. if (stl_cd1400breakisr(portp, ioaddr))
  1210. goto stl_txalldone;
  1211. head = portp->tx.head;
  1212. tail = portp->tx.tail;
  1213. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  1214. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  1215.     (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  1216. set_bit(ASYI_TXLOW, &portp->istate);
  1217. MOD_INC_USE_COUNT;
  1218. if (schedule_task(&portp->tqueue) == 0)
  1219. MOD_DEC_USE_COUNT;
  1220. }
  1221. if (len == 0) {
  1222. outb((SRER + portp->uartaddr), ioaddr);
  1223. srer = inb(ioaddr + EREG_DATA);
  1224. if (srer & SRER_TXDATA) {
  1225. srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
  1226. } else {
  1227. srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
  1228. clear_bit(ASYI_TXBUSY, &portp->istate);
  1229. }
  1230. outb(srer, (ioaddr + EREG_DATA));
  1231. } else {
  1232. len = MIN(len, CD1400_TXFIFOSIZE);
  1233. portp->stats.txtotal += len;
  1234. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  1235. outb((TDR + portp->uartaddr), ioaddr);
  1236. outsb((ioaddr + EREG_DATA), tail, stlen);
  1237. len -= stlen;
  1238. tail += stlen;
  1239. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  1240. tail = portp->tx.buf;
  1241. if (len > 0) {
  1242. outsb((ioaddr + EREG_DATA), tail, len);
  1243. tail += len;
  1244. }
  1245. portp->tx.tail = tail;
  1246. }
  1247. stl_txalldone:
  1248. outb((EOSRR + portp->uartaddr), ioaddr);
  1249. outb(0, (ioaddr + EREG_DATA));
  1250. }
  1251. /*****************************************************************************/
  1252. /*
  1253.  * Receive character interrupt handler. Determine if we have good chars
  1254.  * or bad chars and then process appropriately. Good chars are easy
  1255.  * just shove the lot into the RX buffer and set all status byte to 0.
  1256.  * If a bad RX char then process as required. This routine needs to be
  1257.  * fast!  In practice it is possible that we get an interrupt on a port
  1258.  * that is closed. This can happen on hangups - since they completely
  1259.  * shutdown a port not in user context. Need to handle this case.
  1260.  */
  1261. static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
  1262. {
  1263. stlport_t *portp;
  1264. struct tty_struct *tty;
  1265. unsigned int ioack, len, buflen;
  1266. unsigned char status;
  1267. char ch;
  1268. #if DEBUG
  1269. printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)n", (int) panelp, ioaddr);
  1270. #endif
  1271. ioack = inb(ioaddr + EREG_RXACK);
  1272. if ((ioack & panelp->ackmask) != 0) {
  1273. printk("STALLION: bad RX interrupt ack value=%xn", ioack);
  1274. return;
  1275. }
  1276. portp = panelp->ports[(ioack >> 3)];
  1277. tty = portp->tty;
  1278. if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
  1279. outb((RDCR + portp->uartaddr), ioaddr);
  1280. len = inb(ioaddr + EREG_DATA);
  1281. if ((tty == (struct tty_struct *) NULL) ||
  1282.     (tty->flip.char_buf_ptr == (char *) NULL) ||
  1283.     ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
  1284. len = MIN(len, sizeof(stl_unwanted));
  1285. outb((RDSR + portp->uartaddr), ioaddr);
  1286. insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
  1287. portp->stats.rxlost += len;
  1288. portp->stats.rxtotal += len;
  1289. } else {
  1290. len = MIN(len, buflen);
  1291. if (len > 0) {
  1292. outb((RDSR + portp->uartaddr), ioaddr);
  1293. insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
  1294. memset(tty->flip.flag_buf_ptr, 0, len);
  1295. tty->flip.flag_buf_ptr += len;
  1296. tty->flip.char_buf_ptr += len;
  1297. tty->flip.count += len;
  1298. tty_schedule_flip(tty);
  1299. portp->stats.rxtotal += len;
  1300. }
  1301. }
  1302. } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
  1303. outb((RDSR + portp->uartaddr), ioaddr);
  1304. status = inb(ioaddr + EREG_DATA);
  1305. ch = inb(ioaddr + EREG_DATA);
  1306. if (status & ST_PARITY)
  1307. portp->stats.rxparity++;
  1308. if (status & ST_FRAMING)
  1309. portp->stats.rxframing++;
  1310. if (status & ST_OVERRUN)
  1311. portp->stats.rxoverrun++;
  1312. if (status & ST_BREAK)
  1313. portp->stats.rxbreaks++;
  1314. if (status & ST_SCHARMASK) {
  1315. if ((status & ST_SCHARMASK) == ST_SCHAR1)
  1316. portp->stats.txxon++;
  1317. if ((status & ST_SCHARMASK) == ST_SCHAR2)
  1318. portp->stats.txxoff++;
  1319. goto stl_rxalldone;
  1320. }
  1321. if ((tty != (struct tty_struct *) NULL) &&
  1322.     ((portp->rxignoremsk & status) == 0)) {
  1323. if (portp->rxmarkmsk & status) {
  1324. if (status & ST_BREAK) {
  1325. status = TTY_BREAK;
  1326. if (portp->flags & ASYNC_SAK) {
  1327. do_SAK(tty);
  1328. BRDENABLE(portp->brdnr, portp->pagenr);
  1329. }
  1330. } else if (status & ST_PARITY) {
  1331. status = TTY_PARITY;
  1332. } else if (status & ST_FRAMING) {
  1333. status = TTY_FRAME;
  1334. } else if(status & ST_OVERRUN) {
  1335. status = TTY_OVERRUN;
  1336. } else {
  1337. status = 0;
  1338. }
  1339. } else {
  1340. status = 0;
  1341. }
  1342. if (tty->flip.char_buf_ptr != (char *) NULL) {
  1343. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  1344. *tty->flip.flag_buf_ptr++ = status;
  1345. *tty->flip.char_buf_ptr++ = ch;
  1346. tty->flip.count++;
  1347. }
  1348. tty_schedule_flip(tty);
  1349. }
  1350. }
  1351. } else {
  1352. printk("STALLION: bad RX interrupt ack value=%xn", ioack);
  1353. return;
  1354. }
  1355. stl_rxalldone:
  1356. outb((EOSRR + portp->uartaddr), ioaddr);
  1357. outb(0, (ioaddr + EREG_DATA));
  1358. }
  1359. /*****************************************************************************/
  1360. /*
  1361.  * Modem interrupt handler. The is called when the modem signal line
  1362.  * (DCD) has changed state. Leave most of the work to the off-level
  1363.  * processing routine.
  1364.  */
  1365. static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
  1366. {
  1367. stlport_t *portp;
  1368. unsigned int ioack;
  1369. unsigned char misr;
  1370. #if DEBUG
  1371. printk("stl_cd1400mdmisr(panelp=%x)n", (int) panelp);
  1372. #endif
  1373. ioack = inb(ioaddr + EREG_MDACK);
  1374. if (((ioack & panelp->ackmask) != 0) ||
  1375.     ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
  1376. printk("STALLION: bad MODEM interrupt ack value=%xn", ioack);
  1377. return;
  1378. }
  1379. portp = panelp->ports[(ioack >> 3)];
  1380. outb((MISR + portp->uartaddr), ioaddr);
  1381. misr = inb(ioaddr + EREG_DATA);
  1382. if (misr & MISR_DCD) {
  1383. set_bit(ASYI_DCDCHANGE, &portp->istate);
  1384. MOD_INC_USE_COUNT;
  1385. if (schedule_task(&portp->tqueue) == 0)
  1386. MOD_DEC_USE_COUNT;
  1387. portp->stats.modem++;
  1388. }
  1389. outb((EOSRR + portp->uartaddr), ioaddr);
  1390. outb(0, (ioaddr + EREG_DATA));
  1391. }
  1392. /*****************************************************************************/
  1393. /*                      SC26198 HARDWARE FUNCTIONS                           */
  1394. /*****************************************************************************/
  1395. /*
  1396.  * These functions get/set/update the registers of the sc26198 UARTs.
  1397.  * Access to the sc26198 registers is via an address/data io port pair.
  1398.  * (Maybe should make this inline...)
  1399.  */
  1400. static int stl_sc26198getreg(stlport_t *portp, int regnr)
  1401. {
  1402. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  1403. return(inb(portp->ioaddr + XP_DATA));
  1404. }
  1405. static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
  1406. {
  1407. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  1408. outb(value, (portp->ioaddr + XP_DATA));
  1409. }
  1410. static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
  1411. {
  1412. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  1413. if (inb(portp->ioaddr + XP_DATA) != value) {
  1414. outb(value, (portp->ioaddr + XP_DATA));
  1415. return(1);
  1416. }
  1417. return(0);
  1418. }
  1419. /*****************************************************************************/
  1420. /*
  1421.  * Functions to get and set the sc26198 global registers.
  1422.  */
  1423. static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
  1424. {
  1425. outb(regnr, (portp->ioaddr + XP_ADDR));
  1426. return(inb(portp->ioaddr + XP_DATA));
  1427. }
  1428. #if 0
  1429. static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
  1430. {
  1431. outb(regnr, (portp->ioaddr + XP_ADDR));
  1432. outb(value, (portp->ioaddr + XP_DATA));
  1433. }
  1434. #endif
  1435. /*****************************************************************************/
  1436. /*
  1437.  * Inbitialize the UARTs in a panel. We don't care what sort of board
  1438.  * these ports are on - since the port io registers are almost
  1439.  * identical when dealing with ports.
  1440.  */
  1441. static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
  1442. {
  1443. int chipmask, i;
  1444. int nrchips, ioaddr;
  1445. #if DEBUG
  1446. printk("stl_sc26198panelinit(brdp=%x,panelp=%x)n",
  1447. (int) brdp, (int) panelp);
  1448. #endif
  1449. BRDENABLE(panelp->brdnr, panelp->pagenr);
  1450. /*
  1451.  * Check that each chip is present and started up OK.
  1452.  */
  1453. chipmask = 0;
  1454. nrchips = (panelp->nrports + 4) / SC26198_PORTS;
  1455. if (brdp->brdtype == BRD_ECHPCI)
  1456. outb(panelp->pagenr, brdp->ioctrl);
  1457. for (i = 0; (i < nrchips); i++) {
  1458. ioaddr = panelp->iobase + (i * 4); 
  1459. outb(SCCR, (ioaddr + XP_ADDR));
  1460. outb(CR_RESETALL, (ioaddr + XP_DATA));
  1461. outb(TSTR, (ioaddr + XP_ADDR));
  1462. if (inb(ioaddr + XP_DATA) != 0) {
  1463. printk("STALLION: sc26198 not responding, "
  1464. "brd=%d panel=%d chip=%dn",
  1465. panelp->brdnr, panelp->panelnr, i);
  1466. continue;
  1467. }
  1468. chipmask |= (0x1 << i);
  1469. outb(GCCR, (ioaddr + XP_ADDR));
  1470. outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
  1471. outb(WDTRCR, (ioaddr + XP_ADDR));
  1472. outb(0xff, (ioaddr + XP_DATA));
  1473. }
  1474. BRDDISABLE(panelp->brdnr);
  1475. return(chipmask);
  1476. }
  1477. /*****************************************************************************/
  1478. /*
  1479.  * Initialize hardware specific port registers.
  1480.  */
  1481. static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
  1482. {
  1483. #if DEBUG
  1484. printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)n",
  1485. (int) brdp, (int) panelp, (int) portp);
  1486. #endif
  1487. if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
  1488.     (portp == (stlport_t *) NULL))
  1489. return;
  1490. portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
  1491. portp->uartaddr = (portp->portnr & 0x07) << 4;
  1492. portp->pagenr = panelp->pagenr;
  1493. portp->hwid = 0x1;
  1494. BRDENABLE(portp->brdnr, portp->pagenr);
  1495. stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
  1496. BRDDISABLE(portp->brdnr);
  1497. }
  1498. /*****************************************************************************/
  1499. /*
  1500.  * Set up the sc26198 registers for a port based on the termios port
  1501.  * settings.
  1502.  */
  1503. static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
  1504. {
  1505. stlbrd_t *brdp;
  1506. unsigned long flags;
  1507. unsigned int baudrate;
  1508. unsigned char mr0, mr1, mr2, clk;
  1509. unsigned char imron, imroff, iopr, ipr;
  1510. mr0 = 0;
  1511. mr1 = 0;
  1512. mr2 = 0;
  1513. clk = 0;
  1514. iopr = 0;
  1515. imron = 0;
  1516. imroff = 0;
  1517. brdp = stl_brds[portp->brdnr];
  1518. if (brdp == (stlbrd_t *) NULL)
  1519. return;
  1520. /*
  1521.  * Set up the RX char ignore mask with those RX error types we
  1522.  * can ignore.
  1523.  */
  1524. portp->rxignoremsk = 0;
  1525. if (tiosp->c_iflag & IGNPAR)
  1526. portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
  1527. SR_RXOVERRUN);
  1528. if (tiosp->c_iflag & IGNBRK)
  1529. portp->rxignoremsk |= SR_RXBREAK;
  1530. portp->rxmarkmsk = SR_RXOVERRUN;
  1531. if (tiosp->c_iflag & (INPCK | PARMRK))
  1532. portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
  1533. if (tiosp->c_iflag & BRKINT)
  1534. portp->rxmarkmsk |= SR_RXBREAK;
  1535. /*
  1536.  * Go through the char size, parity and stop bits and set all the
  1537.  * option register appropriately.
  1538.  */
  1539. switch (tiosp->c_cflag & CSIZE) {
  1540. case CS5:
  1541. mr1 |= MR1_CS5;
  1542. break;
  1543. case CS6:
  1544. mr1 |= MR1_CS6;
  1545. break;
  1546. case CS7:
  1547. mr1 |= MR1_CS7;
  1548. break;
  1549. default:
  1550. mr1 |= MR1_CS8;
  1551. break;
  1552. }
  1553. if (tiosp->c_cflag & CSTOPB)
  1554. mr2 |= MR2_STOP2;
  1555. else
  1556. mr2 |= MR2_STOP1;
  1557. if (tiosp->c_cflag & PARENB) {
  1558. if (tiosp->c_cflag & PARODD)
  1559. mr1 |= (MR1_PARENB | MR1_PARODD);
  1560. else
  1561. mr1 |= (MR1_PARENB | MR1_PAREVEN);
  1562. } else {
  1563. mr1 |= MR1_PARNONE;
  1564. }
  1565. mr1 |= MR1_ERRBLOCK;
  1566. /*
  1567.  * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
  1568.  * space for hardware flow control and the like. This should be set to
  1569.  * VMIN.
  1570.  */
  1571. mr2 |= MR2_RXFIFOHALF;
  1572. /*
  1573.  * Calculate the baud rate timers. For now we will just assume that
  1574.  * the input and output baud are the same. The sc26198 has a fixed
  1575.  * baud rate table, so only discrete baud rates possible.
  1576.  */
  1577. baudrate = tiosp->c_cflag & CBAUD;
  1578. if (baudrate & CBAUDEX) {
  1579. baudrate &= ~CBAUDEX;
  1580. if ((baudrate < 1) || (baudrate > 4))
  1581. tiosp->c_cflag &= ~CBAUDEX;
  1582. else
  1583. baudrate += 15;
  1584. }
  1585. baudrate = stl_baudrates[baudrate];
  1586. if ((tiosp->c_cflag & CBAUD) == B38400) {
  1587. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  1588. baudrate = 57600;
  1589. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  1590. baudrate = 115200;
  1591. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  1592. baudrate = 230400;
  1593. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  1594. baudrate = 460800;
  1595. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  1596. baudrate = (portp->baud_base / portp->custom_divisor);
  1597. }
  1598. if (baudrate > STL_SC26198MAXBAUD)
  1599. baudrate = STL_SC26198MAXBAUD;
  1600. if (baudrate > 0) {
  1601. for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
  1602. if (baudrate <= sc26198_baudtable[clk])
  1603. break;
  1604. }
  1605. }
  1606. /*
  1607.  * Check what form of modem signaling is required and set it up.
  1608.  */
  1609. if (tiosp->c_cflag & CLOCAL) {
  1610. portp->flags &= ~ASYNC_CHECK_CD;
  1611. } else {
  1612. iopr |= IOPR_DCDCOS;
  1613. imron |= IR_IOPORT;
  1614. portp->flags |= ASYNC_CHECK_CD;
  1615. }
  1616. /*
  1617.  * Setup sc26198 enhanced modes if we can. In particular we want to
  1618.  * handle as much of the flow control as possible automatically. As
  1619.  * well as saving a few CPU cycles it will also greatly improve flow
  1620.  * control reliability.
  1621.  */
  1622. if (tiosp->c_iflag & IXON) {
  1623. mr0 |= MR0_SWFTX | MR0_SWFT;
  1624. imron |= IR_XONXOFF;
  1625. } else {
  1626. imroff |= IR_XONXOFF;
  1627. }
  1628. if (tiosp->c_iflag & IXOFF)
  1629. mr0 |= MR0_SWFRX;
  1630. if (tiosp->c_cflag & CRTSCTS) {
  1631. mr2 |= MR2_AUTOCTS;
  1632. mr1 |= MR1_AUTORTS;
  1633. }
  1634. /*
  1635.  * All sc26198 register values calculated so go through and set
  1636.  * them all up.
  1637.  */
  1638. #if DEBUG
  1639. printk("SETPORT: portnr=%d panelnr=%d brdnr=%dn",
  1640. portp->portnr, portp->panelnr, portp->brdnr);
  1641. printk("    mr0=%x mr1=%x mr2=%x clk=%xn", mr0, mr1, mr2, clk);
  1642. printk("    iopr=%x imron=%x imroff=%xn", iopr, imron, imroff);
  1643. printk("    schr1=%x schr2=%x schr3=%x schr4=%xn",
  1644. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  1645. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  1646. #endif
  1647. save_flags(flags);
  1648. cli();
  1649. BRDENABLE(portp->brdnr, portp->pagenr);
  1650. stl_sc26198setreg(portp, IMR, 0);
  1651. stl_sc26198updatereg(portp, MR0, mr0);
  1652. stl_sc26198updatereg(portp, MR1, mr1);
  1653. stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
  1654. stl_sc26198updatereg(portp, MR2, mr2);
  1655. stl_sc26198updatereg(portp, IOPIOR,
  1656. ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
  1657. if (baudrate > 0) {
  1658. stl_sc26198setreg(portp, TXCSR, clk);
  1659. stl_sc26198setreg(portp, RXCSR, clk);
  1660. }
  1661. stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
  1662. stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
  1663. ipr = stl_sc26198getreg(portp, IPR);
  1664. if (ipr & IPR_DCD)
  1665. portp->sigs &= ~TIOCM_CD;
  1666. else
  1667. portp->sigs |= TIOCM_CD;
  1668. portp->imr = (portp->imr & ~imroff) | imron;
  1669. stl_sc26198setreg(portp, IMR, portp->imr);
  1670. BRDDISABLE(portp->brdnr);
  1671. restore_flags(flags);
  1672. }
  1673. /*****************************************************************************/
  1674. /*
  1675.  * Set the state of the DTR and RTS signals.
  1676.  */
  1677. static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
  1678. {
  1679. unsigned char iopioron, iopioroff;
  1680. unsigned long flags;
  1681. #if DEBUG
  1682. printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)n",
  1683. (int) portp, dtr, rts);
  1684. #endif
  1685. iopioron = 0;
  1686. iopioroff = 0;
  1687. if (dtr == 0)
  1688. iopioroff |= IPR_DTR;
  1689. else if (dtr > 0)
  1690. iopioron |= IPR_DTR;
  1691. if (rts == 0)
  1692. iopioroff |= IPR_RTS;
  1693. else if (rts > 0)
  1694. iopioron |= IPR_RTS;
  1695. save_flags(flags);
  1696. cli();
  1697. BRDENABLE(portp->brdnr, portp->pagenr);
  1698. stl_sc26198setreg(portp, IOPIOR,
  1699. ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
  1700. BRDDISABLE(portp->brdnr);
  1701. restore_flags(flags);
  1702. }
  1703. /*****************************************************************************/
  1704. /*
  1705.  * Return the state of the signals.
  1706.  */
  1707. static int stl_sc26198getsignals(stlport_t *portp)
  1708. {
  1709. unsigned char ipr;
  1710. unsigned long flags;
  1711. int sigs;
  1712. #if DEBUG
  1713. printk("stl_sc26198getsignals(portp=%x)n", (int) portp);
  1714. #endif
  1715. save_flags(flags);
  1716. cli();
  1717. BRDENABLE(portp->brdnr, portp->pagenr);
  1718. ipr = stl_sc26198getreg(portp, IPR);
  1719. BRDDISABLE(portp->brdnr);
  1720. restore_flags(flags);
  1721. sigs = 0;
  1722. sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
  1723. sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
  1724. sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
  1725. sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
  1726. sigs |= TIOCM_DSR;
  1727. return(sigs);
  1728. }
  1729. /*****************************************************************************/
  1730. /*
  1731.  * Enable/Disable the Transmitter and/or Receiver.
  1732.  */
  1733. static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
  1734. {
  1735. unsigned char ccr;
  1736. unsigned long flags;
  1737. #if DEBUG
  1738. printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)n",
  1739. (int) portp, rx, tx);
  1740. #endif
  1741. ccr = portp->crenable;
  1742. if (tx == 0)
  1743. ccr &= ~CR_TXENABLE;
  1744. else if (tx > 0)
  1745. ccr |= CR_TXENABLE;
  1746. if (rx == 0)
  1747. ccr &= ~CR_RXENABLE;
  1748. else if (rx > 0)
  1749. ccr |= CR_RXENABLE;
  1750. save_flags(flags);
  1751. cli();
  1752. BRDENABLE(portp->brdnr, portp->pagenr);
  1753. stl_sc26198setreg(portp, SCCR, ccr);
  1754. BRDDISABLE(portp->brdnr);
  1755. portp->crenable = ccr;
  1756. restore_flags(flags);
  1757. }
  1758. /*****************************************************************************/
  1759. /*
  1760.  * Start/stop the Transmitter and/or Receiver.
  1761.  */
  1762. static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
  1763. {
  1764. unsigned char imr;
  1765. unsigned long flags;
  1766. #if DEBUG
  1767. printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)n",
  1768. (int) portp, rx, tx);
  1769. #endif
  1770. imr = portp->imr;
  1771. if (tx == 0)
  1772. imr &= ~IR_TXRDY;
  1773. else if (tx == 1)
  1774. imr |= IR_TXRDY;
  1775. if (rx == 0)
  1776. imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
  1777. else if (rx > 0)
  1778. imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
  1779. save_flags(flags);
  1780. cli();
  1781. BRDENABLE(portp->brdnr, portp->pagenr);
  1782. stl_sc26198setreg(portp, IMR, imr);
  1783. BRDDISABLE(portp->brdnr);
  1784. portp->imr = imr;
  1785. if (tx > 0)
  1786. set_bit(ASYI_TXBUSY, &portp->istate);
  1787. restore_flags(flags);
  1788. }
  1789. /*****************************************************************************/
  1790. /*
  1791.  * Disable all interrupts from this port.
  1792.  */
  1793. static void stl_sc26198disableintrs(stlport_t *portp)
  1794. {
  1795. unsigned long flags;
  1796. #if DEBUG
  1797. printk("stl_sc26198disableintrs(portp=%x)n", (int) portp);
  1798. #endif
  1799. save_flags(flags);
  1800. cli();
  1801. BRDENABLE(portp->brdnr, portp->pagenr);
  1802. portp->imr = 0;
  1803. stl_sc26198setreg(portp, IMR, 0);
  1804. BRDDISABLE(portp->brdnr);
  1805. restore_flags(flags);
  1806. }
  1807. /*****************************************************************************/
  1808. static void stl_sc26198sendbreak(stlport_t *portp, int len)
  1809. {
  1810. unsigned long flags;
  1811. #if DEBUG
  1812. printk("stl_sc26198sendbreak(portp=%x,len=%d)n", (int) portp, len);
  1813. #endif
  1814. save_flags(flags);
  1815. cli();
  1816. BRDENABLE(portp->brdnr, portp->pagenr);
  1817. if (len == 1) {
  1818. stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
  1819. portp->stats.txbreaks++;
  1820. } else {
  1821. stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
  1822. }
  1823. BRDDISABLE(portp->brdnr);
  1824. restore_flags(flags);
  1825. }
  1826. /*****************************************************************************/
  1827. /*
  1828.  * Take flow control actions...
  1829.  */
  1830. static void stl_sc26198flowctrl(stlport_t *portp, int state)
  1831. {
  1832. struct tty_struct *tty;
  1833. unsigned long flags;
  1834. unsigned char mr0;
  1835. #if DEBUG
  1836. printk("stl_sc26198flowctrl(portp=%x,state=%x)n", (int) portp, state);
  1837. #endif
  1838. if (portp == (stlport_t *) NULL)
  1839. return;
  1840. tty = portp->tty;
  1841. if (tty == (struct tty_struct *) NULL)
  1842. return;
  1843. save_flags(flags);
  1844. cli();
  1845. BRDENABLE(portp->brdnr, portp->pagenr);
  1846. if (state) {
  1847. if (tty->termios->c_iflag & IXOFF) {
  1848. mr0 = stl_sc26198getreg(portp, MR0);
  1849. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  1850. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  1851. mr0 |= MR0_SWFRX;
  1852. portp->stats.rxxon++;
  1853. stl_sc26198wait(portp);
  1854. stl_sc26198setreg(portp, MR0, mr0);
  1855. }
  1856. /*
  1857.  * Question: should we return RTS to what it was before? It may
  1858.  * have been set by an ioctl... Suppose not, since if you have
  1859.  * hardware flow control set then it is pretty silly to go and
  1860.  * set the RTS line by hand.
  1861.  */
  1862. if (tty->termios->c_cflag & CRTSCTS) {
  1863. stl_sc26198setreg(portp, MR1,
  1864. (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
  1865. stl_sc26198setreg(portp, IOPIOR,
  1866. (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
  1867. portp->stats.rxrtson++;
  1868. }
  1869. } else {
  1870. if (tty->termios->c_iflag & IXOFF) {
  1871. mr0 = stl_sc26198getreg(portp, MR0);
  1872. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  1873. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  1874. mr0 &= ~MR0_SWFRX;
  1875. portp->stats.rxxoff++;
  1876. stl_sc26198wait(portp);
  1877. stl_sc26198setreg(portp, MR0, mr0);
  1878. }
  1879. if (tty->termios->c_cflag & CRTSCTS) {
  1880. stl_sc26198setreg(portp, MR1,
  1881. (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
  1882. stl_sc26198setreg(portp, IOPIOR,
  1883. (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
  1884. portp->stats.rxrtsoff++;
  1885. }
  1886. }
  1887. BRDDISABLE(portp->brdnr);
  1888. restore_flags(flags);
  1889. }
  1890. /*****************************************************************************/
  1891. /*
  1892.  * Send a flow control character.
  1893.  */
  1894. static void stl_sc26198sendflow(stlport_t *portp, int state)
  1895. {
  1896. struct tty_struct *tty;
  1897. unsigned long flags;
  1898. unsigned char mr0;
  1899. #if DEBUG
  1900. printk("stl_sc26198sendflow(portp=%x,state=%x)n", (int) portp, state);
  1901. #endif
  1902. if (portp == (stlport_t *) NULL)
  1903. return;
  1904. tty = portp->tty;
  1905. if (tty == (struct tty_struct *) NULL)
  1906. return;
  1907. save_flags(flags);
  1908. cli();
  1909. BRDENABLE(portp->brdnr, portp->pagenr);
  1910. if (state) {
  1911. mr0 = stl_sc26198getreg(portp, MR0);
  1912. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  1913. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  1914. mr0 |= MR0_SWFRX;
  1915. portp->stats.rxxon++;
  1916. stl_sc26198wait(portp);
  1917. stl_sc26198setreg(portp, MR0, mr0);
  1918. } else {
  1919. mr0 = stl_sc26198getreg(portp, MR0);
  1920. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  1921. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  1922. mr0 &= ~MR0_SWFRX;
  1923. portp->stats.rxxoff++;
  1924. stl_sc26198wait(portp);
  1925. stl_sc26198setreg(portp, MR0, mr0);
  1926. }
  1927. BRDDISABLE(portp->brdnr);
  1928. restore_flags(flags);
  1929. }
  1930. /*****************************************************************************/
  1931. static void stl_sc26198flush(stlport_t *portp)
  1932. {
  1933. unsigned long flags;
  1934. #if DEBUG
  1935. printk("stl_sc26198flush(portp=%x)n", (int) portp);
  1936. #endif
  1937. if (portp == (stlport_t *) NULL)
  1938. return;
  1939. save_flags(flags);
  1940. cli();
  1941. BRDENABLE(portp->brdnr, portp->pagenr);
  1942. stl_sc26198setreg(portp, SCCR, CR_TXRESET);
  1943. stl_sc26198setreg(portp, SCCR, portp->crenable);
  1944. BRDDISABLE(portp->brdnr);
  1945. portp->tx.tail = portp->tx.head;
  1946. restore_flags(flags);
  1947. }
  1948. /*****************************************************************************/
  1949. /*
  1950.  * Return the current state of data flow on this port. This is only
  1951.  * really interresting when determining if data has fully completed
  1952.  * transmission or not... The sc26198 interrupt scheme cannot
  1953.  * determine when all data has actually drained, so we need to
  1954.  * check the port statusy register to be sure.
  1955.  */
  1956. static int stl_sc26198datastate(stlport_t *portp)
  1957. {
  1958. unsigned long flags;
  1959. unsigned char sr;
  1960. #if DEBUG
  1961. printk("stl_sc26198datastate(portp=%x)n", (int) portp);
  1962. #endif
  1963. if (portp == (stlport_t *) NULL)
  1964. return(0);
  1965. if (test_bit(ASYI_TXBUSY, &portp->istate))
  1966. return(1);
  1967. save_flags(flags);
  1968. cli();
  1969. BRDENABLE(portp->brdnr, portp->pagenr);
  1970. sr = stl_sc26198getreg(portp, SR);
  1971. BRDDISABLE(portp->brdnr);
  1972. restore_flags(flags);
  1973. return((sr & SR_TXEMPTY) ? 0 : 1);
  1974. }
  1975. /*****************************************************************************/
  1976. /*
  1977.  * Delay for a small amount of time, to give the sc26198 a chance
  1978.  * to process a command...
  1979.  */
  1980. static void stl_sc26198wait(stlport_t *portp)
  1981. {
  1982. int i;
  1983. #if DEBUG
  1984. printk("stl_sc26198wait(portp=%x)n", (int) portp);
  1985. #endif
  1986. if (portp == (stlport_t *) NULL)
  1987. return;
  1988. for (i = 0; (i < 20); i++)
  1989. stl_sc26198getglobreg(portp, TSTR);
  1990. }
  1991. /*****************************************************************************/
  1992. /*
  1993.  * If we are TX flow controlled and in IXANY mode then we may
  1994.  * need to unflow control here. We gotta do this because of the
  1995.  * automatic flow control modes of the sc26198.
  1996.  */
  1997. static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
  1998. {
  1999. unsigned char mr0;
  2000. mr0 = stl_sc26198getreg(portp, MR0);
  2001. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  2002. stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
  2003. stl_sc26198wait(portp);
  2004. stl_sc26198setreg(portp, MR0, mr0);
  2005. clear_bit(ASYI_TXFLOWED, &portp->istate);
  2006. }
  2007. /*****************************************************************************/
  2008. /*
  2009.  * Interrupt service routine for sc26198 panels.
  2010.  */
  2011. static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
  2012. {
  2013. stlport_t *portp;
  2014. unsigned int iack;
  2015. /* 
  2016.  * Work around bug in sc26198 chip... Cannot have A6 address
  2017.  * line of UART high, else iack will be returned as 0.
  2018.  */
  2019. outb(0, (iobase + 1));
  2020. iack = inb(iobase + XP_IACK);
  2021. portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
  2022. if (iack & IVR_RXDATA)
  2023. stl_sc26198rxisr(portp, iack);
  2024. else if (iack & IVR_TXDATA)
  2025. stl_sc26198txisr(portp);
  2026. else
  2027. stl_sc26198otherisr(portp, iack);
  2028. }
  2029. /*****************************************************************************/
  2030. /*
  2031.  * Transmit interrupt handler. This has gotta be fast!  Handling TX
  2032.  * chars is pretty simple, stuff as many as possible from the TX buffer
  2033.  * into the sc26198 FIFO.
  2034.  * In practice it is possible that interrupts are enabled but that the
  2035.  * port has been hung up. Need to handle not having any TX buffer here,
  2036.  * this is done by using the side effect that head and tail will also
  2037.  * be NULL if the buffer has been freed.
  2038.  */
  2039. static void stl_sc26198txisr(stlport_t *portp)
  2040. {
  2041. unsigned int ioaddr;
  2042. unsigned char mr0;
  2043. int len, stlen;
  2044. char *head, *tail;
  2045. #if DEBUG
  2046. printk("stl_sc26198txisr(portp=%x)n", (int) portp);
  2047. #endif
  2048. ioaddr = portp->ioaddr;
  2049. head = portp->tx.head;
  2050. tail = portp->tx.tail;
  2051. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  2052. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  2053.     (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  2054. set_bit(ASYI_TXLOW, &portp->istate);
  2055. MOD_INC_USE_COUNT;
  2056. if (schedule_task(&portp->tqueue) == 0)
  2057. MOD_DEC_USE_COUNT;
  2058. }
  2059. if (len == 0) {
  2060. outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
  2061. mr0 = inb(ioaddr + XP_DATA);
  2062. if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
  2063. portp->imr &= ~IR_TXRDY;
  2064. outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
  2065. outb(portp->imr, (ioaddr + XP_DATA));
  2066. clear_bit(ASYI_TXBUSY, &portp->istate);
  2067. } else {
  2068. mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
  2069. outb(mr0, (ioaddr + XP_DATA));
  2070. }
  2071. } else {
  2072. len = MIN(len, SC26198_TXFIFOSIZE);
  2073. portp->stats.txtotal += len;
  2074. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  2075. outb(GTXFIFO, (ioaddr + XP_ADDR));
  2076. outsb((ioaddr + XP_DATA), tail, stlen);
  2077. len -= stlen;
  2078. tail += stlen;
  2079. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  2080. tail = portp->tx.buf;
  2081. if (len > 0) {
  2082. outsb((ioaddr + XP_DATA), tail, len);
  2083. tail += len;
  2084. }
  2085. portp->tx.tail = tail;
  2086. }
  2087. }
  2088. /*****************************************************************************/
  2089. /*
  2090.  * Receive character interrupt handler. Determine if we have good chars
  2091.  * or bad chars and then process appropriately. Good chars are easy
  2092.  * just shove the lot into the RX buffer and set all status byte to 0.
  2093.  * If a bad RX char then process as required. This routine needs to be
  2094.  * fast!  In practice it is possible that we get an interrupt on a port
  2095.  * that is closed. This can happen on hangups - since they completely
  2096.  * shutdown a port not in user context. Need to handle this case.
  2097.  */
  2098. static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
  2099. {
  2100. struct tty_struct *tty;
  2101. unsigned int len, buflen, ioaddr;
  2102. #if DEBUG
  2103. printk("stl_sc26198rxisr(portp=%x,iack=%x)n", (int) portp, iack);
  2104. #endif
  2105. tty = portp->tty;
  2106. ioaddr = portp->ioaddr;
  2107. outb(GIBCR, (ioaddr + XP_ADDR));
  2108. len = inb(ioaddr + XP_DATA) + 1;
  2109. if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
  2110. if ((tty == (struct tty_struct *) NULL) ||
  2111.     (tty->flip.char_buf_ptr == (char *) NULL) ||
  2112.     ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
  2113. len = MIN(len, sizeof(stl_unwanted));
  2114. outb(GRXFIFO, (ioaddr + XP_ADDR));
  2115. insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
  2116. portp->stats.rxlost += len;
  2117. portp->stats.rxtotal += len;
  2118. } else {
  2119. len = MIN(len, buflen);
  2120. if (len > 0) {
  2121. outb(GRXFIFO, (ioaddr + XP_ADDR));
  2122. insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
  2123. memset(tty->flip.flag_buf_ptr, 0, len);
  2124. tty->flip.flag_buf_ptr += len;
  2125. tty->flip.char_buf_ptr += len;
  2126. tty->flip.count += len;
  2127. tty_schedule_flip(tty);
  2128. portp->stats.rxtotal += len;
  2129. }
  2130. }
  2131. } else {
  2132. stl_sc26198rxbadchars(portp);
  2133. }
  2134. /*
  2135.  * If we are TX flow controlled and in IXANY mode then we may need
  2136.  * to unflow control here. We gotta do this because of the automatic
  2137.  * flow control modes of the sc26198.
  2138.  */
  2139. if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
  2140. if ((tty != (struct tty_struct *) NULL) &&
  2141.     (tty->termios != (struct termios *) NULL) &&
  2142.     (tty->termios->c_iflag & IXANY)) {
  2143. stl_sc26198txunflow(portp, tty);
  2144. }
  2145. }
  2146. }
  2147. /*****************************************************************************/
  2148. /*
  2149.  * Process an RX bad character.
  2150.  */
  2151. static void inline stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
  2152. {
  2153. struct tty_struct *tty;
  2154. unsigned int ioaddr;
  2155. tty = portp->tty;
  2156. ioaddr = portp->ioaddr;
  2157. if (status & SR_RXPARITY)
  2158. portp->stats.rxparity++;
  2159. if (status & SR_RXFRAMING)
  2160. portp->stats.rxframing++;
  2161. if (status & SR_RXOVERRUN)
  2162. portp->stats.rxoverrun++;
  2163. if (status & SR_RXBREAK)
  2164. portp->stats.rxbreaks++;
  2165. if ((tty != (struct tty_struct *) NULL) &&
  2166.     ((portp->rxignoremsk & status) == 0)) {
  2167. if (portp->rxmarkmsk & status) {
  2168. if (status & SR_RXBREAK) {
  2169. status = TTY_BREAK;
  2170. if (portp->flags & ASYNC_SAK) {
  2171. do_SAK(tty);
  2172. BRDENABLE(portp->brdnr, portp->pagenr);
  2173. }
  2174. } else if (status & SR_RXPARITY) {
  2175. status = TTY_PARITY;
  2176. } else if (status & SR_RXFRAMING) {
  2177. status = TTY_FRAME;
  2178. } else if(status & SR_RXOVERRUN) {
  2179. status = TTY_OVERRUN;
  2180. } else {
  2181. status = 0;
  2182. }
  2183. } else {
  2184. status = 0;
  2185. }
  2186. if (tty->flip.char_buf_ptr != (char *) NULL) {
  2187. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  2188. *tty->flip.flag_buf_ptr++ = status;
  2189. *tty->flip.char_buf_ptr++ = ch;
  2190. tty->flip.count++;
  2191. }
  2192. tty_schedule_flip(tty);
  2193. }
  2194. if (status == 0)
  2195. portp->stats.rxtotal++;
  2196. }
  2197. }
  2198. /*****************************************************************************/
  2199. /*
  2200.  * Process all characters in the RX FIFO of the UART. Check all char
  2201.  * status bytes as well, and process as required. We need to check
  2202.  * all bytes in the FIFO, in case some more enter the FIFO while we
  2203.  * are here. To get the exact character error type we need to switch
  2204.  * into CHAR error mode (that is why we need to make sure we empty
  2205.  * the FIFO).
  2206.  */
  2207. static void stl_sc26198rxbadchars(stlport_t *portp)
  2208. {
  2209. unsigned char status, mr1;
  2210. char ch;
  2211. /*
  2212.  * To get the precise error type for each character we must switch
  2213.  * back into CHAR error mode.
  2214.  */
  2215. mr1 = stl_sc26198getreg(portp, MR1);
  2216. stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
  2217. while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
  2218. stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
  2219. ch = stl_sc26198getreg(portp, RXFIFO);
  2220. stl_sc26198rxbadch(portp, status, ch);
  2221. }
  2222. /*
  2223.  * To get correct interrupt class we must switch back into BLOCK
  2224.  * error mode.
  2225.  */
  2226. stl_sc26198setreg(portp, MR1, mr1);
  2227. }
  2228. /*****************************************************************************/
  2229. /*
  2230.  * Other interrupt handler. This includes modem signals, flow
  2231.  * control actions, etc. Most stuff is left to off-level interrupt
  2232.  * processing time.
  2233.  */
  2234. static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
  2235. {
  2236. unsigned char cir, ipr, xisr;
  2237. #if DEBUG
  2238. printk("stl_sc26198otherisr(portp=%x,iack=%x)n", (int) portp, iack);
  2239. #endif
  2240. cir = stl_sc26198getglobreg(portp, CIR);
  2241. switch (cir & CIR_SUBTYPEMASK) {
  2242. case CIR_SUBCOS:
  2243. ipr = stl_sc26198getreg(portp, IPR);
  2244. if (ipr & IPR_DCDCHANGE) {
  2245. set_bit(ASYI_DCDCHANGE, &portp->istate);
  2246. MOD_INC_USE_COUNT;
  2247. if (schedule_task(&portp->tqueue) == 0)
  2248. MOD_DEC_USE_COUNT;
  2249. portp->stats.modem++;
  2250. }
  2251. break;
  2252. case CIR_SUBXONXOFF:
  2253. xisr = stl_sc26198getreg(portp, XISR);
  2254. if (xisr & XISR_RXXONGOT) {
  2255. set_bit(ASYI_TXFLOWED, &portp->istate);
  2256. portp->stats.txxoff++;
  2257. }
  2258. if (xisr & XISR_RXXOFFGOT) {
  2259. clear_bit(ASYI_TXFLOWED, &portp->istate);
  2260. portp->stats.txxon++;
  2261. }
  2262. break;
  2263. case CIR_SUBBREAK:
  2264. stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
  2265. stl_sc26198rxbadchars(portp);
  2266. break;
  2267. default:
  2268. break;
  2269. }
  2270. }
  2271. /*****************************************************************************/