PageRenderTime 58ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/staging/tty/serial167.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2
C | 2489 lines | 1831 code | 302 blank | 356 comment | 312 complexity | 7c7603d25598577481a09104f77c7255 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * linux/drivers/char/serial167.c
  3. *
  4. * Driver for MVME166/7 board serial ports, which are via a CD2401.
  5. * Based very much on cyclades.c.
  6. *
  7. * MVME166/7 work by Richard Hirst [richard@sleepie.demon.co.uk]
  8. *
  9. * ==============================================================
  10. *
  11. * static char rcsid[] =
  12. * "$Revision: 1.36.1.4 $$Date: 1995/03/29 06:14:14 $";
  13. *
  14. * linux/kernel/cyclades.c
  15. *
  16. * Maintained by Marcio Saito (cyclades@netcom.com) and
  17. * Randolph Bentson (bentson@grieg.seaslug.org)
  18. *
  19. * Much of the design and some of the code came from serial.c
  20. * which was copyright (C) 1991, 1992 Linus Torvalds. It was
  21. * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
  22. * and then fixed as suggested by Michael K. Johnson 12/12/92.
  23. *
  24. * This version does not support shared irq's.
  25. *
  26. * $Log: cyclades.c,v $
  27. * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
  28. * disambiguate between Cyclom-16Y and Cyclom-32Ye;
  29. *
  30. * Changes:
  31. *
  32. * 200 lines of changes record removed - RGH 11-10-95, starting work on
  33. * converting this to drive serial ports on mvme166 (cd2401).
  34. *
  35. * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/08/25
  36. * - get rid of verify_area
  37. * - use get_user to access memory from userspace in set_threshold,
  38. * set_default_threshold and set_timeout
  39. * - don't use the panic function in serial167_init
  40. * - do resource release on failure on serial167_init
  41. * - include missing restore_flags in mvme167_serial_console_setup
  42. *
  43. * Kars de Jong <jongk@linux-m68k.org> - 2004/09/06
  44. * - replace bottom half handler with task queue handler
  45. */
  46. #include <linux/errno.h>
  47. #include <linux/signal.h>
  48. #include <linux/sched.h>
  49. #include <linux/timer.h>
  50. #include <linux/tty.h>
  51. #include <linux/interrupt.h>
  52. #include <linux/serial.h>
  53. #include <linux/serialP.h>
  54. #include <linux/string.h>
  55. #include <linux/fcntl.h>
  56. #include <linux/ptrace.h>
  57. #include <linux/serial167.h>
  58. #include <linux/delay.h>
  59. #include <linux/major.h>
  60. #include <linux/mm.h>
  61. #include <linux/console.h>
  62. #include <linux/module.h>
  63. #include <linux/bitops.h>
  64. #include <linux/tty_flip.h>
  65. #include <linux/gfp.h>
  66. #include <asm/system.h>
  67. #include <asm/io.h>
  68. #include <asm/mvme16xhw.h>
  69. #include <asm/bootinfo.h>
  70. #include <asm/setup.h>
  71. #include <linux/types.h>
  72. #include <linux/kernel.h>
  73. #include <asm/uaccess.h>
  74. #include <linux/init.h>
  75. #define SERIAL_PARANOIA_CHECK
  76. #undef SERIAL_DEBUG_OPEN
  77. #undef SERIAL_DEBUG_THROTTLE
  78. #undef SERIAL_DEBUG_OTHER
  79. #undef SERIAL_DEBUG_IO
  80. #undef SERIAL_DEBUG_COUNT
  81. #undef SERIAL_DEBUG_DTR
  82. #undef CYCLOM_16Y_HACK
  83. #define CYCLOM_ENABLE_MONITORING
  84. #define WAKEUP_CHARS 256
  85. #define STD_COM_FLAGS (0)
  86. static struct tty_driver *cy_serial_driver;
  87. extern int serial_console;
  88. static struct cyclades_port *serial_console_info = NULL;
  89. static unsigned int serial_console_cflag = 0;
  90. u_char initial_console_speed;
  91. /* Base address of cd2401 chip on mvme166/7 */
  92. #define BASE_ADDR (0xfff45000)
  93. #define pcc2chip ((volatile u_char *)0xfff42000)
  94. #define PccSCCMICR 0x1d
  95. #define PccSCCTICR 0x1e
  96. #define PccSCCRICR 0x1f
  97. #define PccTPIACKR 0x25
  98. #define PccRPIACKR 0x27
  99. #define PccIMLR 0x3f
  100. /* This is the per-port data structure */
  101. struct cyclades_port cy_port[] = {
  102. /* CARD# */
  103. {-1}, /* ttyS0 */
  104. {-1}, /* ttyS1 */
  105. {-1}, /* ttyS2 */
  106. {-1}, /* ttyS3 */
  107. };
  108. #define NR_PORTS ARRAY_SIZE(cy_port)
  109. /*
  110. * This is used to look up the divisor speeds and the timeouts
  111. * We're normally limited to 15 distinct baud rates. The extra
  112. * are accessed via settings in info->flags.
  113. * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  114. * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  115. * HI VHI
  116. */
  117. static int baud_table[] = {
  118. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
  119. 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
  120. 0
  121. };
  122. #if 0
  123. static char baud_co[] = { /* 25 MHz clock option table */
  124. /* value => 00 01 02 03 04 */
  125. /* divide by 8 32 128 512 2048 */
  126. 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
  127. 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  128. };
  129. static char baud_bpr[] = { /* 25 MHz baud rate period table */
  130. 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
  131. 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
  132. };
  133. #endif
  134. /* I think 166 brd clocks 2401 at 20MHz.... */
  135. /* These values are written directly to tcor, and >> 5 for writing to rcor */
  136. static u_char baud_co[] = { /* 20 MHz clock option table */
  137. 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
  138. 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  139. };
  140. /* These values written directly to tbpr/rbpr */
  141. static u_char baud_bpr[] = { /* 20 MHz baud rate period table */
  142. 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
  143. 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10
  144. };
  145. static u_char baud_cor4[] = { /* receive threshold */
  146. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  147. 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07
  148. };
  149. static void shutdown(struct cyclades_port *);
  150. static int startup(struct cyclades_port *);
  151. static void cy_throttle(struct tty_struct *);
  152. static void cy_unthrottle(struct tty_struct *);
  153. static void config_setup(struct cyclades_port *);
  154. #ifdef CYCLOM_SHOW_STATUS
  155. static void show_status(int);
  156. #endif
  157. /*
  158. * I have my own version of udelay(), as it is needed when initialising
  159. * the chip, before the delay loop has been calibrated. Should probably
  160. * reference one of the vmechip2 or pccchip2 counter for an accurate
  161. * delay, but this wild guess will do for now.
  162. */
  163. void my_udelay(long us)
  164. {
  165. u_char x;
  166. volatile u_char *p = &x;
  167. int i;
  168. while (us--)
  169. for (i = 100; i; i--)
  170. x |= *p;
  171. }
  172. static inline int serial_paranoia_check(struct cyclades_port *info, char *name,
  173. const char *routine)
  174. {
  175. #ifdef SERIAL_PARANOIA_CHECK
  176. if (!info) {
  177. printk("Warning: null cyclades_port for (%s) in %s\n", name,
  178. routine);
  179. return 1;
  180. }
  181. if (info < &cy_port[0] || info >= &cy_port[NR_PORTS]) {
  182. printk("Warning: cyclades_port out of range for (%s) in %s\n",
  183. name, routine);
  184. return 1;
  185. }
  186. if (info->magic != CYCLADES_MAGIC) {
  187. printk("Warning: bad magic number for serial struct (%s) in "
  188. "%s\n", name, routine);
  189. return 1;
  190. }
  191. #endif
  192. return 0;
  193. } /* serial_paranoia_check */
  194. #if 0
  195. /* The following diagnostic routines allow the driver to spew
  196. information on the screen, even (especially!) during interrupts.
  197. */
  198. void SP(char *data)
  199. {
  200. unsigned long flags;
  201. local_irq_save(flags);
  202. printk(KERN_EMERG "%s", data);
  203. local_irq_restore(flags);
  204. }
  205. char scrn[2];
  206. void CP(char data)
  207. {
  208. unsigned long flags;
  209. local_irq_save(flags);
  210. scrn[0] = data;
  211. printk(KERN_EMERG "%c", scrn);
  212. local_irq_restore(flags);
  213. } /* CP */
  214. void CP1(int data)
  215. {
  216. (data < 10) ? CP(data + '0') : CP(data + 'A' - 10);
  217. } /* CP1 */
  218. void CP2(int data)
  219. {
  220. CP1((data >> 4) & 0x0f);
  221. CP1(data & 0x0f);
  222. } /* CP2 */
  223. void CP4(int data)
  224. {
  225. CP2((data >> 8) & 0xff);
  226. CP2(data & 0xff);
  227. } /* CP4 */
  228. void CP8(long data)
  229. {
  230. CP4((data >> 16) & 0xffff);
  231. CP4(data & 0xffff);
  232. } /* CP8 */
  233. #endif
  234. /* This routine waits up to 1000 micro-seconds for the previous
  235. command to the Cirrus chip to complete and then issues the
  236. new command. An error is returned if the previous command
  237. didn't finish within the time limit.
  238. */
  239. u_short write_cy_cmd(volatile u_char * base_addr, u_char cmd)
  240. {
  241. unsigned long flags;
  242. volatile int i;
  243. local_irq_save(flags);
  244. /* Check to see that the previous command has completed */
  245. for (i = 0; i < 100; i++) {
  246. if (base_addr[CyCCR] == 0) {
  247. break;
  248. }
  249. my_udelay(10L);
  250. }
  251. /* if the CCR never cleared, the previous command
  252. didn't finish within the "reasonable time" */
  253. if (i == 10) {
  254. local_irq_restore(flags);
  255. return (-1);
  256. }
  257. /* Issue the new command */
  258. base_addr[CyCCR] = cmd;
  259. local_irq_restore(flags);
  260. return (0);
  261. } /* write_cy_cmd */
  262. /* cy_start and cy_stop provide software output flow control as a
  263. function of XON/XOFF, software CTS, and other such stuff. */
  264. static void cy_stop(struct tty_struct *tty)
  265. {
  266. struct cyclades_port *info = tty->driver_data;
  267. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  268. int channel;
  269. unsigned long flags;
  270. #ifdef SERIAL_DEBUG_OTHER
  271. printk("cy_stop %s\n", tty->name); /* */
  272. #endif
  273. if (serial_paranoia_check(info, tty->name, "cy_stop"))
  274. return;
  275. channel = info->line;
  276. local_irq_save(flags);
  277. base_addr[CyCAR] = (u_char) (channel); /* index channel */
  278. base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
  279. local_irq_restore(flags);
  280. } /* cy_stop */
  281. static void cy_start(struct tty_struct *tty)
  282. {
  283. struct cyclades_port *info = tty->driver_data;
  284. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  285. int channel;
  286. unsigned long flags;
  287. #ifdef SERIAL_DEBUG_OTHER
  288. printk("cy_start %s\n", tty->name); /* */
  289. #endif
  290. if (serial_paranoia_check(info, tty->name, "cy_start"))
  291. return;
  292. channel = info->line;
  293. local_irq_save(flags);
  294. base_addr[CyCAR] = (u_char) (channel);
  295. base_addr[CyIER] |= CyTxMpty;
  296. local_irq_restore(flags);
  297. } /* cy_start */
  298. /* The real interrupt service routines are called
  299. whenever the card wants its hand held--chars
  300. received, out buffer empty, modem change, etc.
  301. */
  302. static irqreturn_t cd2401_rxerr_interrupt(int irq, void *dev_id)
  303. {
  304. struct tty_struct *tty;
  305. struct cyclades_port *info;
  306. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  307. unsigned char err, rfoc;
  308. int channel;
  309. char data;
  310. /* determine the channel and change to that context */
  311. channel = (u_short) (base_addr[CyLICR] >> 2);
  312. info = &cy_port[channel];
  313. info->last_active = jiffies;
  314. if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
  315. /* This is a receive timeout interrupt, ignore it */
  316. base_addr[CyREOIR] = CyNOTRANS;
  317. return IRQ_HANDLED;
  318. }
  319. /* Read a byte of data if there is any - assume the error
  320. * is associated with this character */
  321. if ((rfoc = base_addr[CyRFOC]) != 0)
  322. data = base_addr[CyRDR];
  323. else
  324. data = 0;
  325. /* if there is nowhere to put the data, discard it */
  326. if (info->tty == 0) {
  327. base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
  328. return IRQ_HANDLED;
  329. } else { /* there is an open port for this data */
  330. tty = info->tty;
  331. if (err & info->ignore_status_mask) {
  332. base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
  333. return IRQ_HANDLED;
  334. }
  335. if (tty_buffer_request_room(tty, 1) != 0) {
  336. if (err & info->read_status_mask) {
  337. if (err & CyBREAK) {
  338. tty_insert_flip_char(tty, data,
  339. TTY_BREAK);
  340. if (info->flags & ASYNC_SAK) {
  341. do_SAK(tty);
  342. }
  343. } else if (err & CyFRAME) {
  344. tty_insert_flip_char(tty, data,
  345. TTY_FRAME);
  346. } else if (err & CyPARITY) {
  347. tty_insert_flip_char(tty, data,
  348. TTY_PARITY);
  349. } else if (err & CyOVERRUN) {
  350. tty_insert_flip_char(tty, 0,
  351. TTY_OVERRUN);
  352. /*
  353. If the flip buffer itself is
  354. overflowing, we still lose
  355. the next incoming character.
  356. */
  357. if (tty_buffer_request_room(tty, 1) !=
  358. 0) {
  359. tty_insert_flip_char(tty, data,
  360. TTY_FRAME);
  361. }
  362. /* These two conditions may imply */
  363. /* a normal read should be done. */
  364. /* else if(data & CyTIMEOUT) */
  365. /* else if(data & CySPECHAR) */
  366. } else {
  367. tty_insert_flip_char(tty, 0,
  368. TTY_NORMAL);
  369. }
  370. } else {
  371. tty_insert_flip_char(tty, data, TTY_NORMAL);
  372. }
  373. } else {
  374. /* there was a software buffer overrun
  375. and nothing could be done about it!!! */
  376. }
  377. }
  378. tty_schedule_flip(tty);
  379. /* end of service */
  380. base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
  381. return IRQ_HANDLED;
  382. } /* cy_rxerr_interrupt */
  383. static irqreturn_t cd2401_modem_interrupt(int irq, void *dev_id)
  384. {
  385. struct cyclades_port *info;
  386. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  387. int channel;
  388. int mdm_change;
  389. int mdm_status;
  390. /* determine the channel and change to that context */
  391. channel = (u_short) (base_addr[CyLICR] >> 2);
  392. info = &cy_port[channel];
  393. info->last_active = jiffies;
  394. mdm_change = base_addr[CyMISR];
  395. mdm_status = base_addr[CyMSVR1];
  396. if (info->tty == 0) { /* nowhere to put the data, ignore it */
  397. ;
  398. } else {
  399. if ((mdm_change & CyDCD)
  400. && (info->flags & ASYNC_CHECK_CD)) {
  401. if (mdm_status & CyDCD) {
  402. /* CP('!'); */
  403. wake_up_interruptible(&info->open_wait);
  404. } else {
  405. /* CP('@'); */
  406. tty_hangup(info->tty);
  407. wake_up_interruptible(&info->open_wait);
  408. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  409. }
  410. }
  411. if ((mdm_change & CyCTS)
  412. && (info->flags & ASYNC_CTS_FLOW)) {
  413. if (info->tty->stopped) {
  414. if (mdm_status & CyCTS) {
  415. /* !!! cy_start isn't used because... */
  416. info->tty->stopped = 0;
  417. base_addr[CyIER] |= CyTxMpty;
  418. tty_wakeup(info->tty);
  419. }
  420. } else {
  421. if (!(mdm_status & CyCTS)) {
  422. /* !!! cy_stop isn't used because... */
  423. info->tty->stopped = 1;
  424. base_addr[CyIER] &=
  425. ~(CyTxMpty | CyTxRdy);
  426. }
  427. }
  428. }
  429. if (mdm_status & CyDSR) {
  430. }
  431. }
  432. base_addr[CyMEOIR] = 0;
  433. return IRQ_HANDLED;
  434. } /* cy_modem_interrupt */
  435. static irqreturn_t cd2401_tx_interrupt(int irq, void *dev_id)
  436. {
  437. struct cyclades_port *info;
  438. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  439. int channel;
  440. int char_count, saved_cnt;
  441. int outch;
  442. /* determine the channel and change to that context */
  443. channel = (u_short) (base_addr[CyLICR] >> 2);
  444. /* validate the port number (as configured and open) */
  445. if ((channel < 0) || (NR_PORTS <= channel)) {
  446. base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
  447. base_addr[CyTEOIR] = CyNOTRANS;
  448. return IRQ_HANDLED;
  449. }
  450. info = &cy_port[channel];
  451. info->last_active = jiffies;
  452. if (info->tty == 0) {
  453. base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
  454. base_addr[CyTEOIR] = CyNOTRANS;
  455. return IRQ_HANDLED;
  456. }
  457. /* load the on-chip space available for outbound data */
  458. saved_cnt = char_count = base_addr[CyTFTC];
  459. if (info->x_char) { /* send special char */
  460. outch = info->x_char;
  461. base_addr[CyTDR] = outch;
  462. char_count--;
  463. info->x_char = 0;
  464. }
  465. if (info->x_break) {
  466. /* The Cirrus chip requires the "Embedded Transmit
  467. Commands" of start break, delay, and end break
  468. sequences to be sent. The duration of the
  469. break is given in TICs, which runs at HZ
  470. (typically 100) and the PPR runs at 200 Hz,
  471. so the delay is duration * 200/HZ, and thus a
  472. break can run from 1/100 sec to about 5/4 sec.
  473. Need to check these values - RGH 141095.
  474. */
  475. base_addr[CyTDR] = 0; /* start break */
  476. base_addr[CyTDR] = 0x81;
  477. base_addr[CyTDR] = 0; /* delay a bit */
  478. base_addr[CyTDR] = 0x82;
  479. base_addr[CyTDR] = info->x_break * 200 / HZ;
  480. base_addr[CyTDR] = 0; /* terminate break */
  481. base_addr[CyTDR] = 0x83;
  482. char_count -= 7;
  483. info->x_break = 0;
  484. }
  485. while (char_count > 0) {
  486. if (!info->xmit_cnt) {
  487. base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
  488. break;
  489. }
  490. if (info->xmit_buf == 0) {
  491. base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
  492. break;
  493. }
  494. if (info->tty->stopped || info->tty->hw_stopped) {
  495. base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
  496. break;
  497. }
  498. /* Because the Embedded Transmit Commands have been
  499. enabled, we must check to see if the escape
  500. character, NULL, is being sent. If it is, we
  501. must ensure that there is room for it to be
  502. doubled in the output stream. Therefore we
  503. no longer advance the pointer when the character
  504. is fetched, but rather wait until after the check
  505. for a NULL output character. (This is necessary
  506. because there may not be room for the two chars
  507. needed to send a NULL.
  508. */
  509. outch = info->xmit_buf[info->xmit_tail];
  510. if (outch) {
  511. info->xmit_cnt--;
  512. info->xmit_tail = (info->xmit_tail + 1)
  513. & (PAGE_SIZE - 1);
  514. base_addr[CyTDR] = outch;
  515. char_count--;
  516. } else {
  517. if (char_count > 1) {
  518. info->xmit_cnt--;
  519. info->xmit_tail = (info->xmit_tail + 1)
  520. & (PAGE_SIZE - 1);
  521. base_addr[CyTDR] = outch;
  522. base_addr[CyTDR] = 0;
  523. char_count--;
  524. char_count--;
  525. } else {
  526. break;
  527. }
  528. }
  529. }
  530. if (info->xmit_cnt < WAKEUP_CHARS)
  531. tty_wakeup(info->tty);
  532. base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
  533. return IRQ_HANDLED;
  534. } /* cy_tx_interrupt */
  535. static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id)
  536. {
  537. struct tty_struct *tty;
  538. struct cyclades_port *info;
  539. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  540. int channel;
  541. char data;
  542. int char_count;
  543. int save_cnt;
  544. /* determine the channel and change to that context */
  545. channel = (u_short) (base_addr[CyLICR] >> 2);
  546. info = &cy_port[channel];
  547. info->last_active = jiffies;
  548. save_cnt = char_count = base_addr[CyRFOC];
  549. /* if there is nowhere to put the data, discard it */
  550. if (info->tty == 0) {
  551. while (char_count--) {
  552. data = base_addr[CyRDR];
  553. }
  554. } else { /* there is an open port for this data */
  555. tty = info->tty;
  556. /* load # characters available from the chip */
  557. #ifdef CYCLOM_ENABLE_MONITORING
  558. ++info->mon.int_count;
  559. info->mon.char_count += char_count;
  560. if (char_count > info->mon.char_max)
  561. info->mon.char_max = char_count;
  562. info->mon.char_last = char_count;
  563. #endif
  564. while (char_count--) {
  565. data = base_addr[CyRDR];
  566. tty_insert_flip_char(tty, data, TTY_NORMAL);
  567. #ifdef CYCLOM_16Y_HACK
  568. udelay(10L);
  569. #endif
  570. }
  571. tty_schedule_flip(tty);
  572. }
  573. /* end of service */
  574. base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
  575. return IRQ_HANDLED;
  576. } /* cy_rx_interrupt */
  577. /* This is called whenever a port becomes active;
  578. interrupts are enabled and DTR & RTS are turned on.
  579. */
  580. static int startup(struct cyclades_port *info)
  581. {
  582. unsigned long flags;
  583. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  584. int channel;
  585. if (info->flags & ASYNC_INITIALIZED) {
  586. return 0;
  587. }
  588. if (!info->type) {
  589. if (info->tty) {
  590. set_bit(TTY_IO_ERROR, &info->tty->flags);
  591. }
  592. return 0;
  593. }
  594. if (!info->xmit_buf) {
  595. info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
  596. if (!info->xmit_buf) {
  597. return -ENOMEM;
  598. }
  599. }
  600. config_setup(info);
  601. channel = info->line;
  602. #ifdef SERIAL_DEBUG_OPEN
  603. printk("startup channel %d\n", channel);
  604. #endif
  605. local_irq_save(flags);
  606. base_addr[CyCAR] = (u_char) channel;
  607. write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);
  608. base_addr[CyCAR] = (u_char) channel; /* !!! Is this needed? */
  609. base_addr[CyMSVR1] = CyRTS;
  610. /* CP('S');CP('1'); */
  611. base_addr[CyMSVR2] = CyDTR;
  612. #ifdef SERIAL_DEBUG_DTR
  613. printk("cyc: %d: raising DTR\n", __LINE__);
  614. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
  615. base_addr[CyMSVR2]);
  616. #endif
  617. base_addr[CyIER] |= CyRxData;
  618. info->flags |= ASYNC_INITIALIZED;
  619. if (info->tty) {
  620. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  621. }
  622. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  623. local_irq_restore(flags);
  624. #ifdef SERIAL_DEBUG_OPEN
  625. printk(" done\n");
  626. #endif
  627. return 0;
  628. } /* startup */
  629. void start_xmit(struct cyclades_port *info)
  630. {
  631. unsigned long flags;
  632. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  633. int channel;
  634. channel = info->line;
  635. local_irq_save(flags);
  636. base_addr[CyCAR] = channel;
  637. base_addr[CyIER] |= CyTxMpty;
  638. local_irq_restore(flags);
  639. } /* start_xmit */
  640. /*
  641. * This routine shuts down a serial port; interrupts are disabled,
  642. * and DTR is dropped if the hangup on close termio flag is on.
  643. */
  644. static void shutdown(struct cyclades_port *info)
  645. {
  646. unsigned long flags;
  647. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  648. int channel;
  649. if (!(info->flags & ASYNC_INITIALIZED)) {
  650. /* CP('$'); */
  651. return;
  652. }
  653. channel = info->line;
  654. #ifdef SERIAL_DEBUG_OPEN
  655. printk("shutdown channel %d\n", channel);
  656. #endif
  657. /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
  658. SENT BEFORE DROPPING THE LINE !!! (Perhaps
  659. set some flag that is read when XMTY happens.)
  660. Other choices are to delay some fixed interval
  661. or schedule some later processing.
  662. */
  663. local_irq_save(flags);
  664. if (info->xmit_buf) {
  665. free_page((unsigned long)info->xmit_buf);
  666. info->xmit_buf = NULL;
  667. }
  668. base_addr[CyCAR] = (u_char) channel;
  669. if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
  670. base_addr[CyMSVR1] = 0;
  671. /* CP('C');CP('1'); */
  672. base_addr[CyMSVR2] = 0;
  673. #ifdef SERIAL_DEBUG_DTR
  674. printk("cyc: %d: dropping DTR\n", __LINE__);
  675. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
  676. base_addr[CyMSVR2]);
  677. #endif
  678. }
  679. write_cy_cmd(base_addr, CyDIS_RCVR);
  680. /* it may be appropriate to clear _XMIT at
  681. some later date (after testing)!!! */
  682. if (info->tty) {
  683. set_bit(TTY_IO_ERROR, &info->tty->flags);
  684. }
  685. info->flags &= ~ASYNC_INITIALIZED;
  686. local_irq_restore(flags);
  687. #ifdef SERIAL_DEBUG_OPEN
  688. printk(" done\n");
  689. #endif
  690. } /* shutdown */
  691. /*
  692. * This routine finds or computes the various line characteristics.
  693. */
  694. static void config_setup(struct cyclades_port *info)
  695. {
  696. unsigned long flags;
  697. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  698. int channel;
  699. unsigned cflag;
  700. int i;
  701. unsigned char ti, need_init_chan = 0;
  702. if (!info->tty || !info->tty->termios) {
  703. return;
  704. }
  705. if (info->line == -1) {
  706. return;
  707. }
  708. cflag = info->tty->termios->c_cflag;
  709. /* baud rate */
  710. i = cflag & CBAUD;
  711. #ifdef CBAUDEX
  712. /* Starting with kernel 1.1.65, there is direct support for
  713. higher baud rates. The following code supports those
  714. changes. The conditional aspect allows this driver to be
  715. used for earlier as well as later kernel versions. (The
  716. mapping is slightly different from serial.c because there
  717. is still the possibility of supporting 75 kbit/sec with
  718. the Cyclades board.)
  719. */
  720. if (i & CBAUDEX) {
  721. if (i == B57600)
  722. i = 16;
  723. else if (i == B115200)
  724. i = 18;
  725. #ifdef B78600
  726. else if (i == B78600)
  727. i = 17;
  728. #endif
  729. else
  730. info->tty->termios->c_cflag &= ~CBAUDEX;
  731. }
  732. #endif
  733. if (i == 15) {
  734. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  735. i += 1;
  736. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  737. i += 3;
  738. }
  739. /* Don't ever change the speed of the console port. It will
  740. * run at the speed specified in bootinfo, or at 19.2K */
  741. /* Actually, it should run at whatever speed 166Bug was using */
  742. /* Note info->timeout isn't used at present */
  743. if (info != serial_console_info) {
  744. info->tbpr = baud_bpr[i]; /* Tx BPR */
  745. info->tco = baud_co[i]; /* Tx CO */
  746. info->rbpr = baud_bpr[i]; /* Rx BPR */
  747. info->rco = baud_co[i] >> 5; /* Rx CO */
  748. if (baud_table[i] == 134) {
  749. info->timeout =
  750. (info->xmit_fifo_size * HZ * 30 / 269) + 2;
  751. /* get it right for 134.5 baud */
  752. } else if (baud_table[i]) {
  753. info->timeout =
  754. (info->xmit_fifo_size * HZ * 15 / baud_table[i]) +
  755. 2;
  756. /* this needs to be propagated into the card info */
  757. } else {
  758. info->timeout = 0;
  759. }
  760. }
  761. /* By tradition (is it a standard?) a baud rate of zero
  762. implies the line should be/has been closed. A bit
  763. later in this routine such a test is performed. */
  764. /* byte size and parity */
  765. info->cor7 = 0;
  766. info->cor6 = 0;
  767. info->cor5 = 0;
  768. info->cor4 = (info->default_threshold ? info->default_threshold : baud_cor4[i]); /* receive threshold */
  769. /* Following two lines added 101295, RGH. */
  770. /* It is obviously wrong to access CyCORx, and not info->corx here,
  771. * try and remember to fix it later! */
  772. channel = info->line;
  773. base_addr[CyCAR] = (u_char) channel;
  774. if (C_CLOCAL(info->tty)) {
  775. if (base_addr[CyIER] & CyMdmCh)
  776. base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */
  777. /* ignore 1->0 modem transitions */
  778. if (base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD))
  779. base_addr[CyCOR4] &= ~(CyDSR | CyCTS | CyDCD);
  780. /* ignore 0->1 modem transitions */
  781. if (base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD))
  782. base_addr[CyCOR5] &= ~(CyDSR | CyCTS | CyDCD);
  783. } else {
  784. if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
  785. base_addr[CyIER] |= CyMdmCh; /* with modem intr */
  786. /* act on 1->0 modem transitions */
  787. if ((base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD)) !=
  788. (CyDSR | CyCTS | CyDCD))
  789. base_addr[CyCOR4] |= CyDSR | CyCTS | CyDCD;
  790. /* act on 0->1 modem transitions */
  791. if ((base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD)) !=
  792. (CyDSR | CyCTS | CyDCD))
  793. base_addr[CyCOR5] |= CyDSR | CyCTS | CyDCD;
  794. }
  795. info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
  796. info->cor2 = CyETC;
  797. switch (cflag & CSIZE) {
  798. case CS5:
  799. info->cor1 = Cy_5_BITS;
  800. break;
  801. case CS6:
  802. info->cor1 = Cy_6_BITS;
  803. break;
  804. case CS7:
  805. info->cor1 = Cy_7_BITS;
  806. break;
  807. case CS8:
  808. info->cor1 = Cy_8_BITS;
  809. break;
  810. }
  811. if (cflag & PARENB) {
  812. if (cflag & PARODD) {
  813. info->cor1 |= CyPARITY_O;
  814. } else {
  815. info->cor1 |= CyPARITY_E;
  816. }
  817. } else {
  818. info->cor1 |= CyPARITY_NONE;
  819. }
  820. /* CTS flow control flag */
  821. #if 0
  822. /* Don't complcate matters for now! RGH 141095 */
  823. if (cflag & CRTSCTS) {
  824. info->flags |= ASYNC_CTS_FLOW;
  825. info->cor2 |= CyCtsAE;
  826. } else {
  827. info->flags &= ~ASYNC_CTS_FLOW;
  828. info->cor2 &= ~CyCtsAE;
  829. }
  830. #endif
  831. if (cflag & CLOCAL)
  832. info->flags &= ~ASYNC_CHECK_CD;
  833. else
  834. info->flags |= ASYNC_CHECK_CD;
  835. /***********************************************
  836. The hardware option, CyRtsAO, presents RTS when
  837. the chip has characters to send. Since most modems
  838. use RTS as reverse (inbound) flow control, this
  839. option is not used. If inbound flow control is
  840. necessary, DTR can be programmed to provide the
  841. appropriate signals for use with a non-standard
  842. cable. Contact Marcio Saito for details.
  843. ***********************************************/
  844. channel = info->line;
  845. local_irq_save(flags);
  846. base_addr[CyCAR] = (u_char) channel;
  847. /* CyCMR set once only in mvme167_init_serial() */
  848. if (base_addr[CyLICR] != channel << 2)
  849. base_addr[CyLICR] = channel << 2;
  850. if (base_addr[CyLIVR] != 0x5c)
  851. base_addr[CyLIVR] = 0x5c;
  852. /* tx and rx baud rate */
  853. if (base_addr[CyCOR1] != info->cor1)
  854. need_init_chan = 1;
  855. if (base_addr[CyTCOR] != info->tco)
  856. base_addr[CyTCOR] = info->tco;
  857. if (base_addr[CyTBPR] != info->tbpr)
  858. base_addr[CyTBPR] = info->tbpr;
  859. if (base_addr[CyRCOR] != info->rco)
  860. base_addr[CyRCOR] = info->rco;
  861. if (base_addr[CyRBPR] != info->rbpr)
  862. base_addr[CyRBPR] = info->rbpr;
  863. /* set line characteristics according configuration */
  864. if (base_addr[CySCHR1] != START_CHAR(info->tty))
  865. base_addr[CySCHR1] = START_CHAR(info->tty);
  866. if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
  867. base_addr[CySCHR2] = STOP_CHAR(info->tty);
  868. if (base_addr[CySCRL] != START_CHAR(info->tty))
  869. base_addr[CySCRL] = START_CHAR(info->tty);
  870. if (base_addr[CySCRH] != START_CHAR(info->tty))
  871. base_addr[CySCRH] = START_CHAR(info->tty);
  872. if (base_addr[CyCOR1] != info->cor1)
  873. base_addr[CyCOR1] = info->cor1;
  874. if (base_addr[CyCOR2] != info->cor2)
  875. base_addr[CyCOR2] = info->cor2;
  876. if (base_addr[CyCOR3] != info->cor3)
  877. base_addr[CyCOR3] = info->cor3;
  878. if (base_addr[CyCOR4] != info->cor4)
  879. base_addr[CyCOR4] = info->cor4;
  880. if (base_addr[CyCOR5] != info->cor5)
  881. base_addr[CyCOR5] = info->cor5;
  882. if (base_addr[CyCOR6] != info->cor6)
  883. base_addr[CyCOR6] = info->cor6;
  884. if (base_addr[CyCOR7] != info->cor7)
  885. base_addr[CyCOR7] = info->cor7;
  886. if (need_init_chan)
  887. write_cy_cmd(base_addr, CyINIT_CHAN);
  888. base_addr[CyCAR] = (u_char) channel; /* !!! Is this needed? */
  889. /* 2ms default rx timeout */
  890. ti = info->default_timeout ? info->default_timeout : 0x02;
  891. if (base_addr[CyRTPRL] != ti)
  892. base_addr[CyRTPRL] = ti;
  893. if (base_addr[CyRTPRH] != 0)
  894. base_addr[CyRTPRH] = 0;
  895. /* Set up RTS here also ????? RGH 141095 */
  896. if (i == 0) { /* baud rate is zero, turn off line */
  897. if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
  898. base_addr[CyMSVR2] = 0;
  899. #ifdef SERIAL_DEBUG_DTR
  900. printk("cyc: %d: dropping DTR\n", __LINE__);
  901. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
  902. base_addr[CyMSVR2]);
  903. #endif
  904. } else {
  905. if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
  906. base_addr[CyMSVR2] = CyDTR;
  907. #ifdef SERIAL_DEBUG_DTR
  908. printk("cyc: %d: raising DTR\n", __LINE__);
  909. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
  910. base_addr[CyMSVR2]);
  911. #endif
  912. }
  913. if (info->tty) {
  914. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  915. }
  916. local_irq_restore(flags);
  917. } /* config_setup */
  918. static int cy_put_char(struct tty_struct *tty, unsigned char ch)
  919. {
  920. struct cyclades_port *info = tty->driver_data;
  921. unsigned long flags;
  922. #ifdef SERIAL_DEBUG_IO
  923. printk("cy_put_char %s(0x%02x)\n", tty->name, ch);
  924. #endif
  925. if (serial_paranoia_check(info, tty->name, "cy_put_char"))
  926. return 0;
  927. if (!info->xmit_buf)
  928. return 0;
  929. local_irq_save(flags);
  930. if (info->xmit_cnt >= PAGE_SIZE - 1) {
  931. local_irq_restore(flags);
  932. return 0;
  933. }
  934. info->xmit_buf[info->xmit_head++] = ch;
  935. info->xmit_head &= PAGE_SIZE - 1;
  936. info->xmit_cnt++;
  937. local_irq_restore(flags);
  938. return 1;
  939. } /* cy_put_char */
  940. static void cy_flush_chars(struct tty_struct *tty)
  941. {
  942. struct cyclades_port *info = tty->driver_data;
  943. unsigned long flags;
  944. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  945. int channel;
  946. #ifdef SERIAL_DEBUG_IO
  947. printk("cy_flush_chars %s\n", tty->name); /* */
  948. #endif
  949. if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
  950. return;
  951. if (info->xmit_cnt <= 0 || tty->stopped
  952. || tty->hw_stopped || !info->xmit_buf)
  953. return;
  954. channel = info->line;
  955. local_irq_save(flags);
  956. base_addr[CyCAR] = channel;
  957. base_addr[CyIER] |= CyTxMpty;
  958. local_irq_restore(flags);
  959. } /* cy_flush_chars */
  960. /* This routine gets called when tty_write has put something into
  961. the write_queue. If the port is not already transmitting stuff,
  962. start it off by enabling interrupts. The interrupt service
  963. routine will then ensure that the characters are sent. If the
  964. port is already active, there is no need to kick it.
  965. */
  966. static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
  967. {
  968. struct cyclades_port *info = tty->driver_data;
  969. unsigned long flags;
  970. int c, total = 0;
  971. #ifdef SERIAL_DEBUG_IO
  972. printk("cy_write %s\n", tty->name); /* */
  973. #endif
  974. if (serial_paranoia_check(info, tty->name, "cy_write")) {
  975. return 0;
  976. }
  977. if (!info->xmit_buf) {
  978. return 0;
  979. }
  980. while (1) {
  981. local_irq_save(flags);
  982. c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
  983. SERIAL_XMIT_SIZE - info->xmit_head));
  984. if (c <= 0) {
  985. local_irq_restore(flags);
  986. break;
  987. }
  988. memcpy(info->xmit_buf + info->xmit_head, buf, c);
  989. info->xmit_head =
  990. (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1);
  991. info->xmit_cnt += c;
  992. local_irq_restore(flags);
  993. buf += c;
  994. count -= c;
  995. total += c;
  996. }
  997. if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
  998. start_xmit(info);
  999. }
  1000. return total;
  1001. } /* cy_write */
  1002. static int cy_write_room(struct tty_struct *tty)
  1003. {
  1004. struct cyclades_port *info = tty->driver_data;
  1005. int ret;
  1006. #ifdef SERIAL_DEBUG_IO
  1007. printk("cy_write_room %s\n", tty->name); /* */
  1008. #endif
  1009. if (serial_paranoia_check(info, tty->name, "cy_write_room"))
  1010. return 0;
  1011. ret = PAGE_SIZE - info->xmit_cnt - 1;
  1012. if (ret < 0)
  1013. ret = 0;
  1014. return ret;
  1015. } /* cy_write_room */
  1016. static int cy_chars_in_buffer(struct tty_struct *tty)
  1017. {
  1018. struct cyclades_port *info = tty->driver_data;
  1019. #ifdef SERIAL_DEBUG_IO
  1020. printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */
  1021. #endif
  1022. if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
  1023. return 0;
  1024. return info->xmit_cnt;
  1025. } /* cy_chars_in_buffer */
  1026. static void cy_flush_buffer(struct tty_struct *tty)
  1027. {
  1028. struct cyclades_port *info = tty->driver_data;
  1029. unsigned long flags;
  1030. #ifdef SERIAL_DEBUG_IO
  1031. printk("cy_flush_buffer %s\n", tty->name); /* */
  1032. #endif
  1033. if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
  1034. return;
  1035. local_irq_save(flags);
  1036. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1037. local_irq_restore(flags);
  1038. tty_wakeup(tty);
  1039. } /* cy_flush_buffer */
  1040. /* This routine is called by the upper-layer tty layer to signal
  1041. that incoming characters should be throttled or that the
  1042. throttle should be released.
  1043. */
  1044. static void cy_throttle(struct tty_struct *tty)
  1045. {
  1046. struct cyclades_port *info = tty->driver_data;
  1047. unsigned long flags;
  1048. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1049. int channel;
  1050. #ifdef SERIAL_DEBUG_THROTTLE
  1051. char buf[64];
  1052. printk("throttle %s: %d....\n", tty_name(tty, buf),
  1053. tty->ldisc.chars_in_buffer(tty));
  1054. printk("cy_throttle %s\n", tty->name);
  1055. #endif
  1056. if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
  1057. return;
  1058. }
  1059. if (I_IXOFF(tty)) {
  1060. info->x_char = STOP_CHAR(tty);
  1061. /* Should use the "Send Special Character" feature!!! */
  1062. }
  1063. channel = info->line;
  1064. local_irq_save(flags);
  1065. base_addr[CyCAR] = (u_char) channel;
  1066. base_addr[CyMSVR1] = 0;
  1067. local_irq_restore(flags);
  1068. } /* cy_throttle */
  1069. static void cy_unthrottle(struct tty_struct *tty)
  1070. {
  1071. struct cyclades_port *info = tty->driver_data;
  1072. unsigned long flags;
  1073. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1074. int channel;
  1075. #ifdef SERIAL_DEBUG_THROTTLE
  1076. char buf[64];
  1077. printk("throttle %s: %d....\n", tty_name(tty, buf),
  1078. tty->ldisc.chars_in_buffer(tty));
  1079. printk("cy_unthrottle %s\n", tty->name);
  1080. #endif
  1081. if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
  1082. return;
  1083. }
  1084. if (I_IXOFF(tty)) {
  1085. info->x_char = START_CHAR(tty);
  1086. /* Should use the "Send Special Character" feature!!! */
  1087. }
  1088. channel = info->line;
  1089. local_irq_save(flags);
  1090. base_addr[CyCAR] = (u_char) channel;
  1091. base_addr[CyMSVR1] = CyRTS;
  1092. local_irq_restore(flags);
  1093. } /* cy_unthrottle */
  1094. static int
  1095. get_serial_info(struct cyclades_port *info,
  1096. struct serial_struct __user * retinfo)
  1097. {
  1098. struct serial_struct tmp;
  1099. /* CP('g'); */
  1100. if (!retinfo)
  1101. return -EFAULT;
  1102. memset(&tmp, 0, sizeof(tmp));
  1103. tmp.type = info->type;
  1104. tmp.line = info->line;
  1105. tmp.port = info->line;
  1106. tmp.irq = 0;
  1107. tmp.flags = info->flags;
  1108. tmp.baud_base = 0; /*!!! */
  1109. tmp.close_delay = info->close_delay;
  1110. tmp.custom_divisor = 0; /*!!! */
  1111. tmp.hub6 = 0; /*!!! */
  1112. return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
  1113. } /* get_serial_info */
  1114. static int
  1115. set_serial_info(struct cyclades_port *info,
  1116. struct serial_struct __user * new_info)
  1117. {
  1118. struct serial_struct new_serial;
  1119. struct cyclades_port old_info;
  1120. /* CP('s'); */
  1121. if (!new_info)
  1122. return -EFAULT;
  1123. if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
  1124. return -EFAULT;
  1125. old_info = *info;
  1126. if (!capable(CAP_SYS_ADMIN)) {
  1127. if ((new_serial.close_delay != info->close_delay) ||
  1128. ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
  1129. (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
  1130. return -EPERM;
  1131. info->flags = ((info->flags & ~ASYNC_USR_MASK) |
  1132. (new_serial.flags & ASYNC_USR_MASK));
  1133. goto check_and_exit;
  1134. }
  1135. /*
  1136. * OK, past this point, all the error checking has been done.
  1137. * At this point, we start making changes.....
  1138. */
  1139. info->flags = ((info->flags & ~ASYNC_FLAGS) |
  1140. (new_serial.flags & ASYNC_FLAGS));
  1141. info->close_delay = new_serial.close_delay;
  1142. check_and_exit:
  1143. if (info->flags & ASYNC_INITIALIZED) {
  1144. config_setup(info);
  1145. return 0;
  1146. }
  1147. return startup(info);
  1148. } /* set_serial_info */
  1149. static int cy_tiocmget(struct tty_struct *tty)
  1150. {
  1151. struct cyclades_port *info = tty->driver_data;
  1152. int channel;
  1153. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1154. unsigned long flags;
  1155. unsigned char status;
  1156. channel = info->line;
  1157. local_irq_save(flags);
  1158. base_addr[CyCAR] = (u_char) channel;
  1159. status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
  1160. local_irq_restore(flags);
  1161. return ((status & CyRTS) ? TIOCM_RTS : 0)
  1162. | ((status & CyDTR) ? TIOCM_DTR : 0)
  1163. | ((status & CyDCD) ? TIOCM_CAR : 0)
  1164. | ((status & CyDSR) ? TIOCM_DSR : 0)
  1165. | ((status & CyCTS) ? TIOCM_CTS : 0);
  1166. } /* cy_tiocmget */
  1167. static int
  1168. cy_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear)
  1169. {
  1170. struct cyclades_port *info = tty->driver_data;
  1171. int channel;
  1172. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1173. unsigned long flags;
  1174. channel = info->line;
  1175. if (set & TIOCM_RTS) {
  1176. local_irq_save(flags);
  1177. base_addr[CyCAR] = (u_char) channel;
  1178. base_addr[CyMSVR1] = CyRTS;
  1179. local_irq_restore(flags);
  1180. }
  1181. if (set & TIOCM_DTR) {
  1182. local_irq_save(flags);
  1183. base_addr[CyCAR] = (u_char) channel;
  1184. /* CP('S');CP('2'); */
  1185. base_addr[CyMSVR2] = CyDTR;
  1186. #ifdef SERIAL_DEBUG_DTR
  1187. printk("cyc: %d: raising DTR\n", __LINE__);
  1188. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
  1189. base_addr[CyMSVR2]);
  1190. #endif
  1191. local_irq_restore(flags);
  1192. }
  1193. if (clear & TIOCM_RTS) {
  1194. local_irq_save(flags);
  1195. base_addr[CyCAR] = (u_char) channel;
  1196. base_addr[CyMSVR1] = 0;
  1197. local_irq_restore(flags);
  1198. }
  1199. if (clear & TIOCM_DTR) {
  1200. local_irq_save(flags);
  1201. base_addr[CyCAR] = (u_char) channel;
  1202. /* CP('C');CP('2'); */
  1203. base_addr[CyMSVR2] = 0;
  1204. #ifdef SERIAL_DEBUG_DTR
  1205. printk("cyc: %d: dropping DTR\n", __LINE__);
  1206. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
  1207. base_addr[CyMSVR2]);
  1208. #endif
  1209. local_irq_restore(flags);
  1210. }
  1211. return 0;
  1212. } /* set_modem_info */
  1213. static void send_break(struct cyclades_port *info, int duration)
  1214. { /* Let the transmit ISR take care of this (since it
  1215. requires stuffing characters into the output stream).
  1216. */
  1217. info->x_break = duration;
  1218. if (!info->xmit_cnt) {
  1219. start_xmit(info);
  1220. }
  1221. } /* send_break */
  1222. static int
  1223. get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
  1224. {
  1225. if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
  1226. return -EFAULT;
  1227. info->mon.int_count = 0;
  1228. info->mon.char_count = 0;
  1229. info->mon.char_max = 0;
  1230. info->mon.char_last = 0;
  1231. return 0;
  1232. }
  1233. static int set_threshold(struct cyclades_port *info, unsigned long __user * arg)
  1234. {
  1235. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1236. unsigned long value;
  1237. int channel;
  1238. if (get_user(value, arg))
  1239. return -EFAULT;
  1240. channel = info->line;
  1241. info->cor4 &= ~CyREC_FIFO;
  1242. info->cor4 |= value & CyREC_FIFO;
  1243. base_addr[CyCOR4] = info->cor4;
  1244. return 0;
  1245. }
  1246. static int
  1247. get_threshold(struct cyclades_port *info, unsigned long __user * value)
  1248. {
  1249. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1250. int channel;
  1251. unsigned long tmp;
  1252. channel = info->line;
  1253. tmp = base_addr[CyCOR4] & CyREC_FIFO;
  1254. return put_user(tmp, value);
  1255. }
  1256. static int
  1257. set_default_threshold(struct cyclades_port *info, unsigned long __user * arg)
  1258. {
  1259. unsigned long value;
  1260. if (get_user(value, arg))
  1261. return -EFAULT;
  1262. info->default_threshold = value & 0x0f;
  1263. return 0;
  1264. }
  1265. static int
  1266. get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
  1267. {
  1268. return put_user(info->default_threshold, value);
  1269. }
  1270. static int set_timeout(struct cyclades_port *info, unsigned long __user * arg)
  1271. {
  1272. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1273. int channel;
  1274. unsigned long value;
  1275. if (get_user(value, arg))
  1276. return -EFAULT;
  1277. channel = info->line;
  1278. base_addr[CyRTPRL] = value & 0xff;
  1279. base_addr[CyRTPRH] = (value >> 8) & 0xff;
  1280. return 0;
  1281. }
  1282. static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
  1283. {
  1284. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1285. int channel;
  1286. unsigned long tmp;
  1287. channel = info->line;
  1288. tmp = base_addr[CyRTPRL];
  1289. return put_user(tmp, value);
  1290. }
  1291. static int set_default_timeout(struct cyclades_port *info, unsigned long value)
  1292. {
  1293. info->default_timeout = value & 0xff;
  1294. return 0;
  1295. }
  1296. static int
  1297. get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
  1298. {
  1299. return put_user(info->default_timeout, value);
  1300. }
  1301. static int
  1302. cy_ioctl(struct tty_struct *tty,
  1303. unsigned int cmd, unsigned long arg)
  1304. {
  1305. struct cyclades_port *info = tty->driver_data;
  1306. int ret_val = 0;
  1307. void __user *argp = (void __user *)arg;
  1308. #ifdef SERIAL_DEBUG_OTHER
  1309. printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
  1310. #endif
  1311. tty_lock();
  1312. switch (cmd) {
  1313. case CYGETMON:
  1314. ret_val = get_mon_info(info, argp);
  1315. break;
  1316. case CYGETTHRESH:
  1317. ret_val = get_threshold(info, argp);
  1318. break;
  1319. case CYSETTHRESH:
  1320. ret_val = set_threshold(info, argp);
  1321. break;
  1322. case CYGETDEFTHRESH:
  1323. ret_val = get_default_threshold(info, argp);
  1324. break;
  1325. case CYSETDEFTHRESH:
  1326. ret_val = set_default_threshold(info, argp);
  1327. break;
  1328. case CYGETTIMEOUT:
  1329. ret_val = get_timeout(info, argp);
  1330. break;
  1331. case CYSETTIMEOUT:
  1332. ret_val = set_timeout(info, argp);
  1333. break;
  1334. case CYGETDEFTIMEOUT:
  1335. ret_val = get_default_timeout(info, argp);
  1336. break;
  1337. case CYSETDEFTIMEOUT:
  1338. ret_val = set_default_timeout(info, (unsigned long)arg);
  1339. break;
  1340. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1341. ret_val = tty_check_change(tty);
  1342. if (ret_val)
  1343. break;
  1344. tty_wait_until_sent(tty, 0);
  1345. if (!arg)
  1346. send_break(info, HZ / 4); /* 1/4 second */
  1347. break;
  1348. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1349. ret_val = tty_check_change(tty);
  1350. if (ret_val)
  1351. break;
  1352. tty_wait_until_sent(tty, 0);
  1353. send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
  1354. break;
  1355. /* The following commands are incompletely implemented!!! */
  1356. case TIOCGSERIAL:
  1357. ret_val = get_serial_info(info, argp);
  1358. break;
  1359. case TIOCSSERIAL:
  1360. ret_val = set_serial_info(info, argp);
  1361. break;
  1362. default:
  1363. ret_val = -ENOIOCTLCMD;
  1364. }
  1365. tty_unlock();
  1366. #ifdef SERIAL_DEBUG_OTHER
  1367. printk("cy_ioctl done\n");
  1368. #endif
  1369. return ret_val;
  1370. } /* cy_ioctl */
  1371. static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
  1372. {
  1373. struct cyclades_port *info = tty->driver_data;
  1374. #ifdef SERIAL_DEBUG_OTHER
  1375. printk("cy_set_termios %s\n", tty->name);
  1376. #endif
  1377. if (tty->termios->c_cflag == old_termios->c_cflag)
  1378. return;
  1379. config_setup(info);
  1380. if ((old_termios->c_cflag & CRTSCTS) &&
  1381. !(tty->termios->c_cflag & CRTSCTS)) {
  1382. tty->stopped = 0;
  1383. cy_start(tty);
  1384. }
  1385. #ifdef tytso_patch_94Nov25_1726
  1386. if (!(old_termios->c_cflag & CLOCAL) &&
  1387. (tty->termios->c_cflag & CLOCAL))
  1388. wake_up_interruptible(&info->open_wait);
  1389. #endif
  1390. } /* cy_set_termios */
  1391. static void cy_close(struct tty_struct *tty, struct file *filp)
  1392. {
  1393. struct cyclades_port *info = tty->driver_data;
  1394. /* CP('C'); */
  1395. #ifdef SERIAL_DEBUG_OTHER
  1396. printk("cy_close %s\n", tty->name);
  1397. #endif
  1398. if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
  1399. return;
  1400. }
  1401. #ifdef SERIAL_DEBUG_OPEN
  1402. printk("cy_close %s, count = %d\n", tty->name, info->count);
  1403. #endif
  1404. if ((tty->count == 1) && (info->count != 1)) {
  1405. /*
  1406. * Uh, oh. tty->count is 1, which means that the tty
  1407. * structure will be freed. Info->count should always
  1408. * be one in these conditions. If it's greater than
  1409. * one, we've got real problems, since it means the
  1410. * serial port won't be shutdown.
  1411. */
  1412. printk("cy_close: bad serial port count; tty->count is 1, "
  1413. "info->count is %d\n", info->count);
  1414. info->count = 1;
  1415. }
  1416. #ifdef SERIAL_DEBUG_COUNT
  1417. printk("cyc: %d: decrementing count to %d\n", __LINE__,
  1418. info->count - 1);
  1419. #endif
  1420. if (--info->count < 0) {
  1421. printk("cy_close: bad serial port count for ttys%d: %d\n",
  1422. info->line, info->count);
  1423. #ifdef SERIAL_DEBUG_COUNT
  1424. printk("cyc: %d: setting count to 0\n", __LINE__);
  1425. #endif
  1426. info->count = 0;
  1427. }
  1428. if (info->count)
  1429. return;
  1430. info->flags |= ASYNC_CLOSING;
  1431. if (info->flags & ASYNC_INITIALIZED)
  1432. tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
  1433. shutdown(info);
  1434. cy_flush_buffer(tty);
  1435. tty_ldisc_flush(tty);
  1436. info->tty = NULL;
  1437. if (info->blocked_open) {
  1438. if (info->close_delay) {
  1439. msleep_interruptible(jiffies_to_msecs
  1440. (info->close_delay));
  1441. }
  1442. wake_up_interruptible(&info->open_wait);
  1443. }
  1444. info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
  1445. wake_up_interruptible(&info->close_wait);
  1446. #ifdef SERIAL_DEBUG_OTHER
  1447. printk("cy_close done\n");
  1448. #endif
  1449. } /* cy_close */
  1450. /*
  1451. * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
  1452. */
  1453. void cy_hangup(struct tty_struct *tty)
  1454. {
  1455. struct cyclades_port *info = tty->driver_data;
  1456. #ifdef SERIAL_DEBUG_OTHER
  1457. printk("cy_hangup %s\n", tty->name); /* */
  1458. #endif
  1459. if (serial_paranoia_check(info, tty->name, "cy_hangup"))
  1460. return;
  1461. shutdown(info);
  1462. #if 0
  1463. info->event = 0;
  1464. info->count = 0;
  1465. #ifdef SERIAL_DEBUG_COUNT
  1466. printk("cyc: %d: setting count to 0\n", __LINE__);
  1467. #endif
  1468. info->tty = 0;
  1469. #endif
  1470. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  1471. wake_up_interruptible(&info->open_wait);
  1472. } /* cy_hangup */
  1473. /*
  1474. * ------------------------------------------------------------
  1475. * cy_open() and friends
  1476. * ------------------------------------------------------------
  1477. */
  1478. static int
  1479. block_til_ready(struct tty_struct *tty, struct file *filp,
  1480. struct cyclades_port *info)
  1481. {
  1482. DECLARE_WAITQUEUE(wait, current);
  1483. unsigned long flags;
  1484. int channel;
  1485. int retval;
  1486. volatile u_char *base_addr = (u_char *) BASE_ADDR;
  1487. /*
  1488. * If the device is in the middle of being closed, then block
  1489. * until it's done, and then try again.
  1490. */
  1491. if (info->flags & ASYNC_CLOSING) {
  1492. interruptible_sleep_on(&info->close_wait);
  1493. if (info->flags & ASYNC_HUP_NOTIFY) {
  1494. return -EAGAIN;
  1495. } else {
  1496. return -ERESTARTSYS;
  1497. }
  1498. }
  1499. /*
  1500. * If non-blocking mode is set, then make the check up front
  1501. * and then exit.
  1502. */
  1503. if (filp->f_flags & O_NONBLOCK) {
  1504. info->flags |= ASYNC_NORMAL_ACTIVE;
  1505. return 0;
  1506. }
  1507. /*
  1508. * Block waiting for the carrier detect and the line to become
  1509. * free (i.e., not in use by the callout). While we are in
  1510. * this loop, info->count is dropped by one, so that
  1511. * cy_close() knows when to free things. We restore it upon
  1512. * exit, either normal or abnormal.
  1513. */
  1514. retval = 0;
  1515. add_wait_queue(&info->open_wait, &wait);
  1516. #ifdef SERIAL_DEBUG_OPEN
  1517. printk("block_til_ready before block: %s, count = %d\n",
  1518. tty->name, info->count);
  1519. /**/
  1520. #endif
  1521. info->count--;
  1522. #ifdef SERIAL_DEBUG_COUNT
  1523. printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
  1524. #endif
  1525. info->blocked_open++;
  1526. channel = info->line;
  1527. while (1) {
  1528. local_irq_save(flags);
  1529. base_addr[CyCAR] = (u_char) channel;
  1530. base_addr[CyMSVR1] = CyRTS;
  1531. /* CP('S');CP('4'); */
  1532. base_addr[CyMSVR2] = CyDTR;
  1533. #ifdef SERIAL_DEBUG_DTR
  1534. printk("cyc: %d: raising DTR\n", __LINE__);
  1535. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
  1536. base_addr[CyMSVR2]);
  1537. #endif
  1538. local_irq_restore(flags);
  1539. set_current_state(TASK_INTERRUPTIBLE);
  1540. if (tty_hung_up_p(filp)
  1541. || !(info->flags & ASYNC_INITIALIZED)) {
  1542. if (info->flags & ASYNC_HUP_NOTIFY) {
  1543. retval = -EAGAIN;
  1544. } else {
  1545. retval = -ERESTARTSYS;
  1546. }
  1547. break;
  1548. }
  1549. local_irq_save(flags);
  1550. base_addr[CyCAR] = (u_char) channel;
  1551. /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
  1552. if (!(info->flags & ASYNC_CLOSING)
  1553. && (C_CLOCAL(tty)
  1554. || (base_addr[CyMSVR1] & CyDCD))) {
  1555. local_irq_restore(flags);
  1556. break;
  1557. }
  1558. local_irq_restore(flags);
  1559. if (signal_pending(current)) {
  1560. retval = -ERESTARTSYS;
  1561. break;
  1562. }
  1563. #ifdef SERIAL_DEBUG_OPEN
  1564. printk("block_til_ready blocking: %s, count = %d\n",
  1565. tty->name, info->count);
  1566. /**/
  1567. #endif
  1568. tty_unlock();
  1569. schedule();
  1570. tty_lock();
  1571. }
  1572. __set_current_state(TASK_RUNNING);
  1573. remove_wait_queue(&info->open_wait, &wait);
  1574. if (!tty_hung_up_p(filp)) {
  1575. info->count++;
  1576. #ifdef SERIAL_DEBUG_COUNT
  1577. printk("cyc: %d: incrementing count to %d\n", __LINE__,
  1578. info->count);
  1579. #endif
  1580. }
  1581. info->blocked_open--;
  1582. #ifdef SERIAL_DEBUG_OPEN
  1583. printk("block_til_ready after blocking: %s, count = %d\n",
  1584. tty->name, info->count);
  1585. /**/
  1586. #endif
  1587. if (retval)
  1588. return retval;
  1589. info->flags |= ASYNC_NORMAL_ACTIVE;
  1590. return 0;
  1591. } /* block_til_ready */
  1592. /*
  1593. * This routine is called whenever a serial port is opened. It
  1594. * performs the serial-specific initialization for the tty structure.
  1595. */
  1596. int cy_open(struct tty_struct *tty, struct file *filp)
  1597. {
  1598. struct cyclades_port *info;
  1599. int retval, line;
  1600. /* CP('O'); */
  1601. line = tty->index;
  1602. if ((line < 0) || (NR_PORTS <= line)) {
  1603. return -ENODEV;
  1604. }
  1605. info = &cy_port[line];
  1606. if (info->line < 0) {
  1607. return -ENODEV;
  1608. }
  1609. #ifdef SERIAL_DEBUG_OTHER
  1610. printk("cy_open %s\n", tty->name); /* */
  1611. #endif
  1612. if (serial_paranoia_check(info, tty->name, "cy_open")) {
  1613. return -ENODEV;
  1614. }
  1615. #ifdef SERIAL_DEBUG_OPEN
  1616. printk("cy_open %s, count = %d\n", tty->name, info->count);
  1617. /**/
  1618. #endif
  1619. info->count++;
  1620. #ifdef SERIAL_DEBUG_COUNT
  1621. printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
  1622. #endif
  1623. tty->driver_data = info;
  1624. info->tty = tty;
  1625. /*
  1626. * Start up serial port
  1627. */
  1628. retval = startup(info);
  1629. if (retval) {
  1630. return retval;
  1631. }
  1632. retval = block_til_ready(tty, filp, info);
  1633. if (retval) {
  1634. #ifdef SERIAL_DEBUG_OPEN
  1635. printk("cy_open returning after block_til_ready with %d\n",
  1636. retval);
  1637. #endif
  1638. return retval;
  1639. }
  1640. #ifdef SERIAL_DEBUG_OPEN
  1641. printk("cy_open done\n");
  1642. /**/
  1643. #endif
  1644. return 0;
  1645. } /* cy_open */
  1646. /*
  1647. * ---------------------------------------------------------------------
  1648. * serial167_init() and friends
  1649. *
  1650. * serial167_init() is called at boot-time to initialize the serial driver.
  1651. * ---------------------------------------------------------------------
  1652. */
  1653. /*
  1654. * This routine prints out the appropriate serial driver version
  1655. * number, and identifies which options were configured into this
  1656. * driver.
  1657. */
  1658. static void show_version(void)
  1659. {
  1660. printk("MVME166/167 cd2401 driver\n");
  1661. } /* show_version */
  1662. /* initialize chips on card -- return number of valid
  1663. chips (which is number of ports/4) */
  1664. /*
  1665. * This initialises the hardware to a reasonable state. It should
  1666. * probe the chip first so as to copy 166-Bug setup as a default for
  1667. * port 0. It initialises CMR to CyASYNC; that is never done again, so
  1668. * as to limit the number of CyINIT_CHAN commands in normal running.
  1669. *
  1670. * ... I wonder what I should do if this fails ...
  1671. */
  1672. void mvme167_serial_console_setup(int cflag)
  1673. {
  1674. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1675. int ch;
  1676. u_char spd;
  1677. u_char rcor, rbpr, badspeed = 0;
  1678. unsigned long flags;
  1679. local_irq_save(flags);
  1680. /*
  1681. * First probe channel zero of the chip, to see what speed has
  1682. * been selected.
  1683. */
  1684. base_addr[CyCAR] = 0;
  1685. rcor = base_addr[CyRCOR] << 5;
  1686. rbpr = base_addr[CyRBPR];
  1687. for (spd = 0; spd < sizeof(baud_bpr); spd++)
  1688. if (rbpr == baud_bpr[spd] && rcor == baud_co[spd])
  1689. break;
  1690. if (spd >= sizeof(baud_bpr)) {
  1691. spd = 14; /* 19200 */
  1692. badspeed = 1; /* Failed to identify speed */
  1693. }
  1694. initial_console_speed = spd;
  1695. /* OK, we have chosen a speed, now reset and reinitialise */
  1696. my_udelay(20000L); /* Allow time for any active o/p to complete */
  1697. if (base_addr[CyCCR] != 0x00) {
  1698. local_irq_restore(flags);
  1699. /* printk(" chip is never idle (CCR != 0)\n"); */
  1700. return;
  1701. }
  1702. base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */
  1703. my_udelay(1000L);
  1704. if (base_addr[CyGFRCR] == 0x00) {
  1705. local_irq_restore(flags);
  1706. /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
  1707. return;
  1708. }
  1709. /*
  1710. * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
  1711. * tick
  1712. */
  1713. base_addr[CyTPR] = 10;
  1714. base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */
  1715. base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */
  1716. base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */
  1717. /*
  1718. * Attempt to set up all channels to something reasonable, and
  1719. * bang out a INIT_CHAN command. We should then be able to limit
  1720. * the amount of fiddling we have to do in normal running.
  1721. */
  1722. for (ch = 3; ch >= 0; ch--) {
  1723. base_addr[CyCAR] = (u_char) ch;
  1724. base_addr[CyIER] = 0;
  1725. base_addr[CyCMR] = CyASYNC;
  1726. base_addr[CyLICR] = (u_char) ch << 2;
  1727. base_addr[CyLIVR] = 0x5c;
  1728. base_addr[CyTCOR] = baud_co[spd];
  1729. base_addr[CyTBPR] = baud_bpr[spd];
  1730. base_addr[CyRCOR] = baud_co[spd] >> 5;
  1731. base_addr[CyRBPR] = baud_bpr[spd];
  1732. base_addr[CySCHR1] = 'Q' & 0x1f;
  1733. base_addr[CySCHR2] = 'X' & 0x1f;
  1734. base_addr[CySCRL] = 0;
  1735. base_addr[CySCRH] = 0;
  1736. base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
  1737. base_addr[CyCOR2] = 0;
  1738. base_addr[CyCOR3] = Cy_1_STOP;
  1739. base_addr[CyCOR4] = baud_cor4[spd];
  1740. base_addr[CyCOR5] = 0;
  1741. base_addr[CyCOR6] = 0;
  1742. base_addr[CyCOR7] = 0;
  1743. base_addr[CyRTPRL] = 2;
  1744. base_addr[CyRTPRH] = 0;
  1745. base_addr[CyMSVR1] = 0;
  1746. base_addr[CyMSVR2] = 0;
  1747. write_cy_cmd(base_addr, CyINIT_CHAN | CyDIS_RCVR | CyDIS_XMTR);
  1748. }
  1749. /*
  1750. * Now do specials for channel zero....
  1751. */
  1752. base_addr[CyMSVR1] = CyRTS;
  1753. base_addr[CyMSVR2] = CyDTR;
  1754. base_addr[CyIER] = CyRxData;
  1755. write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);
  1756. local_irq_restore(flags);
  1757. my_udelay(20000L); /* Let it all settle down */
  1758. printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]);
  1759. if (badspeed)
  1760. printk
  1761. (" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
  1762. rcor >> 5, rbpr);
  1763. } /* serial_console_init */
  1764. static const struct tty_operations cy_ops = {
  1765. .open = cy_open,
  1766. .close = cy_close,
  1767. .write = cy_write,
  1768. .put_char = cy_put_char,
  1769. .flush_chars = cy_flush_chars,
  1770. .write_room = cy_write_room,
  1771. .chars_in_buffer = cy_chars_in_buffer,
  1772. .flush_buffer = cy_flush_buffer,
  1773. .ioctl = cy_ioctl,
  1774. .throttle = cy_throttle,
  1775. .unthrottle = cy_unthrottle,
  1776. .set_termios = cy_set_termios,
  1777. .stop = cy_stop,
  1778. .start = cy_start,
  1779. .hangup = cy_hangup,
  1780. .tiocmget = cy_tiocmget,
  1781. .tiocmset = cy_tiocmset,
  1782. };
  1783. /* The serial driver boot-time initialization code!
  1784. Hardware I/O ports are mapped to character special devices on a
  1785. first found, first allocated manner. That is, this code searches
  1786. for Cyclom cards in the system. As each is found, it is probed
  1787. to discover how many chips (and thus how many ports) are present.
  1788. These ports are mapped to the tty ports 64 and upward in monotonic
  1789. fashion. If an 8-port card is replaced with a 16-port card, the
  1790. port mapping on a following card will shift.
  1791. This approach is different from what is used in the other serial
  1792. device driver because the Cyclom is more properly a multiplexer,
  1793. not just an aggregation of serial ports on one card.
  1794. If there are more cards with more ports than have been statically
  1795. allocated above, a warning is printed and the extra ports are ignored.
  1796. */
  1797. static int __init serial167_init(void)
  1798. {
  1799. struct cyclades_port *info;
  1800. int ret = 0;
  1801. int good_ports = 0;
  1802. int port_num = 0;
  1803. int index;
  1804. int DefSpeed;
  1805. #ifdef notyet
  1806. struct sigaction sa;
  1807. #endif
  1808. if (!(mvme16x_config & MVME16x_CONFIG_GOT_CD2401))
  1809. return 0;
  1810. cy_serial_driver = alloc_tty_driver(NR_PORTS);
  1811. if (!cy_serial_driver)
  1812. return -ENOMEM;
  1813. #if 0
  1814. scrn[1] = '\0';
  1815. #endif
  1816. show_version();
  1817. /* Has "console=0,9600n8" been used in bootinfo to change speed? */
  1818. if (serial_console_cflag)
  1819. DefSpeed = serial_console_cflag & 0017;
  1820. else {
  1821. DefSpeed = initial_console_speed;
  1822. serial_console_info = &cy_port[0];
  1823. serial_console_cflag = DefSpeed | CS8;
  1824. #if 0
  1825. serial_console = 64; /*callout_driver.minor_start */
  1826. #endif
  1827. }
  1828. /* Initialize the tty_driver structure */
  1829. cy_serial_driver->owner = THIS_MODULE;
  1830. cy_serial_driver->name = "ttyS";
  1831. cy_serial_driver->major = TTY_MAJOR;
  1832. cy_serial_driver->minor_start = 64;
  1833. cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  1834. cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
  1835. cy_serial_driver->init_termios = tty_std_termios;
  1836. cy_serial_driver->init_termios.c_cflag =
  1837. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  1838. cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
  1839. tty_set_operations(cy_serial_driver, &cy_ops);
  1840. ret = tty_register_driver(cy_serial_driver);
  1841. if (ret) {
  1842. printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
  1843. put_tty_driver(cy_serial_driver);
  1844. return ret;
  1845. }
  1846. port_num = 0;
  1847. info = cy_port;
  1848. for (index = 0; index < 1; index++) {
  1849. good_ports = 4;
  1850. if (port_num < NR_PORTS) {
  1851. while (good_ports-- && port_num < NR_PORTS) {
  1852. /*** initialize port ***/
  1853. info->magic = CYCLADES_MAGIC;
  1854. info->type = PORT_CIRRUS;
  1855. info->card = index;
  1856. info->line = port_num;
  1857. info->flags = STD_COM_FLAGS;
  1858. info->tty = NULL;
  1859. info->xmit_fifo_size = 12;
  1860. info->cor1 = CyPARITY_NONE | Cy_8_BITS;
  1861. info->cor2 = CyETC;
  1862. info->cor3 = Cy_1_STOP;
  1863. info->cor4 = 0x08; /* _very_ small receive threshold */
  1864. info->cor5 = 0;
  1865. info->cor6 = 0;
  1866. info->cor7 = 0;
  1867. info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
  1868. info->tco = baud_co[DefSpeed]; /* Tx CO */
  1869. info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
  1870. info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
  1871. info->close_delay = 0;
  1872. info->x_char = 0;
  1873. info->count = 0;
  1874. #ifdef SERIAL_DEBUG_COUNT
  1875. printk("cyc: %d: setting count to 0\n",
  1876. __LINE__);
  1877. #endif
  1878. info->blocked_open = 0;
  1879. info->default_threshold = 0;
  1880. info->default_timeout = 0;
  1881. init_waitqueue_head(&info->open_wait);
  1882. init_waitqueue_head(&info->close_wait);
  1883. /* info->session */
  1884. /* info->pgrp */
  1885. /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
  1886. info->read_status_mask =
  1887. CyTIMEOUT | CySPECHAR | CyBREAK | CyPARITY |
  1888. CyFRAME | CyOVERRUN;
  1889. /* info->timeout */
  1890. printk("ttyS%d ", info->line);
  1891. port_num++;
  1892. info++;
  1893. if (!(port_num & 7)) {
  1894. printk("\n ");
  1895. }
  1896. }
  1897. }
  1898. printk("\n");
  1899. }
  1900. while (port_num < NR_PORTS) {
  1901. info->line = -1;
  1902. port_num++;
  1903. info++;
  1904. }
  1905. ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
  1906. "cd2401_errors", cd2401_rxerr_interrupt);
  1907. if (ret) {
  1908. printk(KERN_ERR "Could't get cd2401_errors IRQ");
  1909. goto cleanup_serial_driver;
  1910. }
  1911. ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
  1912. "cd2401_modem", cd2401_modem_interrupt);
  1913. if (ret) {
  1914. printk(KERN_ERR "Could't get cd2401_modem IRQ");
  1915. goto cleanup_irq_cd2401_errors;
  1916. }
  1917. ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
  1918. "cd2401_txints", cd2401_tx_interrupt);
  1919. if (ret) {
  1920. printk(KERN_ERR "Could't get cd2401_txints IRQ");
  1921. goto cleanup_irq_cd2401_modem;
  1922. }
  1923. ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
  1924. "cd2401_rxints", cd2401_rx_interrupt);
  1925. if (ret) {
  1926. printk(KERN_ERR "Could't get cd2401_rxints IRQ");
  1927. goto cleanup_irq_cd2401_txints;
  1928. }
  1929. /* Now we have registered the interrupt handlers, allow the interrupts */
  1930. pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */
  1931. pcc2chip[PccSCCTICR] = 0x15;
  1932. pcc2chip[PccSCCRICR] = 0x15;
  1933. pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */
  1934. return 0;
  1935. cleanup_irq_cd2401_txints:
  1936. free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
  1937. cleanup_irq_cd2401_modem:
  1938. free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
  1939. cleanup_irq_cd2401_errors:
  1940. free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
  1941. cleanup_serial_driver:
  1942. if (tty_unregister_driver(cy_serial_driver))
  1943. printk(KERN_ERR
  1944. "Couldn't unregister MVME166/7 serial driver\n");
  1945. put_tty_driver(cy_serial_driver);
  1946. return ret;
  1947. } /* serial167_init */
  1948. module_init(serial167_init);
  1949. #ifdef CYCLOM_SHOW_STATUS
  1950. static void show_status(int line_num)
  1951. {
  1952. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1953. int channel;
  1954. struct cyclades_port *info;
  1955. unsigned long flags;
  1956. info = &cy_port[line_num];
  1957. channel = info->line;
  1958. printk(" channel %d\n", channel);
  1959. /**/ printk(" cy_port\n");
  1960. printk(" card line flags = %d %d %x\n",
  1961. info->card, info->line, info->flags);
  1962. printk
  1963. (" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
  1964. (long)info->tty, info->read_status_mask, info->timeout,
  1965. info->xmit_fifo_size);
  1966. printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
  1967. info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
  1968. info->cor6, info->cor7);
  1969. printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n", info->tbpr, info->tco,
  1970. info->rbpr, info->rco);
  1971. printk(" close_delay event count = %d %d %d\n", info->close_delay,
  1972. info->event, info->count);
  1973. printk(" x_char blocked_open = %x %x\n", info->x_char,
  1974. info->blocked_open);
  1975. printk(" open_wait = %lx %lx %lx\n", (long)info->open_wait);
  1976. local_irq_save(flags);
  1977. /* Global Registers */
  1978. printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
  1979. printk(" CyCAR %x\n", base_addr[CyCAR]);
  1980. printk(" CyRISR %x\n", base_addr[CyRISR]);
  1981. printk(" CyTISR %x\n", base_addr[CyTISR]);
  1982. printk(" CyMISR %x\n", base_addr[CyMISR]);
  1983. printk(" CyRIR %x\n", base_addr[CyRIR]);
  1984. printk(" CyTIR %x\n", base_addr[CyTIR]);
  1985. printk(" CyMIR %x\n", base_addr[CyMIR]);
  1986. printk(" CyTPR %x\n", base_addr[CyTPR]);
  1987. base_addr[CyCAR] = (u_char) channel;
  1988. /* Virtual Registers */
  1989. #if 0
  1990. printk(" CyRIVR %x\n", base_addr[CyRIVR]);
  1991. printk(" CyTIVR %x\n", base_addr[CyTIVR]);
  1992. printk(" CyMIVR %x\n", base_addr[CyMIVR]);
  1993. printk(" CyMISR %x\n", base_addr[CyMISR]);
  1994. #endif
  1995. /* Channel Registers */
  1996. printk(" CyCCR %x\n", base_addr[CyCCR]);
  1997. printk(" CyIER %x\n", base_addr[CyIER]);
  1998. printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
  1999. printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
  2000. printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
  2001. printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
  2002. printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
  2003. #if 0
  2004. printk(" CyCCSR %x\n", base_addr[CyCCSR]);
  2005. printk(" CyRDCR %x\n", base_addr[CyRDCR]);
  2006. #endif
  2007. printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
  2008. printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
  2009. #if 0
  2010. printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
  2011. printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
  2012. printk(" CySCRL %x\n", base_addr[CySCRL]);
  2013. printk(" CySCRH %x\n", base_addr[CySCRH]);
  2014. printk(" CyLNC %x\n", base_addr[CyLNC]);
  2015. printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
  2016. printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
  2017. #endif
  2018. printk(" CyRTPRL %x\n", base_addr[CyRTPRL]);
  2019. printk(" CyRTPRH %x\n", base_addr[CyRTPRH]);
  2020. printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
  2021. printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
  2022. printk(" CyRBPR %x\n", base_addr[CyRBPR]);
  2023. printk(" CyRCOR %x\n", base_addr[CyRCOR]);
  2024. printk(" CyTBPR %x\n", base_addr[CyTBPR]);
  2025. printk(" CyTCOR %x\n", base_addr[CyTCOR]);
  2026. local_irq_restore(flags);
  2027. } /* show_status */
  2028. #endif
  2029. #if 0
  2030. /* Dummy routine in mvme16x/config.c for now */
  2031. /* Serial console setup. Called from linux/init/main.c */
  2032. void console_setup(char *str, int *ints)
  2033. {
  2034. char *s;
  2035. int baud, bits, parity;
  2036. int cflag = 0;
  2037. /* Sanity check. */
  2038. if (ints[0] > 3 || ints[1] > 3)
  2039. return;
  2040. /* Get baud, bits and parity */
  2041. baud = 2400;
  2042. bits = 8;
  2043. parity = 'n';
  2044. if (ints[2])
  2045. baud = ints[2];
  2046. if ((s = strchr(str, ','))) {
  2047. do {
  2048. s++;
  2049. } while (*s >= '0' && *s <= '9');
  2050. if (*s)
  2051. parity = *s++;
  2052. if (*s)
  2053. bits = *s - '0';
  2054. }
  2055. /* Now construct a cflag setting. */
  2056. switch (baud) {
  2057. case 1200:
  2058. cflag |= B1200;
  2059. break;
  2060. case 9600:
  2061. cflag |= B9600;
  2062. break;
  2063. case 19200:
  2064. cflag |= B19200;
  2065. break;
  2066. case 38400:
  2067. cflag |= B38400;
  2068. break;
  2069. case 2400:
  2070. default:
  2071. cflag |= B2400;
  2072. break;
  2073. }
  2074. switch (bits) {
  2075. case 7:
  2076. cflag |= CS7;
  2077. break;
  2078. default:
  2079. case 8:
  2080. cflag |= CS8;
  2081. break;
  2082. }
  2083. switch (parity) {
  2084. case 'o':
  2085. case 'O':
  2086. cflag |= PARODD;
  2087. break;
  2088. case 'e':
  2089. case 'E':
  2090. cflag |= PARENB;
  2091. break;
  2092. }
  2093. serial_console_info = &cy_port[ints[1]];
  2094. serial_console_cflag = cflag;
  2095. serial_console = ints[1] + 64; /*callout_driver.minor_start */
  2096. }
  2097. #endif
  2098. /*
  2099. * The following is probably out of date for 2.1.x serial console stuff.
  2100. *
  2101. * The console is registered early on from arch/m68k/kernel/setup.c, and
  2102. * it therefore relies on the chip being setup correctly by 166-Bug. This
  2103. * seems reasonable, as the serial port has been used to invoke the system
  2104. * boot. It also means that this function must not rely on any data
  2105. * initialisation performed by serial167_init() etc.
  2106. *
  2107. * Of course, once the console has been registered, we had better ensure
  2108. * that serial167_init() doesn't leave the chip non-functional.
  2109. *
  2110. * The console must be locked when we get here.
  2111. */
  2112. void serial167_console_write(struct console *co, const char *str,
  2113. unsigned count)
  2114. {
  2115. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  2116. unsigned long flags;
  2117. volatile u_char sink;
  2118. u_char ier;
  2119. int port;
  2120. u_char do_lf = 0;
  2121. int i = 0;
  2122. local_irq_save(flags);
  2123. /* Ensure transmitter is enabled! */
  2124. port = 0;
  2125. base_addr[CyCAR] = (u_char) port;
  2126. while (base_addr[CyCCR])
  2127. ;
  2128. base_addr[CyCCR] = CyENB_XMTR;
  2129. ier = base_addr[CyIER];
  2130. base_addr[CyIER] = CyTxMpty;
  2131. while (1) {
  2132. if (pcc2chip[PccSCCTICR] & 0x20) {
  2133. /* We have a Tx int. Acknowledge it */
  2134. sink = pcc2chip[PccTPIACKR];
  2135. if ((base_addr[CyLICR] >> 2) == port) {
  2136. if (i == count) {
  2137. /* Last char of string is now output */
  2138. base_addr[CyTEOIR] = CyNOTRANS;
  2139. break;
  2140. }
  2141. if (do_lf) {
  2142. base_addr[CyTDR] = '\n';
  2143. str++;
  2144. i++;
  2145. do_lf = 0;
  2146. } else if (*str == '\n') {
  2147. base_addr[CyTDR] = '\r';
  2148. do_lf = 1;
  2149. } else {
  2150. base_addr[CyTDR] = *str++;
  2151. i++;
  2152. }
  2153. base_addr[CyTEOIR] = 0;
  2154. } else
  2155. base_addr[CyTEOIR] = CyNOTRANS;
  2156. }
  2157. }
  2158. base_addr[CyIER] = ier;
  2159. local_irq_restore(flags);
  2160. }
  2161. static struct tty_driver *serial167_console_device(struct console *c,
  2162. int *index)
  2163. {
  2164. *index = c->index;
  2165. return cy_serial_driver;
  2166. }
  2167. static struct console sercons = {
  2168. .name = "ttyS",
  2169. .write = serial167_console_write,
  2170. .device = serial167_console_device,
  2171. .flags = CON_PRINTBUFFER,
  2172. .index = -1,
  2173. };
  2174. static int __init serial167_console_init(void)
  2175. {
  2176. if (vme_brdtype == VME_TYPE_MVME166 ||
  2177. vme_brdtype == VME_TYPE_MVME167 ||
  2178. vme_brdtype == VME_TYPE_MVME177) {
  2179. mvme167_serial_console_setup(0);
  2180. register_console(&sercons);
  2181. }
  2182. return 0;
  2183. }
  2184. console_initcall(serial167_console_init);
  2185. MODULE_LICENSE("GPL");