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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* -*- linux-c -*- */
  2. /* $Id: 8253xtty.c,v 1.23 2002/02/10 22:17:25 martillo Exp $
  3.  * sab82532.c: ASYNC Driver for the SIEMENS SAB82532 DUSCC.
  4.  *
  5.  * Copyright (C) 1997  Eddie C. Dost  (ecd@skynet.be)
  6.  *
  7.  * Modified by Francois Wautier 2000 (fw@auroratech.com)
  8.  *
  9.  * Extended extensively by Joachim Martillo 2001 (Telford002@aol.com)
  10.  *  to provide synchronous/asynchronous TTY/Callout/character/network device
  11.  *  capabilities.
  12.  *
  13.  * Modifications and extensions
  14.  * Copyright (C) 2001 By Joachim Martillo, Telford Tools, Inc.
  15.  *
  16.  * This program is free software; you can redistribute it and/or
  17.  * modify it under the terms of the GNU General Public License
  18.  * as published by the Free Software Foundation; either version
  19.  * 2 of the License, or (at your option) any later version.
  20.  */
  21. /* Standard in kernel modules */
  22. #define DEFINE_VARIABLE
  23. #include <linux/module.h>   /* Specifically, a module */
  24. #include <asm/io.h>
  25. #include <linux/timer.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/tty.h>
  28. #include <linux/tty_flip.h>
  29. #include <linux/mm.h>
  30. #include <linux/version.h>
  31. #include <asm/uaccess.h>
  32. #include <linux/pci.h>
  33. #include "8253xctl.h"
  34. #include "sp502.h"
  35. DECLARE_TASK_QUEUE(tq_8253x_serial); /* this just initializes a list head called */
  36.      /* tq_8253x_serial*/
  37. struct tty_driver sab8253x_serial_driver, sab8253x_callout_driver, sync_sab8253x_serial_driver;
  38. int sab8253x_refcount;
  39. /* Trace things on serial device, useful for console debugging: */
  40. #undef SERIAL_LOG_DEVICE
  41. #ifdef SERIAL_LOG_DEVICE
  42. static void dprint_init(int tty);
  43. #endif
  44. static void sab8253x_change_speed(struct sab_port *port);
  45. static struct tty_struct **sab8253x_tableASY = 0; /* make dynamic */
  46. static struct tty_struct **sab8253x_tableCUA = 0; /* make dynamic */
  47. static struct tty_struct **sab8253x_tableSYN = 0; /* make dynamic */
  48. static struct termios **sab8253x_termios = 0 ;
  49. static struct termios **sab8253x_termios_locked = 0;
  50. #ifdef MODULE
  51. #undef XCONFIG_SERIAL_CONSOLE /* leaving out CONFIG_SERIAL_CONSOLE for now */
  52. #endif
  53. #ifdef XCONFIG_SERIAL_CONSOLE /* not really implemented yet */
  54. extern int serial_console;
  55. struct console sab8253x_console;
  56. int sab8253x_console_init(void);
  57. #endif
  58. #ifndef MIN
  59. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  60. #endif
  61. char sab8253x_serial_version[16];
  62. static void sab8253x_flush_to_ldisc(void *private_)
  63. {
  64. struct tty_struct *tty = (struct tty_struct *) private_;
  65. unsigned char *cp;
  66. char *fp;
  67. int count;
  68. struct sab_port *port;
  69. struct sk_buff *skb;  
  70. if(tty)
  71. {
  72. port = (struct sab_port *)tty->driver_data; /* probably a silly check */
  73. }
  74. else
  75. {
  76. return;
  77. }
  78. if(!port)
  79. {
  80. return;
  81. }
  82. if (test_bit(TTY_DONT_FLIP, &tty->flags)) 
  83. {
  84. queue_task(&tty->flip.tqueue, &tq_timer);
  85. return;
  86. }
  87. /* note that a hangup may have occurred -- perhaps should check for that */
  88. port->DoingInterrupt = 1;
  89. while(port->sab8253xc_rcvbuflist && (skb_queue_len(port->sab8253xc_rcvbuflist) > 0))
  90. {
  91. skb = skb_dequeue(port->sab8253xc_rcvbuflist);
  92. count = skb->data_len;
  93. cp = skb->data;
  94. fp = skb->data + (count/2);
  95. (*tty->ldisc.receive_buf)(tty, cp, fp, count/2);
  96. dev_kfree_skb_any(skb);
  97. }
  98. port->DoingInterrupt = 0;
  99. }
  100. /* only used asynchronously */
  101. static void inline sab8253x_tec_wait(struct sab_port *port)
  102. {
  103. int count = port->tec_timeout;
  104. while((READB(port, star) & SAB82532_STAR_TEC) && --count)
  105. {
  106. udelay(1);
  107. }
  108. }
  109. void sab8253x_start_tx(struct sab_port *port)
  110. {
  111. unsigned long flags;
  112. register int count;
  113. register int total;
  114. register int offset;
  115. char temporary[32];
  116. register unsigned int slopspace;
  117. register int sendsize;
  118. unsigned int totaltransmit;
  119. unsigned fifospace;
  120. unsigned loadedcount;
  121. struct tty_struct *tty = port->tty;
  122. fifospace = port->xmit_fifo_size;
  123. loadedcount = 0;
  124. if(port->sabnext2.transmit == NULL)
  125. {
  126. return;
  127. }
  128. save_flags(flags); 
  129. cli();
  130. while(count = port->sabnext2.transmit->Count, (count & OWNER) == OWN_SAB)
  131. {
  132. count &= ~OWN_SAB; /* OWN_SAB is really 0 but cannot guarantee in the future */
  133. if(port->sabnext2.transmit->HostVaddr)
  134. {
  135. total = (port->sabnext2.transmit->HostVaddr->tail - 
  136.  port->sabnext2.transmit->HostVaddr->data); /* packet size */
  137. }
  138. else
  139. {
  140. total = 0; /* the data is only in the crc/trailer */
  141. }
  142. if(tty && (tty->stopped || tty->hw_stopped))
  143. { /* works for frame that only has a trailer (crc) */
  144. port->interrupt_mask1 |= SAB82532_IMR1_XPR;
  145. WRITEB(port, imr1, port->interrupt_mask1);
  146. restore_flags(flags); /* can't send */
  147. return;
  148. }
  149. offset = (total - count); /* offset to data still to send */
  150. port->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS);
  151. WRITEB(port, imr1, port->interrupt_mask1);
  152. port->all_sent = 0;
  153. if(READB(port,star) & SAB82532_STAR_XFW)
  154. {
  155. if(count <= fifospace)
  156. {
  157. port->xmit_cnt = count;
  158. slopspace = 0;
  159. sendsize = 0;
  160. if(port->sabnext2.transmit->sendcrc) 
  161. /* obviously should not happen for async but might use for
  162.    priority transmission */
  163. {
  164. slopspace = fifospace - count;
  165. }
  166. if(slopspace)
  167. {
  168. if(count)
  169. {
  170. memcpy(temporary, &port->sabnext2.transmit->HostVaddr->data[offset], 
  171.        count);
  172. }
  173. sendsize = MIN(slopspace, (4 - port->sabnext2.transmit->crcindex)); 
  174. /* how many bytes to send */
  175. memcpy(&temporary[count], 
  176.        &((unsigned char*)(&port->sabnext2.transmit->crc))
  177.        [port->sabnext2.transmit->crcindex], 
  178.        sendsize);
  179. port->sabnext2.transmit->crcindex += sendsize;
  180. if(port->sabnext2.transmit->crcindex >= 4)
  181. {
  182. port->sabnext2.transmit->sendcrc = 0;
  183. }
  184. port->xmit_buf = temporary;
  185. }
  186. else
  187. {
  188. port->xmit_buf = /* set up wrifefifo variables */
  189. &port->sabnext2.transmit->HostVaddr->data[offset];
  190. }
  191. port->xmit_cnt += sendsize;
  192. count = 0;
  193. }
  194. else
  195. {
  196. count -= fifospace;
  197. port->xmit_cnt = fifospace;
  198. port->xmit_buf = /* set up wrifefifo variables */
  199. &port->sabnext2.transmit->HostVaddr->data[offset];
  200. }
  201. port->xmit_tail= 0;
  202. loadedcount = port->xmit_cnt;
  203. (*port->writefifo)(port);
  204. totaltransmit = Sab8253xCountTransmitDescriptors(port);
  205. if((sab8253xt_listsize - totaltransmit) > 2) 
  206. {
  207. sab8253x_sched_event(port, SAB8253X_EVENT_WRITE_WAKEUP);
  208. }
  209. if((sab8253xt_listsize - totaltransmit) > (sab8253xt_listsize/2))
  210. {
  211. port->buffergreedy = 0;
  212. }
  213. else
  214. {
  215. port->buffergreedy = 1;
  216. }
  217. port->xmit_buf = NULL; /* this var is used to indicate whether to call kfree */
  218. fifospace -= loadedcount;
  219. if ((count <= 0) && (port->sabnext2.transmit->sendcrc == 0))
  220. {
  221. port->sabnext2.transmit->Count = OWN_DRIVER;
  222. #ifdef FREEININTERRUPT /* treat this routine as if taking place in interrupt */
  223. if(port->sabnext2.transmit->HostVaddr)
  224. {
  225. skb_unlink(port->sabnext2.transmit->HostVaddr);
  226. dev_kfree_skb_any(port->sabnext2.transmit->HostVaddr);
  227. port->sabnext2.transmit->HostVaddr = 0; /* no skb */
  228. }
  229. port->sabnext2.transmit->crcindex = 0; /* no single byte */
  230. #endif
  231. port->sabnext2.transmit = port->sabnext2.transmit->VNext;
  232. if((port->sabnext2.transmit->Count & OWNER) == OWN_SAB)
  233. {
  234. if(fifospace > 0)
  235. {
  236. continue; /* the only place where this code really loops */
  237. }
  238. if(fifospace < 0)
  239. {
  240. printk(KERN_ALERT "sab8253x:  bad math in interrupt handler.n");
  241. }
  242. port->interrupt_mask1 &= ~(SAB82532_IMR1_XPR);
  243. WRITEB(port, imr1, port->interrupt_mask1);
  244. }
  245. else
  246. {
  247. port->interrupt_mask1 |= SAB82532_IMR1_XPR;
  248. WRITEB(port, imr1, port->interrupt_mask1);
  249. }
  250. sab8253x_cec_wait(port);
  251. /* Issue a Transmit Frame command. */
  252. WRITEB(port, cmdr, SAB82532_CMDR_XF); 
  253. /* This could be optimized to load from next skbuff */
  254. /* SAB82532_CMDR_XF is the same as SAB82532_CMDR_XTF */
  255. restore_flags(flags);
  256. return;
  257. }
  258. sab8253x_cec_wait(port);
  259. /* Issue a Transmit Frame command. */
  260. WRITEB(port, cmdr, SAB82532_CMDR_XF); /* same as SAB82532_CMDR_XTF */
  261. port->sabnext2.transmit->Count = (count|OWN_SAB);
  262. }
  263. port->interrupt_mask1 &= ~(SAB82532_IMR1_XPR);
  264. WRITEB(port, imr1, port->interrupt_mask1);
  265. restore_flags(flags);
  266. return;
  267. }
  268. /*  The While loop only exits via return*/
  269. /* we get here by skipping the loop  */
  270. port->interrupt_mask1 |= SAB82532_IMR1_XPR;
  271. WRITEB(port, imr1, port->interrupt_mask1);
  272. restore_flags(flags);
  273. return;
  274. }
  275. /*
  276.  * ------------------------------------------------------------
  277.  * sab8253x_stop() and sab8253x_start()
  278.  *
  279.  * This routines are called before setting or resetting tty->stopped.
  280.  * They enable or disable transmitter interrupts, as necessary.
  281.  * ------------------------------------------------------------
  282.  */
  283. static void sab8253x_stop(struct tty_struct *tty)
  284. {
  285. struct sab_port *port = (struct sab_port *)tty->driver_data;
  286. unsigned long flags;
  287. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_stop"))
  288. {
  289. return;
  290. }
  291. save_flags(flags); 
  292. cli(); /* maybe should turn off ALLS as well
  293.    but the stop flags are checked
  294.    so ALLS is probably harmless
  295.    and I have seen too much evil
  296.    associated with that interrupt*/
  297. port->interrupt_mask1 |= SAB82532_IMR1_XPR;
  298. WRITEB(port, imr1, port->interrupt_mask1);
  299. restore_flags(flags);
  300. }
  301. static void sab8253x_start(struct tty_struct *tty)
  302. {
  303. struct sab_port *port = (struct sab_port *)tty->driver_data;
  304. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_start"))
  305. {
  306. return;
  307. }
  308. sab8253x_start_tx(port);
  309. }
  310. /*
  311.  * This routine is used by the interrupt handler to schedule
  312.  * processing in the software interrupt portion of the driver.
  313.  */
  314. /* no obvious changes for sync tty */
  315. static void sab8253x_receive_chars(struct sab_port *port,
  316.     union sab8253x_irq_status *stat)
  317. {
  318. struct tty_struct *tty = port->tty;
  319. unsigned char buf[32];
  320. unsigned char reordered[32];
  321. unsigned char status;
  322. int free_fifo = 0;
  323. int i, count = 0;
  324. struct sk_buff *skb;
  325. /* Read number of BYTES (Character + Status) available. */
  326. if (stat->images[ISR0_IDX] & SAB82532_ISR0_RPF) 
  327. {
  328. count = port->recv_fifo_size;
  329. free_fifo++;
  330. }
  331. if (stat->images[ISR0_IDX] & SAB82532_ISR0_TCD) 
  332. {
  333. count = READB(port,rbcl) & (port->recv_fifo_size - 1);
  334. free_fifo++;
  335. }
  336. /* Issue a FIFO read command in case we where idle. */
  337. if (stat->sreg.isr0 & SAB82532_ISR0_TIME) 
  338. {
  339. sab8253x_cec_wait(port);
  340. WRITEB(port, cmdr, SAB82532_CMDR_RFRD);
  341. }
  342. if (stat->images[ISR0_IDX] & SAB82532_ISR0_RFO) 
  343. { /* FIFO overflow */
  344. free_fifo++;
  345. }
  346. /* Read the FIFO. */
  347. (*port->readfifo)(port, buf, count);
  348. /* Issue Receive Message Complete command. */
  349. if (free_fifo) 
  350. {
  351. sab8253x_cec_wait(port);
  352. WRITEB(port, cmdr, SAB82532_CMDR_RMC);
  353. }
  354. #ifdef CONSOLE_SUPPORT
  355. if (port->is_console)
  356. {
  357. wake_up(&keypress_wait);
  358. }
  359. #endif
  360. if (!tty)
  361. {
  362. return;
  363. }
  364. if(!count)
  365. {
  366. return;
  367. }
  368. for(i = 0; i < count; i += 2)
  369. {
  370. reordered[i/2] = buf[i];
  371. status = buf[i+1];
  372. if (status & SAB82532_RSTAT_PE) 
  373. {
  374. status = TTY_PARITY;
  375. port->icount.parity++;
  376. else if (status & SAB82532_RSTAT_FE) 
  377. {
  378. status = TTY_FRAME;
  379. port->icount.frame++;
  380. }
  381. else
  382. {
  383. status = TTY_NORMAL;
  384. }
  385. reordered[(count+i)/2] = status;
  386. }
  387. if(port->active2.receive == NULL)
  388. {
  389. return;
  390. }
  391. memcpy(port->active2.receive->HostVaddr->tail, reordered, count);
  392. port->active2.receive->HostVaddr->tail += count;
  393. port->active2.receive->HostVaddr->data_len = count;
  394. port->active2.receive->HostVaddr->len = count;
  395. if(skb = dev_alloc_skb(port->recv_fifo_size), skb == NULL) /* use dev_alloc_skb because at int
  396.       there is header space but so what*/
  397. {
  398. port->icount.buf_overrun++;
  399. port->active2.receive->HostVaddr->tail = port->active2.receive->HostVaddr->data; /* clear the buffer */
  400. port->active2.receive->Count = (port->recv_fifo_size|OWN_SAB);
  401. port->active2.receive->HostVaddr->data_len = 0;
  402. port->active2.receive->HostVaddr->len = 0;
  403. }
  404. else
  405. {
  406. skb_unlink(port->active2.receive->HostVaddr);
  407. skb_queue_tail(port->sab8253xc_rcvbuflist, port->active2.receive->HostVaddr);
  408. skb_queue_head(port->sab8253xbuflist, skb);
  409. port->active2.receive->HostVaddr = skb;
  410. port->active2.receive->Count = (port->recv_fifo_size|OWN_SAB);
  411. }
  412. queue_task(&tty->flip.tqueue, &tq_timer);
  413. }
  414. static void sab8253x_transmit_chars(struct sab_port *port,
  415.     union sab8253x_irq_status *stat)
  416. {
  417. if (stat->sreg.isr1 & SAB82532_ISR1_ALLS) /* got an all sent int? */
  418. {
  419. port->interrupt_mask1 |= SAB82532_IMR1_ALLS;
  420. WRITEB(port, imr1, port->interrupt_mask1);
  421. port->all_sent = 1; /* not much else to do */
  422. } /* a very weird chip -- this int only indicates this int */
  423. sab8253x_start_tx(port);
  424. }
  425. static void sab8253x_check_status(struct sab_port *port,
  426.    union sab8253x_irq_status *stat)
  427. {
  428. struct tty_struct *tty = port->tty;
  429. int modem_change = 0;
  430. mctlsig_t         *sig;
  431. struct sk_buff *skb;
  432. if (!tty)
  433. {
  434. return;
  435. }
  436. if(port->active2.receive == NULL)
  437. {
  438. goto check_modem;
  439. }
  440. if (stat->images[ISR1_IDX] & SAB82532_ISR1_BRK) 
  441. {
  442. #ifdef XCONFIG_SERIAL_CONSOLE
  443. if (port->is_console) 
  444. {
  445. batten_down_hatches(info); /* need to add this function */
  446. return;
  447. }
  448. #endif 
  449. port->active2.receive->HostVaddr->tail[0] = 0;
  450. port->active2.receive->HostVaddr->tail[1] = TTY_PARITY;
  451. port->active2.receive->HostVaddr->tail += 2;
  452. port->active2.receive->HostVaddr->data_len = 2;
  453. port->active2.receive->HostVaddr->len = 2;
  454. if(skb = dev_alloc_skb(port->recv_fifo_size), skb == NULL)
  455. {
  456. port->icount.buf_overrun++;
  457. port->active2.receive->HostVaddr->tail = port->active2.receive->HostVaddr->data; 
  458. /* clear the buffer */
  459. port->active2.receive->Count = (port->recv_fifo_size|OWN_SAB);
  460. port->active2.receive->HostVaddr->data_len = 0;
  461. port->active2.receive->HostVaddr->len = 0;
  462. }
  463. else
  464. {
  465. skb_unlink(port->active2.receive->HostVaddr);
  466. skb_queue_tail(port->sab8253xc_rcvbuflist, port->active2.receive->HostVaddr);
  467. skb_queue_head(port->sab8253xbuflist, skb);
  468. port->active2.receive->HostVaddr = skb;
  469. port->active2.receive->Count = (port->recv_fifo_size|OWN_SAB);
  470. }
  471. queue_task(&tty->flip.tqueue, &tq_timer);
  472. port->icount.brk++;
  473. }
  474. if (stat->images[ISR0_IDX] & SAB82532_ISR0_RFO) 
  475. {
  476. port->active2.receive->HostVaddr->tail[0] = 0;
  477. port->active2.receive->HostVaddr->tail[1] = TTY_PARITY;
  478. port->active2.receive->HostVaddr->tail += 2;
  479. port->active2.receive->HostVaddr->data_len = 2;
  480. port->active2.receive->HostVaddr->len = 2;
  481. if(skb = dev_alloc_skb(port->recv_fifo_size), skb == NULL)
  482. {
  483. port->icount.buf_overrun++;
  484. port->active2.receive->HostVaddr->tail = port->active2.receive->HostVaddr->data; 
  485. /* clear the buffer */
  486. port->active2.receive->Count = (port->recv_fifo_size|OWN_SAB);
  487. port->active2.receive->HostVaddr->data_len = 0;
  488. port->active2.receive->HostVaddr->len = 0;
  489. }
  490. else
  491. {
  492. skb_unlink(port->active2.receive->HostVaddr);
  493. skb_queue_tail(port->sab8253xc_rcvbuflist, port->active2.receive->HostVaddr);
  494. skb_queue_head(port->sab8253xbuflist, skb);
  495. port->active2.receive->HostVaddr = skb;
  496. port->active2.receive->Count = (port->recv_fifo_size|OWN_SAB);
  497. }
  498. queue_task(&tty->flip.tqueue, &tq_timer);
  499. port->icount.overrun++;
  500. }
  501.  check_modem:
  502. /* Checking DCD */
  503. sig = &port->dcd;
  504. if (stat->images[sig->irq] & sig->irqmask) 
  505. {
  506. sig->val = ISON(port,dcd);
  507. port->icount.dcd++;
  508. modem_change++;
  509. }
  510. /* Checking CTS */
  511. sig = &port->cts;
  512. if (stat->images[sig->irq] & sig->irqmask) 
  513. {
  514. sig->val = ISON(port,cts);
  515. port->icount.cts++;
  516. modem_change++;
  517. }
  518. /* Checking DSR */
  519. sig = &port->dsr;
  520. if (stat->images[sig->irq] & sig->irqmask) 
  521. {
  522. sig->val = ISON(port,dsr);
  523. port->icount.dsr++;
  524. modem_change++;
  525. }
  526. if (modem_change)
  527. {
  528. wake_up_interruptible(&port->delta_msr_wait); /* incase kernel proc level was waiting on modem change */
  529. }
  530. sig = &port->dcd;
  531. if ((port->flags & FLAG8253X_CHECK_CD) &&
  532.     (stat->images[sig->irq] & sig->irqmask)) 
  533. {
  534. if (sig->val)
  535. {
  536. wake_up_interruptible(&port->open_wait); /* in case waiting in block_til_ready */
  537. }
  538. else if (!((port->flags & FLAG8253X_CALLOUT_ACTIVE) &&
  539.    (port->flags & FLAG8253X_CALLOUT_NOHUP))) 
  540. {
  541. MOD_INC_USE_COUNT; /* in case a close is already in progress
  542.    don't want structures to vanish during
  543.    late processing of hangup */
  544. if (schedule_task(&port->tqueue_hangup) == 0)
  545. {
  546. MOD_DEC_USE_COUNT; /* task schedule failed */
  547. }
  548. }
  549. }
  550. sig = &port->cts;
  551. if (port->flags & FLAG8253X_CTS_FLOW) 
  552. {
  553. if (port->tty->hw_stopped) 
  554. {
  555. if (sig->val) 
  556. {
  557. port->tty->hw_stopped = 0;
  558. sab8253x_sched_event(port, SAB8253X_EVENT_WRITE_WAKEUP);
  559. sab8253x_start_tx(port);
  560. }
  561. else 
  562. {
  563. if (!(sig->val)) 
  564. {
  565. port->tty->hw_stopped = 1;
  566. }
  567. }
  568. }
  569. }
  570. /*
  571.  * This routine is used to handle the "bottom half" processing for the
  572.  * serial driver, known also the "software interrupt" processing.
  573.  * This processing is done at the kernel interrupt level, after the
  574.  * sab8253x_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON.  This
  575.  * is where time-consuming activities which can not be done in the
  576.  * interrupt driver proper are done; the interrupt driver schedules
  577.  * them using sab8253x_sched_event(), and they get done here.
  578.  */
  579. /* The following routine is installed */
  580. /* in the bottom half -- just search */
  581. /* for the init_bh() call */
  582. /* The logic: sab8253x_sched_event() */
  583. /* enqueues the tqueue port entry on */
  584. /* the tq_8253x_serial task list -- */
  585. /* whenever the bottom half is run */
  586. /* sab8253x_do_softint is invoked for */
  587. /* every port that has invoked the bottom */
  588. /* half via sab8253x_sched_event(). */
  589. /* currently only a write wakeevent */
  590. /* wakeup is scheduled -- to tell the */
  591. /* tty driver to send more chars */
  592. /* down to the serial driver.*/
  593. static void sab8253x_do_serial_bh(void)
  594. {
  595. run_task_queue(&tq_8253x_serial);
  596. }
  597. /* I believe the reason for the */
  598. /* bottom half processing below is */
  599. /* the length of time needed to transfer */
  600. /* characters to the TTY driver. */
  601. static void sab8253x_do_softint(void *private_)
  602. {
  603. struct sab_port *port = (struct sab_port *)private_;
  604. struct tty_struct *tty;
  605. tty = port->tty;
  606. if (!tty)
  607. {
  608. return;
  609. }
  610. port->DoingInterrupt = 1;
  611. if (test_and_clear_bit(SAB8253X_EVENT_WRITE_WAKEUP, &port->event)) 
  612. {
  613. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  614.     tty->ldisc.write_wakeup)
  615. (tty->ldisc.write_wakeup)(tty);
  616. wake_up_interruptible(&tty->write_wait); /* in case tty driver waiting on write */
  617. }
  618. port->DoingInterrupt = 0;
  619. }
  620. /*
  621.  * This routine is called from the scheduler tqueue when the interrupt
  622.  * routine has signalled that a hangup has occurred.  The path of
  623.  * hangup processing is:
  624.  *
  625.  *  serial interrupt routine -> (scheduler tqueue) ->
  626.  *  do_serial_hangup() -> tty->hangup() -> sab8253x_hangup()
  627.  * 
  628.  */
  629. /* This logic takes place at kernel */
  630. /* process context through the scheduler*/
  631. /* schedule_task(tqueue_hangup) */
  632. /* takes place in the interrupt handler*/
  633. static void sab8253x_do_serial_hangup(void *private_)
  634. {
  635. struct sab_port *port = (struct sab_port *) private_;
  636. struct tty_struct *tty;
  637. tty = port->tty;
  638. if (tty)
  639. {
  640. tty_hangup(tty);
  641. }
  642. MOD_DEC_USE_COUNT; /* in case busy waiting to unload module */
  643. }
  644. static void
  645. sab8253x_init_line(struct sab_port *port)
  646. {
  647. unsigned char stat;
  648. if(port->chip->c_cim)
  649. {
  650. if(port->chip->c_cim->ci_type == CIM_SP502)
  651. {
  652. aura_sp502_program(port, SP502_OFF_MODE);
  653. }
  654. }
  655. /*
  656.  * Wait for any commands or immediate characters
  657.  */
  658. sab8253x_cec_wait(port);
  659. sab8253x_tec_wait(port);
  660. /*
  661.  * Clear the FIFO buffers.
  662.  */
  663. WRITEB(port, cmdr, SAB82532_CMDR_RRES);
  664. sab8253x_cec_wait(port);
  665. WRITEB(port, cmdr, SAB82532_CMDR_XRES);
  666. /*
  667.  * Clear the interrupt registers.
  668.  */
  669. stat = READB(port, isr0);
  670. stat = READB(port, isr1);
  671. /*
  672.  * Now, initialize the UART 
  673.  */
  674. WRITEB(port, ccr0, 0);   /* power-down */
  675. WRITEB(port, ccr0,
  676.        SAB82532_CCR0_MCE | SAB82532_CCR0_SC_NRZ | SAB82532_CCR0_SM_ASYNC);
  677. WRITEB(port, ccr1,
  678.        SAB82532_CCR1_ODS | SAB82532_CCR1_BCR | 7);
  679. WRITEB(port, ccr2,
  680.        SAB82532_CCR2_BDF | SAB82532_CCR2_SSEL | SAB82532_CCR2_TOE);
  681. WRITEB(port, ccr3, 0);
  682. WRITEB(port, ccr4,
  683.        SAB82532_CCR4_MCK4 | SAB82532_CCR4_EBRG);
  684. WRITEB(port, mode,
  685.        SAB82532_MODE_RTS | SAB82532_MODE_FCTS | SAB82532_MODE_RAC);
  686. WRITEB(port, rfc,
  687.        SAB82532_RFC_DPS | SAB82532_RFC_RFDF);
  688. switch (port->recv_fifo_size) 
  689. {
  690. case 1:
  691. SET_REG_BIT(port,rfc,SAB82532_RFC_RFTH_1);
  692. break;
  693. case 4:
  694. SET_REG_BIT(port,rfc,SAB82532_RFC_RFTH_4);
  695. break;
  696. case 16:
  697. SET_REG_BIT(port,rfc,SAB82532_RFC_RFTH_16);
  698. break;
  699. default:
  700. port->recv_fifo_size = 32;
  701. case 32:
  702. SET_REG_BIT(port,rfc,SAB82532_RFC_RFTH_32);
  703. break;
  704. }
  705. /* power-up */
  706. SET_REG_BIT(port, ccr0, SAB82532_CCR0_PU);
  707. if(port->chip->c_cim)
  708. {
  709. if(port->chip->c_cim->ci_type == CIM_SP502)
  710. {
  711. aura_sp502_program(port, port->sigmode);
  712. }
  713. }
  714. }
  715. static int sab8253x_startup(struct sab_port *port)
  716. {
  717. unsigned long flags;
  718. int retval = 0;
  719. save_flags(flags); cli();
  720. if (port->flags & FLAG8253X_INITIALIZED) 
  721. {
  722. goto errout;
  723. }
  724. port->msgbufindex = 0;
  725. port->xmit_buf = NULL;
  726. port->buffergreedy = 0;
  727. if (!port->regs) 
  728. {
  729. if (port->tty)
  730. {
  731. set_bit(TTY_IO_ERROR, &port->tty->flags);
  732. }
  733. retval = -ENODEV;
  734. goto errout;
  735. }
  736. /*
  737.  * Initialize the Hardware
  738.  */
  739. sab8253x_init_line(port);
  740. if (port->tty->termios->c_cflag & CBAUD) 
  741. {
  742. /* Activate RTS */
  743. RAISE(port,rts);
  744. /* Activate DTR */
  745. RAISE(port,dtr);
  746. }
  747. /*
  748.  * Initialize the modem signals values
  749.  */
  750. port->dcd.val=ISON(port,dcd);
  751. port->cts.val=ISON(port,cts);
  752. port->dsr.val=ISON(port,dsr);
  753. /*
  754.  * Finally, enable interrupts
  755.  */
  756. port->interrupt_mask0 = SAB82532_IMR0_PERR | SAB82532_IMR0_FERR |
  757. SAB82532_IMR0_PLLA;
  758. WRITEB(port, imr0, port->interrupt_mask0);
  759. port->interrupt_mask1 = SAB82532_IMR1_BRKT | SAB82532_IMR1_XOFF |
  760. SAB82532_IMR1_TIN | SAB82532_IMR1_XON |
  761. SAB82532_IMR1_XPR;
  762. WRITEB(port, imr1, port->interrupt_mask1);
  763. port->all_sent = 1;
  764. if (port->tty)
  765. {
  766. clear_bit(TTY_IO_ERROR, &port->tty->flags);
  767. }
  768. port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
  769. /*
  770.  * and set the speed of the serial port
  771.  */
  772. sab8253x_change_speed(port);
  773. port->flags |= FLAG8253X_INITIALIZED;
  774. port->receive_chars = sab8253x_receive_chars;
  775. port->transmit_chars = sab8253x_transmit_chars;
  776. port->check_status = sab8253x_check_status;
  777. port->receive_test = (SAB82532_ISR0_TCD | SAB82532_ISR0_TIME |
  778.       SAB82532_ISR0_RFO | SAB82532_ISR0_RPF);
  779. port->transmit_test = (SAB82532_ISR1_ALLS | SAB82532_ISR1_XPR);
  780. port->check_status_test = SAB82532_ISR1_BRK;
  781. restore_flags(flags);
  782. return 0;
  783.  errout:
  784. restore_flags(flags);
  785. return retval;
  786. }
  787. /*
  788.  * This routine will shutdown a serial port; interrupts are disabled, and
  789.  * DTR is dropped if the hangup on close termio flag is on.
  790.  */
  791. static void sab8253x_shutdown(struct sab_port *port)
  792. {
  793. unsigned long flags;
  794. if (!(port->flags & FLAG8253X_INITIALIZED))
  795. {
  796. return;
  797. }
  798. save_flags(flags); 
  799. cli(); /* Disable interrupts */
  800. /*
  801.  * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
  802.  * here so the queue might never be waken up
  803.  */
  804. wake_up_interruptible(&port->delta_msr_wait); /* shutting down port modem status is pointless */
  805. if (port->xmit_buf) 
  806. {
  807. port->xmit_buf = NULL;
  808. }
  809. #ifdef XCONFIG_SERIAL_CONSOLE
  810. if (port->is_console) 
  811. {
  812. port->interrupt_mask0 = 
  813. SAB82532_IMR0_PERR | SAB82532_IMR0_FERR |
  814. /*SAB82532_IMR0_TIME |*/
  815. SAB82532_IMR0_PLLA | SAB82532_IMR0_CDSC;
  816. WRITEB(port,imr0,port->interrupt_mask0);
  817. port->interrupt_mask1 = 
  818. SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS |
  819. SAB82532_IMR1_XOFF | SAB82532_IMR1_TIN |
  820. SAB82532_IMR1_CSC | SAB82532_IMR1_XON |
  821. SAB82532_IMR1_XPR;
  822. WRITEB(port,imr1,port->interrupt_mask1);
  823. if (port->tty)
  824. {
  825. set_bit(TTY_IO_ERROR, &port->tty->flags);
  826. }
  827. port->flags &= ~FLAG8253X_INITIALIZED;
  828. restore_flags(flags);
  829. return;
  830. }
  831. #endif
  832. /* Disable Interrupts */
  833. port->interrupt_mask0 = 0xff;
  834. WRITEB(port, imr0, port->interrupt_mask0);
  835. port->interrupt_mask1 = 0xff;
  836. WRITEB(port, imr1, port->interrupt_mask1);
  837. if (!port->tty || (port->tty->termios->c_cflag & HUPCL)) 
  838. {
  839. LOWER(port,rts);
  840. LOWER(port,dtr);
  841. }
  842. /* Disable break condition */
  843. CLEAR_REG_BIT(port,dafo,SAB82532_DAFO_XBRK);
  844. /* Disable Receiver */
  845. CLEAR_REG_BIT(port,mode,SAB82532_MODE_RAC);
  846. /* Power Down */
  847. CLEAR_REG_BIT(port,ccr0,SAB82532_CCR0_PU);
  848. if (port->tty)
  849. {
  850. set_bit(TTY_IO_ERROR, &port->tty->flags);
  851. }
  852. port->flags &= ~FLAG8253X_INITIALIZED;
  853. restore_flags(flags);
  854. }
  855. /*
  856.  * This routine is called to set the UART divisor registers to match
  857.  * the specified baud rate for a serial port.
  858.  */
  859. static void sab8253x_change_speed(struct sab_port *port)
  860. {
  861. unsigned long flags,baud;
  862. tcflag_t cflag;
  863. u8         dafo,ccr2=0,ccr4=0,ebrg=0,mode;
  864. int i, bits;
  865. #ifdef DEBUGGING
  866. printk("Change speed!  ");
  867. #endif
  868. if (!port->tty || !port->tty->termios) 
  869. {
  870. #ifdef DEBUGGING
  871. printk("NOT!n");
  872. #endif
  873. return;
  874. }
  875. #ifdef DEBUGGING
  876. printk(" for real.n");
  877. #endif
  878. cflag = port->tty->termios->c_cflag;
  879. /* Byte size and parity */
  880. switch (cflag & CSIZE) 
  881. {
  882. case CS5: 
  883. dafo = SAB82532_DAFO_CHL5; 
  884. bits = 7; 
  885. break;
  886. case CS6: 
  887. dafo = SAB82532_DAFO_CHL6; 
  888. bits = 8; 
  889. break;
  890. case CS7: 
  891. dafo = SAB82532_DAFO_CHL7; 
  892. bits = 9; 
  893. break;
  894. default:
  895. case CS8: 
  896. dafo = SAB82532_DAFO_CHL8; 
  897. bits = 10; 
  898. break;
  899. }
  900. if (cflag & CSTOPB) 
  901. {
  902. dafo |= SAB82532_DAFO_STOP;
  903. bits++;
  904. }
  905. if (cflag & PARENB) 
  906. {
  907. dafo |= SAB82532_DAFO_PARE;
  908. bits++;
  909. }
  910. if (cflag & PARODD) 
  911. {
  912. #ifdef CMSPAR
  913. if (cflag & CMSPAR)
  914. dafo |= SAB82532_DAFO_PAR_MARK;
  915. else
  916. #endif
  917. dafo |= SAB82532_DAFO_PAR_ODD;
  918. else 
  919. {
  920. #ifdef CMSPAR
  921. if (cflag & CMSPAR)
  922. dafo |= SAB82532_DAFO_PAR_SPACE;
  923. else
  924. #endif
  925. dafo |= SAB82532_DAFO_PAR_EVEN;
  926. }
  927. /* Determine EBRG values based on the "encoded"baud rate */
  928. i = cflag & CBAUD;
  929. switch(i)
  930. {
  931. case B0:
  932. baud=0;
  933. break;
  934. case  B50:
  935. baud=100;
  936. break;
  937. case  B75:
  938. baud=150;
  939. break;
  940. case  B110:
  941. baud=220;
  942. break;
  943. case  B134:
  944. baud=269;
  945. break;
  946. case  B150:
  947. baud=300;
  948. break;
  949. case  B200:
  950. baud=400;
  951. break;
  952. case B300:
  953. baud=600;
  954. break;
  955. case B600:
  956. baud=1200;
  957. break;
  958. case B1200:
  959. baud=2400;
  960. break;
  961. case B1800:
  962. baud=3600;
  963. break;
  964. case B2400:
  965. baud=4800;
  966. break;
  967. case B4800:
  968. baud=9600;
  969. break;
  970. case B9600:
  971. baud=19200;
  972. break;
  973. case B19200:
  974. baud=38400;
  975. break;
  976. case  B38400:
  977. if(port->custspeed)
  978. {
  979. baud=port->custspeed<<1;
  980. }
  981. else
  982. {
  983. baud=76800;
  984. }
  985. break;
  986. case B57600:
  987. baud=115200;
  988. break;
  989. #ifdef SKIPTHIS
  990. case B76800:
  991. baud=153600;
  992. break;
  993. case B153600:
  994. baud=307200;
  995. break;
  996. #endif
  997. case B230400:
  998. baud=460800;
  999. break;
  1000. case  B460800:
  1001. baud=921600;
  1002. break;
  1003. case B115200:
  1004. default:
  1005. baud=230400;
  1006. break;
  1007. }
  1008. if(!sab8253x_baud(port,baud,&ebrg,&ccr2,&ccr4,&(port->baud))) 
  1009. {
  1010. printk("Aurora Warning. baudrate %ld could not be set! Using 115200",baud);
  1011. baud=230400;
  1012. sab8253x_baud(port,baud,&ebrg,&ccr2,&ccr4,&(port->baud));
  1013. }
  1014. if (port->baud)
  1015. port->timeout = (port->xmit_fifo_size * HZ * bits) / port->baud;
  1016. else
  1017. port->timeout = 0;
  1018. port->timeout += HZ / 50; /* Add .02 seconds of slop */
  1019. /* CTS flow control flags */
  1020. if (cflag & CRTSCTS)
  1021. port->flags |= FLAG8253X_CTS_FLOW;
  1022. else
  1023. port->flags &= ~(FLAG8253X_CTS_FLOW);
  1024. if (cflag & CLOCAL)
  1025. port->flags &= ~(FLAG8253X_CHECK_CD);
  1026. else
  1027. port->flags |= FLAG8253X_CHECK_CD;
  1028. if (port->tty)
  1029. port->tty->hw_stopped = 0;
  1030. /*
  1031.  * Set up parity check flag
  1032.  * XXX: not implemented, yet.
  1033.  */
  1034. #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
  1035. /*
  1036.  * Characters to ignore
  1037.  * XXX: not implemented, yet.
  1038.  */
  1039. /*
  1040.  * !!! ignore all characters if CREAD is not set
  1041.  * XXX: not implemented, yet.
  1042.  */
  1043. if ((cflag & CREAD) == 0)
  1044. port->ignore_status_mask |= SAB82532_ISR0_RPF |
  1045. /* SAB82532_ISR0_TIME |*/
  1046. SAB82532_ISR0_TCD ;
  1047. save_flags(flags); 
  1048. cli();
  1049. sab8253x_cec_wait(port);
  1050. sab8253x_tec_wait(port);
  1051. WRITEB(port,dafo,dafo);
  1052. WRITEB(port,bgr,ebrg);
  1053. ccr2 |= READB(port,ccr2) & ~(0xc0);
  1054. WRITEB(port,ccr2,ccr2);
  1055. ccr4 |= READB(port,ccr4) & ~(SAB82532_CCR4_EBRG);
  1056. WRITEB(port,ccr4,ccr4);
  1057. if (port->flags & FLAG8253X_CTS_FLOW) 
  1058. {
  1059. mode = READB(port,mode) & ~(SAB82532_MODE_RTS);
  1060. mode |= SAB82532_MODE_FRTS;
  1061. mode  &= ~(SAB82532_MODE_FCTS);
  1062. else 
  1063. {
  1064. mode = READB(port,mode) & ~(SAB82532_MODE_FRTS);
  1065. mode |= SAB82532_MODE_RTS;
  1066. mode |= SAB82532_MODE_FCTS;
  1067. }
  1068. WRITEB(port,mode,mode);
  1069. mode |= SAB82532_MODE_RAC;
  1070. WRITEB(port,mode,mode);
  1071. restore_flags(flags);
  1072. }
  1073. static void sab8253x_flush_chars(struct tty_struct *tty)
  1074. {
  1075. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1076. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_flush_chars"))
  1077. {
  1078. return;
  1079. }
  1080. if ((Sab8253xCountTransmit(port) <= 0) || tty->stopped || tty->hw_stopped)
  1081. {
  1082. return;
  1083. }
  1084. sab8253x_start_tx(port);
  1085. }
  1086. static int sab8253x_write(struct tty_struct * tty, int from_user,
  1087.    const unsigned char *buf, int count)
  1088. {
  1089. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1090. struct sk_buff *skb = NULL;
  1091. int truelength = 0;
  1092. int do_queue = 1;
  1093. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_write"))
  1094. {
  1095. return 0;
  1096. }
  1097. if(count == 0)
  1098. {
  1099. return 0;
  1100. }
  1101. if(port->active2.transmit == NULL)
  1102. {
  1103. return 0;
  1104. }
  1105. if((port->active2.transmit->Count & OWNER) == OWN_SAB)
  1106. {
  1107. sab8253x_start_tx(port);
  1108. return 0;
  1109. }
  1110. #ifndef FREEININTERRUPT
  1111. skb = port->active2.transmit->HostVaddr; /* current slot value */
  1112. if(port->buffergreedy == 0) /* are we avoiding buffer free's */
  1113. { /* no */
  1114. if((skb != NULL) || /* not OWN_SAB from above */
  1115.    (port->active2.transmit->crcindex != 0)) 
  1116. {
  1117. register RING_DESCRIPTOR *freeme;
  1118. freeme = port->active2.transmit;
  1119. do
  1120. {
  1121. if((freeme->crcindex == 0) && (freeme->HostVaddr == NULL))
  1122. {
  1123. break;
  1124. }
  1125. if(freeme->HostVaddr)
  1126. {
  1127. skb_unlink((struct sk_buff*)freeme->HostVaddr);
  1128. dev_kfree_skb_any((struct sk_buff*)freeme->HostVaddr);
  1129. freeme->HostVaddr = NULL;
  1130. }
  1131. freeme->sendcrc = 0;
  1132. freeme->crcindex = 0;
  1133. freeme = (RING_DESCRIPTOR*) freeme->VNext;
  1134. }
  1135. while((freeme->Count & OWNER) != OWN_SAB);
  1136. }
  1137. skb = NULL; /* buffer was freed */
  1138. }
  1139. if(skb != NULL) /* potentially useful */
  1140. {
  1141. truelength = (skb->end - skb->head);
  1142. if(truelength >= count)
  1143. {
  1144. skb->data = skb->head; /* this buffer is already queued */
  1145. skb->tail = skb->head;
  1146. do_queue = 0;
  1147. }
  1148. else
  1149. {
  1150. skb_unlink(skb);
  1151. dev_kfree_skb_any(skb);
  1152. skb = NULL;
  1153. port->active2.transmit->HostVaddr = NULL;
  1154. }
  1155. }
  1156. /* in all cases the following is allowed */
  1157. port->active2.transmit->sendcrc = 0;
  1158. port->active2.transmit->crcindex = 0;
  1159. #endif
  1160. if(skb == NULL)
  1161. {
  1162. if(port->DoingInterrupt)
  1163. {
  1164. skb = alloc_skb(count, GFP_ATOMIC);
  1165. }
  1166. else
  1167. {
  1168. skb = alloc_skb(count, GFP_KERNEL);
  1169. }
  1170. }
  1171. if(skb == NULL)
  1172. {
  1173. printk(KERN_ALERT "sab8253xt: no skbuffs available.n");
  1174. return 0;
  1175. }
  1176. if(from_user)
  1177. {
  1178. copy_from_user(skb->data, buf, count);
  1179. }
  1180. else
  1181. {
  1182. memcpy(skb->data, buf, count);
  1183. }
  1184. skb->tail = (skb->data + count);
  1185. skb->data_len = count;
  1186. skb->len = count;
  1187. if(do_queue)
  1188. {
  1189. skb_queue_head(port->sab8253xbuflist, skb);
  1190. }
  1191. port->active2.transmit->HostVaddr = skb;
  1192. port->active2.transmit->sendcrc = 0;
  1193. port->active2.transmit->crcindex = 0;
  1194. port->active2.transmit->Count = (OWN_SAB|count);
  1195. port->active2.transmit = port->active2.transmit->VNext;
  1196. sab8253x_start_tx(port);
  1197. return count;
  1198. }
  1199. static int sab8253x_write_room(struct tty_struct *tty)
  1200. {
  1201. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1202. if(sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_write_room"))
  1203. {
  1204. return 0;
  1205. }
  1206. if(port->active2.transmit == NULL)
  1207. {
  1208. return 0;
  1209. }
  1210. if((port->active2.transmit->Count & OWNER) == OWN_SAB)
  1211. {
  1212. return 0;
  1213. }
  1214. return ((sab8253xt_rbufsize) * /* really should not send buffs bigger than 32 I guess */
  1215. (sab8253xt_listsize - 
  1216.  Sab8253xCountTransmitDescriptors(port)));
  1217. }
  1218. static int sab8253x_chars_in_buffer(struct tty_struct *tty)
  1219. {
  1220. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1221. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_chars_in_bufferS"))
  1222. {
  1223. return 0;
  1224. }
  1225. return Sab8253xCountTransmit(port);
  1226. }
  1227. /*
  1228.  * This function is used to send a high-priority XON/XOFF character to
  1229.  * the device
  1230.  */
  1231. static void sab8253x_send_xchar(struct tty_struct *tty, char ch)
  1232. {
  1233. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1234. unsigned long flags;
  1235. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_send_xchar"))
  1236. {
  1237. return;
  1238. }
  1239. save_flags(flags); 
  1240. cli();
  1241. sab8253x_tec_wait(port);
  1242. WRITEB(port, tic, ch);
  1243. restore_flags(flags);
  1244. }
  1245. /*
  1246.  * ------------------------------------------------------------
  1247.  * sab8253x_throttle()
  1248.  * 
  1249.  * This routine is called by the upper-layer tty layer to signal that
  1250.  * incoming characters should be throttled.
  1251.  * ------------------------------------------------------------
  1252.  */
  1253. static void sab8253x_throttle(struct tty_struct * tty)
  1254. {
  1255. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1256. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_throttle"))
  1257. {
  1258. return;
  1259. }
  1260. if (I_IXOFF(tty))
  1261. {
  1262. sab8253x_send_xchar(tty, STOP_CHAR(tty));
  1263. }
  1264. }
  1265. static void sab8253x_unthrottle(struct tty_struct * tty)
  1266. {
  1267. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1268. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_unthrottle"))
  1269. {
  1270. return;
  1271. }
  1272. if (I_IXOFF(tty)) 
  1273. {
  1274. if (port->x_char)
  1275. {
  1276. port->x_char = 0;
  1277. }
  1278. else
  1279. {
  1280. sab8253x_send_xchar(tty, START_CHAR(tty));
  1281. }
  1282. }
  1283. }
  1284. /*
  1285.  * ------------------------------------------------------------
  1286.  * sab8253x_ioctl() and friends
  1287.  * ------------------------------------------------------------
  1288.  */
  1289. static int sab8253x_get_serial_info(struct sab_port *port,
  1290.      struct serial_struct *retinfo)
  1291. {
  1292. struct serial_struct tmp;
  1293. if (!retinfo)
  1294. {
  1295. return -EFAULT;
  1296. }
  1297. memset(&tmp, 0, sizeof(tmp));
  1298. tmp.type = port->type;
  1299. tmp.line = port->line;
  1300. tmp.port = (unsigned long)port->regs;
  1301. tmp.irq = port->irq;
  1302. tmp.flags = port->flags;
  1303. tmp.xmit_fifo_size = port->xmit_fifo_size;
  1304. tmp.baud_base = 0;
  1305. tmp.close_delay = port->close_delay;
  1306. tmp.closing_wait = port->closing_wait;
  1307. tmp.custom_divisor = port->custom_divisor;
  1308. tmp.hub6 = 0;
  1309. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  1310. {
  1311. return -EFAULT;
  1312. }
  1313. return 0;
  1314. }
  1315. static int sab8253x_set_serial_info(struct sab_port *port,
  1316.      struct serial_struct *new_info)
  1317. {
  1318. return 0;
  1319. }
  1320. /*
  1321.  * get_lsr_info - get line status register info
  1322.  *
  1323.  * Purpose: Let user call ioctl() to get info when the UART physically
  1324.  *      is emptied.  On bus types like RS485, the transmitter must
  1325.  *      release the bus after transmitting. This must be done when
  1326.  *      the transmit shift register is empty, not be done when the
  1327.  *      transmit holding register is empty.  This functionality
  1328.  *      allows an RS485 driver to be written in user space. 
  1329.  */
  1330. static int sab8253x_get_lsr_info(struct sab_port * port, unsigned int *value)
  1331. {
  1332. unsigned int result;
  1333. result = (((Sab8253xCountTransmit(port) <= 0) && port->all_sent) ? TIOCSER_TEMT : 0);
  1334. return put_user(result, value);
  1335. }
  1336. static int sab8253x_get_modem_info(struct sab_port * port, unsigned int *value)
  1337. {
  1338. unsigned int result;
  1339. /* Using the cached values !! After all when changed int occurs
  1340.    and the cache is updated */
  1341. result=  
  1342. ((port->dtr.val) ? TIOCM_DTR : 0)
  1343. | ((port->rts.val) ? TIOCM_RTS : 0)
  1344. | ((port->cts.val) ? TIOCM_CTS : 0)
  1345. | ((port->dsr.val) ? TIOCM_DSR : 0)
  1346. | ((port->dcd.val) ? TIOCM_CAR : 0);
  1347. return put_user(result,value);
  1348. }
  1349. static int sab8253x_set_modem_info(struct sab_port * port, unsigned int cmd,
  1350.    unsigned int *value)
  1351. {
  1352. int error;
  1353. unsigned int arg;
  1354. unsigned long flags;
  1355. error = get_user(arg, value);
  1356. if (error)
  1357. {
  1358. return error;
  1359. }
  1360. save_flags(flags);
  1361. cli();
  1362. switch (cmd) 
  1363. {
  1364. case TIOCMBIS: 
  1365. if (arg & TIOCM_RTS) 
  1366. {
  1367. RAISE(port, rts);
  1368. }
  1369. if (arg & TIOCM_DTR) 
  1370. {
  1371. RAISE(port, dtr);
  1372. }
  1373. break;
  1374. case TIOCMBIC:
  1375. if (arg & TIOCM_RTS) 
  1376. {
  1377. LOWER(port,rts);
  1378. }
  1379. if (arg & TIOCM_DTR) 
  1380. {
  1381. LOWER(port,dtr);
  1382. }
  1383. break;
  1384. case TIOCMSET:
  1385. if (arg & TIOCM_RTS) 
  1386. {
  1387. RAISE(port, rts);
  1388. else 
  1389. {
  1390. LOWER(port,rts);
  1391. }
  1392. if (arg & TIOCM_DTR) 
  1393. {
  1394. RAISE(port, dtr);
  1395. else 
  1396. {
  1397. LOWER(port,dtr);
  1398. }
  1399. break;
  1400. default:
  1401. restore_flags(flags);
  1402. return -EINVAL;
  1403. }
  1404. restore_flags(flags);
  1405. return 0;
  1406. }
  1407. /*
  1408.  * This routine sends a break character out the serial port.
  1409.  */
  1410. static void sab8253x_break(struct tty_struct *tty, int break_state)
  1411. {
  1412. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1413. unsigned long flags;
  1414. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_break"))
  1415. {
  1416. return;
  1417. }
  1418. if (!port->regs)
  1419. {
  1420. return;
  1421. }
  1422. save_flags(flags); 
  1423. cli();
  1424. if (break_state == -1) 
  1425. {
  1426. SET_REG_BIT(port,dafo,SAB82532_DAFO_XBRK);
  1427. else 
  1428. {
  1429. CLEAR_REG_BIT(port,dafo,SAB82532_DAFO_XBRK);
  1430. }
  1431. restore_flags(flags);
  1432. }
  1433. static int sab8253x_ioctl(struct tty_struct *tty, struct file * file,
  1434.   unsigned int cmd, unsigned long arg)
  1435. {
  1436. int error;
  1437. unsigned int wordindex;
  1438. unsigned short *wordptr;
  1439. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1440. struct async_icount cprev, cnow; /* kernel counter temps */
  1441. struct serial_icounter_struct *p_cuser; /* user space */
  1442. SAB_BOARD *bptr;
  1443. unsigned long flags;
  1444. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_ioctl"))
  1445. {
  1446. return -ENODEV;
  1447. }
  1448. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1449.     (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD)  &&
  1450.     (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT) &&
  1451.     (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) 
  1452. {
  1453. if (tty->flags & (1 << TTY_IO_ERROR))
  1454. {
  1455. return -EIO;
  1456. }
  1457. }
  1458. switch (cmd) 
  1459. {
  1460. case ATIS_IOCSPARAMS:
  1461. copy_from_user(&port->ccontrol, (struct channelcontrol*)arg , sizeof(struct channelcontrol));
  1462. break;
  1463. case ATIS_IOCGPARAMS:
  1464. copy_to_user((struct channelcontrol*) arg, &port->ccontrol, sizeof(struct channelcontrol));
  1465. break;
  1466. case ATIS_IOCSSPEED:
  1467. copy_from_user(&port->custspeed, (unsigned long*)arg , sizeof(unsigned long));
  1468. break;
  1469. case ATIS_IOCGSPEED:
  1470. copy_to_user((unsigned long*) arg, &port->custspeed, sizeof(unsigned long));
  1471. break;
  1472. case ATIS_IOCSSEP9050:
  1473. bptr = port->board;
  1474. if(bptr->b_type == BD_WANMCS)
  1475. {
  1476. return -EINVAL;
  1477. }
  1478. copy_from_user((unsigned char*) bptr->b_eprom, (unsigned char*) arg , sizeof(struct sep9050));
  1479. wordptr = (unsigned short*) bptr->b_eprom;
  1480. plx9050_eprom_cmd(&((PLX9050*)(bptr->virtbaseaddress0))->ctrl, 
  1481.   NM93_WENCMD, NM93_WENADDR, 0);
  1482. for(wordindex = 0; wordindex < EPROM9050_SIZE; ++wordindex)
  1483. {
  1484. plx9050_eprom_cmd(&((PLX9050*)(bptr->virtbaseaddress0))->ctrl, 
  1485.   NM93_WRITECMD, 
  1486.   wordindex, wordptr[wordindex]);
  1487. }
  1488. plx9050_eprom_cmd(&((PLX9050*)(bptr->virtbaseaddress0))->ctrl, 
  1489.   NM93_WDSCMD, NM93_WDSADDR, 0);
  1490. break;
  1491. case ATIS_IOCGSEP9050:
  1492. bptr = port->board;
  1493. if(bptr->b_type == BD_WANMCS)
  1494. {
  1495. return -EINVAL;
  1496. }
  1497. if (!plx9050_eprom_read(&((PLX9050*)(bptr->virtbaseaddress0))->ctrl, 
  1498. (unsigned short*) bptr->b_eprom,
  1499. (unsigned char) 0, EPROM9050_SIZE))
  1500. {
  1501. printk(KERN_ALERT "auraXX20n: Could not read serial eprom.n");
  1502. return -EIO;
  1503. }
  1504. copy_to_user((unsigned char*) arg, (unsigned char*) bptr->b_eprom, sizeof(struct sep9050));
  1505. break;
  1506. case TIOCGSOFTCAR:
  1507. return put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg);
  1508. case TIOCSSOFTCAR:
  1509. error = get_user(arg, (unsigned int *) arg);
  1510. if (error)
  1511. {
  1512. return error;
  1513. }
  1514. tty->termios->c_cflag =
  1515. ((tty->termios->c_cflag & ~CLOCAL) |
  1516.  (arg ? CLOCAL : 0));
  1517. return 0;
  1518. case TIOCMGET:
  1519. return sab8253x_get_modem_info(port, (unsigned int *) arg);
  1520. case TIOCMBIS:
  1521. case TIOCMBIC:
  1522. case TIOCMSET:
  1523. return sab8253x_set_modem_info(port, cmd, (unsigned int *) arg);
  1524. case TIOCGSERIAL:
  1525. return sab8253x_get_serial_info(port,
  1526. (struct serial_struct *) arg);
  1527. case TIOCSSERIAL:
  1528. return sab8253x_set_serial_info(port,
  1529. (struct serial_struct *) arg);
  1530. case TIOCSERGETLSR: /* Get line status register */
  1531. return sab8253x_get_lsr_info(port, (unsigned int *) arg);
  1532. case TIOCSERGSTRUCT:
  1533. if (copy_to_user((struct sab_port *) arg,
  1534.  port, sizeof(struct sab_port)))
  1535. return -EFAULT;
  1536. return 0;
  1537. /*
  1538.  * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
  1539.  * - mask passed in arg for lines of interest
  1540.  *   (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  1541.  * Caller should use TIOCGICOUNT to see which one it was
  1542.  */
  1543. case TIOCMIWAIT:
  1544. save_flags(flags);
  1545. cli();
  1546. /* note the counters on entry */
  1547. cprev = port->icount;
  1548. restore_flags(flags);
  1549. while (1) 
  1550. {
  1551. interruptible_sleep_on(&port->delta_msr_wait); /* waits for a modem signal change */
  1552. /* see if a signal did it */
  1553. if (signal_pending(current))
  1554. {
  1555. return -ERESTARTSYS;
  1556. }
  1557. save_flags(flags);
  1558. cli();
  1559. cnow = port->icount; /* atomic copy */
  1560. restore_flags(flags);
  1561. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 
  1562.     cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
  1563. {
  1564. return -EIO; /* no change => error */
  1565. }
  1566. if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  1567.      ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  1568.      ((arg & TIOCM_CD)  && (cnow.dcd != cprev.dcd)) ||
  1569.      ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
  1570. {
  1571. return 0;
  1572. }
  1573. }
  1574. cprev = cnow;
  1575. }
  1576. /* NOTREACHED */
  1577. break;
  1578. /* 
  1579.  * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  1580.  * Return: write counters to the user passed counter struct
  1581.  * NB: both 1->0 and 0->1 transitions are counted except for
  1582.  *     RI where only 0->1 is counted.
  1583.  */
  1584. case TIOCGICOUNT:
  1585. save_flags(flags);
  1586. cli();
  1587. cnow = port->icount;
  1588. restore_flags(flags);
  1589. p_cuser = (struct serial_icounter_struct *) arg;
  1590. error = put_user(cnow.cts, &p_cuser->cts);
  1591. if (error) 
  1592. {
  1593. return error;
  1594. }
  1595. error = put_user(cnow.dsr, &p_cuser->dsr);
  1596. if (error) 
  1597. {
  1598. return error;
  1599. }
  1600. error = put_user(cnow.rng, &p_cuser->rng);
  1601. if (error) 
  1602. {
  1603. return error;
  1604. }
  1605. error = put_user(cnow.dcd, &p_cuser->dcd);
  1606. if (error) 
  1607. {
  1608. return error;
  1609. }
  1610. return 0;
  1611. case ATIS_IOCSSIGMODE:
  1612. if(port->chip->c_cim)
  1613. {
  1614. if(port->chip->c_cim->ci_type == CIM_SP502)
  1615. {
  1616. copy_from_user(&port->sigmode, (unsigned int*)arg , sizeof(unsigned int));
  1617. return 0;
  1618. }
  1619. }
  1620. return -EINVAL;
  1621. case ATIS_IOCGSIGMODE:
  1622. if(port->chip->c_cim)
  1623. {
  1624. if(port->chip->c_cim->ci_type == CIM_SP502)
  1625. {
  1626. copy_to_user((unsigned int*) arg, &port->sigmode, sizeof(unsigned int));
  1627. return 0;
  1628. }
  1629. }
  1630. return -EINVAL;
  1631. default:
  1632. return -ENOIOCTLCMD;
  1633. }
  1634. return 0;
  1635. }
  1636. static void sab8253x_set_termios(struct tty_struct *tty,
  1637.  struct termios *old_termios)
  1638. {
  1639. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1640. if((tty->termios->c_cflag == old_termios->c_cflag) && 
  1641.    (RELEVANT_IFLAG(tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag)))
  1642. {
  1643. return;
  1644. }
  1645. if(!port)
  1646. {
  1647. return;
  1648. }
  1649. sab8253x_change_speed(port);
  1650. /* Handle transition to B0 status */
  1651. if ((old_termios->c_cflag & CBAUD) &&
  1652.     !(tty->termios->c_cflag & CBAUD)) 
  1653. {
  1654. LOWER(port,rts);
  1655. LOWER(port,dtr);
  1656. }
  1657. /* Handle transition away from B0 status */
  1658. if (!(old_termios->c_cflag & CBAUD) &&
  1659.     (tty->termios->c_cflag & CBAUD)) 
  1660. {
  1661. RAISE(port, dtr);
  1662. if (!tty->hw_stopped ||
  1663.     !(tty->termios->c_cflag & CRTSCTS)) 
  1664. {
  1665. RAISE(port, rts);
  1666. }
  1667. }
  1668. /* Handle turning off CRTSCTS */
  1669. if ((old_termios->c_cflag & CRTSCTS) &&
  1670.     !(tty->termios->c_cflag & CRTSCTS)) 
  1671. {
  1672. tty->hw_stopped = 0;
  1673. sab8253x_start(tty);
  1674. }
  1675. }
  1676. /*
  1677.  * ------------------------------------------------------------
  1678.  * sab8253x_close()
  1679.  * 
  1680.  * This routine is called when the serial port gets closed.  First, we
  1681.  * wait for the last remaining data to be sent.  Then, we unlink its
  1682.  * async structure from the interrupt chain if necessary, and we free
  1683.  * that IRQ if nothing is left in the chain.
  1684.  * ------------------------------------------------------------
  1685.  */
  1686. static void sab8253x_close(struct tty_struct *tty, struct file * filp)
  1687. {
  1688. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1689. unsigned long flags;
  1690. MOD_DEC_USE_COUNT;
  1691. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_close"))
  1692. {
  1693. return;
  1694. }
  1695. if(port->open_type == OPEN_SYNC_NET)
  1696. { /* port->tty field should already be NULL */
  1697. /* port count was not incremented */
  1698. return;
  1699. }
  1700. --(port->count); /* have a valid port */
  1701. if (tty_hung_up_p(filp)) 
  1702. {
  1703. if(port->count == 0) /* shutdown took place in hangup context */
  1704. {
  1705. port->open_type = OPEN_NOT;
  1706. }
  1707. else if(port->count < 0)
  1708. {
  1709. printk(KERN_ALERT "XX20: port->count went negative.n");
  1710. port->count = 0;
  1711. port->open_type = OPEN_NOT;
  1712. }
  1713. return;
  1714. }
  1715. if (port->count < 0) 
  1716. {
  1717. printk(KERN_ALERT "sab8253x_close: bad serial port count for ttys%d: %dn",
  1718.        port->line, port->count);
  1719. port->count = 0;
  1720. }
  1721. if (port->count) 
  1722. {
  1723. return;
  1724. }
  1725. port->flags |= FLAG8253X_CLOSING;
  1726. /*
  1727.  * Save the termios structure, since this port may have
  1728.  * separate termios for callout and dialin.
  1729.  */
  1730. if (port->flags & FLAG8253X_NORMAL_ACTIVE)
  1731. {
  1732. port->normal_termios = *tty->termios;
  1733. }
  1734. if (port->flags & FLAG8253X_CALLOUT_ACTIVE)
  1735. {
  1736. port->callout_termios = *tty->termios;
  1737. }
  1738. /*
  1739.  * Now we wait for the transmit buffer to clear; and we notify 
  1740.  * the line discipline to only process XON/XOFF characters.
  1741.  */
  1742. tty->closing = 1;
  1743. if (port->closing_wait != SAB8253X_CLOSING_WAIT_NONE) 
  1744. {
  1745. tty_wait_until_sent(tty, port->closing_wait); /* wait for drain */
  1746. }
  1747. /*
  1748.  * At this point we stop accepting input.  To do this, we
  1749.  * disable the receive line status interrupts, and turn off
  1750.  * the receiver.
  1751.  */
  1752. save_flags(flags); 
  1753. cli();
  1754. port->interrupt_mask0 |= SAB82532_IMR0_TCD;
  1755. WRITEB(port,imr0,port->interrupt_mask0);
  1756. CLEAR_REG_BIT(port,mode,SAB82532_MODE_RAC); /* ??????? */
  1757. restore_flags(flags);
  1758. if (port->flags & FLAG8253X_INITIALIZED) 
  1759. {
  1760. /*
  1761.  * Before we drop DTR, make sure the UART transmitter
  1762.  * has completely drained; this is especially
  1763.  * important if there is a transmit FIFO!
  1764.  */
  1765. sab8253x_wait_until_sent(tty, port->timeout);
  1766. }
  1767. sab8253x_shutdown(port); /* no more ints on port */
  1768. Sab8253xCleanUpTransceiveN(port); /* should be okay */
  1769. if (tty->driver.flush_buffer)
  1770. {
  1771. tty->driver.flush_buffer(tty);
  1772. }
  1773. if (tty->ldisc.flush_buffer)
  1774. {
  1775. tty->ldisc.flush_buffer(tty);
  1776. }
  1777. tty->closing = 0;
  1778. port->event = 0;
  1779. port->tty = 0;
  1780. if (port->blocked_open) 
  1781. {
  1782. if (port->close_delay) 
  1783. {
  1784. current->state = TASK_INTERRUPTIBLE;
  1785. schedule_timeout(port->close_delay);
  1786. }
  1787. wake_up_interruptible(&port->open_wait); /* deal with open blocks */
  1788. }
  1789. if((port->flags & (FLAG8253X_CALLOUT_ACTIVE | FLAG8253X_NETWORK)) ==
  1790.    (FLAG8253X_CALLOUT_ACTIVE | FLAG8253X_NETWORK) &&
  1791.    port->dev)
  1792. {
  1793. port->flags &= ~(FLAG8253X_NORMAL_ACTIVE|FLAG8253X_CALLOUT_ACTIVE|
  1794.  FLAG8253X_CLOSING); /* leave network set */
  1795. netif_carrier_off(port->dev);
  1796. port->open_type = OPEN_SYNC_NET;
  1797. sab8253x_startupN(port);
  1798. }
  1799. else
  1800. {
  1801. port->flags &= ~(FLAG8253X_NORMAL_ACTIVE|FLAG8253X_CALLOUT_ACTIVE|
  1802.  FLAG8253X_CLOSING);
  1803. wake_up_interruptible(&port->close_wait);
  1804. port->open_type = OPEN_NOT;
  1805. }
  1806. }
  1807. /*
  1808.  * sab8253x_hangup() --- called by tty_hangup() when a hangup is signaled.
  1809.  */
  1810. static void sab8253x_hangup(struct tty_struct *tty)
  1811. {
  1812. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1813. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_hangup"))
  1814. {
  1815. return;
  1816. }
  1817. #ifdef XCONFIG_SERIAL_CONSOLE
  1818. if (port->is_console)
  1819. {
  1820. return;
  1821. }
  1822. #endif
  1823. sab8253x_flush_buffer(tty);
  1824. if(port)
  1825. {
  1826. sab8253x_shutdown(port);
  1827. Sab8253xCleanUpTransceiveN(port); /* this logic is a bit contorted
  1828.      Are we cleaning up the lists
  1829.      because we are waking up a
  1830.      blocked open?  There is possibly
  1831.      an order problem here perhaps the
  1832.      open count should have increased in the
  1833.      int handler so that it could decrease here*/
  1834. port->event = 0;
  1835. port->flags &= ~(FLAG8253X_NORMAL_ACTIVE|FLAG8253X_CALLOUT_ACTIVE);
  1836. port->tty = 0;
  1837. wake_up_interruptible(&port->open_wait); /* deal with blocking open */
  1838. }
  1839. }
  1840. /*
  1841.  * ------------------------------------------------------------
  1842.  * sab8253x_open() and friends
  1843.  * ------------------------------------------------------------
  1844.  */
  1845. /*
  1846.  * This routine is called whenever a serial port is opened.  It
  1847.  * enables interrupts for a serial port, linking in its async structure into
  1848.  * the IRQ chain.   It also performs the serial-specific
  1849.  * initialization for the tty structure.
  1850.  */
  1851. static int sab8253x_open(struct tty_struct *tty, struct file * filp)
  1852. {
  1853. struct sab_port *port;
  1854. int retval, line;
  1855. int counter;
  1856. unsigned long flags;
  1857. MOD_INC_USE_COUNT;
  1858. line = MINOR(tty->device) - tty->driver.minor_start;
  1859. for(counter = 0, port = AuraPortRoot; 
  1860.     (counter < line) && (port != NULL); 
  1861.     ++counter)
  1862. {
  1863. port = port->next;
  1864. }
  1865. if (!port) 
  1866. {
  1867. printk(KERN_ALERT "sab8253x_open: can't find structure for line %dn",
  1868.        line);
  1869. return -ENODEV;
  1870. }
  1871. save_flags(flags); /* Need to protect the port->tty field */
  1872. cli();
  1873. if(port->tty == NULL)
  1874. {
  1875. port->tty = tty; /* may be a standard tty waiting on a call out device */
  1876. tty->flip.tqueue.routine = sab8253x_flush_to_ldisc;
  1877. }
  1878. tty->driver_data = port; /* but the tty devices are unique for each type of open */
  1879. if(port->function == FUNCTION_NA)
  1880. { /* port 2 on 1020s and 1520s */
  1881. ++(port->count);
  1882. restore_flags(flags);
  1883. return -ENODEV;
  1884. }
  1885. /* Check whether or not the port is open in SYNC mode */
  1886. if(port->open_type == OPEN_SYNC_NET)
  1887. {
  1888. if(port->dev && netif_carrier_ok(port->dev));
  1889. {
  1890. port->tty= NULL; /* Don't bother with open counting here
  1891.    but make sure the tty field is NULL*/
  1892. restore_flags(flags);
  1893. return -EBUSY;
  1894. }
  1895. sab8253x_flush_buffer(tty); /* don't restore flags here */
  1896. sab8253x_shutdownN(port);
  1897. }
  1898. else if (port->open_type > OPEN_ASYNC) /* can't have a callout or async line
  1899. * if already open in some sync mode */
  1900. {
  1901. ++(port->count);
  1902. restore_flags(flags);
  1903. return -EBUSY;
  1904. }
  1905. restore_flags(flags);
  1906. if (sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_open"))
  1907. {
  1908. ++(port->count);
  1909. return -ENODEV;
  1910. }
  1911. #ifdef DEBUG_OPEN
  1912. printk("sab8253x_open %s%d, count = %dn", tty->driver.name, port->line,
  1913.        port->count);
  1914. #endif
  1915. /*
  1916.  * If the port is in the middle of closing, bail out now.
  1917.  */
  1918. if (tty_hung_up_p(filp) ||
  1919.     (port->flags & FLAG8253X_CLOSING)) 
  1920. {
  1921. if (port->flags & FLAG8253X_CLOSING)
  1922. {
  1923. interruptible_sleep_on(&port->close_wait);
  1924. }
  1925. #ifdef SERIAL_DO_RESTART
  1926. ++(port->count);
  1927. return ((port->flags & FLAG8253X_HUP_NOTIFY) ?
  1928. -EAGAIN : -ERESTARTSYS);
  1929. #else
  1930. ++(port->count);
  1931. return -EAGAIN;
  1932. #endif
  1933. }
  1934. if(Sab8253xSetUpLists(port))
  1935. {
  1936. ++(port->count);
  1937. return -ENODEV;
  1938. }
  1939. if(Sab8253xInitDescriptors2(port, sab8253xt_listsize, sab8253xt_rbufsize))
  1940. {
  1941. ++(port->count);
  1942. return -ENODEV;
  1943. }
  1944. retval = sab8253x_startup(port);
  1945. if (retval)
  1946. {
  1947. ++(port->count);
  1948. return retval;
  1949. }
  1950. retval = sab8253x_block_til_ready(tty, filp, port);
  1951. ++(port->count);  
  1952. if (retval) 
  1953. {
  1954. return retval;
  1955. }
  1956. port->tty = tty; /* may change here once through the block */
  1957. /* because now the port belongs to an new tty */
  1958. tty->flip.tqueue.routine = sab8253x_flush_to_ldisc; /* in case it was changed */
  1959. if(Sab8253xSetUpLists(port))
  1960. {
  1961. return -ENODEV;
  1962. }
  1963. if(Sab8253xInitDescriptors2(port, sab8253xt_listsize, sab8253xt_rbufsize))
  1964. {
  1965. Sab8253xCleanUpTransceiveN(port); /* the network functions should be okay -- only difference */
  1966. /* is the crc32 that is appended */
  1967. return -ENODEV;
  1968. }
  1969. /*
  1970.  * Start up serial port
  1971.  */
  1972. retval = sab8253x_startup(port); /* just in case closing the cu dev
  1973.   * shutdown the port (but left CD) */
  1974. if (retval)
  1975. {
  1976. return retval;
  1977. }
  1978. if ((port->count == 1) && /* first open */
  1979.     (port->flags & FLAG8253X_SPLIT_TERMIOS)) 
  1980. {
  1981. if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
  1982. {
  1983. *tty->termios = port->normal_termios;
  1984. }
  1985. else 
  1986. {
  1987. *tty->termios = port->callout_termios;
  1988. }
  1989. sab8253x_change_speed(port);
  1990. }
  1991. #ifdef XCONFIG_SERIAL_CONSOLE
  1992. if (sab8253x_console.cflag && sab8253x_console.index == line) 
  1993. {
  1994. tty->termios->c_cflag = sab8253x_console.cflag;
  1995. sab8253x_console.cflag = 0;
  1996. sab8253x_change_speed(port);
  1997. }
  1998. #endif
  1999. port->session = current->session;
  2000. port->pgrp = current->pgrp;
  2001. port->open_type = OPEN_ASYNC;
  2002. return 0;
  2003. }
  2004. static char *signaling[] =
  2005. {
  2006. "OFF  ",
  2007. "RS232",
  2008. "RS422",
  2009. "RS485",
  2010. "RS449",
  2011. "RS530",
  2012. "V.35 "
  2013. };
  2014. static int sab8253x_read_proc(char *page, char **start, off_t off, int count,
  2015.       int *eof, void *data)
  2016. {
  2017. extern struct sab_port * AuraPortRoot;
  2018. struct sab_port *port = AuraPortRoot;
  2019. extern char *board_type[];
  2020. off_t begin = 0;
  2021. int len = 0;
  2022. int portno;
  2023. unsigned int typeno;
  2024. extern int sab8253x_rebootflag;
  2025. #ifdef FREEININTERRUPT
  2026. len += sprintf(page, "serinfo:2.01I driver:%sn", sab8253x_serial_version);
  2027. #else
  2028. len += sprintf(page, "serinfo:2.01N driver:%sn", sab8253x_serial_version);
  2029. #endif
  2030. if(sab8253x_rebootflag)
  2031. {
  2032. len += sprintf(page+len, 
  2033.        "WARNING:  Found %d cards that required reprogramming.  Reboot machine!.n", 
  2034.        sab8253x_rebootflag);
  2035. }
  2036. len += sprintf(page+len, "TTY MAJOR = %d, CUA MAJOR = %d, STTY MAJOR = %d.n", 
  2037.        sab8253x_serial_driver.major, sab8253x_callout_driver.major, 
  2038.        sync_sab8253x_serial_driver.major);
  2039. for (portno = 0; port != NULL; port = port->next, ++portno) 
  2040. {
  2041. typeno = port->board->b_type;
  2042. if(typeno > BD_8520P)
  2043. {
  2044. typeno = 0;
  2045. }
  2046. len += sprintf(page+len, 
  2047.        "%d: port %d: %s: v%d: chip %d: ATI %s: bus %d: slot %d: %s: ", 
  2048.        sab8253x_serial_driver.minor_start + portno,
  2049.        port->portno,
  2050.        (port->chip->chip_type == ESCC2) ? "sab82532" : "sab82538",
  2051.        port->type,
  2052.        port->chip->c_chipno,
  2053.        board_type[port->board->b_type],
  2054.        port->board->b_dev.bus->number,
  2055.        PCI_SLOT(port->board->b_dev.devfn),
  2056.        aura_functionality[((port->function > FUNCTION_UN) ? FUNCTION_UN : port->function)]);
  2057. switch(port->open_type)
  2058. {
  2059. case OPEN_ASYNC:
  2060. len += sprintf(page+len, "openA");
  2061. break;
  2062. case OPEN_SYNC:
  2063. len += sprintf(page+len, "openS");
  2064. break;
  2065. case OPEN_SYNC_NET:
  2066. len += sprintf(page+len, "openN");
  2067. break;   
  2068. case OPEN_SYNC_CHAR:
  2069. len += sprintf(page+len, "openC");
  2070. break;
  2071. case OPEN_NOT:
  2072. len += sprintf(page+len, "close");
  2073. break;
  2074. default:
  2075. len += sprintf(page+len, "open?");
  2076. break;
  2077. }
  2078. if(port->chip->c_cim)
  2079. {
  2080. if(port->chip->c_cim->ci_type == CIM_SP502)
  2081. {
  2082. len += sprintf(page+len, ": %sn", signaling[port->sigmode]);
  2083. }
  2084. else
  2085. {
  2086. len += sprintf(page+len, ": NOPRGn");
  2087. }
  2088. }
  2089. else
  2090. {
  2091. len += sprintf(page+len, ": NOPRGn");
  2092. }
  2093. if (len+begin > off+count)
  2094. {
  2095. goto done;
  2096. }
  2097. if (len+begin < off) 
  2098. {
  2099. begin += len;
  2100. len = 0;
  2101. }
  2102. }
  2103. *eof = 1;
  2104.  done:
  2105. if (off >= len+begin)
  2106. {
  2107. return 0;
  2108. }
  2109. *start = page + (off-begin);
  2110. return ((count < begin+len-off) ? count : begin+len-off);
  2111. }
  2112. /*
  2113.  * ---------------------------------------------------------------------
  2114.  * sab8253x_init() and friends
  2115.  *
  2116.  * sab8253x_init() is called at boot-time to initialize the serial driver.
  2117.  * ---------------------------------------------------------------------
  2118.  */
  2119. static void inline show_aurora_version(void)
  2120. {
  2121. char *revision = "$Revision: 1.23 $";
  2122. char *version, *p;
  2123. version = strchr(revision, ' ');
  2124. strcpy(sab8253x_serial_version, ++version);
  2125. p = strchr(sab8253x_serial_version, ' ');
  2126. *p = '';
  2127. printk("Aurora serial driver version %sn", sab8253x_serial_version);
  2128. }
  2129. #ifndef MODULE
  2130. static int GetMinorStart(void)
  2131. {
  2132. struct tty_driver *ttydriver;
  2133. int minor_start = 0;
  2134. kdev_t device;
  2135. device = MKDEV(TTY_MAJOR, minor_start);
  2136. while(ttydriver = get_tty_driver(device), ttydriver != NULL)
  2137. {
  2138. minor_start += ttydriver->num;
  2139. device = MKDEV(TTY_MAJOR, minor_start);
  2140. }
  2141. return minor_start;
  2142. }
  2143. #endif
  2144. int finish_sab8253x_setup_ttydriver(void) 
  2145. {
  2146. extern unsigned int NumSab8253xPorts;
  2147. sab8253x_tableASY = (struct tty_struct **) kmalloc(NumSab8253xPorts*sizeof(struct tty_struct *), GFP_KERNEL);
  2148. if(sab8253x_tableASY == NULL)
  2149. {
  2150. printk(KERN_ALERT "auraXX20:  Could not allocate memory for sab8253x_tableASY.n");
  2151. return -1;
  2152. }
  2153. memset(sab8253x_tableASY, 0, NumSab8253xPorts*sizeof(struct tty_struct *));
  2154. sab8253x_tableCUA = (struct tty_struct **) kmalloc(NumSab8253xPorts*sizeof(struct tty_struct *), GFP_KERNEL);
  2155. if(sab8253x_tableCUA == NULL)
  2156. {
  2157. printk(KERN_ALERT "auraXX20:  Could not allocate memory for sab8253x_tableCUA.n");
  2158. return -1;
  2159. }
  2160. memset(sab8253x_tableCUA, 0, NumSab8253xPorts*sizeof(struct tty_struct *));
  2161. sab8253x_tableSYN = (struct tty_struct **) kmalloc(NumSab8253xPorts*sizeof(struct tty_struct *), GFP_KERNEL);
  2162. if(sab8253x_tableSYN == NULL)
  2163. {
  2164. printk(KERN_ALERT "auraXX20:  Could not allocate memory for sab8253x_tableSYN.n");
  2165. return -1;
  2166. }
  2167. memset(sab8253x_tableSYN, 0, NumSab8253xPorts*sizeof(struct tty_struct *));
  2168. sab8253x_termios = (struct termios **) kmalloc(NumSab8253xPorts*sizeof(struct termios *), GFP_KERNEL);
  2169. if(sab8253x_termios == NULL)
  2170. {
  2171. printk(KERN_ALERT "auraXX20:  Could not allocate memory for sab8253x_termios.n");
  2172. return -1;
  2173. }
  2174. memset(sab8253x_termios, 0, NumSab8253xPorts*sizeof(struct termios *));
  2175. sab8253x_termios_locked = (struct termios **) kmalloc(NumSab8253xPorts*sizeof(struct termios *), GFP_KERNEL);
  2176. if(sab8253x_termios_locked == NULL)
  2177. {
  2178. printk(KERN_ALERT "auraXX20:  Could not allocate memory for sab8253x_termios_locked.n");
  2179. return -1;
  2180. }
  2181. memset(sab8253x_termios_locked, 0, NumSab8253xPorts*sizeof(struct termios *));
  2182. sync_sab8253x_serial_driver.num = sab8253x_callout_driver.num = sab8253x_serial_driver.num = NumSab8253xPorts;
  2183. sab8253x_serial_driver.table = sab8253x_tableASY;
  2184. sab8253x_callout_driver.table = sab8253x_tableCUA;
  2185. sync_sab8253x_serial_driver.table = sab8253x_tableSYN;
  2186. sync_sab8253x_serial_driver.termios = sab8253x_callout_driver.termios = sab8253x_serial_driver.termios = 
  2187. sab8253x_termios;
  2188. sync_sab8253x_serial_driver.termios_locked = sab8253x_callout_driver.termios_locked = 
  2189. sab8253x_serial_driver.termios_locked = sab8253x_termios_locked;
  2190. if (tty_register_driver(&sab8253x_serial_driver) < 0)
  2191. {
  2192. printk(KERN_ALERT "auraXX20:  Could not register serial driver.n");
  2193. return -1;
  2194. }
  2195. if (tty_register_driver(&sab8253x_callout_driver) < 0)
  2196. {
  2197. printk(KERN_ALERT "auraXX20:  Could not register call out device.n");
  2198. return -1;
  2199. }
  2200. if (tty_register_driver(&sync_sab8253x_serial_driver) < 0)
  2201. {
  2202. printk(KERN_ALERT "auraXX20:  Could not register sync serial device.n");
  2203. return -1;
  2204. }
  2205. return 0;
  2206. }
  2207. void sab8253x_setup_ttydriver(void) 
  2208. {
  2209. #ifdef MODULE
  2210. extern int xx20_minorstart;
  2211. #endif
  2212. init_bh(AURORA_BH, sab8253x_do_serial_bh);
  2213. show_aurora_version();
  2214. /* Initialize the tty_driver structure */
  2215. memset(&sab8253x_serial_driver, 0, sizeof(struct tty_driver));
  2216. sab8253x_serial_driver.magic = TTY_DRIVER_MAGIC;
  2217. sab8253x_serial_driver.driver_name = "auraserial";
  2218. sab8253x_serial_driver.name = "ttyS";
  2219. sab8253x_serial_driver.major = TTY_MAJOR;
  2220. #ifdef MODULE
  2221. sab8253x_serial_driver.minor_start = xx20_minorstart;
  2222. #else
  2223. sab8253x_serial_driver.minor_start = GetMinorStart();
  2224. #endif
  2225. sab8253x_serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
  2226. sab8253x_serial_driver.subtype = SERIAL_TYPE_NORMAL;
  2227. sab8253x_serial_driver.init_termios = tty_std_termios;
  2228. sab8253x_serial_driver.init_termios.c_cflag =
  2229. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  2230. sab8253x_serial_driver.flags = TTY_DRIVER_REAL_RAW;
  2231. sab8253x_serial_driver.refcount = &sab8253x_refcount;
  2232. sab8253x_serial_driver.open = sab8253x_open;
  2233. sab8253x_serial_driver.close = sab8253x_close;
  2234. sab8253x_serial_driver.write = sab8253x_write;
  2235. sab8253x_serial_driver.put_char = NULL; /*sab8253x_put_char is evil.*/
  2236. sab8253x_serial_driver.flush_chars = sab8253x_flush_chars;
  2237. sab8253x_serial_driver.write_room = sab8253x_write_room;
  2238. sab8253x_serial_driver.chars_in_buffer = sab8253x_chars_in_buffer;
  2239. sab8253x_serial_driver.flush_buffer = sab8253x_flush_buffer;
  2240. sab8253x_serial_driver.ioctl = sab8253x_ioctl;
  2241. sab8253x_serial_driver.throttle = sab8253x_throttle;
  2242. sab8253x_serial_driver.unthrottle = sab8253x_unthrottle;
  2243. sab8253x_serial_driver.send_xchar = sab8253x_send_xchar;
  2244. sab8253x_serial_driver.set_termios = sab8253x_set_termios;
  2245. sab8253x_serial_driver.stop = sab8253x_stop;
  2246. sab8253x_serial_driver.start = sab8253x_start;
  2247. sab8253x_serial_driver.hangup = sab8253x_hangup;
  2248. sab8253x_serial_driver.break_ctl = sab8253x_break;
  2249. sab8253x_serial_driver.wait_until_sent = sab8253x_wait_until_sent;
  2250. sab8253x_serial_driver.read_proc = sab8253x_read_proc;
  2251. /*
  2252.  * The callout device is just like normal device except for
  2253.  * major number and the subtype code.
  2254.  */
  2255. sab8253x_callout_driver = sab8253x_serial_driver;
  2256. sab8253x_callout_driver.name = "cua";
  2257. sab8253x_callout_driver.major = TTYAUX_MAJOR;
  2258. sab8253x_callout_driver.subtype = SERIAL_TYPE_CALLOUT;
  2259. sab8253x_callout_driver.read_proc = 0;
  2260. sab8253x_callout_driver.proc_entry = 0;
  2261. sync_sab8253x_serial_driver = sab8253x_serial_driver;
  2262. sync_sab8253x_serial_driver.name = "sttyS";
  2263. sync_sab8253x_serial_driver.major = 0;
  2264. sync_sab8253x_serial_driver.subtype = SERIAL_TYPE_SYNCTTY;
  2265. sync_sab8253x_serial_driver.open = sab8253x_openS;
  2266. sync_sab8253x_serial_driver.close = sab8253x_closeS;
  2267. sync_sab8253x_serial_driver.write = sab8253x_writeS;
  2268. sync_sab8253x_serial_driver.put_char = NULL; /*sab8253x_put_char logic is evil*/
  2269. sync_sab8253x_serial_driver.flush_chars = sab8253x_flush_charsS;
  2270. sync_sab8253x_serial_driver.write_room = sab8253x_write_room;
  2271. sync_sab8253x_serial_driver.chars_in_buffer = sab8253x_chars_in_buffer;
  2272. sync_sab8253x_serial_driver.flush_buffer = sab8253x_flush_buffer;
  2273. sync_sab8253x_serial_driver.ioctl = sab8253x_ioctl;
  2274. sync_sab8253x_serial_driver.throttle = sab8253x_throttleS;
  2275. sync_sab8253x_serial_driver.unthrottle = sab8253x_unthrottleS;
  2276. sync_sab8253x_serial_driver.send_xchar = sab8253x_send_xcharS;
  2277. sync_sab8253x_serial_driver.set_termios = sab8253x_set_termiosS;
  2278. sync_sab8253x_serial_driver.stop = sab8253x_stopS;
  2279. sync_sab8253x_serial_driver.start = sab8253x_startS;
  2280. sync_sab8253x_serial_driver.hangup = sab8253x_hangupS;
  2281. sync_sab8253x_serial_driver.break_ctl = sab8253x_breakS;
  2282. sync_sab8253x_serial_driver.wait_until_sent = sab8253x_wait_until_sent;
  2283. sync_sab8253x_serial_driver.read_proc = 0;
  2284. sync_sab8253x_serial_driver.proc_entry = 0;
  2285. }
  2286. void sab8253x_setup_ttyport(struct sab_port *p_port) 
  2287. {
  2288. p_port->magic = SAB_MAGIC;
  2289. p_port->custom_divisor = 16;
  2290. p_port->close_delay = 5*HZ/10;
  2291. p_port->closing_wait = 30*HZ;
  2292. p_port->tec_timeout = SAB8253X_MAX_TEC_DELAY;
  2293. p_port->cec_timeout = SAB8253X_MAX_CEC_DELAY;
  2294. p_port->x_char = 0;
  2295. p_port->event = 0;
  2296. p_port->flags= FLAG8253X_BOOT_AUTOCONF | FLAG8253X_SKIP_TEST;
  2297. p_port->blocked_open = 0;
  2298. p_port->all_sent = 1; /* probably not needed */
  2299. p_port->tqueue.sync = 0; /* for later */
  2300. p_port->tqueue.routine = sab8253x_do_softint;
  2301. p_port->tqueue.data = p_port;
  2302. p_port->tqueue_hangup.sync = 0; /* for later */
  2303. p_port->tqueue_hangup.routine = sab8253x_do_serial_hangup;
  2304. p_port->tqueue_hangup.data = p_port;
  2305. p_port->callout_termios = sab8253x_callout_driver.init_termios;
  2306. p_port->normal_termios = sab8253x_serial_driver.init_termios; /* these are being shared */
  2307. /* between asynchronous and */
  2308. /* asynchronous ttys */
  2309. init_waitqueue_head(&p_port->open_wait);
  2310. init_waitqueue_head(&p_port->close_wait);
  2311. init_waitqueue_head(&p_port->delta_msr_wait);
  2312. init_waitqueue_head(&p_port->write_wait);
  2313. init_waitqueue_head(&p_port->read_wait);
  2314. p_port->count = 0; /* maybe not needed */
  2315. p_port->icount.cts = p_port->icount.dsr = 
  2316. p_port->icount.rng = p_port->icount.dcd = 0;
  2317. p_port->cts.val = p_port->dsr.val = 
  2318. p_port->dcd.val = 0;
  2319. p_port->icount.rx = p_port->icount.tx = 0;
  2320. p_port->icount.frame = p_port->icount.parity = 0;
  2321. p_port->icount.overrun = p_port->icount.brk = 0;
  2322. p_port->xmit_fifo_size = 32;
  2323. p_port->recv_fifo_size = 32;
  2324. p_port->xmit_buf = NULL;
  2325. p_port->receive_chars = sab8253x_receive_chars;
  2326. p_port->transmit_chars = sab8253x_transmit_chars;
  2327. p_port->check_status = sab8253x_check_status;
  2328. p_port->receive_test = (SAB82532_ISR0_TCD | SAB82532_ISR0_TIME |
  2329. SAB82532_ISR0_RFO | SAB82532_ISR0_RPF);
  2330. p_port->transmit_test = (SAB82532_ISR1_ALLS | SAB82532_ISR1_XPR);
  2331. p_port->check_status_test = SAB82532_ISR1_BRK;
  2332. /* put in default sync control channel values
  2333.  * not needed for async -- I think these work
  2334.  * for bisync*/
  2335. p_port->ccontrol.ccr0 = DEFAULT_CCR0;
  2336. p_port->ccontrol.ccr1 = DEFAULT_CCR1;
  2337. p_port->ccontrol.ccr2 = DEFAULT_CCR2;
  2338. p_port->ccontrol.ccr3 = DEFAULT_CCR3;
  2339. p_port->ccontrol.ccr4 = DEFAULT_CCR4;
  2340. p_port->ccontrol.mode = DEFAULT_MODE;
  2341. p_port->ccontrol.rlcr = DEFAULT_RLCR;
  2342. }
  2343. void sab8253x_cleanup_ttydriver(void)
  2344. {
  2345. unsigned long flags;
  2346. int e1, e2;
  2347. save_flags(flags);
  2348. cli();
  2349. if(sab8253x_tableASY) 
  2350. kfree(sab8253x_tableASY);
  2351. if(sab8253x_tableCUA) 
  2352. kfree(sab8253x_tableCUA);
  2353. if(sab8253x_tableSYN) 
  2354. kfree(sab8253x_tableSYN);
  2355. if(sab8253x_termios) 
  2356. kfree(sab8253x_termios);
  2357. if(sab8253x_termios_locked) 
  2358. kfree(sab8253x_termios_locked);
  2359. remove_bh(AURORA_BH);
  2360. if ((e1 = tty_unregister_driver(&sab8253x_serial_driver)))
  2361. {
  2362. printk("SERIAL: failed to unregister serial driver (%d)n",
  2363.        e1);
  2364. }
  2365. if ((e2 = tty_unregister_driver(&sab8253x_callout_driver)))
  2366. {
  2367. printk("SERIAL: failed to unregister callout driver (%d)n", 
  2368.        e2);
  2369. }
  2370. if ((e2 = tty_unregister_driver(&sync_sab8253x_serial_driver)))
  2371. {
  2372. printk("SERIAL: failed to unregister callout driver (%d)n", 
  2373.        e2);
  2374. }
  2375. restore_flags(flags);  
  2376. }
  2377. /* THE CODE BELOW HAS NOT YET BEEN MODIFIED!!!! FW */
  2378. #ifdef XCONFIG_SERIAL_CONSOLE
  2379. static inline void
  2380. sab8253x_console_putchar(struct sab8253x *info, char c)
  2381. {
  2382. unsigned long flags;
  2383. save_flags(flags); cli();
  2384. sab8253x_tec_wait(info);
  2385. WRITEB(port,tic,c);
  2386. restore_flags(flags);
  2387. }
  2388. static void
  2389. sab8253x_console_write(struct console *con, const char *s, unsigned n)
  2390. {
  2391. struct sab8253x *info;
  2392. int i;
  2393. info = sab8253x_chain;
  2394. for (i = con->index; i; i--) {
  2395. info = info->next;
  2396. if (!info)
  2397. return;
  2398. }
  2399. for (i = 0; i < n; i++) {
  2400. if (*s == 'n')
  2401. sab8253x_console_putchar(info, 'r');
  2402. sab8253x_console_putchar(info, *s++);
  2403. }
  2404. sab8253x_tec_wait(info);
  2405. }
  2406. static int
  2407. sab8253x_console_wait_key(struct console *con)
  2408. {
  2409. sleep_on(&keypress_wait);
  2410. return 0;
  2411. }
  2412. static kdev_t
  2413. sab8253x_console_device(struct console *con)
  2414. {
  2415. return MKDEV(TTY_MAJOR, 64 + con->index);
  2416. }
  2417. static int
  2418. sab8253x_console_setup(struct console *con, char *options)
  2419. {
  2420. struct sab8253x *info;
  2421. unsigned int ebrg;
  2422. tcflag_t cflag;
  2423. unsigned char dafo;
  2424. int i, bits;
  2425. unsigned long flags;
  2426. info = sab8253x_chain;
  2427. for (i = con->index; i; i--) 
  2428. {
  2429. info = info->next;
  2430. if (!info)
  2431. return -ENODEV;
  2432. }
  2433. info->is_console = 1;
  2434. /*
  2435.  * Initialize the hardware
  2436.  */
  2437. sab8253x_init_line(info);
  2438. /*
  2439.  * Finally, enable interrupts
  2440.  */
  2441. info->interrupt_mask0 = SAB82532_IMR0_PERR | SAB82532_IMR0_FERR |
  2442. /*SAB82532_IMR0_TIME*/ | SAB82532_IMR0_PLLA/*| SAB82532_IMR0_CDSC*/;
  2443. WRITEB(port,imr0,info->interrupt_mask0);
  2444. info->interrupt_mask1 = SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS |
  2445. SAB82532_IMR1_XOFF | SAB82532_IMR1_TIN |
  2446. SAB82532_IMR1_CSC | SAB82532_IMR1_XON |
  2447. SAB82532_IMR1_XPR;
  2448. WRITEB(port,imr1,info->interrupt_mask1);
  2449. printk("Console: ttyS%d (SAB82532)n", info->line);
  2450. sunserial_console_termios(con);
  2451. cflag = con->cflag;
  2452. /* Byte size and parity */
  2453. switch (cflag & CSIZE) 
  2454. {
  2455. case CS5: dafo = SAB82532_DAFO_CHL5; bits = 7; break;
  2456. case CS6: dafo = SAB82532_DAFO_CHL6; bits = 8; break;
  2457. case CS7: dafo = SAB82532_DAFO_CHL7; bits = 9; break;
  2458. case CS8: dafo = SAB82532_DAFO_CHL8; bits = 10; break;
  2459. /* Never happens, but GCC is too dumb to figure it out */
  2460. default:  dafo = SAB82532_DAFO_CHL5; bits = 7; break;
  2461. }
  2462. if (cflag & CSTOPB) 
  2463. {
  2464. dafo |= SAB82532_DAFO_STOP;
  2465. bits++;
  2466. }
  2467. if (cflag & PARENB) 
  2468. {
  2469. dafo |= SAB82532_DAFO_PARE;
  2470. bits++;
  2471. }
  2472. if (cflag & PARODD) 
  2473. {
  2474. #ifdef CMSPAR
  2475. if (cflag & CMSPAR)
  2476. dafo |= SAB82532_DAFO_PAR_MARK;
  2477. else
  2478. #endif
  2479. dafo |= SAB82532_DAFO_PAR_ODD;
  2480. else 
  2481. {
  2482. #ifdef CMSPAR
  2483. if (cflag & CMSPAR)
  2484. dafo |= SAB82532_DAFO_PAR_SPACE;
  2485. else
  2486. #endif
  2487. dafo |= SAB82532_DAFO_PAR_EVEN;
  2488. }
  2489. /* Determine EBRG values based on baud rate */
  2490. i = cflag & CBAUD;
  2491. if (i & CBAUDEX) 
  2492. {
  2493. i &= ~(CBAUDEX);
  2494. if ((i < 1) || ((i + 15) >= NR_EBRG_VALUES))
  2495. cflag &= ~CBAUDEX;
  2496. else
  2497. i += 15;
  2498. }
  2499. ebrg = ebrg_tabl[i].n;
  2500. ebrg |= (ebrg_table[i].m << 6);
  2501. info->baud = ebrg_table[i].baud;
  2502. if (info->baud)
  2503. info->timeout = (info->xmit_fifo_size * HZ * bits) / info->baud;
  2504. else
  2505. info->timeout = 0;
  2506. info->timeout += HZ / 50; /* Add .02 seconds of slop */
  2507. /* CTS flow control flags */
  2508. if (cflag & CRTSCTS)
  2509. info->flags |= FLAG8253X_CTS_FLOW;
  2510. else
  2511. info->flags &= ~(FLAG8253X_CTS_FLOW);
  2512. if (cflag & CLOCAL)
  2513. info->flags &= ~(FLAG8253X_CHECK_CD);
  2514. else
  2515. info->flags |= FLAG8253X_CHECK_CD;
  2516. save_flags(flags); cli();
  2517. sab8253x_cec_wait(info);
  2518. sab8253x_tec_wait(info);
  2519. WRITEB(port,dafo,dafo);
  2520. WRITEB(port,bgr,ebrg & 0xff);
  2521. info->regs->rw.ccr2 &= ~(0xc0);
  2522. info->regs->rw.ccr2 |= (ebrg >> 2) & 0xc0;
  2523. if (info->flags & FLAG8253X_CTS_FLOW) 
  2524. {
  2525. info->regs->rw.mode &= ~(SAB82532_MODE_RTS);
  2526. info->regs->rw.mode |= SAB82532_MODE_FRTS;
  2527. info->regs->rw.mode &= ~(SAB82532_MODE_FCTS);
  2528. else 
  2529. {
  2530. info->regs->rw.mode |= SAB82532_MODE_RTS;
  2531. info->regs->rw.mode &= ~(SAB82532_MODE_FRTS);
  2532. info->regs->rw.mode |= SAB82532_MODE_FCTS;
  2533. }
  2534. info->regs->rw.pvr &= ~(info->pvr_dtr_bit);
  2535. info->regs->rw.mode |= SAB82532_MODE_RAC;
  2536. restore_flags(flags);
  2537. return 0;
  2538. }
  2539. static struct console sab8253x_console = 
  2540. {
  2541. "ttyS",
  2542. sab8253x_console_write,
  2543. NULL,
  2544. sab8253x_console_device,
  2545. sab8253x_console_wait_key,
  2546. NULL,
  2547. sab8253x_console_setup,
  2548. CON_PRINTBUFFER,
  2549. -1,
  2550. 0,
  2551. NULL
  2552. };
  2553. int sab8253x_console_init(void)
  2554. {
  2555. extern int con_is_present(void);
  2556. extern int su_console_registered;
  2557. if (con_is_present() || su_console_registered)
  2558. return 0;
  2559. if (!sab8253x_chain) 
  2560. {
  2561. prom_printf("sab8253x_console_setup: can't get SAB8253X chain");
  2562. prom_halt();
  2563. }
  2564. sab8253x_console.index = serial_console - 1;
  2565. register_console(&sab8253x_console);
  2566. return 0;
  2567. }
  2568. #ifdef SERIAL_LOG_DEVICE
  2569. static int serial_log_device = 0;
  2570. static void
  2571. dprint_init(int tty)
  2572. {
  2573. serial_console = tty + 1;
  2574. sab8253x_console.index = tty;
  2575. sab8253x_console_setup(&sab8253x_console, "");
  2576. serial_console = 0;
  2577. serial_log_device = tty + 1;
  2578. }
  2579. int
  2580. dprintf(const char *fmt, ...)
  2581. {
  2582. static char buffer[4096];
  2583. va_list args;
  2584. int i;
  2585. if (!serial_log_device)
  2586. return 0;
  2587. va_start(args, fmt);
  2588. i = vsprintf(buffer, fmt, args);
  2589. va_end(args);
  2590. sab8253x_console.write(&sab8253x_console, buffer, i);
  2591. return i;
  2592. }
  2593. #endif /* SERIAL_LOG_DEVICE */
  2594. #endif /* XCONFIG_SERIAL_CONSOLE */