vme_scc.c 28 KB

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