vme_scc.c 28 KB

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