vme_scc.c 28 KB

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