PageRenderTime 71ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/char/stallion.c

https://bitbucket.org/evzijst/gittest
C | 5197 lines | 3602 code | 765 blank | 830 comment | 795 complexity | 61f0d2e5e8c11ce6db5bedb3fbc920ec MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  1. /*****************************************************************************/
  2. /*
  3. * stallion.c -- stallion multiport serial driver.
  4. *
  5. * Copyright (C) 1996-1999 Stallion Technologies
  6. * Copyright (C) 1994-1996 Greg Ungerer.
  7. *
  8. * This code is loosely based on the Linux serial driver, written by
  9. * Linus Torvalds, Theodore T'so and others.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*****************************************************************************/
  26. #include <linux/config.h>
  27. #include <linux/module.h>
  28. #include <linux/slab.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/tty.h>
  31. #include <linux/tty_flip.h>
  32. #include <linux/serial.h>
  33. #include <linux/cd1400.h>
  34. #include <linux/sc26198.h>
  35. #include <linux/comstats.h>
  36. #include <linux/stallion.h>
  37. #include <linux/ioport.h>
  38. #include <linux/init.h>
  39. #include <linux/smp_lock.h>
  40. #include <linux/devfs_fs_kernel.h>
  41. #include <linux/device.h>
  42. #include <linux/delay.h>
  43. #include <asm/io.h>
  44. #include <asm/uaccess.h>
  45. #ifdef CONFIG_PCI
  46. #include <linux/pci.h>
  47. #endif
  48. /*****************************************************************************/
  49. /*
  50. * Define different board types. Use the standard Stallion "assigned"
  51. * board numbers. Boards supported in this driver are abbreviated as
  52. * EIO = EasyIO and ECH = EasyConnection 8/32.
  53. */
  54. #define BRD_EASYIO 20
  55. #define BRD_ECH 21
  56. #define BRD_ECHMC 22
  57. #define BRD_ECHPCI 26
  58. #define BRD_ECH64PCI 27
  59. #define BRD_EASYIOPCI 28
  60. /*
  61. * Define a configuration structure to hold the board configuration.
  62. * Need to set this up in the code (for now) with the boards that are
  63. * to be configured into the system. This is what needs to be modified
  64. * when adding/removing/modifying boards. Each line entry in the
  65. * stl_brdconf[] array is a board. Each line contains io/irq/memory
  66. * ranges for that board (as well as what type of board it is).
  67. * Some examples:
  68. * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
  69. * This line would configure an EasyIO board (4 or 8, no difference),
  70. * at io address 2a0 and irq 10.
  71. * Another example:
  72. * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
  73. * This line will configure an EasyConnection 8/32 board at primary io
  74. * address 2a8, secondary io address 280 and irq 12.
  75. * Enter as many lines into this array as you want (only the first 4
  76. * will actually be used!). Any combination of EasyIO and EasyConnection
  77. * boards can be specified. EasyConnection 8/32 boards can share their
  78. * secondary io addresses between each other.
  79. *
  80. * NOTE: there is no need to put any entries in this table for PCI
  81. * boards. They will be found automatically by the driver - provided
  82. * PCI BIOS32 support is compiled into the kernel.
  83. */
  84. typedef struct {
  85. int brdtype;
  86. int ioaddr1;
  87. int ioaddr2;
  88. unsigned long memaddr;
  89. int irq;
  90. int irqtype;
  91. } stlconf_t;
  92. static stlconf_t stl_brdconf[] = {
  93. /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
  94. };
  95. static int stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
  96. /*****************************************************************************/
  97. /*
  98. * Define some important driver characteristics. Device major numbers
  99. * allocated as per Linux Device Registry.
  100. */
  101. #ifndef STL_SIOMEMMAJOR
  102. #define STL_SIOMEMMAJOR 28
  103. #endif
  104. #ifndef STL_SERIALMAJOR
  105. #define STL_SERIALMAJOR 24
  106. #endif
  107. #ifndef STL_CALLOUTMAJOR
  108. #define STL_CALLOUTMAJOR 25
  109. #endif
  110. /*
  111. * Set the TX buffer size. Bigger is better, but we don't want
  112. * to chew too much memory with buffers!
  113. */
  114. #define STL_TXBUFLOW 512
  115. #define STL_TXBUFSIZE 4096
  116. /*****************************************************************************/
  117. /*
  118. * Define our local driver identity first. Set up stuff to deal with
  119. * all the local structures required by a serial tty driver.
  120. */
  121. static char *stl_drvtitle = "Stallion Multiport Serial Driver";
  122. static char *stl_drvname = "stallion";
  123. static char *stl_drvversion = "5.6.0";
  124. static struct tty_driver *stl_serial;
  125. /*
  126. * We will need to allocate a temporary write buffer for chars that
  127. * come direct from user space. The problem is that a copy from user
  128. * space might cause a page fault (typically on a system that is
  129. * swapping!). All ports will share one buffer - since if the system
  130. * is already swapping a shared buffer won't make things any worse.
  131. */
  132. static char *stl_tmpwritebuf;
  133. static DECLARE_MUTEX(stl_tmpwritesem);
  134. /*
  135. * Define a local default termios struct. All ports will be created
  136. * with this termios initially. Basically all it defines is a raw port
  137. * at 9600, 8 data bits, 1 stop bit.
  138. */
  139. static struct termios stl_deftermios = {
  140. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  141. .c_cc = INIT_C_CC,
  142. };
  143. /*
  144. * Define global stats structures. Not used often, and can be
  145. * re-used for each stats call.
  146. */
  147. static comstats_t stl_comstats;
  148. static combrd_t stl_brdstats;
  149. static stlbrd_t stl_dummybrd;
  150. static stlport_t stl_dummyport;
  151. /*
  152. * Define global place to put buffer overflow characters.
  153. */
  154. static char stl_unwanted[SC26198_RXFIFOSIZE];
  155. /*****************************************************************************/
  156. static stlbrd_t *stl_brds[STL_MAXBRDS];
  157. /*
  158. * Per board state flags. Used with the state field of the board struct.
  159. * Not really much here!
  160. */
  161. #define BRD_FOUND 0x1
  162. /*
  163. * Define the port structure istate flags. These set of flags are
  164. * modified at interrupt time - so setting and reseting them needs
  165. * to be atomic. Use the bit clear/setting routines for this.
  166. */
  167. #define ASYI_TXBUSY 1
  168. #define ASYI_TXLOW 2
  169. #define ASYI_DCDCHANGE 3
  170. #define ASYI_TXFLOWED 4
  171. /*
  172. * Define an array of board names as printable strings. Handy for
  173. * referencing boards when printing trace and stuff.
  174. */
  175. static char *stl_brdnames[] = {
  176. (char *) NULL,
  177. (char *) NULL,
  178. (char *) NULL,
  179. (char *) NULL,
  180. (char *) NULL,
  181. (char *) NULL,
  182. (char *) NULL,
  183. (char *) NULL,
  184. (char *) NULL,
  185. (char *) NULL,
  186. (char *) NULL,
  187. (char *) NULL,
  188. (char *) NULL,
  189. (char *) NULL,
  190. (char *) NULL,
  191. (char *) NULL,
  192. (char *) NULL,
  193. (char *) NULL,
  194. (char *) NULL,
  195. (char *) NULL,
  196. "EasyIO",
  197. "EC8/32-AT",
  198. "EC8/32-MC",
  199. (char *) NULL,
  200. (char *) NULL,
  201. (char *) NULL,
  202. "EC8/32-PCI",
  203. "EC8/64-PCI",
  204. "EasyIO-PCI",
  205. };
  206. /*****************************************************************************/
  207. /*
  208. * Define some string labels for arguments passed from the module
  209. * load line. These allow for easy board definitions, and easy
  210. * modification of the io, memory and irq resoucres.
  211. */
  212. static int stl_nargs = 0;
  213. static char *board0[4];
  214. static char *board1[4];
  215. static char *board2[4];
  216. static char *board3[4];
  217. static char **stl_brdsp[] = {
  218. (char **) &board0,
  219. (char **) &board1,
  220. (char **) &board2,
  221. (char **) &board3
  222. };
  223. /*
  224. * Define a set of common board names, and types. This is used to
  225. * parse any module arguments.
  226. */
  227. typedef struct stlbrdtype {
  228. char *name;
  229. int type;
  230. } stlbrdtype_t;
  231. static stlbrdtype_t stl_brdstr[] = {
  232. { "easyio", BRD_EASYIO },
  233. { "eio", BRD_EASYIO },
  234. { "20", BRD_EASYIO },
  235. { "ec8/32", BRD_ECH },
  236. { "ec8/32-at", BRD_ECH },
  237. { "ec8/32-isa", BRD_ECH },
  238. { "ech", BRD_ECH },
  239. { "echat", BRD_ECH },
  240. { "21", BRD_ECH },
  241. { "ec8/32-mc", BRD_ECHMC },
  242. { "ec8/32-mca", BRD_ECHMC },
  243. { "echmc", BRD_ECHMC },
  244. { "echmca", BRD_ECHMC },
  245. { "22", BRD_ECHMC },
  246. { "ec8/32-pc", BRD_ECHPCI },
  247. { "ec8/32-pci", BRD_ECHPCI },
  248. { "26", BRD_ECHPCI },
  249. { "ec8/64-pc", BRD_ECH64PCI },
  250. { "ec8/64-pci", BRD_ECH64PCI },
  251. { "ech-pci", BRD_ECH64PCI },
  252. { "echpci", BRD_ECH64PCI },
  253. { "echpc", BRD_ECH64PCI },
  254. { "27", BRD_ECH64PCI },
  255. { "easyio-pc", BRD_EASYIOPCI },
  256. { "easyio-pci", BRD_EASYIOPCI },
  257. { "eio-pci", BRD_EASYIOPCI },
  258. { "eiopci", BRD_EASYIOPCI },
  259. { "28", BRD_EASYIOPCI },
  260. };
  261. /*
  262. * Define the module agruments.
  263. */
  264. MODULE_AUTHOR("Greg Ungerer");
  265. MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
  266. MODULE_LICENSE("GPL");
  267. module_param_array(board0, charp, &stl_nargs, 0);
  268. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
  269. module_param_array(board1, charp, &stl_nargs, 0);
  270. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
  271. module_param_array(board2, charp, &stl_nargs, 0);
  272. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
  273. module_param_array(board3, charp, &stl_nargs, 0);
  274. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
  275. /*****************************************************************************/
  276. /*
  277. * Hardware ID bits for the EasyIO and ECH boards. These defines apply
  278. * to the directly accessible io ports of these boards (not the uarts -
  279. * they are in cd1400.h and sc26198.h).
  280. */
  281. #define EIO_8PORTRS 0x04
  282. #define EIO_4PORTRS 0x05
  283. #define EIO_8PORTDI 0x00
  284. #define EIO_8PORTM 0x06
  285. #define EIO_MK3 0x03
  286. #define EIO_IDBITMASK 0x07
  287. #define EIO_BRDMASK 0xf0
  288. #define ID_BRD4 0x10
  289. #define ID_BRD8 0x20
  290. #define ID_BRD16 0x30
  291. #define EIO_INTRPEND 0x08
  292. #define EIO_INTEDGE 0x00
  293. #define EIO_INTLEVEL 0x08
  294. #define EIO_0WS 0x10
  295. #define ECH_ID 0xa0
  296. #define ECH_IDBITMASK 0xe0
  297. #define ECH_BRDENABLE 0x08
  298. #define ECH_BRDDISABLE 0x00
  299. #define ECH_INTENABLE 0x01
  300. #define ECH_INTDISABLE 0x00
  301. #define ECH_INTLEVEL 0x02
  302. #define ECH_INTEDGE 0x00
  303. #define ECH_INTRPEND 0x01
  304. #define ECH_BRDRESET 0x01
  305. #define ECHMC_INTENABLE 0x01
  306. #define ECHMC_BRDRESET 0x02
  307. #define ECH_PNLSTATUS 2
  308. #define ECH_PNL16PORT 0x20
  309. #define ECH_PNLIDMASK 0x07
  310. #define ECH_PNLXPID 0x40
  311. #define ECH_PNLINTRPEND 0x80
  312. #define ECH_ADDR2MASK 0x1e0
  313. /*
  314. * Define the vector mapping bits for the programmable interrupt board
  315. * hardware. These bits encode the interrupt for the board to use - it
  316. * is software selectable (except the EIO-8M).
  317. */
  318. static unsigned char stl_vecmap[] = {
  319. 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
  320. 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
  321. };
  322. /*
  323. * Set up enable and disable macros for the ECH boards. They require
  324. * the secondary io address space to be activated and deactivated.
  325. * This way all ECH boards can share their secondary io region.
  326. * If this is an ECH-PCI board then also need to set the page pointer
  327. * to point to the correct page.
  328. */
  329. #define BRDENABLE(brdnr,pagenr) \
  330. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  331. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
  332. stl_brds[(brdnr)]->ioctrl); \
  333. else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
  334. outb((pagenr), stl_brds[(brdnr)]->ioctrl);
  335. #define BRDDISABLE(brdnr) \
  336. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  337. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
  338. stl_brds[(brdnr)]->ioctrl);
  339. #define STL_CD1400MAXBAUD 230400
  340. #define STL_SC26198MAXBAUD 460800
  341. #define STL_BAUDBASE 115200
  342. #define STL_CLOSEDELAY (5 * HZ / 10)
  343. /*****************************************************************************/
  344. #ifdef CONFIG_PCI
  345. /*
  346. * Define the Stallion PCI vendor and device IDs.
  347. */
  348. #ifndef PCI_VENDOR_ID_STALLION
  349. #define PCI_VENDOR_ID_STALLION 0x124d
  350. #endif
  351. #ifndef PCI_DEVICE_ID_ECHPCI832
  352. #define PCI_DEVICE_ID_ECHPCI832 0x0000
  353. #endif
  354. #ifndef PCI_DEVICE_ID_ECHPCI864
  355. #define PCI_DEVICE_ID_ECHPCI864 0x0002
  356. #endif
  357. #ifndef PCI_DEVICE_ID_EIOPCI
  358. #define PCI_DEVICE_ID_EIOPCI 0x0003
  359. #endif
  360. /*
  361. * Define structure to hold all Stallion PCI boards.
  362. */
  363. typedef struct stlpcibrd {
  364. unsigned short vendid;
  365. unsigned short devid;
  366. int brdtype;
  367. } stlpcibrd_t;
  368. static stlpcibrd_t stl_pcibrds[] = {
  369. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
  370. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
  371. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
  372. { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
  373. };
  374. static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
  375. #endif
  376. /*****************************************************************************/
  377. /*
  378. * Define macros to extract a brd/port number from a minor number.
  379. */
  380. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  381. #define MINOR2PORT(min) ((min) & 0x3f)
  382. /*
  383. * Define a baud rate table that converts termios baud rate selector
  384. * into the actual baud rate value. All baud rate calculations are
  385. * based on the actual baud rate required.
  386. */
  387. static unsigned int stl_baudrates[] = {
  388. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  389. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
  390. };
  391. /*
  392. * Define some handy local macros...
  393. */
  394. #undef MIN
  395. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  396. #undef TOLOWER
  397. #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
  398. /*****************************************************************************/
  399. /*
  400. * Declare all those functions in this driver!
  401. */
  402. static void stl_argbrds(void);
  403. static int stl_parsebrd(stlconf_t *confp, char **argp);
  404. static unsigned long stl_atol(char *str);
  405. int stl_init(void);
  406. static int stl_open(struct tty_struct *tty, struct file *filp);
  407. static void stl_close(struct tty_struct *tty, struct file *filp);
  408. static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
  409. static void stl_putchar(struct tty_struct *tty, unsigned char ch);
  410. static void stl_flushchars(struct tty_struct *tty);
  411. static int stl_writeroom(struct tty_struct *tty);
  412. static int stl_charsinbuffer(struct tty_struct *tty);
  413. static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  414. static void stl_settermios(struct tty_struct *tty, struct termios *old);
  415. static void stl_throttle(struct tty_struct *tty);
  416. static void stl_unthrottle(struct tty_struct *tty);
  417. static void stl_stop(struct tty_struct *tty);
  418. static void stl_start(struct tty_struct *tty);
  419. static void stl_flushbuffer(struct tty_struct *tty);
  420. static void stl_breakctl(struct tty_struct *tty, int state);
  421. static void stl_waituntilsent(struct tty_struct *tty, int timeout);
  422. static void stl_sendxchar(struct tty_struct *tty, char ch);
  423. static void stl_hangup(struct tty_struct *tty);
  424. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
  425. static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
  426. static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
  427. static int stl_brdinit(stlbrd_t *brdp);
  428. static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
  429. static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
  430. static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
  431. static int stl_getbrdstats(combrd_t __user *bp);
  432. static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
  433. static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
  434. static int stl_getportstruct(stlport_t __user *arg);
  435. static int stl_getbrdstruct(stlbrd_t __user *arg);
  436. static int stl_waitcarrier(stlport_t *portp, struct file *filp);
  437. static int stl_eiointr(stlbrd_t *brdp);
  438. static int stl_echatintr(stlbrd_t *brdp);
  439. static int stl_echmcaintr(stlbrd_t *brdp);
  440. static int stl_echpciintr(stlbrd_t *brdp);
  441. static int stl_echpci64intr(stlbrd_t *brdp);
  442. static void stl_offintr(void *private);
  443. static void *stl_memalloc(int len);
  444. static stlbrd_t *stl_allocbrd(void);
  445. static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
  446. static inline int stl_initbrds(void);
  447. static inline int stl_initeio(stlbrd_t *brdp);
  448. static inline int stl_initech(stlbrd_t *brdp);
  449. static inline int stl_getbrdnr(void);
  450. #ifdef CONFIG_PCI
  451. static inline int stl_findpcibrds(void);
  452. static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
  453. #endif
  454. /*
  455. * CD1400 uart specific handling functions.
  456. */
  457. static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
  458. static int stl_cd1400getreg(stlport_t *portp, int regnr);
  459. static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
  460. static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
  461. static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  462. static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
  463. static int stl_cd1400getsignals(stlport_t *portp);
  464. static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
  465. static void stl_cd1400ccrwait(stlport_t *portp);
  466. static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
  467. static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
  468. static void stl_cd1400disableintrs(stlport_t *portp);
  469. static void stl_cd1400sendbreak(stlport_t *portp, int len);
  470. static void stl_cd1400flowctrl(stlport_t *portp, int state);
  471. static void stl_cd1400sendflow(stlport_t *portp, int state);
  472. static void stl_cd1400flush(stlport_t *portp);
  473. static int stl_cd1400datastate(stlport_t *portp);
  474. static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
  475. static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
  476. static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
  477. static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
  478. static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
  479. static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
  480. /*
  481. * SC26198 uart specific handling functions.
  482. */
  483. static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
  484. static int stl_sc26198getreg(stlport_t *portp, int regnr);
  485. static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
  486. static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
  487. static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
  488. static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  489. static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
  490. static int stl_sc26198getsignals(stlport_t *portp);
  491. static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
  492. static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
  493. static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
  494. static void stl_sc26198disableintrs(stlport_t *portp);
  495. static void stl_sc26198sendbreak(stlport_t *portp, int len);
  496. static void stl_sc26198flowctrl(stlport_t *portp, int state);
  497. static void stl_sc26198sendflow(stlport_t *portp, int state);
  498. static void stl_sc26198flush(stlport_t *portp);
  499. static int stl_sc26198datastate(stlport_t *portp);
  500. static void stl_sc26198wait(stlport_t *portp);
  501. static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
  502. static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
  503. static void stl_sc26198txisr(stlport_t *port);
  504. static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
  505. static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
  506. static void stl_sc26198rxbadchars(stlport_t *portp);
  507. static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
  508. /*****************************************************************************/
  509. /*
  510. * Generic UART support structure.
  511. */
  512. typedef struct uart {
  513. int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
  514. void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  515. void (*setport)(stlport_t *portp, struct termios *tiosp);
  516. int (*getsignals)(stlport_t *portp);
  517. void (*setsignals)(stlport_t *portp, int dtr, int rts);
  518. void (*enablerxtx)(stlport_t *portp, int rx, int tx);
  519. void (*startrxtx)(stlport_t *portp, int rx, int tx);
  520. void (*disableintrs)(stlport_t *portp);
  521. void (*sendbreak)(stlport_t *portp, int len);
  522. void (*flowctrl)(stlport_t *portp, int state);
  523. void (*sendflow)(stlport_t *portp, int state);
  524. void (*flush)(stlport_t *portp);
  525. int (*datastate)(stlport_t *portp);
  526. void (*intr)(stlpanel_t *panelp, unsigned int iobase);
  527. } uart_t;
  528. /*
  529. * Define some macros to make calling these functions nice and clean.
  530. */
  531. #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
  532. #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
  533. #define stl_setport (* ((uart_t *) portp->uartp)->setport)
  534. #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
  535. #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
  536. #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
  537. #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
  538. #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
  539. #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
  540. #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
  541. #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
  542. #define stl_flush (* ((uart_t *) portp->uartp)->flush)
  543. #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
  544. /*****************************************************************************/
  545. /*
  546. * CD1400 UART specific data initialization.
  547. */
  548. static uart_t stl_cd1400uart = {
  549. stl_cd1400panelinit,
  550. stl_cd1400portinit,
  551. stl_cd1400setport,
  552. stl_cd1400getsignals,
  553. stl_cd1400setsignals,
  554. stl_cd1400enablerxtx,
  555. stl_cd1400startrxtx,
  556. stl_cd1400disableintrs,
  557. stl_cd1400sendbreak,
  558. stl_cd1400flowctrl,
  559. stl_cd1400sendflow,
  560. stl_cd1400flush,
  561. stl_cd1400datastate,
  562. stl_cd1400eiointr
  563. };
  564. /*
  565. * Define the offsets within the register bank of a cd1400 based panel.
  566. * These io address offsets are common to the EasyIO board as well.
  567. */
  568. #define EREG_ADDR 0
  569. #define EREG_DATA 4
  570. #define EREG_RXACK 5
  571. #define EREG_TXACK 6
  572. #define EREG_MDACK 7
  573. #define EREG_BANKSIZE 8
  574. #define CD1400_CLK 25000000
  575. #define CD1400_CLK8M 20000000
  576. /*
  577. * Define the cd1400 baud rate clocks. These are used when calculating
  578. * what clock and divisor to use for the required baud rate. Also
  579. * define the maximum baud rate allowed, and the default base baud.
  580. */
  581. static int stl_cd1400clkdivs[] = {
  582. CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
  583. };
  584. /*****************************************************************************/
  585. /*
  586. * SC26198 UART specific data initization.
  587. */
  588. static uart_t stl_sc26198uart = {
  589. stl_sc26198panelinit,
  590. stl_sc26198portinit,
  591. stl_sc26198setport,
  592. stl_sc26198getsignals,
  593. stl_sc26198setsignals,
  594. stl_sc26198enablerxtx,
  595. stl_sc26198startrxtx,
  596. stl_sc26198disableintrs,
  597. stl_sc26198sendbreak,
  598. stl_sc26198flowctrl,
  599. stl_sc26198sendflow,
  600. stl_sc26198flush,
  601. stl_sc26198datastate,
  602. stl_sc26198intr
  603. };
  604. /*
  605. * Define the offsets within the register bank of a sc26198 based panel.
  606. */
  607. #define XP_DATA 0
  608. #define XP_ADDR 1
  609. #define XP_MODID 2
  610. #define XP_STATUS 2
  611. #define XP_IACK 3
  612. #define XP_BANKSIZE 4
  613. /*
  614. * Define the sc26198 baud rate table. Offsets within the table
  615. * represent the actual baud rate selector of sc26198 registers.
  616. */
  617. static unsigned int sc26198_baudtable[] = {
  618. 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
  619. 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
  620. 230400, 460800, 921600
  621. };
  622. #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
  623. /*****************************************************************************/
  624. /*
  625. * Define the driver info for a user level control device. Used mainly
  626. * to get at port stats - only not using the port device itself.
  627. */
  628. static struct file_operations stl_fsiomem = {
  629. .owner = THIS_MODULE,
  630. .ioctl = stl_memioctl,
  631. };
  632. /*****************************************************************************/
  633. static struct class_simple *stallion_class;
  634. /*
  635. * Loadable module initialization stuff.
  636. */
  637. static int __init stallion_module_init(void)
  638. {
  639. unsigned long flags;
  640. #ifdef DEBUG
  641. printk("init_module()\n");
  642. #endif
  643. save_flags(flags);
  644. cli();
  645. stl_init();
  646. restore_flags(flags);
  647. return(0);
  648. }
  649. /*****************************************************************************/
  650. static void __exit stallion_module_exit(void)
  651. {
  652. stlbrd_t *brdp;
  653. stlpanel_t *panelp;
  654. stlport_t *portp;
  655. unsigned long flags;
  656. int i, j, k;
  657. #ifdef DEBUG
  658. printk("cleanup_module()\n");
  659. #endif
  660. printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
  661. stl_drvversion);
  662. save_flags(flags);
  663. cli();
  664. /*
  665. * Free up all allocated resources used by the ports. This includes
  666. * memory and interrupts. As part of this process we will also do
  667. * a hangup on every open port - to try to flush out any processes
  668. * hanging onto ports.
  669. */
  670. i = tty_unregister_driver(stl_serial);
  671. put_tty_driver(stl_serial);
  672. if (i) {
  673. printk("STALLION: failed to un-register tty driver, "
  674. "errno=%d\n", -i);
  675. restore_flags(flags);
  676. return;
  677. }
  678. for (i = 0; i < 4; i++) {
  679. devfs_remove("staliomem/%d", i);
  680. class_simple_device_remove(MKDEV(STL_SIOMEMMAJOR, i));
  681. }
  682. devfs_remove("staliomem");
  683. if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
  684. printk("STALLION: failed to un-register serial memory device, "
  685. "errno=%d\n", -i);
  686. class_simple_destroy(stallion_class);
  687. if (stl_tmpwritebuf != (char *) NULL)
  688. kfree(stl_tmpwritebuf);
  689. for (i = 0; (i < stl_nrbrds); i++) {
  690. if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
  691. continue;
  692. free_irq(brdp->irq, brdp);
  693. for (j = 0; (j < STL_MAXPANELS); j++) {
  694. panelp = brdp->panels[j];
  695. if (panelp == (stlpanel_t *) NULL)
  696. continue;
  697. for (k = 0; (k < STL_PORTSPERPANEL); k++) {
  698. portp = panelp->ports[k];
  699. if (portp == (stlport_t *) NULL)
  700. continue;
  701. if (portp->tty != (struct tty_struct *) NULL)
  702. stl_hangup(portp->tty);
  703. if (portp->tx.buf != (char *) NULL)
  704. kfree(portp->tx.buf);
  705. kfree(portp);
  706. }
  707. kfree(panelp);
  708. }
  709. release_region(brdp->ioaddr1, brdp->iosize1);
  710. if (brdp->iosize2 > 0)
  711. release_region(brdp->ioaddr2, brdp->iosize2);
  712. kfree(brdp);
  713. stl_brds[i] = (stlbrd_t *) NULL;
  714. }
  715. restore_flags(flags);
  716. }
  717. module_init(stallion_module_init);
  718. module_exit(stallion_module_exit);
  719. /*****************************************************************************/
  720. /*
  721. * Check for any arguments passed in on the module load command line.
  722. */
  723. static void stl_argbrds(void)
  724. {
  725. stlconf_t conf;
  726. stlbrd_t *brdp;
  727. int i;
  728. #ifdef DEBUG
  729. printk("stl_argbrds()\n");
  730. #endif
  731. for (i = stl_nrbrds; (i < stl_nargs); i++) {
  732. memset(&conf, 0, sizeof(conf));
  733. if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
  734. continue;
  735. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  736. continue;
  737. stl_nrbrds = i + 1;
  738. brdp->brdnr = i;
  739. brdp->brdtype = conf.brdtype;
  740. brdp->ioaddr1 = conf.ioaddr1;
  741. brdp->ioaddr2 = conf.ioaddr2;
  742. brdp->irq = conf.irq;
  743. brdp->irqtype = conf.irqtype;
  744. stl_brdinit(brdp);
  745. }
  746. }
  747. /*****************************************************************************/
  748. /*
  749. * Convert an ascii string number into an unsigned long.
  750. */
  751. static unsigned long stl_atol(char *str)
  752. {
  753. unsigned long val;
  754. int base, c;
  755. char *sp;
  756. val = 0;
  757. sp = str;
  758. if ((*sp == '0') && (*(sp+1) == 'x')) {
  759. base = 16;
  760. sp += 2;
  761. } else if (*sp == '0') {
  762. base = 8;
  763. sp++;
  764. } else {
  765. base = 10;
  766. }
  767. for (; (*sp != 0); sp++) {
  768. c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
  769. if ((c < 0) || (c >= base)) {
  770. printk("STALLION: invalid argument %s\n", str);
  771. val = 0;
  772. break;
  773. }
  774. val = (val * base) + c;
  775. }
  776. return(val);
  777. }
  778. /*****************************************************************************/
  779. /*
  780. * Parse the supplied argument string, into the board conf struct.
  781. */
  782. static int stl_parsebrd(stlconf_t *confp, char **argp)
  783. {
  784. char *sp;
  785. int nrbrdnames, i;
  786. #ifdef DEBUG
  787. printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
  788. #endif
  789. if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
  790. return(0);
  791. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  792. *sp = TOLOWER(*sp);
  793. nrbrdnames = sizeof(stl_brdstr) / sizeof(stlbrdtype_t);
  794. for (i = 0; (i < nrbrdnames); i++) {
  795. if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
  796. break;
  797. }
  798. if (i >= nrbrdnames) {
  799. printk("STALLION: unknown board name, %s?\n", argp[0]);
  800. return(0);
  801. }
  802. confp->brdtype = stl_brdstr[i].type;
  803. i = 1;
  804. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  805. confp->ioaddr1 = stl_atol(argp[i]);
  806. i++;
  807. if (confp->brdtype == BRD_ECH) {
  808. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  809. confp->ioaddr2 = stl_atol(argp[i]);
  810. i++;
  811. }
  812. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  813. confp->irq = stl_atol(argp[i]);
  814. return(1);
  815. }
  816. /*****************************************************************************/
  817. /*
  818. * Local driver kernel memory allocation routine.
  819. */
  820. static void *stl_memalloc(int len)
  821. {
  822. return((void *) kmalloc(len, GFP_KERNEL));
  823. }
  824. /*****************************************************************************/
  825. /*
  826. * Allocate a new board structure. Fill out the basic info in it.
  827. */
  828. static stlbrd_t *stl_allocbrd(void)
  829. {
  830. stlbrd_t *brdp;
  831. brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
  832. if (brdp == (stlbrd_t *) NULL) {
  833. printk("STALLION: failed to allocate memory (size=%d)\n",
  834. sizeof(stlbrd_t));
  835. return((stlbrd_t *) NULL);
  836. }
  837. memset(brdp, 0, sizeof(stlbrd_t));
  838. brdp->magic = STL_BOARDMAGIC;
  839. return(brdp);
  840. }
  841. /*****************************************************************************/
  842. static int stl_open(struct tty_struct *tty, struct file *filp)
  843. {
  844. stlport_t *portp;
  845. stlbrd_t *brdp;
  846. unsigned int minordev;
  847. int brdnr, panelnr, portnr, rc;
  848. #ifdef DEBUG
  849. printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
  850. (int) filp, tty->name);
  851. #endif
  852. minordev = tty->index;
  853. brdnr = MINOR2BRD(minordev);
  854. if (brdnr >= stl_nrbrds)
  855. return(-ENODEV);
  856. brdp = stl_brds[brdnr];
  857. if (brdp == (stlbrd_t *) NULL)
  858. return(-ENODEV);
  859. minordev = MINOR2PORT(minordev);
  860. for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  861. if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
  862. break;
  863. if (minordev < brdp->panels[panelnr]->nrports) {
  864. portnr = minordev;
  865. break;
  866. }
  867. minordev -= brdp->panels[panelnr]->nrports;
  868. }
  869. if (portnr < 0)
  870. return(-ENODEV);
  871. portp = brdp->panels[panelnr]->ports[portnr];
  872. if (portp == (stlport_t *) NULL)
  873. return(-ENODEV);
  874. /*
  875. * On the first open of the device setup the port hardware, and
  876. * initialize the per port data structure.
  877. */
  878. portp->tty = tty;
  879. tty->driver_data = portp;
  880. portp->refcount++;
  881. if ((portp->flags & ASYNC_INITIALIZED) == 0) {
  882. if (portp->tx.buf == (char *) NULL) {
  883. portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
  884. if (portp->tx.buf == (char *) NULL)
  885. return(-ENOMEM);
  886. portp->tx.head = portp->tx.buf;
  887. portp->tx.tail = portp->tx.buf;
  888. }
  889. stl_setport(portp, tty->termios);
  890. portp->sigs = stl_getsignals(portp);
  891. stl_setsignals(portp, 1, 1);
  892. stl_enablerxtx(portp, 1, 1);
  893. stl_startrxtx(portp, 1, 0);
  894. clear_bit(TTY_IO_ERROR, &tty->flags);
  895. portp->flags |= ASYNC_INITIALIZED;
  896. }
  897. /*
  898. * Check if this port is in the middle of closing. If so then wait
  899. * until it is closed then return error status, based on flag settings.
  900. * The sleep here does not need interrupt protection since the wakeup
  901. * for it is done with the same context.
  902. */
  903. if (portp->flags & ASYNC_CLOSING) {
  904. interruptible_sleep_on(&portp->close_wait);
  905. if (portp->flags & ASYNC_HUP_NOTIFY)
  906. return(-EAGAIN);
  907. return(-ERESTARTSYS);
  908. }
  909. /*
  910. * Based on type of open being done check if it can overlap with any
  911. * previous opens still in effect. If we are a normal serial device
  912. * then also we might have to wait for carrier.
  913. */
  914. if (!(filp->f_flags & O_NONBLOCK)) {
  915. if ((rc = stl_waitcarrier(portp, filp)) != 0)
  916. return(rc);
  917. }
  918. portp->flags |= ASYNC_NORMAL_ACTIVE;
  919. return(0);
  920. }
  921. /*****************************************************************************/
  922. /*
  923. * Possibly need to wait for carrier (DCD signal) to come high. Say
  924. * maybe because if we are clocal then we don't need to wait...
  925. */
  926. static int stl_waitcarrier(stlport_t *portp, struct file *filp)
  927. {
  928. unsigned long flags;
  929. int rc, doclocal;
  930. #ifdef DEBUG
  931. printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
  932. #endif
  933. rc = 0;
  934. doclocal = 0;
  935. if (portp->tty->termios->c_cflag & CLOCAL)
  936. doclocal++;
  937. save_flags(flags);
  938. cli();
  939. portp->openwaitcnt++;
  940. if (! tty_hung_up_p(filp))
  941. portp->refcount--;
  942. for (;;) {
  943. stl_setsignals(portp, 1, 1);
  944. if (tty_hung_up_p(filp) ||
  945. ((portp->flags & ASYNC_INITIALIZED) == 0)) {
  946. if (portp->flags & ASYNC_HUP_NOTIFY)
  947. rc = -EBUSY;
  948. else
  949. rc = -ERESTARTSYS;
  950. break;
  951. }
  952. if (((portp->flags & ASYNC_CLOSING) == 0) &&
  953. (doclocal || (portp->sigs & TIOCM_CD))) {
  954. break;
  955. }
  956. if (signal_pending(current)) {
  957. rc = -ERESTARTSYS;
  958. break;
  959. }
  960. interruptible_sleep_on(&portp->open_wait);
  961. }
  962. if (! tty_hung_up_p(filp))
  963. portp->refcount++;
  964. portp->openwaitcnt--;
  965. restore_flags(flags);
  966. return(rc);
  967. }
  968. /*****************************************************************************/
  969. static void stl_close(struct tty_struct *tty, struct file *filp)
  970. {
  971. stlport_t *portp;
  972. unsigned long flags;
  973. #ifdef DEBUG
  974. printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
  975. #endif
  976. portp = tty->driver_data;
  977. if (portp == (stlport_t *) NULL)
  978. return;
  979. save_flags(flags);
  980. cli();
  981. if (tty_hung_up_p(filp)) {
  982. restore_flags(flags);
  983. return;
  984. }
  985. if ((tty->count == 1) && (portp->refcount != 1))
  986. portp->refcount = 1;
  987. if (portp->refcount-- > 1) {
  988. restore_flags(flags);
  989. return;
  990. }
  991. portp->refcount = 0;
  992. portp->flags |= ASYNC_CLOSING;
  993. /*
  994. * May want to wait for any data to drain before closing. The BUSY
  995. * flag keeps track of whether we are still sending or not - it is
  996. * very accurate for the cd1400, not quite so for the sc26198.
  997. * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
  998. */
  999. tty->closing = 1;
  1000. if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  1001. tty_wait_until_sent(tty, portp->closing_wait);
  1002. stl_waituntilsent(tty, (HZ / 2));
  1003. portp->flags &= ~ASYNC_INITIALIZED;
  1004. stl_disableintrs(portp);
  1005. if (tty->termios->c_cflag & HUPCL)
  1006. stl_setsignals(portp, 0, 0);
  1007. stl_enablerxtx(portp, 0, 0);
  1008. stl_flushbuffer(tty);
  1009. portp->istate = 0;
  1010. if (portp->tx.buf != (char *) NULL) {
  1011. kfree(portp->tx.buf);
  1012. portp->tx.buf = (char *) NULL;
  1013. portp->tx.head = (char *) NULL;
  1014. portp->tx.tail = (char *) NULL;
  1015. }
  1016. set_bit(TTY_IO_ERROR, &tty->flags);
  1017. tty_ldisc_flush(tty);
  1018. tty->closing = 0;
  1019. portp->tty = (struct tty_struct *) NULL;
  1020. if (portp->openwaitcnt) {
  1021. if (portp->close_delay)
  1022. msleep_interruptible(jiffies_to_msecs(portp->close_delay));
  1023. wake_up_interruptible(&portp->open_wait);
  1024. }
  1025. portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1026. wake_up_interruptible(&portp->close_wait);
  1027. restore_flags(flags);
  1028. }
  1029. /*****************************************************************************/
  1030. /*
  1031. * Write routine. Take data and stuff it in to the TX ring queue.
  1032. * If transmit interrupts are not running then start them.
  1033. */
  1034. static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
  1035. {
  1036. stlport_t *portp;
  1037. unsigned int len, stlen;
  1038. unsigned char *chbuf;
  1039. char *head, *tail;
  1040. #ifdef DEBUG
  1041. printk("stl_write(tty=%x,buf=%x,count=%d)\n",
  1042. (int) tty, (int) buf, count);
  1043. #endif
  1044. if ((tty == (struct tty_struct *) NULL) ||
  1045. (stl_tmpwritebuf == (char *) NULL))
  1046. return(0);
  1047. portp = tty->driver_data;
  1048. if (portp == (stlport_t *) NULL)
  1049. return(0);
  1050. if (portp->tx.buf == (char *) NULL)
  1051. return(0);
  1052. /*
  1053. * If copying direct from user space we must cater for page faults,
  1054. * causing us to "sleep" here for a while. To handle this copy in all
  1055. * the data we need now, into a local buffer. Then when we got it all
  1056. * copy it into the TX buffer.
  1057. */
  1058. chbuf = (unsigned char *) buf;
  1059. head = portp->tx.head;
  1060. tail = portp->tx.tail;
  1061. if (head >= tail) {
  1062. len = STL_TXBUFSIZE - (head - tail) - 1;
  1063. stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
  1064. } else {
  1065. len = tail - head - 1;
  1066. stlen = len;
  1067. }
  1068. len = MIN(len, count);
  1069. count = 0;
  1070. while (len > 0) {
  1071. stlen = MIN(len, stlen);
  1072. memcpy(head, chbuf, stlen);
  1073. len -= stlen;
  1074. chbuf += stlen;
  1075. count += stlen;
  1076. head += stlen;
  1077. if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
  1078. head = portp->tx.buf;
  1079. stlen = tail - head;
  1080. }
  1081. }
  1082. portp->tx.head = head;
  1083. clear_bit(ASYI_TXLOW, &portp->istate);
  1084. stl_startrxtx(portp, -1, 1);
  1085. return(count);
  1086. }
  1087. /*****************************************************************************/
  1088. static void stl_putchar(struct tty_struct *tty, unsigned char ch)
  1089. {
  1090. stlport_t *portp;
  1091. unsigned int len;
  1092. char *head, *tail;
  1093. #ifdef DEBUG
  1094. printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
  1095. #endif
  1096. if (tty == (struct tty_struct *) NULL)
  1097. return;
  1098. portp = tty->driver_data;
  1099. if (portp == (stlport_t *) NULL)
  1100. return;
  1101. if (portp->tx.buf == (char *) NULL)
  1102. return;
  1103. head = portp->tx.head;
  1104. tail = portp->tx.tail;
  1105. len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
  1106. len--;
  1107. if (len > 0) {
  1108. *head++ = ch;
  1109. if (head >= (portp->tx.buf + STL_TXBUFSIZE))
  1110. head = portp->tx.buf;
  1111. }
  1112. portp->tx.head = head;
  1113. }
  1114. /*****************************************************************************/
  1115. /*
  1116. * If there are any characters in the buffer then make sure that TX
  1117. * interrupts are on and get'em out. Normally used after the putchar
  1118. * routine has been called.
  1119. */
  1120. static void stl_flushchars(struct tty_struct *tty)
  1121. {
  1122. stlport_t *portp;
  1123. #ifdef DEBUG
  1124. printk("stl_flushchars(tty=%x)\n", (int) tty);
  1125. #endif
  1126. if (tty == (struct tty_struct *) NULL)
  1127. return;
  1128. portp = tty->driver_data;
  1129. if (portp == (stlport_t *) NULL)
  1130. return;
  1131. if (portp->tx.buf == (char *) NULL)
  1132. return;
  1133. #if 0
  1134. if (tty->stopped || tty->hw_stopped ||
  1135. (portp->tx.head == portp->tx.tail))
  1136. return;
  1137. #endif
  1138. stl_startrxtx(portp, -1, 1);
  1139. }
  1140. /*****************************************************************************/
  1141. static int stl_writeroom(struct tty_struct *tty)
  1142. {
  1143. stlport_t *portp;
  1144. char *head, *tail;
  1145. #ifdef DEBUG
  1146. printk("stl_writeroom(tty=%x)\n", (int) tty);
  1147. #endif
  1148. if (tty == (struct tty_struct *) NULL)
  1149. return(0);
  1150. portp = tty->driver_data;
  1151. if (portp == (stlport_t *) NULL)
  1152. return(0);
  1153. if (portp->tx.buf == (char *) NULL)
  1154. return(0);
  1155. head = portp->tx.head;
  1156. tail = portp->tx.tail;
  1157. return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
  1158. }
  1159. /*****************************************************************************/
  1160. /*
  1161. * Return number of chars in the TX buffer. Normally we would just
  1162. * calculate the number of chars in the buffer and return that, but if
  1163. * the buffer is empty and TX interrupts are still on then we return
  1164. * that the buffer still has 1 char in it. This way whoever called us
  1165. * will not think that ALL chars have drained - since the UART still
  1166. * must have some chars in it (we are busy after all).
  1167. */
  1168. static int stl_charsinbuffer(struct tty_struct *tty)
  1169. {
  1170. stlport_t *portp;
  1171. unsigned int size;
  1172. char *head, *tail;
  1173. #ifdef DEBUG
  1174. printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
  1175. #endif
  1176. if (tty == (struct tty_struct *) NULL)
  1177. return(0);
  1178. portp = tty->driver_data;
  1179. if (portp == (stlport_t *) NULL)
  1180. return(0);
  1181. if (portp->tx.buf == (char *) NULL)
  1182. return(0);
  1183. head = portp->tx.head;
  1184. tail = portp->tx.tail;
  1185. size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  1186. if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
  1187. size = 1;
  1188. return(size);
  1189. }
  1190. /*****************************************************************************/
  1191. /*
  1192. * Generate the serial struct info.
  1193. */
  1194. static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
  1195. {
  1196. struct serial_struct sio;
  1197. stlbrd_t *brdp;
  1198. #ifdef DEBUG
  1199. printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
  1200. #endif
  1201. memset(&sio, 0, sizeof(struct serial_struct));
  1202. sio.line = portp->portnr;
  1203. sio.port = portp->ioaddr;
  1204. sio.flags = portp->flags;
  1205. sio.baud_base = portp->baud_base;
  1206. sio.close_delay = portp->close_delay;
  1207. sio.closing_wait = portp->closing_wait;
  1208. sio.custom_divisor = portp->custom_divisor;
  1209. sio.hub6 = 0;
  1210. if (portp->uartp == &stl_cd1400uart) {
  1211. sio.type = PORT_CIRRUS;
  1212. sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
  1213. } else {
  1214. sio.type = PORT_UNKNOWN;
  1215. sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
  1216. }
  1217. brdp = stl_brds[portp->brdnr];
  1218. if (brdp != (stlbrd_t *) NULL)
  1219. sio.irq = brdp->irq;
  1220. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
  1221. }
  1222. /*****************************************************************************/
  1223. /*
  1224. * Set port according to the serial struct info.
  1225. * At this point we do not do any auto-configure stuff, so we will
  1226. * just quietly ignore any requests to change irq, etc.
  1227. */
  1228. static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
  1229. {
  1230. struct serial_struct sio;
  1231. #ifdef DEBUG
  1232. printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
  1233. #endif
  1234. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1235. return -EFAULT;
  1236. if (!capable(CAP_SYS_ADMIN)) {
  1237. if ((sio.baud_base != portp->baud_base) ||
  1238. (sio.close_delay != portp->close_delay) ||
  1239. ((sio.flags & ~ASYNC_USR_MASK) !=
  1240. (portp->flags & ~ASYNC_USR_MASK)))
  1241. return(-EPERM);
  1242. }
  1243. portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
  1244. (sio.flags & ASYNC_USR_MASK);
  1245. portp->baud_base = sio.baud_base;
  1246. portp->close_delay = sio.close_delay;
  1247. portp->closing_wait = sio.closing_wait;
  1248. portp->custom_divisor = sio.custom_divisor;
  1249. stl_setport(portp, portp->tty->termios);
  1250. return(0);
  1251. }
  1252. /*****************************************************************************/
  1253. static int stl_tiocmget(struct tty_struct *tty, struct file *file)
  1254. {
  1255. stlport_t *portp;
  1256. if (tty == (struct tty_struct *) NULL)
  1257. return(-ENODEV);
  1258. portp = tty->driver_data;
  1259. if (portp == (stlport_t *) NULL)
  1260. return(-ENODEV);
  1261. if (tty->flags & (1 << TTY_IO_ERROR))
  1262. return(-EIO);
  1263. return stl_getsignals(portp);
  1264. }
  1265. static int stl_tiocmset(struct tty_struct *tty, struct file *file,
  1266. unsigned int set, unsigned int clear)
  1267. {
  1268. stlport_t *portp;
  1269. int rts = -1, dtr = -1;
  1270. if (tty == (struct tty_struct *) NULL)
  1271. return(-ENODEV);
  1272. portp = tty->driver_data;
  1273. if (portp == (stlport_t *) NULL)
  1274. return(-ENODEV);
  1275. if (tty->flags & (1 << TTY_IO_ERROR))
  1276. return(-EIO);
  1277. if (set & TIOCM_RTS)
  1278. rts = 1;
  1279. if (set & TIOCM_DTR)
  1280. dtr = 1;
  1281. if (clear & TIOCM_RTS)
  1282. rts = 0;
  1283. if (clear & TIOCM_DTR)
  1284. dtr = 0;
  1285. stl_setsignals(portp, dtr, rts);
  1286. return 0;
  1287. }
  1288. static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1289. {
  1290. stlport_t *portp;
  1291. unsigned int ival;
  1292. int rc;
  1293. void __user *argp = (void __user *)arg;
  1294. #ifdef DEBUG
  1295. printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
  1296. (int) tty, (int) file, cmd, (int) arg);
  1297. #endif
  1298. if (tty == (struct tty_struct *) NULL)
  1299. return(-ENODEV);
  1300. portp = tty->driver_data;
  1301. if (portp == (stlport_t *) NULL)
  1302. return(-ENODEV);
  1303. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1304. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1305. if (tty->flags & (1 << TTY_IO_ERROR))
  1306. return(-EIO);
  1307. }
  1308. rc = 0;
  1309. switch (cmd) {
  1310. case TIOCGSOFTCAR:
  1311. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  1312. (unsigned __user *) argp);
  1313. break;
  1314. case TIOCSSOFTCAR:
  1315. if (get_user(ival, (unsigned int __user *) arg))
  1316. return -EFAULT;
  1317. tty->termios->c_cflag =
  1318. (tty->termios->c_cflag & ~CLOCAL) |
  1319. (ival ? CLOCAL : 0);
  1320. break;
  1321. case TIOCGSERIAL:
  1322. rc = stl_getserial(portp, argp);
  1323. break;
  1324. case TIOCSSERIAL:
  1325. rc = stl_setserial(portp, argp);
  1326. break;
  1327. case COM_GETPORTSTATS:
  1328. rc = stl_getportstats(portp, argp);
  1329. break;
  1330. case COM_CLRPORTSTATS:
  1331. rc = stl_clrportstats(portp, argp);
  1332. break;
  1333. case TIOCSERCONFIG:
  1334. case TIOCSERGWILD:
  1335. case TIOCSERSWILD:
  1336. case TIOCSERGETLSR:
  1337. case TIOCSERGSTRUCT:
  1338. case TIOCSERGETMULTI:
  1339. case TIOCSERSETMULTI:
  1340. default:
  1341. rc = -ENOIOCTLCMD;
  1342. break;
  1343. }
  1344. return(rc);
  1345. }
  1346. /*****************************************************************************/
  1347. static void stl_settermios(struct tty_struct *tty, struct termios *old)
  1348. {
  1349. stlport_t *portp;
  1350. struct termios *tiosp;
  1351. #ifdef DEBUG
  1352. printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
  1353. #endif
  1354. if (tty == (struct tty_struct *) NULL)
  1355. return;
  1356. portp = tty->driver_data;
  1357. if (portp == (stlport_t *) NULL)
  1358. return;
  1359. tiosp = tty->termios;
  1360. if ((tiosp->c_cflag == old->c_cflag) &&
  1361. (tiosp->c_iflag == old->c_iflag))
  1362. return;
  1363. stl_setport(portp, tiosp);
  1364. stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
  1365. -1);
  1366. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
  1367. tty->hw_stopped = 0;
  1368. stl_start(tty);
  1369. }
  1370. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1371. wake_up_interruptible(&portp->open_wait);
  1372. }
  1373. /*****************************************************************************/
  1374. /*
  1375. * Attempt to flow control who ever is sending us data. Based on termios
  1376. * settings use software or/and hardware flow control.
  1377. */
  1378. static void stl_throttle(struct tty_struct *tty)
  1379. {
  1380. stlport_t *portp;
  1381. #ifdef DEBUG
  1382. printk("stl_throttle(tty=%x)\n", (int) tty);
  1383. #endif
  1384. if (tty == (struct tty_struct *) NULL)
  1385. return;
  1386. portp = tty->driver_data;
  1387. if (portp == (stlport_t *) NULL)
  1388. return;
  1389. stl_flowctrl(portp, 0);
  1390. }
  1391. /*****************************************************************************/
  1392. /*
  1393. * Unflow control the device sending us data...
  1394. */
  1395. static void stl_unthrottle(struct tty_struct *tty)
  1396. {
  1397. stlport_t *portp;
  1398. #ifdef DEBUG
  1399. printk("stl_unthrottle(tty=%x)\n", (int) tty);
  1400. #endif
  1401. if (tty == (struct tty_struct *) NULL)
  1402. return;
  1403. portp = tty->driver_data;
  1404. if (portp == (stlport_t *) NULL)
  1405. return;
  1406. stl_flowctrl(portp, 1);
  1407. }
  1408. /*****************************************************************************/
  1409. /*
  1410. * Stop the transmitter. Basically to do this we will just turn TX
  1411. * interrupts off.
  1412. */
  1413. static void stl_stop(struct tty_struct *tty)
  1414. {
  1415. stlport_t *portp;
  1416. #ifdef DEBUG
  1417. printk("stl_stop(tty=%x)\n", (int) tty);
  1418. #endif
  1419. if (tty == (struct tty_struct *) NULL)
  1420. return;
  1421. portp = tty->driver_data;
  1422. if (portp == (stlport_t *) NULL)
  1423. return;
  1424. stl_startrxtx(portp, -1, 0);
  1425. }
  1426. /*****************************************************************************/
  1427. /*
  1428. * Start the transmitter again. Just turn TX interrupts back on.
  1429. */
  1430. static void stl_start(struct tty_struct *tty)
  1431. {
  1432. stlport_t *portp;
  1433. #ifdef DEBUG
  1434. printk("stl_start(tty=%x)\n", (int) tty);
  1435. #endif
  1436. if (tty == (struct tty_struct *) NULL)
  1437. return;
  1438. portp = tty->driver_data;
  1439. if (portp == (stlport_t *) NULL)
  1440. return;
  1441. stl_startrxtx(portp, -1, 1);
  1442. }
  1443. /*****************************************************************************/
  1444. /*
  1445. * Hangup this port. This is pretty much like closing the port, only
  1446. * a little more brutal. No waiting for data to drain. Shutdown the
  1447. * port and maybe drop signals.
  1448. */
  1449. static void stl_hangup(struct tty_struct *tty)
  1450. {
  1451. stlport_t *portp;
  1452. #ifdef DEBUG
  1453. printk("stl_hangup(tty=%x)\n", (int) tty);
  1454. #endif
  1455. if (tty == (struct tty_struct *) NULL)
  1456. return;
  1457. portp = tty->driver_data;
  1458. if (portp == (stlport_t *) NULL)
  1459. return;
  1460. portp->flags &= ~ASYNC_INITIALIZED;
  1461. stl_disableintrs(portp);
  1462. if (tty->termios->c_cflag & HUPCL)
  1463. stl_setsignals(portp, 0, 0);
  1464. stl_enablerxtx(portp, 0, 0);
  1465. stl_flushbuffer(tty);
  1466. portp->istate = 0;
  1467. set_bit(TTY_IO_ERROR, &tty->flags);
  1468. if (portp->tx.buf != (char *) NULL) {
  1469. kfree(portp->tx.buf);
  1470. portp->tx.buf = (char *) NULL;
  1471. portp->tx.head = (char *) NULL;
  1472. portp->tx.tail = (char *) NULL;
  1473. }
  1474. portp->tty = (struct tty_struct *) NULL;
  1475. portp->flags &= ~ASYNC_NORMAL_ACTIVE;
  1476. portp->refcount = 0;
  1477. wake_up_interruptible(&portp->open_wait);
  1478. }
  1479. /*****************************************************************************/
  1480. static void stl_flushbuffer(struct tty_struct *tty)
  1481. {
  1482. stlport_t *portp;
  1483. #ifdef DEBUG
  1484. printk("stl_flushbuffer(tty=%x)\n", (int) tty);
  1485. #endif
  1486. if (tty == (struct tty_struct *) NULL)
  1487. return;
  1488. portp = tty->driver_data;
  1489. if (portp == (stlport_t *) NULL)
  1490. return;
  1491. stl_flush(portp);
  1492. tty_wakeup(tty);
  1493. }
  1494. /*****************************************************************************/
  1495. static void stl_breakctl(struct tty_struct *tty, int state)
  1496. {
  1497. stlport_t *portp;
  1498. #ifdef DEBUG
  1499. printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
  1500. #endif
  1501. if (tty == (struct tty_struct *) NULL)
  1502. return;
  1503. portp = tty->driver_data;
  1504. if (portp == (stlport_t *) NULL)
  1505. return;
  1506. stl_sendbreak(portp, ((state == -1) ? 1 : 2));
  1507. }
  1508. /*****************************************************************************/
  1509. static void stl_waituntilsent(struct tty_struct *tty, int timeout)
  1510. {
  1511. stlport_t *portp;
  1512. unsigned long tend;
  1513. #ifdef DEBUG
  1514. printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
  1515. #endif
  1516. if (tty == (struct tty_struct *) NULL)
  1517. return;
  1518. portp = tty->driver_data;
  1519. if (portp == (stlport_t *) NULL)
  1520. return;
  1521. if (timeout == 0)
  1522. timeout = HZ;
  1523. tend = jiffies + timeout;
  1524. while (stl_datastate(portp)) {
  1525. if (signal_pending(current))
  1526. break;
  1527. msleep_interruptible(20);
  1528. if (time_after_eq(jiffies, tend))
  1529. break;
  1530. }
  1531. }
  1532. /*****************************************************************************/
  1533. static void stl_sendxchar(struct tty_struct *tty, char ch)
  1534. {
  1535. stlport_t *portp;
  1536. #ifdef DEBUG
  1537. printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
  1538. #endif
  1539. if (tty == (struct tty_struct *) NULL)
  1540. return;
  1541. portp = tty->driver_data;
  1542. if (portp == (stlport_t *) NULL)
  1543. return;
  1544. if (ch == STOP_CHAR(tty))
  1545. stl_sendflow(portp, 0);
  1546. else if (ch == START_CHAR(tty))
  1547. stl_sendflow(portp, 1);
  1548. else
  1549. stl_putchar(tty, ch);
  1550. }
  1551. /*****************************************************************************/
  1552. #define MAXLINE 80
  1553. /*
  1554. * Format info for a specified port. The line is deliberately limited
  1555. * to 80 characters. (If it is too long it will be truncated, if too
  1556. * short then padded with spaces).
  1557. */
  1558. static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
  1559. {
  1560. char *sp;
  1561. int sigs, cnt;
  1562. sp = pos;
  1563. sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
  1564. portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
  1565. (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
  1566. if (portp->stats.rxframing)
  1567. sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
  1568. if (portp->stats.rxparity)
  1569. sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
  1570. if (portp->stats.rxbreaks)
  1571. sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
  1572. if (portp->stats.rxoverrun)
  1573. sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
  1574. sigs = stl_getsignals(portp);
  1575. cnt = sprintf(sp, "%s%s%s%s%s ",
  1576. (sigs & TIOCM_RTS) ? "|RTS" : "",
  1577. (sigs & TIOCM_CTS) ? "|CTS" : "",
  1578. (sigs & TIOCM_DTR) ? "|DTR" : "",
  1579. (sigs & TIOCM_CD) ? "|DCD" : "",
  1580. (sigs & TIOCM_DSR) ? "|DSR" : "");
  1581. *sp = ' ';
  1582. sp += cnt;
  1583. for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
  1584. *sp++ = ' ';
  1585. if (cnt >= MAXLINE)
  1586. pos[(MAXLINE - 2)] = '+';
  1587. pos[(MAXLINE - 1)] = '\n';
  1588. return(MAXLINE);
  1589. }
  1590. /*****************************************************************************/
  1591. /*
  1592. * Port info, read from the /proc file system.
  1593. */
  1594. static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
  1595. {
  1596. stlbrd_t *brdp;
  1597. stlpanel_t *panelp;
  1598. stlport_t *portp;
  1599. int brdnr, panelnr, portnr, totalport;
  1600. int curoff, maxoff;
  1601. char *pos;
  1602. #ifdef DEBUG
  1603. printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
  1604. "data=%x\n", (int) page, (int) start, (int) off, count,
  1605. (int) eof, (int) data);
  1606. #endif
  1607. pos = page;
  1608. totalport = 0;
  1609. curoff = 0;
  1610. if (off == 0) {
  1611. pos += sprintf(pos, "%s: version %s", stl_drvtitle,
  1612. stl_drvversion);
  1613. while (pos < (page + MAXLINE - 1))
  1614. *pos++ = ' ';
  1615. *pos++ = '\n';
  1616. }
  1617. curoff = MAXLINE;
  1618. /*
  1619. * We scan through for each board, panel and port. The offset is
  1620. * calculated on the fly, and irrelevant ports are skipped.
  1621. */
  1622. for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
  1623. brdp = stl_brds[brdnr];
  1624. if (brdp == (stlbrd_t *) NULL)
  1625. continue;
  1626. if (brdp->state == 0)
  1627. continue;
  1628. maxoff = curoff + (brdp->nrports * MAXLINE);
  1629. if (off >= maxoff) {
  1630. curoff = maxoff;
  1631. continue;
  1632. }
  1633. totalport = brdnr * STL_MAXPORTS;
  1634. for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
  1635. panelp = brdp->panels[panelnr];
  1636. if (panelp == (stlpanel_t *) NULL)
  1637. continue;
  1638. maxoff = curoff + (panelp->nrports * MAXLINE);
  1639. if (off >= maxoff) {
  1640. curoff = maxoff;
  1641. totalport += panelp->nrports;
  1642. continue;
  1643. }
  1644. for (portnr = 0; (portnr < panelp->nrports); portnr++,
  1645. totalport++) {
  1646. portp = panelp->ports[portnr];
  1647. if (portp == (stlport_t *) NULL)
  1648. continue;
  1649. if (off >= (curoff += MAXLINE))
  1650. continue;
  1651. if ((pos - page + MAXLINE) > count)
  1652. goto stl_readdone;
  1653. pos += stl_portinfo(portp, totalport, pos);
  1654. }
  1655. }
  1656. }
  1657. *eof = 1;
  1658. stl_readdone:
  1659. *start = page;
  1660. return(pos - page);
  1661. }
  1662. /*****************************************************************************/
  1663. /*
  1664. * All board interrupts are vectored through here first. This code then
  1665. * calls off to the approrpriate board interrupt handlers.
  1666. */
  1667. static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
  1668. {
  1669. stlbrd_t *brdp = (stlbrd_t *) dev_id;
  1670. #ifdef DEBUG
  1671. printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
  1672. (int) regs);
  1673. #endif
  1674. return IRQ_RETVAL((* brdp->isr)(brdp));
  1675. }
  1676. /*****************************************************************************/
  1677. /*
  1678. * Interrupt service routine for EasyIO board types.
  1679. */
  1680. static int stl_eiointr(stlbrd_t *brdp)
  1681. {
  1682. stlpanel_t *panelp;
  1683. unsigned int iobase;
  1684. int handled = 0;
  1685. panelp = brdp->panels[0];
  1686. iobase = panelp->iobase;
  1687. while (inb(brdp->iostatus) & EIO_INTRPEND) {
  1688. handled = 1;
  1689. (* panelp->isr)(panelp, iobase);
  1690. }
  1691. return handled;
  1692. }
  1693. /*****************************************************************************/
  1694. /*
  1695. * Interrupt service routine for ECH-AT board types.
  1696. */
  1697. static int stl_echatintr(stlbrd_t *brdp)
  1698. {
  1699. stlpanel_t *panelp;
  1700. unsigned int ioaddr;
  1701. int bnknr;
  1702. int handled = 0;
  1703. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  1704. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1705. handled = 1;
  1706. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1707. ioaddr = brdp->bnkstataddr[bnknr];
  1708. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1709. panelp = brdp->bnk2panel[bnknr];
  1710. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1711. }
  1712. }
  1713. }
  1714. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  1715. return handled;
  1716. }
  1717. /*****************************************************************************/
  1718. /*
  1719. * Interrupt service routine for ECH-MCA board types.
  1720. */
  1721. static int stl_echmcaintr(stlbrd_t *brdp)
  1722. {
  1723. stlpanel_t *panelp;
  1724. unsigned int ioaddr;
  1725. int bnknr;
  1726. int handled = 0;
  1727. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1728. handled = 1;
  1729. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1730. ioaddr = brdp->bnkstataddr[bnknr];
  1731. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1732. panelp = brdp->bnk2panel[bnknr];
  1733. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1734. }
  1735. }
  1736. }
  1737. return handled;
  1738. }
  1739. /*****************************************************************************/
  1740. /*
  1741. * Interrupt service routine for ECH-PCI board types.
  1742. */
  1743. static int stl_echpciintr(stlbrd_t *brdp)
  1744. {
  1745. stlpanel_t *panelp;
  1746. unsigned int ioaddr;
  1747. int bnknr, recheck;
  1748. int handled = 0;
  1749. while (1) {
  1750. recheck = 0;
  1751. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1752. outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
  1753. ioaddr = brdp->bnkstataddr[bnknr];
  1754. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1755. panelp = brdp->bnk2panel[bnknr];
  1756. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1757. recheck++;
  1758. handled = 1;
  1759. }
  1760. }
  1761. if (! recheck)
  1762. break;
  1763. }
  1764. return handled;
  1765. }
  1766. /*****************************************************************************/
  1767. /*
  1768. * Interrupt service routine for ECH-8/64-PCI board types.
  1769. */
  1770. static int stl_echpci64intr(stlbrd_t *brdp)
  1771. {
  1772. stlpanel_t *panelp;
  1773. unsigned int ioaddr;
  1774. int bnknr;
  1775. int handled = 0;
  1776. while (inb(brdp->ioctrl) & 0x1) {
  1777. handled = 1;
  1778. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1779. ioaddr = brdp->bnkstataddr[bnknr];
  1780. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1781. panelp = brdp->bnk2panel[bnknr];
  1782. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1783. }
  1784. }
  1785. }
  1786. return handled;
  1787. }
  1788. /*****************************************************************************/
  1789. /*
  1790. * Service an off-level request for some channel.
  1791. */
  1792. static void stl_offintr(void *private)
  1793. {
  1794. stlport_t *portp;
  1795. struct tty_struct *tty;
  1796. unsigned int oldsigs;
  1797. portp = private;
  1798. #ifdef DEBUG
  1799. printk("stl_offintr(portp=%x)\n", (int) portp);
  1800. #endif
  1801. if (portp == (stlport_t *) NULL)
  1802. return;
  1803. tty = portp->tty;
  1804. if (tty == (struct tty_struct *) NULL)
  1805. return;
  1806. lock_kernel();
  1807. if (test_bit(ASYI_TXLOW, &portp->istate)) {
  1808. tty_wakeup(tty);
  1809. }
  1810. if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
  1811. clear_bit(ASYI_DCDCHANGE, &portp->istate);
  1812. oldsigs = portp->sigs;
  1813. portp->sigs = stl_getsignals(portp);
  1814. if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
  1815. wake_up_interruptible(&portp->open_wait);
  1816. if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
  1817. if (portp->flags & ASYNC_CHECK_CD)
  1818. tty_hangup(tty); /* FIXME: module removal race here - AKPM */
  1819. }
  1820. }
  1821. unlock_kernel();
  1822. }
  1823. /*****************************************************************************/
  1824. /*
  1825. * Initialize all the ports on a panel.
  1826. */
  1827. static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
  1828. {
  1829. stlport_t *portp;
  1830. int chipmask, i;
  1831. #ifdef DEBUG
  1832. printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
  1833. #endif
  1834. chipmask = stl_panelinit(brdp, panelp);
  1835. /*
  1836. * All UART's are initialized (if found!). Now go through and setup
  1837. * each ports data structures.
  1838. */
  1839. for (i = 0; (i < panelp->nrports); i++) {
  1840. portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
  1841. if (portp == (stlport_t *) NULL) {
  1842. printk("STALLION: failed to allocate memory "
  1843. "(size=%d)\n", sizeof(stlport_t));
  1844. break;
  1845. }
  1846. memset(portp, 0, sizeof(stlport_t));
  1847. portp->magic = STL_PORTMAGIC;
  1848. portp->portnr = i;
  1849. portp->brdnr = panelp->brdnr;
  1850. portp->panelnr = panelp->panelnr;
  1851. portp->uartp = panelp->uartp;
  1852. portp->clk = brdp->clk;
  1853. portp->baud_base = STL_BAUDBASE;
  1854. portp->close_delay = STL_CLOSEDELAY;
  1855. portp->closing_wait = 30 * HZ;
  1856. INIT_WORK(&portp->tqueue, stl_offintr, portp);
  1857. init_waitqueue_head(&portp->open_wait);
  1858. init_waitqueue_head(&portp->close_wait);
  1859. portp->stats.brd = portp->brdnr;
  1860. portp->stats.panel = portp->panelnr;
  1861. portp->stats.port = portp->portnr;
  1862. panelp->ports[i] = portp;
  1863. stl_portinit(brdp, panelp, portp);
  1864. }
  1865. return(0);
  1866. }
  1867. /*****************************************************************************/
  1868. /*
  1869. * Try to find and initialize an EasyIO board.
  1870. */
  1871. static inline int stl_initeio(stlbrd_t *brdp)
  1872. {
  1873. stlpanel_t *panelp;
  1874. unsigned int status;
  1875. char *name;
  1876. int rc;
  1877. #ifdef DEBUG
  1878. printk("stl_initeio(brdp=%x)\n", (int) brdp);
  1879. #endif
  1880. brdp->ioctrl = brdp->ioaddr1 + 1;
  1881. brdp->iostatus = brdp->ioaddr1 + 2;
  1882. status = inb(brdp->iostatus);
  1883. if ((status & EIO_IDBITMASK) == EIO_MK3)
  1884. brdp->ioctrl++;
  1885. /*
  1886. * Handle board specific stuff now. The real difference is PCI
  1887. * or not PCI.
  1888. */
  1889. if (brdp->brdtype == BRD_EASYIOPCI) {
  1890. brdp->iosize1 = 0x80;
  1891. brdp->iosize2 = 0x80;
  1892. name = "serial(EIO-PCI)";
  1893. outb(0x41, (brdp->ioaddr2 + 0x4c));
  1894. } else {
  1895. brdp->iosize1 = 8;
  1896. name = "serial(EIO)";
  1897. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1898. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1899. printk("STALLION: invalid irq=%d for brd=%d\n",
  1900. brdp->irq, brdp->brdnr);
  1901. return(-EINVAL);
  1902. }
  1903. outb((stl_vecmap[brdp->irq] | EIO_0WS |
  1904. ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
  1905. brdp->ioctrl);
  1906. }
  1907. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  1908. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  1909. "%x conflicts with another device\n", brdp->brdnr,
  1910. brdp->ioaddr1);
  1911. return(-EBUSY);
  1912. }
  1913. if (brdp->iosize2 > 0)
  1914. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  1915. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  1916. "address %x conflicts with another device\n",
  1917. brdp->brdnr, brdp->ioaddr2);
  1918. printk(KERN_WARNING "STALLION: Warning, also "
  1919. "releasing board %d I/O address %x \n",
  1920. brdp->brdnr, brdp->ioaddr1);
  1921. release_region(brdp->ioaddr1, brdp->iosize1);
  1922. return(-EBUSY);
  1923. }
  1924. /*
  1925. * Everything looks OK, so let's go ahead and probe for the hardware.
  1926. */
  1927. brdp->clk = CD1400_CLK;
  1928. brdp->isr = stl_eiointr;
  1929. switch (status & EIO_IDBITMASK) {
  1930. case EIO_8PORTM:
  1931. brdp->clk = CD1400_CLK8M;
  1932. /* fall thru */
  1933. case EIO_8PORTRS:
  1934. case EIO_8PORTDI:
  1935. brdp->nrports = 8;
  1936. break;
  1937. case EIO_4PORTRS:
  1938. brdp->nrports = 4;
  1939. break;
  1940. case EIO_MK3:
  1941. switch (status & EIO_BRDMASK) {
  1942. case ID_BRD4:
  1943. brdp->nrports = 4;
  1944. break;
  1945. case ID_BRD8:
  1946. brdp->nrports = 8;
  1947. break;
  1948. case ID_BRD16:
  1949. brdp->nrports = 16;
  1950. break;
  1951. default:
  1952. return(-ENODEV);
  1953. }
  1954. break;
  1955. default:
  1956. return(-ENODEV);
  1957. }
  1958. /*
  1959. * We have verified that the board is actually present, so now we
  1960. * can complete the setup.
  1961. */
  1962. panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
  1963. if (panelp == (stlpanel_t *) NULL) {
  1964. printk(KERN_WARNING "STALLION: failed to allocate memory "
  1965. "(size=%d)\n", sizeof(stlpanel_t));
  1966. return(-ENOMEM);
  1967. }
  1968. memset(panelp, 0, sizeof(stlpanel_t));
  1969. panelp->magic = STL_PANELMAGIC;
  1970. panelp->brdnr = brdp->brdnr;
  1971. panelp->panelnr = 0;
  1972. panelp->nrports = brdp->nrports;
  1973. panelp->iobase = brdp->ioaddr1;
  1974. panelp->hwid = status;
  1975. if ((status & EIO_IDBITMASK) == EIO_MK3) {
  1976. panelp->uartp = (void *) &stl_sc26198uart;
  1977. panelp->isr = stl_sc26198intr;
  1978. } else {
  1979. panelp->uartp = (void *) &stl_cd1400uart;
  1980. panelp->isr = stl_cd1400eiointr;
  1981. }
  1982. brdp->panels[0] = panelp;
  1983. brdp->nrpanels = 1;
  1984. brdp->state |= BRD_FOUND;
  1985. brdp->hwid = status;
  1986. if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
  1987. printk("STALLION: failed to register interrupt "
  1988. "routine for %s irq=%d\n", name, brdp->irq);
  1989. rc = -ENODEV;
  1990. } else {
  1991. rc = 0;
  1992. }
  1993. return(rc);
  1994. }
  1995. /*****************************************************************************/
  1996. /*
  1997. * Try to find an ECH board and initialize it. This code is capable of
  1998. * dealing with all types of ECH board.
  1999. */
  2000. static inline int stl_initech(stlbrd_t *brdp)
  2001. {
  2002. stlpanel_t *panelp;
  2003. unsigned int status, nxtid, ioaddr, conflict;
  2004. int panelnr, banknr, i;
  2005. char *name;
  2006. #ifdef DEBUG
  2007. printk("stl_initech(brdp=%x)\n", (int) brdp);
  2008. #endif
  2009. status = 0;
  2010. conflict = 0;
  2011. /*
  2012. * Set up the initial board register contents for boards. This varies a
  2013. * bit between the different board types. So we need to handle each
  2014. * separately. Also do a check that the supplied IRQ is good.
  2015. */
  2016. switch (brdp->brdtype) {
  2017. case BRD_ECH:
  2018. brdp->isr = stl_echatintr;
  2019. brdp->ioctrl = brdp->ioaddr1 + 1;
  2020. brdp->iostatus = brdp->ioaddr1 + 1;
  2021. status = inb(brdp->iostatus);
  2022. if ((status & ECH_IDBITMASK) != ECH_ID)
  2023. return(-ENODEV);
  2024. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  2025. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  2026. printk("STALLION: invalid irq=%d for brd=%d\n",
  2027. brdp->irq, brdp->brdnr);
  2028. return(-EINVAL);
  2029. }
  2030. status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
  2031. status |= (stl_vecmap[brdp->irq] << 1);
  2032. outb((status | ECH_BRDRESET), brdp->ioaddr1);
  2033. brdp->ioctrlval = ECH_INTENABLE |
  2034. ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
  2035. for (i = 0; (i < 10); i++)
  2036. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  2037. brdp->iosize1 = 2;
  2038. brdp->iosize2 = 32;
  2039. name = "serial(EC8/32)";
  2040. outb(status, brdp->ioaddr1);
  2041. break;
  2042. case BRD_ECHMC:
  2043. brdp->isr = stl_echmcaintr;
  2044. brdp->ioctrl = brdp->ioaddr1 + 0x20;
  2045. brdp->iostatus = brdp->ioctrl;
  2046. status = inb(brdp->iostatus);
  2047. if ((status & ECH_IDBITMASK) != ECH_ID)
  2048. return(-ENODEV);
  2049. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  2050. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  2051. printk("STALLION: invalid irq=%d for brd=%d\n",
  2052. brdp->irq, brdp->brdnr);
  2053. return(-EINVAL);
  2054. }
  2055. outb(ECHMC_BRDRESET, brdp->ioctrl);
  2056. outb(ECHMC_INTENABLE, brdp->ioctrl);
  2057. brdp->iosize1 = 64;
  2058. name = "serial(EC8/32-MC)";
  2059. break;
  2060. case BRD_ECHPCI:
  2061. brdp->isr = stl_echpciintr;
  2062. brdp->ioctrl = brdp->ioaddr1 + 2;
  2063. brdp->iosize1 = 4;
  2064. brdp->iosize2 = 8;
  2065. name = "serial(EC8/32-PCI)";
  2066. break;
  2067. case BRD_ECH64PCI:
  2068. brdp->isr = stl_echpci64intr;
  2069. brdp->ioctrl = brdp->ioaddr2 + 0x40;
  2070. outb(0x43, (brdp->ioaddr1 + 0x4c));
  2071. brdp->iosize1 = 0x80;
  2072. brdp->iosize2 = 0x80;
  2073. name = "serial(EC8/64-PCI)";
  2074. break;
  2075. default:
  2076. printk("STALLION: unknown board type=%d\n", brdp->brdtype);
  2077. return(-EINVAL);
  2078. break;
  2079. }
  2080. /*
  2081. * Check boards for possible IO address conflicts and return fail status
  2082. * if an IO conflict found.
  2083. */
  2084. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  2085. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  2086. "%x conflicts with another device\n", brdp->brdnr,
  2087. brdp->ioaddr1);
  2088. return(-EBUSY);
  2089. }
  2090. if (brdp->iosize2 > 0)
  2091. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  2092. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  2093. "address %x conflicts with another device\n",
  2094. brdp->brdnr, brdp->ioaddr2);
  2095. printk(KERN_WARNING "STALLION: Warning, also "
  2096. "releasing board %d I/O address %x \n",
  2097. brdp->brdnr, brdp->ioaddr1);
  2098. release_region(brdp->ioaddr1, brdp->iosize1);
  2099. return(-EBUSY);
  2100. }
  2101. /*
  2102. * Scan through the secondary io address space looking for panels.
  2103. * As we find'em allocate and initialize panel structures for each.
  2104. */
  2105. brdp->clk = CD1400_CLK;
  2106. brdp->hwid = status;
  2107. ioaddr = brdp->ioaddr2;
  2108. banknr = 0;
  2109. panelnr = 0;
  2110. nxtid = 0;
  2111. for (i = 0; (i < STL_MAXPANELS); i++) {
  2112. if (brdp->brdtype == BRD_ECHPCI) {
  2113. outb(nxtid, brdp->ioctrl);
  2114. ioaddr = brdp->ioaddr2;
  2115. }
  2116. status = inb(ioaddr + ECH_PNLSTATUS);
  2117. if ((status & ECH_PNLIDMASK) != nxtid)
  2118. break;
  2119. panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
  2120. if (panelp == (stlpanel_t *) NULL) {
  2121. printk("STALLION: failed to allocate memory "
  2122. "(size=%d)\n", sizeof(stlpanel_t));
  2123. break;
  2124. }
  2125. memset(panelp, 0, sizeof(stlpanel_t));
  2126. panelp->magic = STL_PANELMAGIC;
  2127. panelp->brdnr = brdp->brdnr;
  2128. panelp->panelnr = panelnr;
  2129. panelp->iobase = ioaddr;
  2130. panelp->pagenr = nxtid;
  2131. panelp->hwid = status;
  2132. brdp->bnk2panel[banknr] = panelp;
  2133. brdp->bnkpageaddr[banknr] = nxtid;
  2134. brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
  2135. if (status & ECH_PNLXPID) {
  2136. panelp->uartp = (void *) &stl_sc26198uart;
  2137. panelp->isr = stl_sc26198intr;
  2138. if (status & ECH_PNL16PORT) {
  2139. panelp->nrports = 16;
  2140. brdp->bnk2panel[banknr] = panelp;
  2141. brdp->bnkpageaddr[banknr] = nxtid;
  2142. brdp->bnkstataddr[banknr++] = ioaddr + 4 +
  2143. ECH_PNLSTATUS;
  2144. } else {
  2145. panelp->nrports = 8;
  2146. }
  2147. } else {
  2148. panelp->uartp = (void *) &stl_cd1400uart;
  2149. panelp->isr = stl_cd1400echintr;
  2150. if (status & ECH_PNL16PORT) {
  2151. panelp->nrports = 16;
  2152. panelp->ackmask = 0x80;
  2153. if (brdp->brdtype != BRD_ECHPCI)
  2154. ioaddr += EREG_BANKSIZE;
  2155. brdp->bnk2panel[banknr] = panelp;
  2156. brdp->bnkpageaddr[banknr] = ++nxtid;
  2157. brdp->bnkstataddr[banknr++] = ioaddr +
  2158. ECH_PNLSTATUS;
  2159. } else {
  2160. panelp->nrports = 8;
  2161. panelp->ackmask = 0xc0;
  2162. }
  2163. }
  2164. nxtid++;
  2165. ioaddr += EREG_BANKSIZE;
  2166. brdp->nrports += panelp->nrports;
  2167. brdp->panels[panelnr++] = panelp;
  2168. if ((brdp->brdtype != BRD_ECHPCI) &&
  2169. (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
  2170. break;
  2171. }
  2172. brdp->nrpanels = panelnr;
  2173. brdp->nrbnks = banknr;
  2174. if (brdp->brdtype == BRD_ECH)
  2175. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  2176. brdp->state |= BRD_FOUND;
  2177. if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
  2178. printk("STALLION: failed to register interrupt "
  2179. "routine for %s irq=%d\n", name, brdp->irq);
  2180. i = -ENODEV;
  2181. } else {
  2182. i = 0;
  2183. }
  2184. return(i);
  2185. }
  2186. /*****************************************************************************/
  2187. /*
  2188. * Initialize and configure the specified board.
  2189. * Scan through all the boards in the configuration and see what we
  2190. * can find. Handle EIO and the ECH boards a little differently here
  2191. * since the initial search and setup is very different.
  2192. */
  2193. static int __init stl_brdinit(stlbrd_t *brdp)
  2194. {
  2195. int i;
  2196. #ifdef DEBUG
  2197. printk("stl_brdinit(brdp=%x)\n", (int) brdp);
  2198. #endif
  2199. switch (brdp->brdtype) {
  2200. case BRD_EASYIO:
  2201. case BRD_EASYIOPCI:
  2202. stl_initeio(brdp);
  2203. break;
  2204. case BRD_ECH:
  2205. case BRD_ECHMC:
  2206. case BRD_ECHPCI:
  2207. case BRD_ECH64PCI:
  2208. stl_initech(brdp);
  2209. break;
  2210. default:
  2211. printk("STALLION: board=%d is unknown board type=%d\n",
  2212. brdp->brdnr, brdp->brdtype);
  2213. return(ENODEV);
  2214. }
  2215. stl_brds[brdp->brdnr] = brdp;
  2216. if ((brdp->state & BRD_FOUND) == 0) {
  2217. printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
  2218. stl_brdnames[brdp->brdtype], brdp->brdnr,
  2219. brdp->ioaddr1, brdp->irq);
  2220. return(ENODEV);
  2221. }
  2222. for (i = 0; (i < STL_MAXPANELS); i++)
  2223. if (brdp->panels[i] != (stlpanel_t *) NULL)
  2224. stl_initports(brdp, brdp->panels[i]);
  2225. printk("STALLION: %s found, board=%d io=%x irq=%d "
  2226. "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
  2227. brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
  2228. brdp->nrports);
  2229. return(0);
  2230. }
  2231. /*****************************************************************************/
  2232. /*
  2233. * Find the next available board number that is free.
  2234. */
  2235. static inline int stl_getbrdnr(void)
  2236. {
  2237. int i;
  2238. for (i = 0; (i < STL_MAXBRDS); i++) {
  2239. if (stl_brds[i] == (stlbrd_t *) NULL) {
  2240. if (i >= stl_nrbrds)
  2241. stl_nrbrds = i + 1;
  2242. return(i);
  2243. }
  2244. }
  2245. return(-1);
  2246. }
  2247. /*****************************************************************************/
  2248. #ifdef CONFIG_PCI
  2249. /*
  2250. * We have a Stallion board. Allocate a board structure and
  2251. * initialize it. Read its IO and IRQ resources from PCI
  2252. * configuration space.
  2253. */
  2254. static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
  2255. {
  2256. stlbrd_t *brdp;
  2257. #ifdef DEBUG
  2258. printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
  2259. devp->bus->number, devp->devfn);
  2260. #endif
  2261. if (pci_enable_device(devp))
  2262. return(-EIO);
  2263. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  2264. return(-ENOMEM);
  2265. if ((brdp->brdnr = stl_getbrdnr()) < 0) {
  2266. printk("STALLION: too many boards found, "
  2267. "maximum supported %d\n", STL_MAXBRDS);
  2268. return(0);
  2269. }
  2270. brdp->brdtype = brdtype;
  2271. /*
  2272. * Different Stallion boards use the BAR registers in different ways,
  2273. * so set up io addresses based on board type.
  2274. */
  2275. #ifdef DEBUG
  2276. printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
  2277. pci_resource_start(devp, 0), pci_resource_start(devp, 1),
  2278. pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
  2279. #endif
  2280. /*
  2281. * We have all resources from the board, so let's setup the actual
  2282. * board structure now.
  2283. */
  2284. switch (brdtype) {
  2285. case BRD_ECHPCI:
  2286. brdp->ioaddr2 = pci_resource_start(devp, 0);
  2287. brdp->ioaddr1 = pci_resource_start(devp, 1);
  2288. break;
  2289. case BRD_ECH64PCI:
  2290. brdp->ioaddr2 = pci_resource_start(devp, 2);
  2291. brdp->ioaddr1 = pci_resource_start(devp, 1);
  2292. break;
  2293. case BRD_EASYIOPCI:
  2294. brdp->ioaddr1 = pci_resource_start(devp, 2);
  2295. brdp->ioaddr2 = pci_resource_start(devp, 1);
  2296. break;
  2297. default:
  2298. printk("STALLION: unknown PCI board type=%d\n", brdtype);
  2299. break;
  2300. }
  2301. brdp->irq = devp->irq;
  2302. stl_brdinit(brdp);
  2303. return(0);
  2304. }
  2305. /*****************************************************************************/
  2306. /*
  2307. * Find all Stallion PCI boards that might be installed. Initialize each
  2308. * one as it is found.
  2309. */
  2310. static inline int stl_findpcibrds(void)
  2311. {
  2312. struct pci_dev *dev = NULL;
  2313. int i, rc;
  2314. #ifdef DEBUG
  2315. printk("stl_findpcibrds()\n");
  2316. #endif
  2317. for (i = 0; (i < stl_nrpcibrds); i++)
  2318. while ((dev = pci_find_device(stl_pcibrds[i].vendid,
  2319. stl_pcibrds[i].devid, dev))) {
  2320. /*
  2321. * Found a device on the PCI bus that has our vendor and
  2322. * device ID. Need to check now that it is really us.
  2323. */
  2324. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  2325. continue;
  2326. rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
  2327. if (rc)
  2328. return(rc);
  2329. }
  2330. return(0);
  2331. }
  2332. #endif
  2333. /*****************************************************************************/
  2334. /*
  2335. * Scan through all the boards in the configuration and see what we
  2336. * can find. Handle EIO and the ECH boards a little differently here
  2337. * since the initial search and setup is too different.
  2338. */
  2339. static inline int stl_initbrds(void)
  2340. {
  2341. stlbrd_t *brdp;
  2342. stlconf_t *confp;
  2343. int i;
  2344. #ifdef DEBUG
  2345. printk("stl_initbrds()\n");
  2346. #endif
  2347. if (stl_nrbrds > STL_MAXBRDS) {
  2348. printk("STALLION: too many boards in configuration table, "
  2349. "truncating to %d\n", STL_MAXBRDS);
  2350. stl_nrbrds = STL_MAXBRDS;
  2351. }
  2352. /*
  2353. * Firstly scan the list of static boards configured. Allocate
  2354. * resources and initialize the boards as found.
  2355. */
  2356. for (i = 0; (i < stl_nrbrds); i++) {
  2357. confp = &stl_brdconf[i];
  2358. stl_parsebrd(confp, stl_brdsp[i]);
  2359. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  2360. return(-ENOMEM);
  2361. brdp->brdnr = i;
  2362. brdp->brdtype = confp->brdtype;
  2363. brdp->ioaddr1 = confp->ioaddr1;
  2364. brdp->ioaddr2 = confp->ioaddr2;
  2365. brdp->irq = confp->irq;
  2366. brdp->irqtype = confp->irqtype;
  2367. stl_brdinit(brdp);
  2368. }
  2369. /*
  2370. * Find any dynamically supported boards. That is via module load
  2371. * line options or auto-detected on the PCI bus.
  2372. */
  2373. stl_argbrds();
  2374. #ifdef CONFIG_PCI
  2375. stl_findpcibrds();
  2376. #endif
  2377. return(0);
  2378. }
  2379. /*****************************************************************************/
  2380. /*
  2381. * Return the board stats structure to user app.
  2382. */
  2383. static int stl_getbrdstats(combrd_t __user *bp)
  2384. {
  2385. stlbrd_t *brdp;
  2386. stlpanel_t *panelp;
  2387. int i;
  2388. if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
  2389. return -EFAULT;
  2390. if (stl_brdstats.brd >= STL_MAXBRDS)
  2391. return(-ENODEV);
  2392. brdp = stl_brds[stl_brdstats.brd];
  2393. if (brdp == (stlbrd_t *) NULL)
  2394. return(-ENODEV);
  2395. memset(&stl_brdstats, 0, sizeof(combrd_t));
  2396. stl_brdstats.brd = brdp->brdnr;
  2397. stl_brdstats.type = brdp->brdtype;
  2398. stl_brdstats.hwid = brdp->hwid;
  2399. stl_brdstats.state = brdp->state;
  2400. stl_brdstats.ioaddr = brdp->ioaddr1;
  2401. stl_brdstats.ioaddr2 = brdp->ioaddr2;
  2402. stl_brdstats.irq = brdp->irq;
  2403. stl_brdstats.nrpanels = brdp->nrpanels;
  2404. stl_brdstats.nrports = brdp->nrports;
  2405. for (i = 0; (i < brdp->nrpanels); i++) {
  2406. panelp = brdp->panels[i];
  2407. stl_brdstats.panels[i].panel = i;
  2408. stl_brdstats.panels[i].hwid = panelp->hwid;
  2409. stl_brdstats.panels[i].nrports = panelp->nrports;
  2410. }
  2411. return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
  2412. }
  2413. /*****************************************************************************/
  2414. /*
  2415. * Resolve the referenced port number into a port struct pointer.
  2416. */
  2417. static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
  2418. {
  2419. stlbrd_t *brdp;
  2420. stlpanel_t *panelp;
  2421. if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
  2422. return((stlport_t *) NULL);
  2423. brdp = stl_brds[brdnr];
  2424. if (brdp == (stlbrd_t *) NULL)
  2425. return((stlport_t *) NULL);
  2426. if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
  2427. return((stlport_t *) NULL);
  2428. panelp = brdp->panels[panelnr];
  2429. if (panelp == (stlpanel_t *) NULL)
  2430. return((stlport_t *) NULL);
  2431. if ((portnr < 0) || (portnr >= panelp->nrports))
  2432. return((stlport_t *) NULL);
  2433. return(panelp->ports[portnr]);
  2434. }
  2435. /*****************************************************************************/
  2436. /*
  2437. * Return the port stats structure to user app. A NULL port struct
  2438. * pointer passed in means that we need to find out from the app
  2439. * what port to get stats for (used through board control device).
  2440. */
  2441. static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
  2442. {
  2443. unsigned char *head, *tail;
  2444. unsigned long flags;
  2445. if (!portp) {
  2446. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2447. return -EFAULT;
  2448. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2449. stl_comstats.port);
  2450. if (portp == (stlport_t *) NULL)
  2451. return(-ENODEV);
  2452. }
  2453. portp->stats.state = portp->istate;
  2454. portp->stats.flags = portp->flags;
  2455. portp->stats.hwid = portp->hwid;
  2456. portp->stats.ttystate = 0;
  2457. portp->stats.cflags = 0;
  2458. portp->stats.iflags = 0;
  2459. portp->stats.oflags = 0;
  2460. portp->stats.lflags = 0;
  2461. portp->stats.rxbuffered = 0;
  2462. save_flags(flags);
  2463. cli();
  2464. if (portp->tty != (struct tty_struct *) NULL) {
  2465. if (portp->tty->driver_data == portp) {
  2466. portp->stats.ttystate = portp->tty->flags;
  2467. portp->stats.rxbuffered = portp->tty->flip.count;
  2468. if (portp->tty->termios != (struct termios *) NULL) {
  2469. portp->stats.cflags = portp->tty->termios->c_cflag;
  2470. portp->stats.iflags = portp->tty->termios->c_iflag;
  2471. portp->stats.oflags = portp->tty->termios->c_oflag;
  2472. portp->stats.lflags = portp->tty->termios->c_lflag;
  2473. }
  2474. }
  2475. }
  2476. restore_flags(flags);
  2477. head = portp->tx.head;
  2478. tail = portp->tx.tail;
  2479. portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
  2480. (STL_TXBUFSIZE - (tail - head)));
  2481. portp->stats.signals = (unsigned long) stl_getsignals(portp);
  2482. return copy_to_user(cp, &portp->stats,
  2483. sizeof(comstats_t)) ? -EFAULT : 0;
  2484. }
  2485. /*****************************************************************************/
  2486. /*
  2487. * Clear the port stats structure. We also return it zeroed out...
  2488. */
  2489. static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
  2490. {
  2491. if (!portp) {
  2492. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2493. return -EFAULT;
  2494. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2495. stl_comstats.port);
  2496. if (portp == (stlport_t *) NULL)
  2497. return(-ENODEV);
  2498. }
  2499. memset(&portp->stats, 0, sizeof(comstats_t));
  2500. portp->stats.brd = portp->brdnr;
  2501. portp->stats.panel = portp->panelnr;
  2502. portp->stats.port = portp->portnr;
  2503. return copy_to_user(cp, &portp->stats,
  2504. sizeof(comstats_t)) ? -EFAULT : 0;
  2505. }
  2506. /*****************************************************************************/
  2507. /*
  2508. * Return the entire driver ports structure to a user app.
  2509. */
  2510. static int stl_getportstruct(stlport_t __user *arg)
  2511. {
  2512. stlport_t *portp;
  2513. if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
  2514. return -EFAULT;
  2515. portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
  2516. stl_dummyport.portnr);
  2517. if (!portp)
  2518. return -ENODEV;
  2519. return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
  2520. }
  2521. /*****************************************************************************/
  2522. /*
  2523. * Return the entire driver board structure to a user app.
  2524. */
  2525. static int stl_getbrdstruct(stlbrd_t __user *arg)
  2526. {
  2527. stlbrd_t *brdp;
  2528. if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
  2529. return -EFAULT;
  2530. if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
  2531. return -ENODEV;
  2532. brdp = stl_brds[stl_dummybrd.brdnr];
  2533. if (!brdp)
  2534. return(-ENODEV);
  2535. return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
  2536. }
  2537. /*****************************************************************************/
  2538. /*
  2539. * The "staliomem" device is also required to do some special operations
  2540. * on the board and/or ports. In this driver it is mostly used for stats
  2541. * collection.
  2542. */
  2543. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  2544. {
  2545. int brdnr, rc;
  2546. void __user *argp = (void __user *)arg;
  2547. #ifdef DEBUG
  2548. printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
  2549. (int) fp, cmd, (int) arg);
  2550. #endif
  2551. brdnr = iminor(ip);
  2552. if (brdnr >= STL_MAXBRDS)
  2553. return(-ENODEV);
  2554. rc = 0;
  2555. switch (cmd) {
  2556. case COM_GETPORTSTATS:
  2557. rc = stl_getportstats(NULL, argp);
  2558. break;
  2559. case COM_CLRPORTSTATS:
  2560. rc = stl_clrportstats(NULL, argp);
  2561. break;
  2562. case COM_GETBRDSTATS:
  2563. rc = stl_getbrdstats(argp);
  2564. break;
  2565. case COM_READPORT:
  2566. rc = stl_getportstruct(argp);
  2567. break;
  2568. case COM_READBOARD:
  2569. rc = stl_getbrdstruct(argp);
  2570. break;
  2571. default:
  2572. rc = -ENOIOCTLCMD;
  2573. break;
  2574. }
  2575. return(rc);
  2576. }
  2577. static struct tty_operations stl_ops = {
  2578. .open = stl_open,
  2579. .close = stl_close,
  2580. .write = stl_write,
  2581. .put_char = stl_putchar,
  2582. .flush_chars = stl_flushchars,
  2583. .write_room = stl_writeroom,
  2584. .chars_in_buffer = stl_charsinbuffer,
  2585. .ioctl = stl_ioctl,
  2586. .set_termios = stl_settermios,
  2587. .throttle = stl_throttle,
  2588. .unthrottle = stl_unthrottle,
  2589. .stop = stl_stop,
  2590. .start = stl_start,
  2591. .hangup = stl_hangup,
  2592. .flush_buffer = stl_flushbuffer,
  2593. .break_ctl = stl_breakctl,
  2594. .wait_until_sent = stl_waituntilsent,
  2595. .send_xchar = stl_sendxchar,
  2596. .read_proc = stl_readproc,
  2597. .tiocmget = stl_tiocmget,
  2598. .tiocmset = stl_tiocmset,
  2599. };
  2600. /*****************************************************************************/
  2601. int __init stl_init(void)
  2602. {
  2603. int i;
  2604. printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
  2605. stl_initbrds();
  2606. stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  2607. if (!stl_serial)
  2608. return -1;
  2609. /*
  2610. * Allocate a temporary write buffer.
  2611. */
  2612. stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
  2613. if (stl_tmpwritebuf == (char *) NULL)
  2614. printk("STALLION: failed to allocate memory (size=%d)\n",
  2615. STL_TXBUFSIZE);
  2616. /*
  2617. * Set up a character driver for per board stuff. This is mainly used
  2618. * to do stats ioctls on the ports.
  2619. */
  2620. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
  2621. printk("STALLION: failed to register serial board device\n");
  2622. devfs_mk_dir("staliomem");
  2623. stallion_class = class_simple_create(THIS_MODULE, "staliomem");
  2624. for (i = 0; i < 4; i++) {
  2625. devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
  2626. S_IFCHR|S_IRUSR|S_IWUSR,
  2627. "staliomem/%d", i);
  2628. class_simple_device_add(stallion_class, MKDEV(STL_SIOMEMMAJOR, i), NULL, "staliomem%d", i);
  2629. }
  2630. stl_serial->owner = THIS_MODULE;
  2631. stl_serial->driver_name = stl_drvname;
  2632. stl_serial->name = "ttyE";
  2633. stl_serial->devfs_name = "tts/E";
  2634. stl_serial->major = STL_SERIALMAJOR;
  2635. stl_serial->minor_start = 0;
  2636. stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
  2637. stl_serial->subtype = SERIAL_TYPE_NORMAL;
  2638. stl_serial->init_termios = stl_deftermios;
  2639. stl_serial->flags = TTY_DRIVER_REAL_RAW;
  2640. tty_set_operations(stl_serial, &stl_ops);
  2641. if (tty_register_driver(stl_serial)) {
  2642. put_tty_driver(stl_serial);
  2643. printk("STALLION: failed to register serial driver\n");
  2644. return -1;
  2645. }
  2646. return(0);
  2647. }
  2648. /*****************************************************************************/
  2649. /* CD1400 HARDWARE FUNCTIONS */
  2650. /*****************************************************************************/
  2651. /*
  2652. * These functions get/set/update the registers of the cd1400 UARTs.
  2653. * Access to the cd1400 registers is via an address/data io port pair.
  2654. * (Maybe should make this inline...)
  2655. */
  2656. static int stl_cd1400getreg(stlport_t *portp, int regnr)
  2657. {
  2658. outb((regnr + portp->uartaddr), portp->ioaddr);
  2659. return(inb(portp->ioaddr + EREG_DATA));
  2660. }
  2661. static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
  2662. {
  2663. outb((regnr + portp->uartaddr), portp->ioaddr);
  2664. outb(value, portp->ioaddr + EREG_DATA);
  2665. }
  2666. static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
  2667. {
  2668. outb((regnr + portp->uartaddr), portp->ioaddr);
  2669. if (inb(portp->ioaddr + EREG_DATA) != value) {
  2670. outb(value, portp->ioaddr + EREG_DATA);
  2671. return(1);
  2672. }
  2673. return(0);
  2674. }
  2675. /*****************************************************************************/
  2676. /*
  2677. * Inbitialize the UARTs in a panel. We don't care what sort of board
  2678. * these ports are on - since the port io registers are almost
  2679. * identical when dealing with ports.
  2680. */
  2681. static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
  2682. {
  2683. unsigned int gfrcr;
  2684. int chipmask, i, j;
  2685. int nrchips, uartaddr, ioaddr;
  2686. #ifdef DEBUG
  2687. printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
  2688. #endif
  2689. BRDENABLE(panelp->brdnr, panelp->pagenr);
  2690. /*
  2691. * Check that each chip is present and started up OK.
  2692. */
  2693. chipmask = 0;
  2694. nrchips = panelp->nrports / CD1400_PORTS;
  2695. for (i = 0; (i < nrchips); i++) {
  2696. if (brdp->brdtype == BRD_ECHPCI) {
  2697. outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
  2698. ioaddr = panelp->iobase;
  2699. } else {
  2700. ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
  2701. }
  2702. uartaddr = (i & 0x01) ? 0x080 : 0;
  2703. outb((GFRCR + uartaddr), ioaddr);
  2704. outb(0, (ioaddr + EREG_DATA));
  2705. outb((CCR + uartaddr), ioaddr);
  2706. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2707. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2708. outb((GFRCR + uartaddr), ioaddr);
  2709. for (j = 0; (j < CCR_MAXWAIT); j++) {
  2710. if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
  2711. break;
  2712. }
  2713. if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
  2714. printk("STALLION: cd1400 not responding, "
  2715. "brd=%d panel=%d chip=%d\n",
  2716. panelp->brdnr, panelp->panelnr, i);
  2717. continue;
  2718. }
  2719. chipmask |= (0x1 << i);
  2720. outb((PPR + uartaddr), ioaddr);
  2721. outb(PPR_SCALAR, (ioaddr + EREG_DATA));
  2722. }
  2723. BRDDISABLE(panelp->brdnr);
  2724. return(chipmask);
  2725. }
  2726. /*****************************************************************************/
  2727. /*
  2728. * Initialize hardware specific port registers.
  2729. */
  2730. static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
  2731. {
  2732. #ifdef DEBUG
  2733. printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
  2734. (int) brdp, (int) panelp, (int) portp);
  2735. #endif
  2736. if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
  2737. (portp == (stlport_t *) NULL))
  2738. return;
  2739. portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
  2740. (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
  2741. portp->uartaddr = (portp->portnr & 0x04) << 5;
  2742. portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
  2743. BRDENABLE(portp->brdnr, portp->pagenr);
  2744. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2745. stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
  2746. portp->hwid = stl_cd1400getreg(portp, GFRCR);
  2747. BRDDISABLE(portp->brdnr);
  2748. }
  2749. /*****************************************************************************/
  2750. /*
  2751. * Wait for the command register to be ready. We will poll this,
  2752. * since it won't usually take too long to be ready.
  2753. */
  2754. static void stl_cd1400ccrwait(stlport_t *portp)
  2755. {
  2756. int i;
  2757. for (i = 0; (i < CCR_MAXWAIT); i++) {
  2758. if (stl_cd1400getreg(portp, CCR) == 0) {
  2759. return;
  2760. }
  2761. }
  2762. printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
  2763. portp->portnr, portp->panelnr, portp->brdnr);
  2764. }
  2765. /*****************************************************************************/
  2766. /*
  2767. * Set up the cd1400 registers for a port based on the termios port
  2768. * settings.
  2769. */
  2770. static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
  2771. {
  2772. stlbrd_t *brdp;
  2773. unsigned long flags;
  2774. unsigned int clkdiv, baudrate;
  2775. unsigned char cor1, cor2, cor3;
  2776. unsigned char cor4, cor5, ccr;
  2777. unsigned char srer, sreron, sreroff;
  2778. unsigned char mcor1, mcor2, rtpr;
  2779. unsigned char clk, div;
  2780. cor1 = 0;
  2781. cor2 = 0;
  2782. cor3 = 0;
  2783. cor4 = 0;
  2784. cor5 = 0;
  2785. ccr = 0;
  2786. rtpr = 0;
  2787. clk = 0;
  2788. div = 0;
  2789. mcor1 = 0;
  2790. mcor2 = 0;
  2791. sreron = 0;
  2792. sreroff = 0;
  2793. brdp = stl_brds[portp->brdnr];
  2794. if (brdp == (stlbrd_t *) NULL)
  2795. return;
  2796. /*
  2797. * Set up the RX char ignore mask with those RX error types we
  2798. * can ignore. We can get the cd1400 to help us out a little here,
  2799. * it will ignore parity errors and breaks for us.
  2800. */
  2801. portp->rxignoremsk = 0;
  2802. if (tiosp->c_iflag & IGNPAR) {
  2803. portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
  2804. cor1 |= COR1_PARIGNORE;
  2805. }
  2806. if (tiosp->c_iflag & IGNBRK) {
  2807. portp->rxignoremsk |= ST_BREAK;
  2808. cor4 |= COR4_IGNBRK;
  2809. }
  2810. portp->rxmarkmsk = ST_OVERRUN;
  2811. if (tiosp->c_iflag & (INPCK | PARMRK))
  2812. portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
  2813. if (tiosp->c_iflag & BRKINT)
  2814. portp->rxmarkmsk |= ST_BREAK;
  2815. /*
  2816. * Go through the char size, parity and stop bits and set all the
  2817. * option register appropriately.
  2818. */
  2819. switch (tiosp->c_cflag & CSIZE) {
  2820. case CS5:
  2821. cor1 |= COR1_CHL5;
  2822. break;
  2823. case CS6:
  2824. cor1 |= COR1_CHL6;
  2825. break;
  2826. case CS7:
  2827. cor1 |= COR1_CHL7;
  2828. break;
  2829. default:
  2830. cor1 |= COR1_CHL8;
  2831. break;
  2832. }
  2833. if (tiosp->c_cflag & CSTOPB)
  2834. cor1 |= COR1_STOP2;
  2835. else
  2836. cor1 |= COR1_STOP1;
  2837. if (tiosp->c_cflag & PARENB) {
  2838. if (tiosp->c_cflag & PARODD)
  2839. cor1 |= (COR1_PARENB | COR1_PARODD);
  2840. else
  2841. cor1 |= (COR1_PARENB | COR1_PAREVEN);
  2842. } else {
  2843. cor1 |= COR1_PARNONE;
  2844. }
  2845. /*
  2846. * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
  2847. * space for hardware flow control and the like. This should be set to
  2848. * VMIN. Also here we will set the RX data timeout to 10ms - this should
  2849. * really be based on VTIME.
  2850. */
  2851. cor3 |= FIFO_RXTHRESHOLD;
  2852. rtpr = 2;
  2853. /*
  2854. * Calculate the baud rate timers. For now we will just assume that
  2855. * the input and output baud are the same. Could have used a baud
  2856. * table here, but this way we can generate virtually any baud rate
  2857. * we like!
  2858. */
  2859. baudrate = tiosp->c_cflag & CBAUD;
  2860. if (baudrate & CBAUDEX) {
  2861. baudrate &= ~CBAUDEX;
  2862. if ((baudrate < 1) || (baudrate > 4))
  2863. tiosp->c_cflag &= ~CBAUDEX;
  2864. else
  2865. baudrate += 15;
  2866. }
  2867. baudrate = stl_baudrates[baudrate];
  2868. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2869. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2870. baudrate = 57600;
  2871. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2872. baudrate = 115200;
  2873. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2874. baudrate = 230400;
  2875. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2876. baudrate = 460800;
  2877. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2878. baudrate = (portp->baud_base / portp->custom_divisor);
  2879. }
  2880. if (baudrate > STL_CD1400MAXBAUD)
  2881. baudrate = STL_CD1400MAXBAUD;
  2882. if (baudrate > 0) {
  2883. for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
  2884. clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
  2885. if (clkdiv < 0x100)
  2886. break;
  2887. }
  2888. div = (unsigned char) clkdiv;
  2889. }
  2890. /*
  2891. * Check what form of modem signaling is required and set it up.
  2892. */
  2893. if ((tiosp->c_cflag & CLOCAL) == 0) {
  2894. mcor1 |= MCOR1_DCD;
  2895. mcor2 |= MCOR2_DCD;
  2896. sreron |= SRER_MODEM;
  2897. portp->flags |= ASYNC_CHECK_CD;
  2898. } else {
  2899. portp->flags &= ~ASYNC_CHECK_CD;
  2900. }
  2901. /*
  2902. * Setup cd1400 enhanced modes if we can. In particular we want to
  2903. * handle as much of the flow control as possible automatically. As
  2904. * well as saving a few CPU cycles it will also greatly improve flow
  2905. * control reliability.
  2906. */
  2907. if (tiosp->c_iflag & IXON) {
  2908. cor2 |= COR2_TXIBE;
  2909. cor3 |= COR3_SCD12;
  2910. if (tiosp->c_iflag & IXANY)
  2911. cor2 |= COR2_IXM;
  2912. }
  2913. if (tiosp->c_cflag & CRTSCTS) {
  2914. cor2 |= COR2_CTSAE;
  2915. mcor1 |= FIFO_RTSTHRESHOLD;
  2916. }
  2917. /*
  2918. * All cd1400 register values calculated so go through and set
  2919. * them all up.
  2920. */
  2921. #ifdef DEBUG
  2922. printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  2923. portp->portnr, portp->panelnr, portp->brdnr);
  2924. printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
  2925. cor1, cor2, cor3, cor4, cor5);
  2926. printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
  2927. mcor1, mcor2, rtpr, sreron, sreroff);
  2928. printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
  2929. printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  2930. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  2931. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  2932. #endif
  2933. save_flags(flags);
  2934. cli();
  2935. BRDENABLE(portp->brdnr, portp->pagenr);
  2936. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
  2937. srer = stl_cd1400getreg(portp, SRER);
  2938. stl_cd1400setreg(portp, SRER, 0);
  2939. if (stl_cd1400updatereg(portp, COR1, cor1))
  2940. ccr = 1;
  2941. if (stl_cd1400updatereg(portp, COR2, cor2))
  2942. ccr = 1;
  2943. if (stl_cd1400updatereg(portp, COR3, cor3))
  2944. ccr = 1;
  2945. if (ccr) {
  2946. stl_cd1400ccrwait(portp);
  2947. stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
  2948. }
  2949. stl_cd1400setreg(portp, COR4, cor4);
  2950. stl_cd1400setreg(portp, COR5, cor5);
  2951. stl_cd1400setreg(portp, MCOR1, mcor1);
  2952. stl_cd1400setreg(portp, MCOR2, mcor2);
  2953. if (baudrate > 0) {
  2954. stl_cd1400setreg(portp, TCOR, clk);
  2955. stl_cd1400setreg(portp, TBPR, div);
  2956. stl_cd1400setreg(portp, RCOR, clk);
  2957. stl_cd1400setreg(portp, RBPR, div);
  2958. }
  2959. stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
  2960. stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
  2961. stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
  2962. stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
  2963. stl_cd1400setreg(portp, RTPR, rtpr);
  2964. mcor1 = stl_cd1400getreg(portp, MSVR1);
  2965. if (mcor1 & MSVR1_DCD)
  2966. portp->sigs |= TIOCM_CD;
  2967. else
  2968. portp->sigs &= ~TIOCM_CD;
  2969. stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
  2970. BRDDISABLE(portp->brdnr);
  2971. restore_flags(flags);
  2972. }
  2973. /*****************************************************************************/
  2974. /*
  2975. * Set the state of the DTR and RTS signals.
  2976. */
  2977. static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
  2978. {
  2979. unsigned char msvr1, msvr2;
  2980. unsigned long flags;
  2981. #ifdef DEBUG
  2982. printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
  2983. (int) portp, dtr, rts);
  2984. #endif
  2985. msvr1 = 0;
  2986. msvr2 = 0;
  2987. if (dtr > 0)
  2988. msvr1 = MSVR1_DTR;
  2989. if (rts > 0)
  2990. msvr2 = MSVR2_RTS;
  2991. save_flags(flags);
  2992. cli();
  2993. BRDENABLE(portp->brdnr, portp->pagenr);
  2994. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2995. if (rts >= 0)
  2996. stl_cd1400setreg(portp, MSVR2, msvr2);
  2997. if (dtr >= 0)
  2998. stl_cd1400setreg(portp, MSVR1, msvr1);
  2999. BRDDISABLE(portp->brdnr);
  3000. restore_flags(flags);
  3001. }
  3002. /*****************************************************************************/
  3003. /*
  3004. * Return the state of the signals.
  3005. */
  3006. static int stl_cd1400getsignals(stlport_t *portp)
  3007. {
  3008. unsigned char msvr1, msvr2;
  3009. unsigned long flags;
  3010. int sigs;
  3011. #ifdef DEBUG
  3012. printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
  3013. #endif
  3014. save_flags(flags);
  3015. cli();
  3016. BRDENABLE(portp->brdnr, portp->pagenr);
  3017. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3018. msvr1 = stl_cd1400getreg(portp, MSVR1);
  3019. msvr2 = stl_cd1400getreg(portp, MSVR2);
  3020. BRDDISABLE(portp->brdnr);
  3021. restore_flags(flags);
  3022. sigs = 0;
  3023. sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
  3024. sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
  3025. sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
  3026. sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
  3027. #if 0
  3028. sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
  3029. sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
  3030. #else
  3031. sigs |= TIOCM_DSR;
  3032. #endif
  3033. return(sigs);
  3034. }
  3035. /*****************************************************************************/
  3036. /*
  3037. * Enable/Disable the Transmitter and/or Receiver.
  3038. */
  3039. static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
  3040. {
  3041. unsigned char ccr;
  3042. unsigned long flags;
  3043. #ifdef DEBUG
  3044. printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
  3045. (int) portp, rx, tx);
  3046. #endif
  3047. ccr = 0;
  3048. if (tx == 0)
  3049. ccr |= CCR_TXDISABLE;
  3050. else if (tx > 0)
  3051. ccr |= CCR_TXENABLE;
  3052. if (rx == 0)
  3053. ccr |= CCR_RXDISABLE;
  3054. else if (rx > 0)
  3055. ccr |= CCR_RXENABLE;
  3056. save_flags(flags);
  3057. cli();
  3058. BRDENABLE(portp->brdnr, portp->pagenr);
  3059. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3060. stl_cd1400ccrwait(portp);
  3061. stl_cd1400setreg(portp, CCR, ccr);
  3062. stl_cd1400ccrwait(portp);
  3063. BRDDISABLE(portp->brdnr);
  3064. restore_flags(flags);
  3065. }
  3066. /*****************************************************************************/
  3067. /*
  3068. * Start/stop the Transmitter and/or Receiver.
  3069. */
  3070. static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
  3071. {
  3072. unsigned char sreron, sreroff;
  3073. unsigned long flags;
  3074. #ifdef DEBUG
  3075. printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
  3076. (int) portp, rx, tx);
  3077. #endif
  3078. sreron = 0;
  3079. sreroff = 0;
  3080. if (tx == 0)
  3081. sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
  3082. else if (tx == 1)
  3083. sreron |= SRER_TXDATA;
  3084. else if (tx >= 2)
  3085. sreron |= SRER_TXEMPTY;
  3086. if (rx == 0)
  3087. sreroff |= SRER_RXDATA;
  3088. else if (rx > 0)
  3089. sreron |= SRER_RXDATA;
  3090. save_flags(flags);
  3091. cli();
  3092. BRDENABLE(portp->brdnr, portp->pagenr);
  3093. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3094. stl_cd1400setreg(portp, SRER,
  3095. ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
  3096. BRDDISABLE(portp->brdnr);
  3097. if (tx > 0)
  3098. set_bit(ASYI_TXBUSY, &portp->istate);
  3099. restore_flags(flags);
  3100. }
  3101. /*****************************************************************************/
  3102. /*
  3103. * Disable all interrupts from this port.
  3104. */
  3105. static void stl_cd1400disableintrs(stlport_t *portp)
  3106. {
  3107. unsigned long flags;
  3108. #ifdef DEBUG
  3109. printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
  3110. #endif
  3111. save_flags(flags);
  3112. cli();
  3113. BRDENABLE(portp->brdnr, portp->pagenr);
  3114. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3115. stl_cd1400setreg(portp, SRER, 0);
  3116. BRDDISABLE(portp->brdnr);
  3117. restore_flags(flags);
  3118. }
  3119. /*****************************************************************************/
  3120. static void stl_cd1400sendbreak(stlport_t *portp, int len)
  3121. {
  3122. unsigned long flags;
  3123. #ifdef DEBUG
  3124. printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
  3125. #endif
  3126. save_flags(flags);
  3127. cli();
  3128. BRDENABLE(portp->brdnr, portp->pagenr);
  3129. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3130. stl_cd1400setreg(portp, SRER,
  3131. ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
  3132. SRER_TXEMPTY));
  3133. BRDDISABLE(portp->brdnr);
  3134. portp->brklen = len;
  3135. if (len == 1)
  3136. portp->stats.txbreaks++;
  3137. restore_flags(flags);
  3138. }
  3139. /*****************************************************************************/
  3140. /*
  3141. * Take flow control actions...
  3142. */
  3143. static void stl_cd1400flowctrl(stlport_t *portp, int state)
  3144. {
  3145. struct tty_struct *tty;
  3146. unsigned long flags;
  3147. #ifdef DEBUG
  3148. printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
  3149. #endif
  3150. if (portp == (stlport_t *) NULL)
  3151. return;
  3152. tty = portp->tty;
  3153. if (tty == (struct tty_struct *) NULL)
  3154. return;
  3155. save_flags(flags);
  3156. cli();
  3157. BRDENABLE(portp->brdnr, portp->pagenr);
  3158. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3159. if (state) {
  3160. if (tty->termios->c_iflag & IXOFF) {
  3161. stl_cd1400ccrwait(portp);
  3162. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  3163. portp->stats.rxxon++;
  3164. stl_cd1400ccrwait(portp);
  3165. }
  3166. /*
  3167. * Question: should we return RTS to what it was before? It may
  3168. * have been set by an ioctl... Suppose not, since if you have
  3169. * hardware flow control set then it is pretty silly to go and
  3170. * set the RTS line by hand.
  3171. */
  3172. if (tty->termios->c_cflag & CRTSCTS) {
  3173. stl_cd1400setreg(portp, MCOR1,
  3174. (stl_cd1400getreg(portp, MCOR1) |
  3175. FIFO_RTSTHRESHOLD));
  3176. stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
  3177. portp->stats.rxrtson++;
  3178. }
  3179. } else {
  3180. if (tty->termios->c_iflag & IXOFF) {
  3181. stl_cd1400ccrwait(portp);
  3182. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  3183. portp->stats.rxxoff++;
  3184. stl_cd1400ccrwait(portp);
  3185. }
  3186. if (tty->termios->c_cflag & CRTSCTS) {
  3187. stl_cd1400setreg(portp, MCOR1,
  3188. (stl_cd1400getreg(portp, MCOR1) & 0xf0));
  3189. stl_cd1400setreg(portp, MSVR2, 0);
  3190. portp->stats.rxrtsoff++;
  3191. }
  3192. }
  3193. BRDDISABLE(portp->brdnr);
  3194. restore_flags(flags);
  3195. }
  3196. /*****************************************************************************/
  3197. /*
  3198. * Send a flow control character...
  3199. */
  3200. static void stl_cd1400sendflow(stlport_t *portp, int state)
  3201. {
  3202. struct tty_struct *tty;
  3203. unsigned long flags;
  3204. #ifdef DEBUG
  3205. printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
  3206. #endif
  3207. if (portp == (stlport_t *) NULL)
  3208. return;
  3209. tty = portp->tty;
  3210. if (tty == (struct tty_struct *) NULL)
  3211. return;
  3212. save_flags(flags);
  3213. cli();
  3214. BRDENABLE(portp->brdnr, portp->pagenr);
  3215. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3216. if (state) {
  3217. stl_cd1400ccrwait(portp);
  3218. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  3219. portp->stats.rxxon++;
  3220. stl_cd1400ccrwait(portp);
  3221. } else {
  3222. stl_cd1400ccrwait(portp);
  3223. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  3224. portp->stats.rxxoff++;
  3225. stl_cd1400ccrwait(portp);
  3226. }
  3227. BRDDISABLE(portp->brdnr);
  3228. restore_flags(flags);
  3229. }
  3230. /*****************************************************************************/
  3231. static void stl_cd1400flush(stlport_t *portp)
  3232. {
  3233. unsigned long flags;
  3234. #ifdef DEBUG
  3235. printk("stl_cd1400flush(portp=%x)\n", (int) portp);
  3236. #endif
  3237. if (portp == (stlport_t *) NULL)
  3238. return;
  3239. save_flags(flags);
  3240. cli();
  3241. BRDENABLE(portp->brdnr, portp->pagenr);
  3242. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3243. stl_cd1400ccrwait(portp);
  3244. stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
  3245. stl_cd1400ccrwait(portp);
  3246. portp->tx.tail = portp->tx.head;
  3247. BRDDISABLE(portp->brdnr);
  3248. restore_flags(flags);
  3249. }
  3250. /*****************************************************************************/
  3251. /*
  3252. * Return the current state of data flow on this port. This is only
  3253. * really interresting when determining if data has fully completed
  3254. * transmission or not... This is easy for the cd1400, it accurately
  3255. * maintains the busy port flag.
  3256. */
  3257. static int stl_cd1400datastate(stlport_t *portp)
  3258. {
  3259. #ifdef DEBUG
  3260. printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
  3261. #endif
  3262. if (portp == (stlport_t *) NULL)
  3263. return(0);
  3264. return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
  3265. }
  3266. /*****************************************************************************/
  3267. /*
  3268. * Interrupt service routine for cd1400 EasyIO boards.
  3269. */
  3270. static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
  3271. {
  3272. unsigned char svrtype;
  3273. #ifdef DEBUG
  3274. printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
  3275. (int) panelp, iobase);
  3276. #endif
  3277. outb(SVRR, iobase);
  3278. svrtype = inb(iobase + EREG_DATA);
  3279. if (panelp->nrports > 4) {
  3280. outb((SVRR + 0x80), iobase);
  3281. svrtype |= inb(iobase + EREG_DATA);
  3282. }
  3283. if (svrtype & SVRR_RX)
  3284. stl_cd1400rxisr(panelp, iobase);
  3285. else if (svrtype & SVRR_TX)
  3286. stl_cd1400txisr(panelp, iobase);
  3287. else if (svrtype & SVRR_MDM)
  3288. stl_cd1400mdmisr(panelp, iobase);
  3289. }
  3290. /*****************************************************************************/
  3291. /*
  3292. * Interrupt service routine for cd1400 panels.
  3293. */
  3294. static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
  3295. {
  3296. unsigned char svrtype;
  3297. #ifdef DEBUG
  3298. printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
  3299. iobase);
  3300. #endif
  3301. outb(SVRR, iobase);
  3302. svrtype = inb(iobase + EREG_DATA);
  3303. outb((SVRR + 0x80), iobase);
  3304. svrtype |= inb(iobase + EREG_DATA);
  3305. if (svrtype & SVRR_RX)
  3306. stl_cd1400rxisr(panelp, iobase);
  3307. else if (svrtype & SVRR_TX)
  3308. stl_cd1400txisr(panelp, iobase);
  3309. else if (svrtype & SVRR_MDM)
  3310. stl_cd1400mdmisr(panelp, iobase);
  3311. }
  3312. /*****************************************************************************/
  3313. /*
  3314. * Unfortunately we need to handle breaks in the TX data stream, since
  3315. * this is the only way to generate them on the cd1400.
  3316. */
  3317. static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
  3318. {
  3319. if (portp->brklen == 1) {
  3320. outb((COR2 + portp->uartaddr), ioaddr);
  3321. outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
  3322. (ioaddr + EREG_DATA));
  3323. outb((TDR + portp->uartaddr), ioaddr);
  3324. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3325. outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
  3326. outb((SRER + portp->uartaddr), ioaddr);
  3327. outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
  3328. (ioaddr + EREG_DATA));
  3329. return(1);
  3330. } else if (portp->brklen > 1) {
  3331. outb((TDR + portp->uartaddr), ioaddr);
  3332. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3333. outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
  3334. portp->brklen = -1;
  3335. return(1);
  3336. } else {
  3337. outb((COR2 + portp->uartaddr), ioaddr);
  3338. outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
  3339. (ioaddr + EREG_DATA));
  3340. portp->brklen = 0;
  3341. }
  3342. return(0);
  3343. }
  3344. /*****************************************************************************/
  3345. /*
  3346. * Transmit interrupt handler. This has gotta be fast! Handling TX
  3347. * chars is pretty simple, stuff as many as possible from the TX buffer
  3348. * into the cd1400 FIFO. Must also handle TX breaks here, since they
  3349. * are embedded as commands in the data stream. Oh no, had to use a goto!
  3350. * This could be optimized more, will do when I get time...
  3351. * In practice it is possible that interrupts are enabled but that the
  3352. * port has been hung up. Need to handle not having any TX buffer here,
  3353. * this is done by using the side effect that head and tail will also
  3354. * be NULL if the buffer has been freed.
  3355. */
  3356. static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
  3357. {
  3358. stlport_t *portp;
  3359. int len, stlen;
  3360. char *head, *tail;
  3361. unsigned char ioack, srer;
  3362. #ifdef DEBUG
  3363. printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
  3364. #endif
  3365. ioack = inb(ioaddr + EREG_TXACK);
  3366. if (((ioack & panelp->ackmask) != 0) ||
  3367. ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
  3368. printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
  3369. return;
  3370. }
  3371. portp = panelp->ports[(ioack >> 3)];
  3372. /*
  3373. * Unfortunately we need to handle breaks in the data stream, since
  3374. * this is the only way to generate them on the cd1400. Do it now if
  3375. * a break is to be sent.
  3376. */
  3377. if (portp->brklen != 0)
  3378. if (stl_cd1400breakisr(portp, ioaddr))
  3379. goto stl_txalldone;
  3380. head = portp->tx.head;
  3381. tail = portp->tx.tail;
  3382. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  3383. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  3384. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  3385. set_bit(ASYI_TXLOW, &portp->istate);
  3386. schedule_work(&portp->tqueue);
  3387. }
  3388. if (len == 0) {
  3389. outb((SRER + portp->uartaddr), ioaddr);
  3390. srer = inb(ioaddr + EREG_DATA);
  3391. if (srer & SRER_TXDATA) {
  3392. srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
  3393. } else {
  3394. srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
  3395. clear_bit(ASYI_TXBUSY, &portp->istate);
  3396. }
  3397. outb(srer, (ioaddr + EREG_DATA));
  3398. } else {
  3399. len = MIN(len, CD1400_TXFIFOSIZE);
  3400. portp->stats.txtotal += len;
  3401. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  3402. outb((TDR + portp->uartaddr), ioaddr);
  3403. outsb((ioaddr + EREG_DATA), tail, stlen);
  3404. len -= stlen;
  3405. tail += stlen;
  3406. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  3407. tail = portp->tx.buf;
  3408. if (len > 0) {
  3409. outsb((ioaddr + EREG_DATA), tail, len);
  3410. tail += len;
  3411. }
  3412. portp->tx.tail = tail;
  3413. }
  3414. stl_txalldone:
  3415. outb((EOSRR + portp->uartaddr), ioaddr);
  3416. outb(0, (ioaddr + EREG_DATA));
  3417. }
  3418. /*****************************************************************************/
  3419. /*
  3420. * Receive character interrupt handler. Determine if we have good chars
  3421. * or bad chars and then process appropriately. Good chars are easy
  3422. * just shove the lot into the RX buffer and set all status byte to 0.
  3423. * If a bad RX char then process as required. This routine needs to be
  3424. * fast! In practice it is possible that we get an interrupt on a port
  3425. * that is closed. This can happen on hangups - since they completely
  3426. * shutdown a port not in user context. Need to handle this case.
  3427. */
  3428. static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
  3429. {
  3430. stlport_t *portp;
  3431. struct tty_struct *tty;
  3432. unsigned int ioack, len, buflen;
  3433. unsigned char status;
  3434. char ch;
  3435. #ifdef DEBUG
  3436. printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
  3437. #endif
  3438. ioack = inb(ioaddr + EREG_RXACK);
  3439. if ((ioack & panelp->ackmask) != 0) {
  3440. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3441. return;
  3442. }
  3443. portp = panelp->ports[(ioack >> 3)];
  3444. tty = portp->tty;
  3445. if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
  3446. outb((RDCR + portp->uartaddr), ioaddr);
  3447. len = inb(ioaddr + EREG_DATA);
  3448. if ((tty == (struct tty_struct *) NULL) ||
  3449. (tty->flip.char_buf_ptr == (char *) NULL) ||
  3450. ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
  3451. len = MIN(len, sizeof(stl_unwanted));
  3452. outb((RDSR + portp->uartaddr), ioaddr);
  3453. insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
  3454. portp->stats.rxlost += len;
  3455. portp->stats.rxtotal += len;
  3456. } else {
  3457. len = MIN(len, buflen);
  3458. if (len > 0) {
  3459. outb((RDSR + portp->uartaddr), ioaddr);
  3460. insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
  3461. memset(tty->flip.flag_buf_ptr, 0, len);
  3462. tty->flip.flag_buf_ptr += len;
  3463. tty->flip.char_buf_ptr += len;
  3464. tty->flip.count += len;
  3465. tty_schedule_flip(tty);
  3466. portp->stats.rxtotal += len;
  3467. }
  3468. }
  3469. } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
  3470. outb((RDSR + portp->uartaddr), ioaddr);
  3471. status = inb(ioaddr + EREG_DATA);
  3472. ch = inb(ioaddr + EREG_DATA);
  3473. if (status & ST_PARITY)
  3474. portp->stats.rxparity++;
  3475. if (status & ST_FRAMING)
  3476. portp->stats.rxframing++;
  3477. if (status & ST_OVERRUN)
  3478. portp->stats.rxoverrun++;
  3479. if (status & ST_BREAK)
  3480. portp->stats.rxbreaks++;
  3481. if (status & ST_SCHARMASK) {
  3482. if ((status & ST_SCHARMASK) == ST_SCHAR1)
  3483. portp->stats.txxon++;
  3484. if ((status & ST_SCHARMASK) == ST_SCHAR2)
  3485. portp->stats.txxoff++;
  3486. goto stl_rxalldone;
  3487. }
  3488. if ((tty != (struct tty_struct *) NULL) &&
  3489. ((portp->rxignoremsk & status) == 0)) {
  3490. if (portp->rxmarkmsk & status) {
  3491. if (status & ST_BREAK) {
  3492. status = TTY_BREAK;
  3493. if (portp->flags & ASYNC_SAK) {
  3494. do_SAK(tty);
  3495. BRDENABLE(portp->brdnr, portp->pagenr);
  3496. }
  3497. } else if (status & ST_PARITY) {
  3498. status = TTY_PARITY;
  3499. } else if (status & ST_FRAMING) {
  3500. status = TTY_FRAME;
  3501. } else if(status & ST_OVERRUN) {
  3502. status = TTY_OVERRUN;
  3503. } else {
  3504. status = 0;
  3505. }
  3506. } else {
  3507. status = 0;
  3508. }
  3509. if (tty->flip.char_buf_ptr != (char *) NULL) {
  3510. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  3511. *tty->flip.flag_buf_ptr++ = status;
  3512. *tty->flip.char_buf_ptr++ = ch;
  3513. tty->flip.count++;
  3514. }
  3515. tty_schedule_flip(tty);
  3516. }
  3517. }
  3518. } else {
  3519. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3520. return;
  3521. }
  3522. stl_rxalldone:
  3523. outb((EOSRR + portp->uartaddr), ioaddr);
  3524. outb(0, (ioaddr + EREG_DATA));
  3525. }
  3526. /*****************************************************************************/
  3527. /*
  3528. * Modem interrupt handler. The is called when the modem signal line
  3529. * (DCD) has changed state. Leave most of the work to the off-level
  3530. * processing routine.
  3531. */
  3532. static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
  3533. {
  3534. stlport_t *portp;
  3535. unsigned int ioack;
  3536. unsigned char misr;
  3537. #ifdef DEBUG
  3538. printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
  3539. #endif
  3540. ioack = inb(ioaddr + EREG_MDACK);
  3541. if (((ioack & panelp->ackmask) != 0) ||
  3542. ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
  3543. printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
  3544. return;
  3545. }
  3546. portp = panelp->ports[(ioack >> 3)];
  3547. outb((MISR + portp->uartaddr), ioaddr);
  3548. misr = inb(ioaddr + EREG_DATA);
  3549. if (misr & MISR_DCD) {
  3550. set_bit(ASYI_DCDCHANGE, &portp->istate);
  3551. schedule_work(&portp->tqueue);
  3552. portp->stats.modem++;
  3553. }
  3554. outb((EOSRR + portp->uartaddr), ioaddr);
  3555. outb(0, (ioaddr + EREG_DATA));
  3556. }
  3557. /*****************************************************************************/
  3558. /* SC26198 HARDWARE FUNCTIONS */
  3559. /*****************************************************************************/
  3560. /*
  3561. * These functions get/set/update the registers of the sc26198 UARTs.
  3562. * Access to the sc26198 registers is via an address/data io port pair.
  3563. * (Maybe should make this inline...)
  3564. */
  3565. static int stl_sc26198getreg(stlport_t *portp, int regnr)
  3566. {
  3567. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3568. return(inb(portp->ioaddr + XP_DATA));
  3569. }
  3570. static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
  3571. {
  3572. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3573. outb(value, (portp->ioaddr + XP_DATA));
  3574. }
  3575. static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
  3576. {
  3577. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3578. if (inb(portp->ioaddr + XP_DATA) != value) {
  3579. outb(value, (portp->ioaddr + XP_DATA));
  3580. return(1);
  3581. }
  3582. return(0);
  3583. }
  3584. /*****************************************************************************/
  3585. /*
  3586. * Functions to get and set the sc26198 global registers.
  3587. */
  3588. static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
  3589. {
  3590. outb(regnr, (portp->ioaddr + XP_ADDR));
  3591. return(inb(portp->ioaddr + XP_DATA));
  3592. }
  3593. #if 0
  3594. static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
  3595. {
  3596. outb(regnr, (portp->ioaddr + XP_ADDR));
  3597. outb(value, (portp->ioaddr + XP_DATA));
  3598. }
  3599. #endif
  3600. /*****************************************************************************/
  3601. /*
  3602. * Inbitialize the UARTs in a panel. We don't care what sort of board
  3603. * these ports are on - since the port io registers are almost
  3604. * identical when dealing with ports.
  3605. */
  3606. static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
  3607. {
  3608. int chipmask, i;
  3609. int nrchips, ioaddr;
  3610. #ifdef DEBUG
  3611. printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
  3612. (int) brdp, (int) panelp);
  3613. #endif
  3614. BRDENABLE(panelp->brdnr, panelp->pagenr);
  3615. /*
  3616. * Check that each chip is present and started up OK.
  3617. */
  3618. chipmask = 0;
  3619. nrchips = (panelp->nrports + 4) / SC26198_PORTS;
  3620. if (brdp->brdtype == BRD_ECHPCI)
  3621. outb(panelp->pagenr, brdp->ioctrl);
  3622. for (i = 0; (i < nrchips); i++) {
  3623. ioaddr = panelp->iobase + (i * 4);
  3624. outb(SCCR, (ioaddr + XP_ADDR));
  3625. outb(CR_RESETALL, (ioaddr + XP_DATA));
  3626. outb(TSTR, (ioaddr + XP_ADDR));
  3627. if (inb(ioaddr + XP_DATA) != 0) {
  3628. printk("STALLION: sc26198 not responding, "
  3629. "brd=%d panel=%d chip=%d\n",
  3630. panelp->brdnr, panelp->panelnr, i);
  3631. continue;
  3632. }
  3633. chipmask |= (0x1 << i);
  3634. outb(GCCR, (ioaddr + XP_ADDR));
  3635. outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
  3636. outb(WDTRCR, (ioaddr + XP_ADDR));
  3637. outb(0xff, (ioaddr + XP_DATA));
  3638. }
  3639. BRDDISABLE(panelp->brdnr);
  3640. return(chipmask);
  3641. }
  3642. /*****************************************************************************/
  3643. /*
  3644. * Initialize hardware specific port registers.
  3645. */
  3646. static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
  3647. {
  3648. #ifdef DEBUG
  3649. printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
  3650. (int) brdp, (int) panelp, (int) portp);
  3651. #endif
  3652. if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
  3653. (portp == (stlport_t *) NULL))
  3654. return;
  3655. portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
  3656. portp->uartaddr = (portp->portnr & 0x07) << 4;
  3657. portp->pagenr = panelp->pagenr;
  3658. portp->hwid = 0x1;
  3659. BRDENABLE(portp->brdnr, portp->pagenr);
  3660. stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
  3661. BRDDISABLE(portp->brdnr);
  3662. }
  3663. /*****************************************************************************/
  3664. /*
  3665. * Set up the sc26198 registers for a port based on the termios port
  3666. * settings.
  3667. */
  3668. static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
  3669. {
  3670. stlbrd_t *brdp;
  3671. unsigned long flags;
  3672. unsigned int baudrate;
  3673. unsigned char mr0, mr1, mr2, clk;
  3674. unsigned char imron, imroff, iopr, ipr;
  3675. mr0 = 0;
  3676. mr1 = 0;
  3677. mr2 = 0;
  3678. clk = 0;
  3679. iopr = 0;
  3680. imron = 0;
  3681. imroff = 0;
  3682. brdp = stl_brds[portp->brdnr];
  3683. if (brdp == (stlbrd_t *) NULL)
  3684. return;
  3685. /*
  3686. * Set up the RX char ignore mask with those RX error types we
  3687. * can ignore.
  3688. */
  3689. portp->rxignoremsk = 0;
  3690. if (tiosp->c_iflag & IGNPAR)
  3691. portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
  3692. SR_RXOVERRUN);
  3693. if (tiosp->c_iflag & IGNBRK)
  3694. portp->rxignoremsk |= SR_RXBREAK;
  3695. portp->rxmarkmsk = SR_RXOVERRUN;
  3696. if (tiosp->c_iflag & (INPCK | PARMRK))
  3697. portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
  3698. if (tiosp->c_iflag & BRKINT)
  3699. portp->rxmarkmsk |= SR_RXBREAK;
  3700. /*
  3701. * Go through the char size, parity and stop bits and set all the
  3702. * option register appropriately.
  3703. */
  3704. switch (tiosp->c_cflag & CSIZE) {
  3705. case CS5:
  3706. mr1 |= MR1_CS5;
  3707. break;
  3708. case CS6:
  3709. mr1 |= MR1_CS6;
  3710. break;
  3711. case CS7:
  3712. mr1 |= MR1_CS7;
  3713. break;
  3714. default:
  3715. mr1 |= MR1_CS8;
  3716. break;
  3717. }
  3718. if (tiosp->c_cflag & CSTOPB)
  3719. mr2 |= MR2_STOP2;
  3720. else
  3721. mr2 |= MR2_STOP1;
  3722. if (tiosp->c_cflag & PARENB) {
  3723. if (tiosp->c_cflag & PARODD)
  3724. mr1 |= (MR1_PARENB | MR1_PARODD);
  3725. else
  3726. mr1 |= (MR1_PARENB | MR1_PAREVEN);
  3727. } else {
  3728. mr1 |= MR1_PARNONE;
  3729. }
  3730. mr1 |= MR1_ERRBLOCK;
  3731. /*
  3732. * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
  3733. * space for hardware flow control and the like. This should be set to
  3734. * VMIN.
  3735. */
  3736. mr2 |= MR2_RXFIFOHALF;
  3737. /*
  3738. * Calculate the baud rate timers. For now we will just assume that
  3739. * the input and output baud are the same. The sc26198 has a fixed
  3740. * baud rate table, so only discrete baud rates possible.
  3741. */
  3742. baudrate = tiosp->c_cflag & CBAUD;
  3743. if (baudrate & CBAUDEX) {
  3744. baudrate &= ~CBAUDEX;
  3745. if ((baudrate < 1) || (baudrate > 4))
  3746. tiosp->c_cflag &= ~CBAUDEX;
  3747. else
  3748. baudrate += 15;
  3749. }
  3750. baudrate = stl_baudrates[baudrate];
  3751. if ((tiosp->c_cflag & CBAUD) == B38400) {
  3752. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  3753. baudrate = 57600;
  3754. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  3755. baudrate = 115200;
  3756. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  3757. baudrate = 230400;
  3758. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  3759. baudrate = 460800;
  3760. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  3761. baudrate = (portp->baud_base / portp->custom_divisor);
  3762. }
  3763. if (baudrate > STL_SC26198MAXBAUD)
  3764. baudrate = STL_SC26198MAXBAUD;
  3765. if (baudrate > 0) {
  3766. for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
  3767. if (baudrate <= sc26198_baudtable[clk])
  3768. break;
  3769. }
  3770. }
  3771. /*
  3772. * Check what form of modem signaling is required and set it up.
  3773. */
  3774. if (tiosp->c_cflag & CLOCAL) {
  3775. portp->flags &= ~ASYNC_CHECK_CD;
  3776. } else {
  3777. iopr |= IOPR_DCDCOS;
  3778. imron |= IR_IOPORT;
  3779. portp->flags |= ASYNC_CHECK_CD;
  3780. }
  3781. /*
  3782. * Setup sc26198 enhanced modes if we can. In particular we want to
  3783. * handle as much of the flow control as possible automatically. As
  3784. * well as saving a few CPU cycles it will also greatly improve flow
  3785. * control reliability.
  3786. */
  3787. if (tiosp->c_iflag & IXON) {
  3788. mr0 |= MR0_SWFTX | MR0_SWFT;
  3789. imron |= IR_XONXOFF;
  3790. } else {
  3791. imroff |= IR_XONXOFF;
  3792. }
  3793. if (tiosp->c_iflag & IXOFF)
  3794. mr0 |= MR0_SWFRX;
  3795. if (tiosp->c_cflag & CRTSCTS) {
  3796. mr2 |= MR2_AUTOCTS;
  3797. mr1 |= MR1_AUTORTS;
  3798. }
  3799. /*
  3800. * All sc26198 register values calculated so go through and set
  3801. * them all up.
  3802. */
  3803. #ifdef DEBUG
  3804. printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  3805. portp->portnr, portp->panelnr, portp->brdnr);
  3806. printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
  3807. printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
  3808. printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  3809. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  3810. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  3811. #endif
  3812. save_flags(flags);
  3813. cli();
  3814. BRDENABLE(portp->brdnr, portp->pagenr);
  3815. stl_sc26198setreg(portp, IMR, 0);
  3816. stl_sc26198updatereg(portp, MR0, mr0);
  3817. stl_sc26198updatereg(portp, MR1, mr1);
  3818. stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
  3819. stl_sc26198updatereg(portp, MR2, mr2);
  3820. stl_sc26198updatereg(portp, IOPIOR,
  3821. ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
  3822. if (baudrate > 0) {
  3823. stl_sc26198setreg(portp, TXCSR, clk);
  3824. stl_sc26198setreg(portp, RXCSR, clk);
  3825. }
  3826. stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
  3827. stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
  3828. ipr = stl_sc26198getreg(portp, IPR);
  3829. if (ipr & IPR_DCD)
  3830. portp->sigs &= ~TIOCM_CD;
  3831. else
  3832. portp->sigs |= TIOCM_CD;
  3833. portp->imr = (portp->imr & ~imroff) | imron;
  3834. stl_sc26198setreg(portp, IMR, portp->imr);
  3835. BRDDISABLE(portp->brdnr);
  3836. restore_flags(flags);
  3837. }
  3838. /*****************************************************************************/
  3839. /*
  3840. * Set the state of the DTR and RTS signals.
  3841. */
  3842. static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
  3843. {
  3844. unsigned char iopioron, iopioroff;
  3845. unsigned long flags;
  3846. #ifdef DEBUG
  3847. printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
  3848. (int) portp, dtr, rts);
  3849. #endif
  3850. iopioron = 0;
  3851. iopioroff = 0;
  3852. if (dtr == 0)
  3853. iopioroff |= IPR_DTR;
  3854. else if (dtr > 0)
  3855. iopioron |= IPR_DTR;
  3856. if (rts == 0)
  3857. iopioroff |= IPR_RTS;
  3858. else if (rts > 0)
  3859. iopioron |= IPR_RTS;
  3860. save_flags(flags);
  3861. cli();
  3862. BRDENABLE(portp->brdnr, portp->pagenr);
  3863. stl_sc26198setreg(portp, IOPIOR,
  3864. ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
  3865. BRDDISABLE(portp->brdnr);
  3866. restore_flags(flags);
  3867. }
  3868. /*****************************************************************************/
  3869. /*
  3870. * Return the state of the signals.
  3871. */
  3872. static int stl_sc26198getsignals(stlport_t *portp)
  3873. {
  3874. unsigned char ipr;
  3875. unsigned long flags;
  3876. int sigs;
  3877. #ifdef DEBUG
  3878. printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
  3879. #endif
  3880. save_flags(flags);
  3881. cli();
  3882. BRDENABLE(portp->brdnr, portp->pagenr);
  3883. ipr = stl_sc26198getreg(portp, IPR);
  3884. BRDDISABLE(portp->brdnr);
  3885. restore_flags(flags);
  3886. sigs = 0;
  3887. sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
  3888. sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
  3889. sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
  3890. sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
  3891. sigs |= TIOCM_DSR;
  3892. return(sigs);
  3893. }
  3894. /*****************************************************************************/
  3895. /*
  3896. * Enable/Disable the Transmitter and/or Receiver.
  3897. */
  3898. static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
  3899. {
  3900. unsigned char ccr;
  3901. unsigned long flags;
  3902. #ifdef DEBUG
  3903. printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
  3904. (int) portp, rx, tx);
  3905. #endif
  3906. ccr = portp->crenable;
  3907. if (tx == 0)
  3908. ccr &= ~CR_TXENABLE;
  3909. else if (tx > 0)
  3910. ccr |= CR_TXENABLE;
  3911. if (rx == 0)
  3912. ccr &= ~CR_RXENABLE;
  3913. else if (rx > 0)
  3914. ccr |= CR_RXENABLE;
  3915. save_flags(flags);
  3916. cli();
  3917. BRDENABLE(portp->brdnr, portp->pagenr);
  3918. stl_sc26198setreg(portp, SCCR, ccr);
  3919. BRDDISABLE(portp->brdnr);
  3920. portp->crenable = ccr;
  3921. restore_flags(flags);
  3922. }
  3923. /*****************************************************************************/
  3924. /*
  3925. * Start/stop the Transmitter and/or Receiver.
  3926. */
  3927. static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
  3928. {
  3929. unsigned char imr;
  3930. unsigned long flags;
  3931. #ifdef DEBUG
  3932. printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
  3933. (int) portp, rx, tx);
  3934. #endif
  3935. imr = portp->imr;
  3936. if (tx == 0)
  3937. imr &= ~IR_TXRDY;
  3938. else if (tx == 1)
  3939. imr |= IR_TXRDY;
  3940. if (rx == 0)
  3941. imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
  3942. else if (rx > 0)
  3943. imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
  3944. save_flags(flags);
  3945. cli();
  3946. BRDENABLE(portp->brdnr, portp->pagenr);
  3947. stl_sc26198setreg(portp, IMR, imr);
  3948. BRDDISABLE(portp->brdnr);
  3949. portp->imr = imr;
  3950. if (tx > 0)
  3951. set_bit(ASYI_TXBUSY, &portp->istate);
  3952. restore_flags(flags);
  3953. }
  3954. /*****************************************************************************/
  3955. /*
  3956. * Disable all interrupts from this port.
  3957. */
  3958. static void stl_sc26198disableintrs(stlport_t *portp)
  3959. {
  3960. unsigned long flags;
  3961. #ifdef DEBUG
  3962. printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
  3963. #endif
  3964. save_flags(flags);
  3965. cli();
  3966. BRDENABLE(portp->brdnr, portp->pagenr);
  3967. portp->imr = 0;
  3968. stl_sc26198setreg(portp, IMR, 0);
  3969. BRDDISABLE(portp->brdnr);
  3970. restore_flags(flags);
  3971. }
  3972. /*****************************************************************************/
  3973. static void stl_sc26198sendbreak(stlport_t *portp, int len)
  3974. {
  3975. unsigned long flags;
  3976. #ifdef DEBUG
  3977. printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
  3978. #endif
  3979. save_flags(flags);
  3980. cli();
  3981. BRDENABLE(portp->brdnr, portp->pagenr);
  3982. if (len == 1) {
  3983. stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
  3984. portp->stats.txbreaks++;
  3985. } else {
  3986. stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
  3987. }
  3988. BRDDISABLE(portp->brdnr);
  3989. restore_flags(flags);
  3990. }
  3991. /*****************************************************************************/
  3992. /*
  3993. * Take flow control actions...
  3994. */
  3995. static void stl_sc26198flowctrl(stlport_t *portp, int state)
  3996. {
  3997. struct tty_struct *tty;
  3998. unsigned long flags;
  3999. unsigned char mr0;
  4000. #ifdef DEBUG
  4001. printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
  4002. #endif
  4003. if (portp == (stlport_t *) NULL)
  4004. return;
  4005. tty = portp->tty;
  4006. if (tty == (struct tty_struct *) NULL)
  4007. return;
  4008. save_flags(flags);
  4009. cli();
  4010. BRDENABLE(portp->brdnr, portp->pagenr);
  4011. if (state) {
  4012. if (tty->termios->c_iflag & IXOFF) {
  4013. mr0 = stl_sc26198getreg(portp, MR0);
  4014. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4015. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  4016. mr0 |= MR0_SWFRX;
  4017. portp->stats.rxxon++;
  4018. stl_sc26198wait(portp);
  4019. stl_sc26198setreg(portp, MR0, mr0);
  4020. }
  4021. /*
  4022. * Question: should we return RTS to what it was before? It may
  4023. * have been set by an ioctl... Suppose not, since if you have
  4024. * hardware flow control set then it is pretty silly to go and
  4025. * set the RTS line by hand.
  4026. */
  4027. if (tty->termios->c_cflag & CRTSCTS) {
  4028. stl_sc26198setreg(portp, MR1,
  4029. (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
  4030. stl_sc26198setreg(portp, IOPIOR,
  4031. (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
  4032. portp->stats.rxrtson++;
  4033. }
  4034. } else {
  4035. if (tty->termios->c_iflag & IXOFF) {
  4036. mr0 = stl_sc26198getreg(portp, MR0);
  4037. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4038. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  4039. mr0 &= ~MR0_SWFRX;
  4040. portp->stats.rxxoff++;
  4041. stl_sc26198wait(portp);
  4042. stl_sc26198setreg(portp, MR0, mr0);
  4043. }
  4044. if (tty->termios->c_cflag & CRTSCTS) {
  4045. stl_sc26198setreg(portp, MR1,
  4046. (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
  4047. stl_sc26198setreg(portp, IOPIOR,
  4048. (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
  4049. portp->stats.rxrtsoff++;
  4050. }
  4051. }
  4052. BRDDISABLE(portp->brdnr);
  4053. restore_flags(flags);
  4054. }
  4055. /*****************************************************************************/
  4056. /*
  4057. * Send a flow control character.
  4058. */
  4059. static void stl_sc26198sendflow(stlport_t *portp, int state)
  4060. {
  4061. struct tty_struct *tty;
  4062. unsigned long flags;
  4063. unsigned char mr0;
  4064. #ifdef DEBUG
  4065. printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
  4066. #endif
  4067. if (portp == (stlport_t *) NULL)
  4068. return;
  4069. tty = portp->tty;
  4070. if (tty == (struct tty_struct *) NULL)
  4071. return;
  4072. save_flags(flags);
  4073. cli();
  4074. BRDENABLE(portp->brdnr, portp->pagenr);
  4075. if (state) {
  4076. mr0 = stl_sc26198getreg(portp, MR0);
  4077. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4078. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  4079. mr0 |= MR0_SWFRX;
  4080. portp->stats.rxxon++;
  4081. stl_sc26198wait(portp);
  4082. stl_sc26198setreg(portp, MR0, mr0);
  4083. } else {
  4084. mr0 = stl_sc26198getreg(portp, MR0);
  4085. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4086. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  4087. mr0 &= ~MR0_SWFRX;
  4088. portp->stats.rxxoff++;
  4089. stl_sc26198wait(portp);
  4090. stl_sc26198setreg(portp, MR0, mr0);
  4091. }
  4092. BRDDISABLE(portp->brdnr);
  4093. restore_flags(flags);
  4094. }
  4095. /*****************************************************************************/
  4096. static void stl_sc26198flush(stlport_t *portp)
  4097. {
  4098. unsigned long flags;
  4099. #ifdef DEBUG
  4100. printk("stl_sc26198flush(portp=%x)\n", (int) portp);
  4101. #endif
  4102. if (portp == (stlport_t *) NULL)
  4103. return;
  4104. save_flags(flags);
  4105. cli();
  4106. BRDENABLE(portp->brdnr, portp->pagenr);
  4107. stl_sc26198setreg(portp, SCCR, CR_TXRESET);
  4108. stl_sc26198setreg(portp, SCCR, portp->crenable);
  4109. BRDDISABLE(portp->brdnr);
  4110. portp->tx.tail = portp->tx.head;
  4111. restore_flags(flags);
  4112. }
  4113. /*****************************************************************************/
  4114. /*
  4115. * Return the current state of data flow on this port. This is only
  4116. * really interresting when determining if data has fully completed
  4117. * transmission or not... The sc26198 interrupt scheme cannot
  4118. * determine when all data has actually drained, so we need to
  4119. * check the port statusy register to be sure.
  4120. */
  4121. static int stl_sc26198datastate(stlport_t *portp)
  4122. {
  4123. unsigned long flags;
  4124. unsigned char sr;
  4125. #ifdef DEBUG
  4126. printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
  4127. #endif
  4128. if (portp == (stlport_t *) NULL)
  4129. return(0);
  4130. if (test_bit(ASYI_TXBUSY, &portp->istate))
  4131. return(1);
  4132. save_flags(flags);
  4133. cli();
  4134. BRDENABLE(portp->brdnr, portp->pagenr);
  4135. sr = stl_sc26198getreg(portp, SR);
  4136. BRDDISABLE(portp->brdnr);
  4137. restore_flags(flags);
  4138. return((sr & SR_TXEMPTY) ? 0 : 1);
  4139. }
  4140. /*****************************************************************************/
  4141. /*
  4142. * Delay for a small amount of time, to give the sc26198 a chance
  4143. * to process a command...
  4144. */
  4145. static void stl_sc26198wait(stlport_t *portp)
  4146. {
  4147. int i;
  4148. #ifdef DEBUG
  4149. printk("stl_sc26198wait(portp=%x)\n", (int) portp);
  4150. #endif
  4151. if (portp == (stlport_t *) NULL)
  4152. return;
  4153. for (i = 0; (i < 20); i++)
  4154. stl_sc26198getglobreg(portp, TSTR);
  4155. }
  4156. /*****************************************************************************/
  4157. /*
  4158. * If we are TX flow controlled and in IXANY mode then we may
  4159. * need to unflow control here. We gotta do this because of the
  4160. * automatic flow control modes of the sc26198.
  4161. */
  4162. static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
  4163. {
  4164. unsigned char mr0;
  4165. mr0 = stl_sc26198getreg(portp, MR0);
  4166. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4167. stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
  4168. stl_sc26198wait(portp);
  4169. stl_sc26198setreg(portp, MR0, mr0);
  4170. clear_bit(ASYI_TXFLOWED, &portp->istate);
  4171. }
  4172. /*****************************************************************************/
  4173. /*
  4174. * Interrupt service routine for sc26198 panels.
  4175. */
  4176. static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
  4177. {
  4178. stlport_t *portp;
  4179. unsigned int iack;
  4180. /*
  4181. * Work around bug in sc26198 chip... Cannot have A6 address
  4182. * line of UART high, else iack will be returned as 0.
  4183. */
  4184. outb(0, (iobase + 1));
  4185. iack = inb(iobase + XP_IACK);
  4186. portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
  4187. if (iack & IVR_RXDATA)
  4188. stl_sc26198rxisr(portp, iack);
  4189. else if (iack & IVR_TXDATA)
  4190. stl_sc26198txisr(portp);
  4191. else
  4192. stl_sc26198otherisr(portp, iack);
  4193. }
  4194. /*****************************************************************************/
  4195. /*
  4196. * Transmit interrupt handler. This has gotta be fast! Handling TX
  4197. * chars is pretty simple, stuff as many as possible from the TX buffer
  4198. * into the sc26198 FIFO.
  4199. * In practice it is possible that interrupts are enabled but that the
  4200. * port has been hung up. Need to handle not having any TX buffer here,
  4201. * this is done by using the side effect that head and tail will also
  4202. * be NULL if the buffer has been freed.
  4203. */
  4204. static void stl_sc26198txisr(stlport_t *portp)
  4205. {
  4206. unsigned int ioaddr;
  4207. unsigned char mr0;
  4208. int len, stlen;
  4209. char *head, *tail;
  4210. #ifdef DEBUG
  4211. printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
  4212. #endif
  4213. ioaddr = portp->ioaddr;
  4214. head = portp->tx.head;
  4215. tail = portp->tx.tail;
  4216. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  4217. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  4218. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  4219. set_bit(ASYI_TXLOW, &portp->istate);
  4220. schedule_work(&portp->tqueue);
  4221. }
  4222. if (len == 0) {
  4223. outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
  4224. mr0 = inb(ioaddr + XP_DATA);
  4225. if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
  4226. portp->imr &= ~IR_TXRDY;
  4227. outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
  4228. outb(portp->imr, (ioaddr + XP_DATA));
  4229. clear_bit(ASYI_TXBUSY, &portp->istate);
  4230. } else {
  4231. mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
  4232. outb(mr0, (ioaddr + XP_DATA));
  4233. }
  4234. } else {
  4235. len = MIN(len, SC26198_TXFIFOSIZE);
  4236. portp->stats.txtotal += len;
  4237. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  4238. outb(GTXFIFO, (ioaddr + XP_ADDR));
  4239. outsb((ioaddr + XP_DATA), tail, stlen);
  4240. len -= stlen;
  4241. tail += stlen;
  4242. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  4243. tail = portp->tx.buf;
  4244. if (len > 0) {
  4245. outsb((ioaddr + XP_DATA), tail, len);
  4246. tail += len;
  4247. }
  4248. portp->tx.tail = tail;
  4249. }
  4250. }
  4251. /*****************************************************************************/
  4252. /*
  4253. * Receive character interrupt handler. Determine if we have good chars
  4254. * or bad chars and then process appropriately. Good chars are easy
  4255. * just shove the lot into the RX buffer and set all status byte to 0.
  4256. * If a bad RX char then process as required. This routine needs to be
  4257. * fast! In practice it is possible that we get an interrupt on a port
  4258. * that is closed. This can happen on hangups - since they completely
  4259. * shutdown a port not in user context. Need to handle this case.
  4260. */
  4261. static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
  4262. {
  4263. struct tty_struct *tty;
  4264. unsigned int len, buflen, ioaddr;
  4265. #ifdef DEBUG
  4266. printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
  4267. #endif
  4268. tty = portp->tty;
  4269. ioaddr = portp->ioaddr;
  4270. outb(GIBCR, (ioaddr + XP_ADDR));
  4271. len = inb(ioaddr + XP_DATA) + 1;
  4272. if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
  4273. if ((tty == (struct tty_struct *) NULL) ||
  4274. (tty->flip.char_buf_ptr == (char *) NULL) ||
  4275. ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
  4276. len = MIN(len, sizeof(stl_unwanted));
  4277. outb(GRXFIFO, (ioaddr + XP_ADDR));
  4278. insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
  4279. portp->stats.rxlost += len;
  4280. portp->stats.rxtotal += len;
  4281. } else {
  4282. len = MIN(len, buflen);
  4283. if (len > 0) {
  4284. outb(GRXFIFO, (ioaddr + XP_ADDR));
  4285. insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
  4286. memset(tty->flip.flag_buf_ptr, 0, len);
  4287. tty->flip.flag_buf_ptr += len;
  4288. tty->flip.char_buf_ptr += len;
  4289. tty->flip.count += len;
  4290. tty_schedule_flip(tty);
  4291. portp->stats.rxtotal += len;
  4292. }
  4293. }
  4294. } else {
  4295. stl_sc26198rxbadchars(portp);
  4296. }
  4297. /*
  4298. * If we are TX flow controlled and in IXANY mode then we may need
  4299. * to unflow control here. We gotta do this because of the automatic
  4300. * flow control modes of the sc26198.
  4301. */
  4302. if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
  4303. if ((tty != (struct tty_struct *) NULL) &&
  4304. (tty->termios != (struct termios *) NULL) &&
  4305. (tty->termios->c_iflag & IXANY)) {
  4306. stl_sc26198txunflow(portp, tty);
  4307. }
  4308. }
  4309. }
  4310. /*****************************************************************************/
  4311. /*
  4312. * Process an RX bad character.
  4313. */
  4314. static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
  4315. {
  4316. struct tty_struct *tty;
  4317. unsigned int ioaddr;
  4318. tty = portp->tty;
  4319. ioaddr = portp->ioaddr;
  4320. if (status & SR_RXPARITY)
  4321. portp->stats.rxparity++;
  4322. if (status & SR_RXFRAMING)
  4323. portp->stats.rxframing++;
  4324. if (status & SR_RXOVERRUN)
  4325. portp->stats.rxoverrun++;
  4326. if (status & SR_RXBREAK)
  4327. portp->stats.rxbreaks++;
  4328. if ((tty != (struct tty_struct *) NULL) &&
  4329. ((portp->rxignoremsk & status) == 0)) {
  4330. if (portp->rxmarkmsk & status) {
  4331. if (status & SR_RXBREAK) {
  4332. status = TTY_BREAK;
  4333. if (portp->flags & ASYNC_SAK) {
  4334. do_SAK(tty);
  4335. BRDENABLE(portp->brdnr, portp->pagenr);
  4336. }
  4337. } else if (status & SR_RXPARITY) {
  4338. status = TTY_PARITY;
  4339. } else if (status & SR_RXFRAMING) {
  4340. status = TTY_FRAME;
  4341. } else if(status & SR_RXOVERRUN) {
  4342. status = TTY_OVERRUN;
  4343. } else {
  4344. status = 0;
  4345. }
  4346. } else {
  4347. status = 0;
  4348. }
  4349. if (tty->flip.char_buf_ptr != (char *) NULL) {
  4350. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  4351. *tty->flip.flag_buf_ptr++ = status;
  4352. *tty->flip.char_buf_ptr++ = ch;
  4353. tty->flip.count++;
  4354. }
  4355. tty_schedule_flip(tty);
  4356. }
  4357. if (status == 0)
  4358. portp->stats.rxtotal++;
  4359. }
  4360. }
  4361. /*****************************************************************************/
  4362. /*
  4363. * Process all characters in the RX FIFO of the UART. Check all char
  4364. * status bytes as well, and process as required. We need to check
  4365. * all bytes in the FIFO, in case some more enter the FIFO while we
  4366. * are here. To get the exact character error type we need to switch
  4367. * into CHAR error mode (that is why we need to make sure we empty
  4368. * the FIFO).
  4369. */
  4370. static void stl_sc26198rxbadchars(stlport_t *portp)
  4371. {
  4372. unsigned char status, mr1;
  4373. char ch;
  4374. /*
  4375. * To get the precise error type for each character we must switch
  4376. * back into CHAR error mode.
  4377. */
  4378. mr1 = stl_sc26198getreg(portp, MR1);
  4379. stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
  4380. while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
  4381. stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
  4382. ch = stl_sc26198getreg(portp, RXFIFO);
  4383. stl_sc26198rxbadch(portp, status, ch);
  4384. }
  4385. /*
  4386. * To get correct interrupt class we must switch back into BLOCK
  4387. * error mode.
  4388. */
  4389. stl_sc26198setreg(portp, MR1, mr1);
  4390. }
  4391. /*****************************************************************************/
  4392. /*
  4393. * Other interrupt handler. This includes modem signals, flow
  4394. * control actions, etc. Most stuff is left to off-level interrupt
  4395. * processing time.
  4396. */
  4397. static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
  4398. {
  4399. unsigned char cir, ipr, xisr;
  4400. #ifdef DEBUG
  4401. printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
  4402. #endif
  4403. cir = stl_sc26198getglobreg(portp, CIR);
  4404. switch (cir & CIR_SUBTYPEMASK) {
  4405. case CIR_SUBCOS:
  4406. ipr = stl_sc26198getreg(portp, IPR);
  4407. if (ipr & IPR_DCDCHANGE) {
  4408. set_bit(ASYI_DCDCHANGE, &portp->istate);
  4409. schedule_work(&portp->tqueue);
  4410. portp->stats.modem++;
  4411. }
  4412. break;
  4413. case CIR_SUBXONXOFF:
  4414. xisr = stl_sc26198getreg(portp, XISR);
  4415. if (xisr & XISR_RXXONGOT) {
  4416. set_bit(ASYI_TXFLOWED, &portp->istate);
  4417. portp->stats.txxoff++;
  4418. }
  4419. if (xisr & XISR_RXXOFFGOT) {
  4420. clear_bit(ASYI_TXFLOWED, &portp->istate);
  4421. portp->stats.txxon++;
  4422. }
  4423. break;
  4424. case CIR_SUBBREAK:
  4425. stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
  4426. stl_sc26198rxbadchars(portp);
  4427. break;
  4428. default:
  4429. break;
  4430. }
  4431. }
  4432. /*****************************************************************************/