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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * drivers/char/vme_scc.c: MVME147, MVME162, BVME6000 SCC serial ports
  3.  * implementation.
  4.  * Copyright 1999 Richard Hirst <richard@sleepie.demon.co.uk>
  5.  *
  6.  * Based on atari_SCC.c which was
  7.  *   Copyright 1994-95 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
  8.  *   Partially based on PC-Linux serial.c by Linus Torvalds and Theodore Ts'o
  9.  *
  10.  * This file is subject to the terms and conditions of the GNU General Public
  11.  * License.  See the file COPYING in the main directory of this archive
  12.  * for more details.
  13.  *
  14.  */
  15. #include <linux/module.h>
  16. #include <linux/config.h>
  17. #include <linux/kdev_t.h>
  18. #include <asm/io.h>
  19. #include <linux/kernel.h>
  20. #include <linux/sched.h>
  21. #include <linux/ioport.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/errno.h>
  24. #include <linux/tty.h>
  25. #include <linux/tty_flip.h>
  26. #include <linux/mm.h>
  27. #include <linux/serial.h>
  28. #include <linux/fcntl.h>
  29. #include <linux/major.h>
  30. #include <linux/delay.h>
  31. #include <linux/tqueue.h>
  32. #include <linux/version.h>
  33. #include <linux/slab.h>
  34. #include <linux/miscdevice.h>
  35. #include <linux/console.h>
  36. #include <linux/init.h>
  37. #include <asm/setup.h>
  38. #include <asm/bootinfo.h>
  39. #ifdef CONFIG_MVME147_SCC
  40. #include <asm/mvme147hw.h>
  41. #endif
  42. #ifdef CONFIG_MVME162_SCC
  43. #include <asm/mvme16xhw.h>
  44. #endif
  45. #ifdef CONFIG_BVME6000_SCC
  46. #include <asm/bvme6000hw.h>
  47. #endif
  48. #include <linux/generic_serial.h>
  49. #include "scc.h"
  50. #define CHANNEL_A 0
  51. #define CHANNEL_B 1
  52. #define SCC_MINOR_BASE 64
  53. /* Shadows for all SCC write registers */
  54. static unsigned char scc_shadow[2][16];
  55. /* Location to access for SCC register access delay */
  56. static volatile unsigned char *scc_del = NULL;
  57. /* To keep track of STATUS_REG state for detection of Ext/Status int source */
  58. static unsigned char scc_last_status_reg[2];
  59. /***************************** Prototypes *****************************/
  60. /* Function prototypes */
  61. static void scc_disable_tx_interrupts(void * ptr);
  62. static void scc_enable_tx_interrupts(void * ptr);
  63. static void scc_disable_rx_interrupts(void * ptr);
  64. static void scc_enable_rx_interrupts(void * ptr);
  65. static int  scc_get_CD(void * ptr);
  66. static void scc_shutdown_port(void * ptr);
  67. static int scc_set_real_termios(void  *ptr);
  68. static void scc_hungup(void  *ptr);
  69. static void scc_close(void  *ptr);
  70. static int scc_chars_in_buffer(void * ptr);
  71. static int scc_open(struct tty_struct * tty, struct file * filp);
  72. static int scc_ioctl(struct tty_struct * tty, struct file * filp,
  73.                      unsigned int cmd, unsigned long arg);
  74. static void scc_throttle(struct tty_struct *tty);
  75. static void scc_unthrottle(struct tty_struct *tty);
  76. static void scc_tx_int(int irq, void *data, struct pt_regs *fp);
  77. static void scc_rx_int(int irq, void *data, struct pt_regs *fp);
  78. static void scc_stat_int(int irq, void *data, struct pt_regs *fp);
  79. static void scc_spcond_int(int irq, void *data, struct pt_regs *fp);
  80. static void scc_setsignals(struct scc_port *port, int dtr, int rts);
  81. static void scc_break_ctl(struct tty_struct *tty, int break_state);
  82. static struct tty_driver scc_driver, scc_callout_driver;
  83. static struct tty_struct *scc_table[2] = { NULL, };
  84. static struct termios * scc_termios[2];
  85. static struct termios * scc_termios_locked[2];
  86. struct scc_port scc_ports[2];
  87. int scc_refcount;
  88. int scc_initialized = 0;
  89. /*---------------------------------------------------------------------------
  90.  * Interface from generic_serial.c back here
  91.  *--------------------------------------------------------------------------*/
  92. static struct real_driver scc_real_driver = {
  93.         scc_disable_tx_interrupts,
  94.         scc_enable_tx_interrupts,
  95.         scc_disable_rx_interrupts,
  96.         scc_enable_rx_interrupts,
  97.         scc_get_CD,
  98.         scc_shutdown_port,
  99.         scc_set_real_termios,
  100.         scc_chars_in_buffer,
  101.         scc_close,
  102.         scc_hungup,
  103.         NULL
  104. };
  105. /*----------------------------------------------------------------------------
  106.  * vme_scc_init() and support functions
  107.  *---------------------------------------------------------------------------*/
  108. static int scc_init_drivers(void)
  109. {
  110. int error;
  111. memset(&scc_driver, 0, sizeof(scc_driver));
  112. scc_driver.magic = TTY_DRIVER_MAGIC;
  113. scc_driver.driver_name = "scc";
  114. #ifdef CONFIG_DEVFS_FS
  115. scc_driver.name = "tts/%d";
  116. #else
  117. scc_driver.name = "ttyS";
  118. #endif
  119. scc_driver.major = TTY_MAJOR;
  120. scc_driver.minor_start = SCC_MINOR_BASE;
  121. scc_driver.num = 2;
  122. scc_driver.type = TTY_DRIVER_TYPE_SERIAL;
  123. scc_driver.subtype = SERIAL_TYPE_NORMAL;
  124. scc_driver.init_termios = tty_std_termios;
  125. scc_driver.init_termios.c_cflag =
  126.   B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  127. scc_driver.flags = TTY_DRIVER_REAL_RAW;
  128. scc_driver.refcount = &scc_refcount;
  129. scc_driver.table = scc_table;
  130. scc_driver.termios = scc_termios;
  131. scc_driver.termios_locked = scc_termios_locked;
  132. scc_driver.open = scc_open;
  133. scc_driver.close = gs_close;
  134. scc_driver.write = gs_write;
  135. scc_driver.put_char = gs_put_char;
  136. scc_driver.flush_chars = gs_flush_chars;
  137. scc_driver.write_room = gs_write_room;
  138. scc_driver.chars_in_buffer = gs_chars_in_buffer;
  139. scc_driver.flush_buffer = gs_flush_buffer;
  140. scc_driver.ioctl = scc_ioctl;
  141. scc_driver.throttle = scc_throttle;
  142. scc_driver.unthrottle = scc_unthrottle;
  143. scc_driver.set_termios = gs_set_termios;
  144. scc_driver.stop = gs_stop;
  145. scc_driver.start = gs_start;
  146. scc_driver.hangup = gs_hangup;
  147. scc_driver.break_ctl = scc_break_ctl;
  148. scc_callout_driver = scc_driver;
  149. #ifdef CONFIG_DEVFS_FS
  150. scc_callout_driver.name = "cua/%d";
  151. #else
  152. scc_callout_driver.name = "cua";
  153. #endif
  154. scc_callout_driver.major = TTYAUX_MAJOR;
  155. scc_callout_driver.subtype = SERIAL_TYPE_CALLOUT;
  156. if ((error = tty_register_driver(&scc_driver))) {
  157. printk(KERN_ERR "scc: Couldn't register scc driver, error = %dn",
  158.        error);
  159. return 1;
  160. }
  161. if ((error = tty_register_driver(&scc_callout_driver))) {
  162. tty_unregister_driver(&scc_driver);
  163. printk(KERN_ERR "scc: Couldn't register scc callout driver, error = %dn",
  164.        error);
  165. return 1;
  166. }
  167. return 0;
  168. }
  169. /* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1).
  170.  */
  171. static void scc_init_portstructs(void)
  172. {
  173. struct scc_port *port;
  174. int i;
  175. for (i = 0; i < 2; i++) {
  176. port = scc_ports + i;
  177. port->gs.callout_termios = tty_std_termios;
  178. port->gs.normal_termios = tty_std_termios;
  179. port->gs.magic = SCC_MAGIC;
  180. port->gs.close_delay = HZ/2;
  181. port->gs.closing_wait = 30 * HZ;
  182. port->gs.rd = &scc_real_driver;
  183. #ifdef NEW_WRITE_LOCKING
  184. port->gs.port_write_sem = MUTEX;
  185. #endif
  186. init_waitqueue_head(&port->gs.open_wait);
  187. init_waitqueue_head(&port->gs.close_wait);
  188. }
  189. }
  190. #ifdef CONFIG_MVME147_SCC
  191. static int mvme147_scc_init(void)
  192. {
  193. struct scc_port *port;
  194. printk(KERN_INFO "SCC: MVME147 Serial Drivern");
  195. /* Init channel A */
  196. port = &scc_ports[0];
  197. port->channel = CHANNEL_A;
  198. port->ctrlp = (volatile unsigned char *)M147_SCC_A_ADDR;
  199. port->datap = port->ctrlp + 1;
  200. port->port_a = &scc_ports[0];
  201. port->port_b = &scc_ports[1];
  202. request_irq(MVME147_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,
  203.             "SCC-A TX", port);
  204. request_irq(MVME147_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,
  205.             "SCC-A status", port);
  206. request_irq(MVME147_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,
  207.             "SCC-A RX", port);
  208. request_irq(MVME147_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,
  209.             "SCC-A special cond", port);
  210. {
  211. SCC_ACCESS_INIT(port);
  212. /* disable interrupts for this channel */
  213. SCCwrite(INT_AND_DMA_REG, 0);
  214. /* Set the interrupt vector */
  215. SCCwrite(INT_VECTOR_REG, MVME147_IRQ_SCC_BASE);
  216. /* Interrupt parameters: vector includes status, status low */
  217. SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
  218. SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
  219. }
  220. /* Init channel B */
  221. port = &scc_ports[1];
  222. port->channel = CHANNEL_B;
  223. port->ctrlp = (volatile unsigned char *)M147_SCC_B_ADDR;
  224. port->datap = port->ctrlp + 1;
  225. port->port_a = &scc_ports[0];
  226. port->port_b = &scc_ports[1];
  227. request_irq(MVME147_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,
  228.             "SCC-B TX", port);
  229. request_irq(MVME147_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,
  230.             "SCC-B status", port);
  231. request_irq(MVME147_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,
  232.             "SCC-B RX", port);
  233. request_irq(MVME147_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,
  234.             "SCC-B special cond", port);
  235. {
  236. SCC_ACCESS_INIT(port);
  237. /* disable interrupts for this channel */
  238. SCCwrite(INT_AND_DMA_REG, 0);
  239. }
  240.         /* Ensure interrupts are enabled in the PCC chip */
  241.         m147_pcc->serial_cntrl=PCC_LEVEL_SERIAL|PCC_INT_ENAB;
  242. /* Initialise the tty driver structures and register */
  243. scc_init_portstructs();
  244. scc_init_drivers();
  245. return 0;
  246. }
  247. #endif
  248. #ifdef CONFIG_MVME162_SCC
  249. static int mvme162_scc_init(void)
  250. {
  251. struct scc_port *port;
  252. if (!(mvme16x_config & MVME16x_CONFIG_GOT_SCCA))
  253. return (-ENODEV);
  254. printk(KERN_INFO "SCC: MVME162 Serial Drivern");
  255. /* Init channel A */
  256. port = &scc_ports[0];
  257. port->channel = CHANNEL_A;
  258. port->ctrlp = (volatile unsigned char *)MVME_SCC_A_ADDR;
  259. port->datap = port->ctrlp + 2;
  260. port->port_a = &scc_ports[0];
  261. port->port_b = &scc_ports[1];
  262. request_irq(MVME162_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,
  263.             "SCC-A TX", port);
  264. request_irq(MVME162_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,
  265.             "SCC-A status", port);
  266. request_irq(MVME162_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,
  267.             "SCC-A RX", port);
  268. request_irq(MVME162_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,
  269.             "SCC-A special cond", port);
  270. {
  271. SCC_ACCESS_INIT(port);
  272. /* disable interrupts for this channel */
  273. SCCwrite(INT_AND_DMA_REG, 0);
  274. /* Set the interrupt vector */
  275. SCCwrite(INT_VECTOR_REG, MVME162_IRQ_SCC_BASE);
  276. /* Interrupt parameters: vector includes status, status low */
  277. SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
  278. SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
  279. }
  280. /* Init channel B */
  281. port = &scc_ports[1];
  282. port->channel = CHANNEL_B;
  283. port->ctrlp = (volatile unsigned char *)MVME_SCC_B_ADDR;
  284. port->datap = port->ctrlp + 2;
  285. port->port_a = &scc_ports[0];
  286. port->port_b = &scc_ports[1];
  287. request_irq(MVME162_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,
  288.             "SCC-B TX", port);
  289. request_irq(MVME162_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,
  290.             "SCC-B status", port);
  291. request_irq(MVME162_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,
  292.             "SCC-B RX", port);
  293. request_irq(MVME162_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,
  294.             "SCC-B special cond", port);
  295. {
  296. SCC_ACCESS_INIT(port); /* Either channel will do */
  297. /* disable interrupts for this channel */
  298. SCCwrite(INT_AND_DMA_REG, 0);
  299. }
  300.         /* Ensure interrupts are enabled in the MC2 chip */
  301.         *(volatile char *)0xfff4201d = 0x14;
  302. /* Initialise the tty driver structures and register */
  303. scc_init_portstructs();
  304. scc_init_drivers();
  305. return 0;
  306. }
  307. #endif
  308. #ifdef CONFIG_BVME6000_SCC
  309. static int bvme6000_scc_init(void)
  310. {
  311. struct scc_port *port;
  312. printk(KERN_INFO "SCC: BVME6000 Serial Drivern");
  313. /* Init channel A */
  314. port = &scc_ports[0];
  315. port->channel = CHANNEL_A;
  316. port->ctrlp = (volatile unsigned char *)BVME_SCC_A_ADDR;
  317. port->datap = port->ctrlp + 4;
  318. port->port_a = &scc_ports[0];
  319. port->port_b = &scc_ports[1];
  320. request_irq(BVME_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,
  321.             "SCC-A TX", port);
  322. request_irq(BVME_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,
  323.             "SCC-A status", port);
  324. request_irq(BVME_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,
  325.             "SCC-A RX", port);
  326. request_irq(BVME_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,
  327.             "SCC-A special cond", port);
  328. {
  329. SCC_ACCESS_INIT(port);
  330. /* disable interrupts for this channel */
  331. SCCwrite(INT_AND_DMA_REG, 0);
  332. /* Set the interrupt vector */
  333. SCCwrite(INT_VECTOR_REG, BVME_IRQ_SCC_BASE);
  334. /* Interrupt parameters: vector includes status, status low */
  335. SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
  336. SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
  337. }
  338. /* Init channel B */
  339. port = &scc_ports[1];
  340. port->channel = CHANNEL_B;
  341. port->ctrlp = (volatile unsigned char *)BVME_SCC_B_ADDR;
  342. port->datap = port->ctrlp + 4;
  343. port->port_a = &scc_ports[0];
  344. port->port_b = &scc_ports[1];
  345. request_irq(BVME_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,
  346.             "SCC-B TX", port);
  347. request_irq(BVME_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,
  348.             "SCC-B status", port);
  349. request_irq(BVME_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,
  350.             "SCC-B RX", port);
  351. request_irq(BVME_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,
  352.             "SCC-B special cond", port);
  353. {
  354. SCC_ACCESS_INIT(port); /* Either channel will do */
  355. /* disable interrupts for this channel */
  356. SCCwrite(INT_AND_DMA_REG, 0);
  357. }
  358. /* Initialise the tty driver structures and register */
  359. scc_init_portstructs();
  360. scc_init_drivers();
  361. return 0;
  362. }
  363. #endif
  364. int vme_scc_init(void)
  365. {
  366. int res = -ENODEV;
  367. static int called = 0;
  368. if (called)
  369. return res;
  370. called = 1;
  371. #ifdef CONFIG_MVME147_SCC
  372. if (MACH_IS_MVME147)
  373. res = mvme147_scc_init();
  374. #endif
  375. #ifdef CONFIG_MVME162_SCC
  376. if (MACH_IS_MVME16x)
  377. res = mvme162_scc_init();
  378. #endif
  379. #ifdef CONFIG_BVME6000_SCC
  380. if (MACH_IS_BVME6000)
  381. res = bvme6000_scc_init();
  382. #endif
  383. return res;
  384. }
  385. /*---------------------------------------------------------------------------
  386.  * Interrupt handlers
  387.  *--------------------------------------------------------------------------*/
  388. static void scc_rx_int(int irq, void *data, struct pt_regs *fp)
  389. {
  390. unsigned char ch;
  391. struct scc_port *port = data;
  392. struct tty_struct *tty = port->gs.tty;
  393. SCC_ACCESS_INIT(port);
  394. ch = SCCread_NB(RX_DATA_REG);
  395. if (!tty) {
  396. printk(KERN_WARNING "scc_rx_int with NULL tty!n");
  397. SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
  398. return;
  399. }
  400. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  401. *tty->flip.char_buf_ptr = ch;
  402. *tty->flip.flag_buf_ptr = 0;
  403. tty->flip.flag_buf_ptr++;
  404. tty->flip.char_buf_ptr++;
  405. tty->flip.count++;
  406. }
  407. /* Check if another character is already ready; in that case, the
  408.  * spcond_int() function must be used, because this character may have an
  409.  * error condition that isn't signalled by the interrupt vector used!
  410.  */
  411. if (SCCread(INT_PENDING_REG) &
  412.     (port->channel == CHANNEL_A ? IPR_A_RX : IPR_B_RX)) {
  413. scc_spcond_int (irq, data, fp);
  414. return;
  415. }
  416. SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
  417. tty_flip_buffer_push(tty);
  418. }
  419. static void scc_spcond_int(int irq, void *data, struct pt_regs *fp)
  420. {
  421. struct scc_port *port = data;
  422. struct tty_struct *tty = port->gs.tty;
  423. unsigned char stat, ch, err;
  424. int int_pending_mask = port->channel == CHANNEL_A ?
  425.                    IPR_A_RX : IPR_B_RX;
  426. SCC_ACCESS_INIT(port);
  427. if (!tty) {
  428. printk(KERN_WARNING "scc_spcond_int with NULL tty!n");
  429. SCCwrite(COMMAND_REG, CR_ERROR_RESET);
  430. SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
  431. return;
  432. }
  433. do {
  434. stat = SCCread(SPCOND_STATUS_REG);
  435. ch = SCCread_NB(RX_DATA_REG);
  436. if (stat & SCSR_RX_OVERRUN)
  437. err = TTY_OVERRUN;
  438. else if (stat & SCSR_PARITY_ERR)
  439. err = TTY_PARITY;
  440. else if (stat & SCSR_CRC_FRAME_ERR)
  441. err = TTY_FRAME;
  442. else
  443. err = 0;
  444. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  445. *tty->flip.char_buf_ptr = ch;
  446. *tty->flip.flag_buf_ptr = err;
  447. tty->flip.flag_buf_ptr++;
  448. tty->flip.char_buf_ptr++;
  449. tty->flip.count++;
  450. }
  451. /* ++TeSche: *All* errors have to be cleared manually,
  452.  * else the condition persists for the next chars
  453.  */
  454. if (err)
  455.   SCCwrite(COMMAND_REG, CR_ERROR_RESET);
  456. } while(SCCread(INT_PENDING_REG) & int_pending_mask);
  457. SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
  458. tty_flip_buffer_push(tty);
  459. }
  460. static void scc_tx_int(int irq, void *data, struct pt_regs *fp)
  461. {
  462. struct scc_port *port = data;
  463. SCC_ACCESS_INIT(port);
  464. if (!port->gs.tty) {
  465. printk(KERN_WARNING "scc_tx_int with NULL tty!n");
  466. SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
  467. SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET);
  468. SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
  469. return;
  470. }
  471. while ((SCCread_NB(STATUS_REG) & SR_TX_BUF_EMPTY)) {
  472. if (port->x_char) {
  473. SCCwrite(TX_DATA_REG, port->x_char);
  474. port->x_char = 0;
  475. }
  476. else if ((port->gs.xmit_cnt <= 0) || port->gs.tty->stopped ||
  477. port->gs.tty->hw_stopped)
  478. break;
  479. else {
  480. SCCwrite(TX_DATA_REG, port->gs.xmit_buf[port->gs.xmit_tail++]);
  481. port->gs.xmit_tail = port->gs.xmit_tail & (SERIAL_XMIT_SIZE-1);
  482. if (--port->gs.xmit_cnt <= 0)
  483. break;
  484. }
  485. }
  486. if ((port->gs.xmit_cnt <= 0) || port->gs.tty->stopped ||
  487. port->gs.tty->hw_stopped) {
  488. /* disable tx interrupts */
  489. SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
  490. SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET);   /* disable tx_int on next tx underrun? */
  491. port->gs.flags &= ~GS_TX_INTEN;
  492. }
  493. if (port->gs.tty && port->gs.xmit_cnt <= port->gs.wakeup_chars) {
  494. if ((port->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  495. port->gs.tty->ldisc.write_wakeup)
  496. (port->gs.tty->ldisc.write_wakeup)(port->gs.tty);
  497. wake_up_interruptible(&port->gs.tty->write_wait);
  498. }
  499. SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
  500. }
  501. static void scc_stat_int(int irq, void *data, struct pt_regs *fp)
  502. {
  503. struct scc_port *port = data;
  504. unsigned channel = port->channel;
  505. unsigned char last_sr, sr, changed;
  506. SCC_ACCESS_INIT(port);
  507. last_sr = scc_last_status_reg[channel];
  508. sr = scc_last_status_reg[channel] = SCCread_NB(STATUS_REG);
  509. changed = last_sr ^ sr;
  510. if (changed & SR_DCD) {
  511. port->c_dcd = !!(sr & SR_DCD);
  512. if (!(port->gs.flags & ASYNC_CHECK_CD))
  513. ; /* Don't report DCD changes */
  514. else if (port->c_dcd) {
  515. if (~(port->gs.flags & ASYNC_NORMAL_ACTIVE) ||
  516. ~(port->gs.flags & ASYNC_CALLOUT_ACTIVE)) {
  517. /* Are we blocking in open?*/
  518. wake_up_interruptible(&port->gs.open_wait);
  519. }
  520. }
  521. else {
  522. if (!((port->gs.flags & ASYNC_CALLOUT_ACTIVE) &&
  523. (port->gs.flags & ASYNC_CALLOUT_NOHUP))) {
  524. if (port->gs.tty)
  525. tty_hangup (port->gs.tty);
  526. }
  527. }
  528. }
  529. SCCwrite(COMMAND_REG, CR_EXTSTAT_RESET);
  530. SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
  531. }
  532. /*---------------------------------------------------------------------------
  533.  * generic_serial.c callback funtions
  534.  *--------------------------------------------------------------------------*/
  535. static void scc_disable_tx_interrupts(void *ptr)
  536. {
  537. struct scc_port *port = ptr;
  538. unsigned long flags;
  539. SCC_ACCESS_INIT(port);
  540. save_flags(flags);
  541. cli();
  542. SCCmod(INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
  543. port->gs.flags &= ~GS_TX_INTEN;
  544. restore_flags(flags);
  545. }
  546. static void scc_enable_tx_interrupts(void *ptr)
  547. {
  548. struct scc_port *port = ptr;
  549. unsigned long flags;
  550. SCC_ACCESS_INIT(port);
  551. save_flags(flags);
  552. cli();
  553. SCCmod(INT_AND_DMA_REG, 0xff, IDR_TX_INT_ENAB);
  554. /* restart the transmitter */
  555. scc_tx_int (0, port, 0);
  556. restore_flags(flags);
  557. }
  558. static void scc_disable_rx_interrupts(void *ptr)
  559. {
  560. struct scc_port *port = ptr;
  561. unsigned long flags;
  562. SCC_ACCESS_INIT(port);
  563. save_flags(flags);
  564. cli();
  565. SCCmod(INT_AND_DMA_REG,
  566.     ~(IDR_RX_INT_MASK|IDR_PARERR_AS_SPCOND|IDR_EXTSTAT_INT_ENAB), 0);
  567. restore_flags(flags);
  568. }
  569. static void scc_enable_rx_interrupts(void *ptr)
  570. {
  571. struct scc_port *port = ptr;
  572. unsigned long flags;
  573. SCC_ACCESS_INIT(port);
  574. save_flags(flags);
  575. cli();
  576. SCCmod(INT_AND_DMA_REG, 0xff,
  577. IDR_EXTSTAT_INT_ENAB|IDR_PARERR_AS_SPCOND|IDR_RX_INT_ALL);
  578. restore_flags(flags);
  579. }
  580. static int scc_get_CD(void *ptr)
  581. {
  582. struct scc_port *port = ptr;
  583. unsigned channel = port->channel;
  584. return !!(scc_last_status_reg[channel] & SR_DCD);
  585. }
  586. static void scc_shutdown_port(void *ptr)
  587. {
  588. struct scc_port *port = ptr;
  589. port->gs.flags &= ~ GS_ACTIVE;
  590. if (port->gs.tty && port->gs.tty->termios->c_cflag & HUPCL) {
  591. scc_setsignals (port, 0, 0);
  592. }
  593. }
  594. static int scc_set_real_termios (void *ptr)
  595. {
  596. /* the SCC has char sizes 5,7,6,8 in that order! */
  597. static int chsize_map[4] = { 0, 2, 1, 3 };
  598. unsigned cflag, baud, chsize, channel, brgval = 0;
  599. unsigned long flags;
  600. struct scc_port *port = ptr;
  601. SCC_ACCESS_INIT(port);
  602. if (!port->gs.tty || !port->gs.tty->termios) return 0;
  603. channel = port->channel;
  604. if (channel == CHANNEL_A)
  605. return 0; /* Settings controlled by boot PROM */
  606. cflag  = port->gs.tty->termios->c_cflag;
  607. baud = port->gs.baud;
  608. chsize = (cflag & CSIZE) >> 4;
  609. if (baud == 0) {
  610. /* speed == 0 -> drop DTR */
  611. save_flags(flags);
  612. cli();
  613. SCCmod(TX_CTRL_REG, ~TCR_DTR, 0);
  614. restore_flags(flags);
  615. return 0;
  616. }
  617. else if ((MACH_IS_MVME16x && (baud < 50 || baud > 38400)) ||
  618.  (MACH_IS_MVME147 && (baud < 50 || baud > 19200)) ||
  619.  (MACH_IS_BVME6000 &&(baud < 50 || baud > 76800))) {
  620. printk(KERN_NOTICE "SCC: Bad speed requested, %dn", baud);
  621. return 0;
  622. }
  623. if (cflag & CLOCAL)
  624. port->gs.flags &= ~ASYNC_CHECK_CD;
  625. else
  626. port->gs.flags |= ASYNC_CHECK_CD;
  627. #ifdef CONFIG_MVME147_SCC
  628. if (MACH_IS_MVME147)
  629. brgval = (M147_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
  630. #endif
  631. #ifdef CONFIG_MVME162_SCC
  632. if (MACH_IS_MVME16x)
  633. brgval = (MVME_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
  634. #endif
  635. #ifdef CONFIG_BVME6000_SCC
  636. if (MACH_IS_BVME6000)
  637. brgval = (BVME_SCC_RTxC + baud/2) / (16 * 2 * baud) - 2;
  638. #endif
  639. /* Now we have all parameters and can go to set them: */
  640. save_flags(flags);
  641. cli();
  642. /* receiver's character size and auto-enables */
  643. SCCmod(RX_CTRL_REG, ~(RCR_CHSIZE_MASK|RCR_AUTO_ENAB_MODE),
  644. (chsize_map[chsize] << 6) |
  645. ((cflag & CRTSCTS) ? RCR_AUTO_ENAB_MODE : 0));
  646. /* parity and stop bits (both, Tx and Rx), clock mode never changes */
  647. SCCmod (AUX1_CTRL_REG,
  648. ~(A1CR_PARITY_MASK | A1CR_MODE_MASK),
  649. ((cflag & PARENB
  650.   ? (cflag & PARODD ? A1CR_PARITY_ODD : A1CR_PARITY_EVEN)
  651.   : A1CR_PARITY_NONE)
  652.  | (cflag & CSTOPB ? A1CR_MODE_ASYNC_2 : A1CR_MODE_ASYNC_1)));
  653. /* sender's character size, set DTR for valid baud rate */
  654. SCCmod(TX_CTRL_REG, ~TCR_CHSIZE_MASK, chsize_map[chsize] << 5 | TCR_DTR);
  655. /* clock sources never change */
  656. /* disable BRG before changing the value */
  657. SCCmod(DPLL_CTRL_REG, ~DCR_BRG_ENAB, 0);
  658. /* BRG value */
  659. SCCwrite(TIMER_LOW_REG, brgval & 0xff);
  660. SCCwrite(TIMER_HIGH_REG, (brgval >> 8) & 0xff);
  661. /* BRG enable, and clock source never changes */
  662. SCCmod(DPLL_CTRL_REG, 0xff, DCR_BRG_ENAB);
  663. restore_flags(flags);
  664. return 0;
  665. }
  666. static int scc_chars_in_buffer (void *ptr)
  667. {
  668. struct scc_port *port = ptr;
  669. SCC_ACCESS_INIT(port);
  670. return (SCCread (SPCOND_STATUS_REG) & SCSR_ALL_SENT) ? 0  : 1;
  671. }
  672. /* Comment taken from sx.c (2.4.0):
  673.    I haven't the foggiest why the decrement use count has to happen
  674.    here. The whole linux serial drivers stuff needs to be redesigned.
  675.    My guess is that this is a hack to minimize the impact of a bug
  676.    elsewhere. Thinking about it some more. (try it sometime) Try
  677.    running minicom on a serial port that is driven by a modularized
  678.    driver. Have the modem hangup. Then remove the driver module. Then
  679.    exit minicom.  I expect an "oops".  -- REW */
  680. static void scc_hungup(void *ptr)
  681. {
  682. scc_disable_tx_interrupts(ptr);
  683. scc_disable_rx_interrupts(ptr);
  684. MOD_DEC_USE_COUNT;
  685. }
  686. static void scc_close(void *ptr)
  687. {
  688. scc_disable_tx_interrupts(ptr);
  689. scc_disable_rx_interrupts(ptr);
  690. MOD_DEC_USE_COUNT;
  691. }
  692. /*---------------------------------------------------------------------------
  693.  * Internal support functions
  694.  *--------------------------------------------------------------------------*/
  695. static void scc_setsignals(struct scc_port *port, int dtr, int rts)
  696. {
  697. unsigned long flags;
  698. unsigned char t;
  699. SCC_ACCESS_INIT(port);
  700. save_flags(flags);
  701. cli();
  702. t = SCCread(TX_CTRL_REG);
  703. if (dtr >= 0) t = dtr? (t | TCR_DTR): (t & ~TCR_DTR);
  704. if (rts >= 0) t = rts? (t | TCR_RTS): (t & ~TCR_RTS);
  705. SCCwrite(TX_CTRL_REG, t);
  706. restore_flags(flags);
  707. }
  708. static void scc_send_xchar(struct tty_struct *tty, char ch)
  709. {
  710. struct scc_port *port = (struct scc_port *)tty->driver_data;
  711. port->x_char = ch;
  712. if (ch)
  713. scc_enable_tx_interrupts(port);
  714. }
  715. /*---------------------------------------------------------------------------
  716.  * Driver entrypoints referenced from above
  717.  *--------------------------------------------------------------------------*/
  718. static int scc_open (struct tty_struct * tty, struct file * filp)
  719. {
  720. int line = MINOR(tty->device) - SCC_MINOR_BASE;
  721. int retval;
  722. struct scc_port *port = &scc_ports[line];
  723. int i, channel = port->channel;
  724. unsigned long flags;
  725. SCC_ACCESS_INIT(port);
  726. #if defined(CONFIG_MVME162_SCC) || defined(CONFIG_MVME147_SCC)
  727. static const struct {
  728. unsigned reg, val;
  729. } mvme_init_tab[] = {
  730. /* Values for MVME162 and MVME147 */
  731. /* no parity, 1 stop bit, async, 1:16 */
  732. { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
  733. /* parity error is special cond, ints disabled, no DMA */
  734. { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
  735. /* Rx 8 bits/char, no auto enable, Rx off */
  736. { RX_CTRL_REG, RCR_CHSIZE_8 },
  737. /* DTR off, Tx 8 bits/char, RTS off, Tx off */
  738. { TX_CTRL_REG, TCR_CHSIZE_8 },
  739. /* special features off */
  740. { AUX2_CTRL_REG, 0 },
  741. { CLK_CTRL_REG, CCR_RXCLK_BRG | CCR_TXCLK_BRG },
  742. { DPLL_CTRL_REG, DCR_BRG_ENAB | DCR_BRG_USE_PCLK },
  743. /* Start Rx */
  744. { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
  745. /* Start Tx */
  746. { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
  747. /* Ext/Stat ints: DCD only */
  748. { INT_CTRL_REG, ICR_ENAB_DCD_INT },
  749. /* Reset Ext/Stat ints */
  750. { COMMAND_REG, CR_EXTSTAT_RESET },
  751. /* ...again */
  752. { COMMAND_REG, CR_EXTSTAT_RESET },
  753. };
  754. #endif
  755. #if defined(CONFIG_BVME6000_SCC)
  756. static const struct {
  757. unsigned reg, val;
  758. } bvme_init_tab[] = {
  759. /* Values for BVME6000 */
  760. /* no parity, 1 stop bit, async, 1:16 */
  761. { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
  762. /* parity error is special cond, ints disabled, no DMA */
  763. { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
  764. /* Rx 8 bits/char, no auto enable, Rx off */
  765. { RX_CTRL_REG, RCR_CHSIZE_8 },
  766. /* DTR off, Tx 8 bits/char, RTS off, Tx off */
  767. { TX_CTRL_REG, TCR_CHSIZE_8 },
  768. /* special features off */
  769. { AUX2_CTRL_REG, 0 },
  770. { CLK_CTRL_REG, CCR_RTxC_XTAL | CCR_RXCLK_BRG | CCR_TXCLK_BRG },
  771. { DPLL_CTRL_REG, DCR_BRG_ENAB },
  772. /* Start Rx */
  773. { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
  774. /* Start Tx */
  775. { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
  776. /* Ext/Stat ints: DCD only */
  777. { INT_CTRL_REG, ICR_ENAB_DCD_INT },
  778. /* Reset Ext/Stat ints */
  779. { COMMAND_REG, CR_EXTSTAT_RESET },
  780. /* ...again */
  781. { COMMAND_REG, CR_EXTSTAT_RESET },
  782. };
  783. #endif
  784. if (!(port->gs.flags & ASYNC_INITIALIZED)) {
  785. save_flags(flags);
  786. cli();
  787. #if defined(CONFIG_MVME147_SCC) || defined(CONFIG_MVME162_SCC)
  788. if (MACH_IS_MVME147 || MACH_IS_MVME16x) {
  789. for (i=0; i<sizeof(mvme_init_tab)/sizeof(*mvme_init_tab); ++i)
  790. SCCwrite(mvme_init_tab[i].reg, mvme_init_tab[i].val);
  791. }
  792. #endif
  793. #if defined(CONFIG_BVME6000_SCC)
  794. if (MACH_IS_BVME6000) {
  795. for (i=0; i<sizeof(bvme_init_tab)/sizeof(*bvme_init_tab); ++i)
  796. SCCwrite(bvme_init_tab[i].reg, bvme_init_tab[i].val);
  797. }
  798. #endif
  799. /* remember status register for detection of DCD and CTS changes */
  800. scc_last_status_reg[channel] = SCCread(STATUS_REG);
  801. port->c_dcd = 0; /* Prevent initial 1->0 interrupt */
  802. scc_setsignals (port, 1,1);
  803. restore_flags(flags);
  804. }
  805. tty->driver_data = port;
  806. port->gs.tty = tty;
  807. port->gs.count++;
  808. retval = gs_init_port(&port->gs);
  809. if (retval) {
  810. port->gs.count--;
  811. return retval;
  812. }
  813. port->gs.flags |= GS_ACTIVE;
  814. if (port->gs.count == 1) {
  815. MOD_INC_USE_COUNT;
  816. }
  817. retval = gs_block_til_ready(port, filp);
  818. if (retval) {
  819. MOD_DEC_USE_COUNT;
  820. port->gs.count--;
  821. return retval;
  822. }
  823. if ((port->gs.count == 1) && (port->gs.flags & ASYNC_SPLIT_TERMIOS)) {
  824. if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
  825. *tty->termios = port->gs.normal_termios;
  826. else 
  827. *tty->termios = port->gs.callout_termios;
  828. scc_set_real_termios (port);
  829. }
  830. port->gs.session = current->session;
  831. port->gs.pgrp = current->pgrp;
  832. port->c_dcd = scc_get_CD (port);
  833. scc_enable_rx_interrupts(port);
  834. return 0;
  835. }
  836. static void scc_throttle (struct tty_struct * tty)
  837. {
  838. struct scc_port *port = (struct scc_port *)tty->driver_data;
  839. unsigned long flags;
  840. SCC_ACCESS_INIT(port);
  841. if (tty->termios->c_cflag & CRTSCTS) {
  842. save_flags(flags);
  843. cli();
  844. SCCmod(TX_CTRL_REG, ~TCR_RTS, 0);
  845. restore_flags(flags);
  846. }
  847. if (I_IXOFF(tty))
  848. scc_send_xchar(tty, STOP_CHAR(tty));
  849. }
  850. static void scc_unthrottle (struct tty_struct * tty)
  851. {
  852. struct scc_port *port = (struct scc_port *)tty->driver_data;
  853. unsigned long flags;
  854. SCC_ACCESS_INIT(port);
  855. if (tty->termios->c_cflag & CRTSCTS) {
  856. save_flags(flags);
  857. cli();
  858. SCCmod(TX_CTRL_REG, 0xff, TCR_RTS);
  859. restore_flags(flags);
  860. }
  861. if (I_IXOFF(tty))
  862. scc_send_xchar(tty, START_CHAR(tty));
  863. }
  864. static int scc_ioctl(struct tty_struct *tty, struct file *file,
  865.      unsigned int cmd, unsigned long arg)
  866. {
  867. return -ENOIOCTLCMD;
  868. }
  869. static void scc_break_ctl(struct tty_struct *tty, int break_state)
  870. {
  871. struct scc_port *port = (struct scc_port *)tty->driver_data;
  872. unsigned long flags;
  873. SCC_ACCESS_INIT(port);
  874. save_flags(flags);
  875. cli();
  876. SCCmod(TX_CTRL_REG, ~TCR_SEND_BREAK, 
  877. break_state ? TCR_SEND_BREAK : 0);
  878. restore_flags(flags);
  879. }
  880. /*---------------------------------------------------------------------------
  881.  * Serial console stuff...
  882.  *--------------------------------------------------------------------------*/
  883. #define scc_delay() do { __asm__ __volatile__ (" nop; nop"); } while (0)
  884. static void scc_ch_write (char ch)
  885. {
  886. volatile char *p = NULL;
  887. #ifdef CONFIG_MVME147_SCC
  888. if (MACH_IS_MVME147)
  889. p = (volatile char *)M147_SCC_A_ADDR;
  890. #endif
  891. #ifdef CONFIG_MVME162_SCC
  892. if (MACH_IS_MVME16x)
  893. p = (volatile char *)MVME_SCC_A_ADDR;
  894. #endif
  895. #ifdef CONFIG_BVME6000_SCC
  896. if (MACH_IS_BVME6000)
  897. p = (volatile char *)BVME_SCC_A_ADDR;
  898. #endif
  899. do {
  900. scc_delay();
  901. }
  902. while (!(*p & 4));
  903. scc_delay();
  904. *p = 8;
  905. scc_delay();
  906. *p = ch;
  907. }
  908. /* The console must be locked when we get here. */
  909. static void scc_console_write (struct console *co, const char *str, unsigned count)
  910. {
  911. unsigned long flags;
  912. save_flags(flags);
  913. cli();
  914. while (count--)
  915. {
  916. if (*str == 'n')
  917. scc_ch_write ('r');
  918. scc_ch_write (*str++);
  919. }
  920. restore_flags(flags);
  921. }
  922. static kdev_t scc_console_device(struct console *c)
  923. {
  924. return MKDEV(TTY_MAJOR, SCC_MINOR_BASE + c->index);
  925. }
  926. static int __init scc_console_setup(struct console *co, char *options)
  927. {
  928. return 0;
  929. }
  930. static struct console sercons = {
  931. name: "ttyS",
  932. write: scc_console_write,
  933. device: scc_console_device,
  934. setup: scc_console_setup,
  935. flags: CON_PRINTBUFFER,
  936. index: -1,
  937. };
  938. void __init vme_scc_console_init(void)
  939. {
  940. if (vme_brdtype == VME_TYPE_MVME147 ||
  941. vme_brdtype == VME_TYPE_MVME162 ||
  942. vme_brdtype == VME_TYPE_MVME172 ||
  943. vme_brdtype == VME_TYPE_BVME4000 ||
  944. vme_brdtype == VME_TYPE_BVME6000)
  945. register_console(&sercons);
  946. }