serial_txx9.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. /*
  2. * drivers/serial/serial_txx9.c
  3. *
  4. * Derived from many drivers using generic_serial interface,
  5. * especially serial_tx3912.c by Steven J. Hill and r39xx_serial.c
  6. * (was in Linux/VR tree) by Jim Pick.
  7. *
  8. * Copyright (C) 1999 Harald Koerfgen
  9. * Copyright (C) 2000 Jim Pick <jim@jimpick.com>
  10. * Copyright (C) 2001 Steven J. Hill (sjhill@realitydiluted.com)
  11. * Copyright (C) 2000-2002 Toshiba Corporation
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. *
  17. * Serial driver for TX3927/TX4927/TX4925/TX4938 internal SIO controller
  18. *
  19. * Revision History:
  20. * 0.30 Initial revision. (Renamed from serial_txx927.c)
  21. * 0.31 Use save_flags instead of local_irq_save.
  22. * 0.32 Support SCLK.
  23. * 0.33 Switch TXX9_TTY_NAME by CONFIG_SERIAL_TXX9_STDSERIAL.
  24. * Support TIOCSERGETLSR.
  25. * 0.34 Support slow baudrate.
  26. * 0.40 Merge codes from mainstream kernel (2.4.22).
  27. * 0.41 Fix console checking in rs_shutdown_port().
  28. * Disable flow-control in serial_console_write().
  29. * 0.42 Fix minor compiler warning.
  30. * 1.00 Kernel 2.6. Converted to new serial core (based on 8250.c).
  31. * 1.01 Set fifosize to make tx_empry called properly.
  32. * Use standard uart_get_divisor.
  33. * 1.02 Cleanup. (import 8250.c changes)
  34. * 1.03 Fix low-latency mode. (import 8250.c changes)
  35. * 1.04 Remove usage of deprecated functions, cleanup.
  36. * 1.05 More strict check in verify_port. Cleanup.
  37. * 1.06 Do not insert a char caused previous overrun.
  38. * Fix some spin_locks.
  39. * Do not call uart_add_one_port for absent ports.
  40. */
  41. #include <linux/config.h>
  42. #if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  43. #define SUPPORT_SYSRQ
  44. #endif
  45. #include <linux/module.h>
  46. #include <linux/ioport.h>
  47. #include <linux/init.h>
  48. #include <linux/console.h>
  49. #include <linux/sysrq.h>
  50. #include <linux/delay.h>
  51. #include <linux/device.h>
  52. #include <linux/pci.h>
  53. #include <linux/tty.h>
  54. #include <linux/tty_flip.h>
  55. #include <linux/serial_core.h>
  56. #include <linux/serial.h>
  57. #include <linux/mutex.h>
  58. #include <asm/io.h>
  59. #include <asm/irq.h>
  60. static char *serial_version = "1.06";
  61. static char *serial_name = "TX39/49 Serial driver";
  62. #define PASS_LIMIT 256
  63. #if !defined(CONFIG_SERIAL_TXX9_STDSERIAL)
  64. /* "ttyS" is used for standard serial driver */
  65. #define TXX9_TTY_NAME "ttyTX"
  66. #define TXX9_TTY_DEVFS_NAME "tttx/"
  67. #define TXX9_TTY_MINOR_START (64 + 64) /* ttyTX0(128), ttyTX1(129) */
  68. #else
  69. /* acts like standard serial driver */
  70. #define TXX9_TTY_NAME "ttyS"
  71. #define TXX9_TTY_DEVFS_NAME "tts/"
  72. #define TXX9_TTY_MINOR_START 64
  73. #endif
  74. #define TXX9_TTY_MAJOR TTY_MAJOR
  75. /* flag aliases */
  76. #define UPF_TXX9_HAVE_CTS_LINE UPF_BUGGY_UART
  77. #define UPF_TXX9_USE_SCLK UPF_MAGIC_MULTIPLIER
  78. #ifdef CONFIG_PCI
  79. /* support for Toshiba TC86C001 SIO */
  80. #define ENABLE_SERIAL_TXX9_PCI
  81. #endif
  82. /*
  83. * Number of serial ports
  84. */
  85. #ifdef ENABLE_SERIAL_TXX9_PCI
  86. #define NR_PCI_BOARDS 4
  87. #define UART_NR (4 + NR_PCI_BOARDS)
  88. #else
  89. #define UART_NR 4
  90. #endif
  91. #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
  92. struct uart_txx9_port {
  93. struct uart_port port;
  94. /*
  95. * We provide a per-port pm hook.
  96. */
  97. void (*pm)(struct uart_port *port,
  98. unsigned int state, unsigned int old);
  99. };
  100. #define TXX9_REGION_SIZE 0x24
  101. /* TXX9 Serial Registers */
  102. #define TXX9_SILCR 0x00
  103. #define TXX9_SIDICR 0x04
  104. #define TXX9_SIDISR 0x08
  105. #define TXX9_SICISR 0x0c
  106. #define TXX9_SIFCR 0x10
  107. #define TXX9_SIFLCR 0x14
  108. #define TXX9_SIBGR 0x18
  109. #define TXX9_SITFIFO 0x1c
  110. #define TXX9_SIRFIFO 0x20
  111. /* SILCR : Line Control */
  112. #define TXX9_SILCR_SCS_MASK 0x00000060
  113. #define TXX9_SILCR_SCS_IMCLK 0x00000000
  114. #define TXX9_SILCR_SCS_IMCLK_BG 0x00000020
  115. #define TXX9_SILCR_SCS_SCLK 0x00000040
  116. #define TXX9_SILCR_SCS_SCLK_BG 0x00000060
  117. #define TXX9_SILCR_UEPS 0x00000010
  118. #define TXX9_SILCR_UPEN 0x00000008
  119. #define TXX9_SILCR_USBL_MASK 0x00000004
  120. #define TXX9_SILCR_USBL_1BIT 0x00000000
  121. #define TXX9_SILCR_USBL_2BIT 0x00000004
  122. #define TXX9_SILCR_UMODE_MASK 0x00000003
  123. #define TXX9_SILCR_UMODE_8BIT 0x00000000
  124. #define TXX9_SILCR_UMODE_7BIT 0x00000001
  125. /* SIDICR : DMA/Int. Control */
  126. #define TXX9_SIDICR_TDE 0x00008000
  127. #define TXX9_SIDICR_RDE 0x00004000
  128. #define TXX9_SIDICR_TIE 0x00002000
  129. #define TXX9_SIDICR_RIE 0x00001000
  130. #define TXX9_SIDICR_SPIE 0x00000800
  131. #define TXX9_SIDICR_CTSAC 0x00000600
  132. #define TXX9_SIDICR_STIE_MASK 0x0000003f
  133. #define TXX9_SIDICR_STIE_OERS 0x00000020
  134. #define TXX9_SIDICR_STIE_CTSS 0x00000010
  135. #define TXX9_SIDICR_STIE_RBRKD 0x00000008
  136. #define TXX9_SIDICR_STIE_TRDY 0x00000004
  137. #define TXX9_SIDICR_STIE_TXALS 0x00000002
  138. #define TXX9_SIDICR_STIE_UBRKD 0x00000001
  139. /* SIDISR : DMA/Int. Status */
  140. #define TXX9_SIDISR_UBRK 0x00008000
  141. #define TXX9_SIDISR_UVALID 0x00004000
  142. #define TXX9_SIDISR_UFER 0x00002000
  143. #define TXX9_SIDISR_UPER 0x00001000
  144. #define TXX9_SIDISR_UOER 0x00000800
  145. #define TXX9_SIDISR_ERI 0x00000400
  146. #define TXX9_SIDISR_TOUT 0x00000200
  147. #define TXX9_SIDISR_TDIS 0x00000100
  148. #define TXX9_SIDISR_RDIS 0x00000080
  149. #define TXX9_SIDISR_STIS 0x00000040
  150. #define TXX9_SIDISR_RFDN_MASK 0x0000001f
  151. /* SICISR : Change Int. Status */
  152. #define TXX9_SICISR_OERS 0x00000020
  153. #define TXX9_SICISR_CTSS 0x00000010
  154. #define TXX9_SICISR_RBRKD 0x00000008
  155. #define TXX9_SICISR_TRDY 0x00000004
  156. #define TXX9_SICISR_TXALS 0x00000002
  157. #define TXX9_SICISR_UBRKD 0x00000001
  158. /* SIFCR : FIFO Control */
  159. #define TXX9_SIFCR_SWRST 0x00008000
  160. #define TXX9_SIFCR_RDIL_MASK 0x00000180
  161. #define TXX9_SIFCR_RDIL_1 0x00000000
  162. #define TXX9_SIFCR_RDIL_4 0x00000080
  163. #define TXX9_SIFCR_RDIL_8 0x00000100
  164. #define TXX9_SIFCR_RDIL_12 0x00000180
  165. #define TXX9_SIFCR_RDIL_MAX 0x00000180
  166. #define TXX9_SIFCR_TDIL_MASK 0x00000018
  167. #define TXX9_SIFCR_TDIL_MASK 0x00000018
  168. #define TXX9_SIFCR_TDIL_1 0x00000000
  169. #define TXX9_SIFCR_TDIL_4 0x00000001
  170. #define TXX9_SIFCR_TDIL_8 0x00000010
  171. #define TXX9_SIFCR_TDIL_MAX 0x00000010
  172. #define TXX9_SIFCR_TFRST 0x00000004
  173. #define TXX9_SIFCR_RFRST 0x00000002
  174. #define TXX9_SIFCR_FRSTE 0x00000001
  175. #define TXX9_SIO_TX_FIFO 8
  176. #define TXX9_SIO_RX_FIFO 16
  177. /* SIFLCR : Flow Control */
  178. #define TXX9_SIFLCR_RCS 0x00001000
  179. #define TXX9_SIFLCR_TES 0x00000800
  180. #define TXX9_SIFLCR_RTSSC 0x00000200
  181. #define TXX9_SIFLCR_RSDE 0x00000100
  182. #define TXX9_SIFLCR_TSDE 0x00000080
  183. #define TXX9_SIFLCR_RTSTL_MASK 0x0000001e
  184. #define TXX9_SIFLCR_RTSTL_MAX 0x0000001e
  185. #define TXX9_SIFLCR_TBRK 0x00000001
  186. /* SIBGR : Baudrate Control */
  187. #define TXX9_SIBGR_BCLK_MASK 0x00000300
  188. #define TXX9_SIBGR_BCLK_T0 0x00000000
  189. #define TXX9_SIBGR_BCLK_T2 0x00000100
  190. #define TXX9_SIBGR_BCLK_T4 0x00000200
  191. #define TXX9_SIBGR_BCLK_T6 0x00000300
  192. #define TXX9_SIBGR_BRD_MASK 0x000000ff
  193. static inline unsigned int sio_in(struct uart_txx9_port *up, int offset)
  194. {
  195. switch (up->port.iotype) {
  196. default:
  197. return __raw_readl(up->port.membase + offset);
  198. case UPIO_PORT:
  199. return inl(up->port.iobase + offset);
  200. }
  201. }
  202. static inline void
  203. sio_out(struct uart_txx9_port *up, int offset, int value)
  204. {
  205. switch (up->port.iotype) {
  206. default:
  207. __raw_writel(value, up->port.membase + offset);
  208. break;
  209. case UPIO_PORT:
  210. outl(value, up->port.iobase + offset);
  211. break;
  212. }
  213. }
  214. static inline void
  215. sio_mask(struct uart_txx9_port *up, int offset, unsigned int value)
  216. {
  217. sio_out(up, offset, sio_in(up, offset) & ~value);
  218. }
  219. static inline void
  220. sio_set(struct uart_txx9_port *up, int offset, unsigned int value)
  221. {
  222. sio_out(up, offset, sio_in(up, offset) | value);
  223. }
  224. static inline void
  225. sio_quot_set(struct uart_txx9_port *up, int quot)
  226. {
  227. quot >>= 1;
  228. if (quot < 256)
  229. sio_out(up, TXX9_SIBGR, quot | TXX9_SIBGR_BCLK_T0);
  230. else if (quot < (256 << 2))
  231. sio_out(up, TXX9_SIBGR, (quot >> 2) | TXX9_SIBGR_BCLK_T2);
  232. else if (quot < (256 << 4))
  233. sio_out(up, TXX9_SIBGR, (quot >> 4) | TXX9_SIBGR_BCLK_T4);
  234. else if (quot < (256 << 6))
  235. sio_out(up, TXX9_SIBGR, (quot >> 6) | TXX9_SIBGR_BCLK_T6);
  236. else
  237. sio_out(up, TXX9_SIBGR, 0xff | TXX9_SIBGR_BCLK_T6);
  238. }
  239. static void serial_txx9_stop_tx(struct uart_port *port)
  240. {
  241. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  242. sio_mask(up, TXX9_SIDICR, TXX9_SIDICR_TIE);
  243. }
  244. static void serial_txx9_start_tx(struct uart_port *port)
  245. {
  246. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  247. sio_set(up, TXX9_SIDICR, TXX9_SIDICR_TIE);
  248. }
  249. static void serial_txx9_stop_rx(struct uart_port *port)
  250. {
  251. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  252. up->port.read_status_mask &= ~TXX9_SIDISR_RDIS;
  253. }
  254. static void serial_txx9_enable_ms(struct uart_port *port)
  255. {
  256. /* TXX9-SIO can not control DTR... */
  257. }
  258. static inline void
  259. receive_chars(struct uart_txx9_port *up, unsigned int *status, struct pt_regs *regs)
  260. {
  261. struct tty_struct *tty = up->port.info->tty;
  262. unsigned char ch;
  263. unsigned int disr = *status;
  264. int max_count = 256;
  265. char flag;
  266. unsigned int next_ignore_status_mask;
  267. do {
  268. ch = sio_in(up, TXX9_SIRFIFO);
  269. flag = TTY_NORMAL;
  270. up->port.icount.rx++;
  271. /* mask out RFDN_MASK bit added by previous overrun */
  272. next_ignore_status_mask =
  273. up->port.ignore_status_mask & ~TXX9_SIDISR_RFDN_MASK;
  274. if (unlikely(disr & (TXX9_SIDISR_UBRK | TXX9_SIDISR_UPER |
  275. TXX9_SIDISR_UFER | TXX9_SIDISR_UOER))) {
  276. /*
  277. * For statistics only
  278. */
  279. if (disr & TXX9_SIDISR_UBRK) {
  280. disr &= ~(TXX9_SIDISR_UFER | TXX9_SIDISR_UPER);
  281. up->port.icount.brk++;
  282. /*
  283. * We do the SysRQ and SAK checking
  284. * here because otherwise the break
  285. * may get masked by ignore_status_mask
  286. * or read_status_mask.
  287. */
  288. if (uart_handle_break(&up->port))
  289. goto ignore_char;
  290. } else if (disr & TXX9_SIDISR_UPER)
  291. up->port.icount.parity++;
  292. else if (disr & TXX9_SIDISR_UFER)
  293. up->port.icount.frame++;
  294. if (disr & TXX9_SIDISR_UOER) {
  295. up->port.icount.overrun++;
  296. /*
  297. * The receiver read buffer still hold
  298. * a char which caused overrun.
  299. * Ignore next char by adding RFDN_MASK
  300. * to ignore_status_mask temporarily.
  301. */
  302. next_ignore_status_mask |=
  303. TXX9_SIDISR_RFDN_MASK;
  304. }
  305. /*
  306. * Mask off conditions which should be ingored.
  307. */
  308. disr &= up->port.read_status_mask;
  309. if (disr & TXX9_SIDISR_UBRK) {
  310. flag = TTY_BREAK;
  311. } else if (disr & TXX9_SIDISR_UPER)
  312. flag = TTY_PARITY;
  313. else if (disr & TXX9_SIDISR_UFER)
  314. flag = TTY_FRAME;
  315. }
  316. if (uart_handle_sysrq_char(&up->port, ch, regs))
  317. goto ignore_char;
  318. uart_insert_char(&up->port, disr, TXX9_SIDISR_UOER, ch, flag);
  319. ignore_char:
  320. up->port.ignore_status_mask = next_ignore_status_mask;
  321. disr = sio_in(up, TXX9_SIDISR);
  322. } while (!(disr & TXX9_SIDISR_UVALID) && (max_count-- > 0));
  323. spin_unlock(&up->port.lock);
  324. tty_flip_buffer_push(tty);
  325. spin_lock(&up->port.lock);
  326. *status = disr;
  327. }
  328. static inline void transmit_chars(struct uart_txx9_port *up)
  329. {
  330. struct circ_buf *xmit = &up->port.info->xmit;
  331. int count;
  332. if (up->port.x_char) {
  333. sio_out(up, TXX9_SITFIFO, up->port.x_char);
  334. up->port.icount.tx++;
  335. up->port.x_char = 0;
  336. return;
  337. }
  338. if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
  339. serial_txx9_stop_tx(&up->port);
  340. return;
  341. }
  342. count = TXX9_SIO_TX_FIFO;
  343. do {
  344. sio_out(up, TXX9_SITFIFO, xmit->buf[xmit->tail]);
  345. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  346. up->port.icount.tx++;
  347. if (uart_circ_empty(xmit))
  348. break;
  349. } while (--count > 0);
  350. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  351. uart_write_wakeup(&up->port);
  352. if (uart_circ_empty(xmit))
  353. serial_txx9_stop_tx(&up->port);
  354. }
  355. static irqreturn_t serial_txx9_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  356. {
  357. int pass_counter = 0;
  358. struct uart_txx9_port *up = dev_id;
  359. unsigned int status;
  360. while (1) {
  361. spin_lock(&up->port.lock);
  362. status = sio_in(up, TXX9_SIDISR);
  363. if (!(sio_in(up, TXX9_SIDICR) & TXX9_SIDICR_TIE))
  364. status &= ~TXX9_SIDISR_TDIS;
  365. if (!(status & (TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS |
  366. TXX9_SIDISR_TOUT))) {
  367. spin_unlock(&up->port.lock);
  368. break;
  369. }
  370. if (status & TXX9_SIDISR_RDIS)
  371. receive_chars(up, &status, regs);
  372. if (status & TXX9_SIDISR_TDIS)
  373. transmit_chars(up);
  374. /* Clear TX/RX Int. Status */
  375. sio_mask(up, TXX9_SIDISR,
  376. TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS |
  377. TXX9_SIDISR_TOUT);
  378. spin_unlock(&up->port.lock);
  379. if (pass_counter++ > PASS_LIMIT)
  380. break;
  381. }
  382. return pass_counter ? IRQ_HANDLED : IRQ_NONE;
  383. }
  384. static unsigned int serial_txx9_tx_empty(struct uart_port *port)
  385. {
  386. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  387. unsigned long flags;
  388. unsigned int ret;
  389. spin_lock_irqsave(&up->port.lock, flags);
  390. ret = (sio_in(up, TXX9_SICISR) & TXX9_SICISR_TXALS) ? TIOCSER_TEMT : 0;
  391. spin_unlock_irqrestore(&up->port.lock, flags);
  392. return ret;
  393. }
  394. static unsigned int serial_txx9_get_mctrl(struct uart_port *port)
  395. {
  396. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  397. unsigned int ret;
  398. ret = ((sio_in(up, TXX9_SIFLCR) & TXX9_SIFLCR_RTSSC) ? 0 : TIOCM_RTS)
  399. | ((sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS) ? 0 : TIOCM_CTS);
  400. return ret;
  401. }
  402. static void serial_txx9_set_mctrl(struct uart_port *port, unsigned int mctrl)
  403. {
  404. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  405. if (mctrl & TIOCM_RTS)
  406. sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSSC);
  407. else
  408. sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSSC);
  409. }
  410. static void serial_txx9_break_ctl(struct uart_port *port, int break_state)
  411. {
  412. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  413. unsigned long flags;
  414. spin_lock_irqsave(&up->port.lock, flags);
  415. if (break_state == -1)
  416. sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
  417. else
  418. sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
  419. spin_unlock_irqrestore(&up->port.lock, flags);
  420. }
  421. static int serial_txx9_startup(struct uart_port *port)
  422. {
  423. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  424. unsigned long flags;
  425. int retval;
  426. /*
  427. * Clear the FIFO buffers and disable them.
  428. * (they will be reenabled in set_termios())
  429. */
  430. sio_set(up, TXX9_SIFCR,
  431. TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  432. /* clear reset */
  433. sio_mask(up, TXX9_SIFCR,
  434. TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  435. sio_out(up, TXX9_SIDICR, 0);
  436. /*
  437. * Clear the interrupt registers.
  438. */
  439. sio_out(up, TXX9_SIDISR, 0);
  440. retval = request_irq(up->port.irq, serial_txx9_interrupt,
  441. SA_SHIRQ, "serial_txx9", up);
  442. if (retval)
  443. return retval;
  444. /*
  445. * Now, initialize the UART
  446. */
  447. spin_lock_irqsave(&up->port.lock, flags);
  448. serial_txx9_set_mctrl(&up->port, up->port.mctrl);
  449. spin_unlock_irqrestore(&up->port.lock, flags);
  450. /* Enable RX/TX */
  451. sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_RSDE | TXX9_SIFLCR_TSDE);
  452. /*
  453. * Finally, enable interrupts.
  454. */
  455. sio_set(up, TXX9_SIDICR, TXX9_SIDICR_RIE);
  456. return 0;
  457. }
  458. static void serial_txx9_shutdown(struct uart_port *port)
  459. {
  460. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  461. unsigned long flags;
  462. /*
  463. * Disable interrupts from this port
  464. */
  465. sio_out(up, TXX9_SIDICR, 0); /* disable all intrs */
  466. spin_lock_irqsave(&up->port.lock, flags);
  467. serial_txx9_set_mctrl(&up->port, up->port.mctrl);
  468. spin_unlock_irqrestore(&up->port.lock, flags);
  469. /*
  470. * Disable break condition
  471. */
  472. sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
  473. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  474. if (up->port.cons && up->port.line == up->port.cons->index) {
  475. free_irq(up->port.irq, up);
  476. return;
  477. }
  478. #endif
  479. /* reset FIFOs */
  480. sio_set(up, TXX9_SIFCR,
  481. TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  482. /* clear reset */
  483. sio_mask(up, TXX9_SIFCR,
  484. TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  485. /* Disable RX/TX */
  486. sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_RSDE | TXX9_SIFLCR_TSDE);
  487. free_irq(up->port.irq, up);
  488. }
  489. static void
  490. serial_txx9_set_termios(struct uart_port *port, struct termios *termios,
  491. struct termios *old)
  492. {
  493. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  494. unsigned int cval, fcr = 0;
  495. unsigned long flags;
  496. unsigned int baud, quot;
  497. cval = sio_in(up, TXX9_SILCR);
  498. /* byte size and parity */
  499. cval &= ~TXX9_SILCR_UMODE_MASK;
  500. switch (termios->c_cflag & CSIZE) {
  501. case CS7:
  502. cval |= TXX9_SILCR_UMODE_7BIT;
  503. break;
  504. default:
  505. case CS5: /* not supported */
  506. case CS6: /* not supported */
  507. case CS8:
  508. cval |= TXX9_SILCR_UMODE_8BIT;
  509. break;
  510. }
  511. cval &= ~TXX9_SILCR_USBL_MASK;
  512. if (termios->c_cflag & CSTOPB)
  513. cval |= TXX9_SILCR_USBL_2BIT;
  514. else
  515. cval |= TXX9_SILCR_USBL_1BIT;
  516. cval &= ~(TXX9_SILCR_UPEN | TXX9_SILCR_UEPS);
  517. if (termios->c_cflag & PARENB)
  518. cval |= TXX9_SILCR_UPEN;
  519. if (!(termios->c_cflag & PARODD))
  520. cval |= TXX9_SILCR_UEPS;
  521. /*
  522. * Ask the core to calculate the divisor for us.
  523. */
  524. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16/2);
  525. quot = uart_get_divisor(port, baud);
  526. /* Set up FIFOs */
  527. /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
  528. fcr = TXX9_SIFCR_TDIL_MAX | TXX9_SIFCR_RDIL_1;
  529. /*
  530. * Ok, we're now changing the port state. Do it with
  531. * interrupts disabled.
  532. */
  533. spin_lock_irqsave(&up->port.lock, flags);
  534. /*
  535. * Update the per-port timeout.
  536. */
  537. uart_update_timeout(port, termios->c_cflag, baud);
  538. up->port.read_status_mask = TXX9_SIDISR_UOER |
  539. TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS;
  540. if (termios->c_iflag & INPCK)
  541. up->port.read_status_mask |= TXX9_SIDISR_UFER | TXX9_SIDISR_UPER;
  542. if (termios->c_iflag & (BRKINT | PARMRK))
  543. up->port.read_status_mask |= TXX9_SIDISR_UBRK;
  544. /*
  545. * Characteres to ignore
  546. */
  547. up->port.ignore_status_mask = 0;
  548. if (termios->c_iflag & IGNPAR)
  549. up->port.ignore_status_mask |= TXX9_SIDISR_UPER | TXX9_SIDISR_UFER;
  550. if (termios->c_iflag & IGNBRK) {
  551. up->port.ignore_status_mask |= TXX9_SIDISR_UBRK;
  552. /*
  553. * If we're ignoring parity and break indicators,
  554. * ignore overruns too (for real raw support).
  555. */
  556. if (termios->c_iflag & IGNPAR)
  557. up->port.ignore_status_mask |= TXX9_SIDISR_UOER;
  558. }
  559. /*
  560. * ignore all characters if CREAD is not set
  561. */
  562. if ((termios->c_cflag & CREAD) == 0)
  563. up->port.ignore_status_mask |= TXX9_SIDISR_RDIS;
  564. /* CTS flow control flag */
  565. if ((termios->c_cflag & CRTSCTS) &&
  566. (up->port.flags & UPF_TXX9_HAVE_CTS_LINE)) {
  567. sio_set(up, TXX9_SIFLCR,
  568. TXX9_SIFLCR_RCS | TXX9_SIFLCR_TES);
  569. } else {
  570. sio_mask(up, TXX9_SIFLCR,
  571. TXX9_SIFLCR_RCS | TXX9_SIFLCR_TES);
  572. }
  573. sio_out(up, TXX9_SILCR, cval);
  574. sio_quot_set(up, quot);
  575. sio_out(up, TXX9_SIFCR, fcr);
  576. serial_txx9_set_mctrl(&up->port, up->port.mctrl);
  577. spin_unlock_irqrestore(&up->port.lock, flags);
  578. }
  579. static void
  580. serial_txx9_pm(struct uart_port *port, unsigned int state,
  581. unsigned int oldstate)
  582. {
  583. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  584. if (up->pm)
  585. up->pm(port, state, oldstate);
  586. }
  587. static int serial_txx9_request_resource(struct uart_txx9_port *up)
  588. {
  589. unsigned int size = TXX9_REGION_SIZE;
  590. int ret = 0;
  591. switch (up->port.iotype) {
  592. default:
  593. if (!up->port.mapbase)
  594. break;
  595. if (!request_mem_region(up->port.mapbase, size, "serial_txx9")) {
  596. ret = -EBUSY;
  597. break;
  598. }
  599. if (up->port.flags & UPF_IOREMAP) {
  600. up->port.membase = ioremap(up->port.mapbase, size);
  601. if (!up->port.membase) {
  602. release_mem_region(up->port.mapbase, size);
  603. ret = -ENOMEM;
  604. }
  605. }
  606. break;
  607. case UPIO_PORT:
  608. if (!request_region(up->port.iobase, size, "serial_txx9"))
  609. ret = -EBUSY;
  610. break;
  611. }
  612. return ret;
  613. }
  614. static void serial_txx9_release_resource(struct uart_txx9_port *up)
  615. {
  616. unsigned int size = TXX9_REGION_SIZE;
  617. switch (up->port.iotype) {
  618. default:
  619. if (!up->port.mapbase)
  620. break;
  621. if (up->port.flags & UPF_IOREMAP) {
  622. iounmap(up->port.membase);
  623. up->port.membase = NULL;
  624. }
  625. release_mem_region(up->port.mapbase, size);
  626. break;
  627. case UPIO_PORT:
  628. release_region(up->port.iobase, size);
  629. break;
  630. }
  631. }
  632. static void serial_txx9_release_port(struct uart_port *port)
  633. {
  634. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  635. serial_txx9_release_resource(up);
  636. }
  637. static int serial_txx9_request_port(struct uart_port *port)
  638. {
  639. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  640. return serial_txx9_request_resource(up);
  641. }
  642. static void serial_txx9_config_port(struct uart_port *port, int uflags)
  643. {
  644. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  645. unsigned long flags;
  646. int ret;
  647. /*
  648. * Find the region that we can probe for. This in turn
  649. * tells us whether we can probe for the type of port.
  650. */
  651. ret = serial_txx9_request_resource(up);
  652. if (ret < 0)
  653. return;
  654. port->type = PORT_TXX9;
  655. up->port.fifosize = TXX9_SIO_TX_FIFO;
  656. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  657. if (up->port.line == up->port.cons->index)
  658. return;
  659. #endif
  660. spin_lock_irqsave(&up->port.lock, flags);
  661. /*
  662. * Reset the UART.
  663. */
  664. sio_out(up, TXX9_SIFCR, TXX9_SIFCR_SWRST);
  665. #ifdef CONFIG_CPU_TX49XX
  666. /* TX4925 BUG WORKAROUND. Accessing SIOC register
  667. * immediately after soft reset causes bus error. */
  668. iob();
  669. udelay(1);
  670. #endif
  671. while (sio_in(up, TXX9_SIFCR) & TXX9_SIFCR_SWRST)
  672. ;
  673. /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
  674. sio_set(up, TXX9_SIFCR,
  675. TXX9_SIFCR_TDIL_MAX | TXX9_SIFCR_RDIL_1);
  676. /* initial settings */
  677. sio_out(up, TXX9_SILCR,
  678. TXX9_SILCR_UMODE_8BIT | TXX9_SILCR_USBL_1BIT |
  679. ((up->port.flags & UPF_TXX9_USE_SCLK) ?
  680. TXX9_SILCR_SCS_SCLK_BG : TXX9_SILCR_SCS_IMCLK_BG));
  681. sio_quot_set(up, uart_get_divisor(port, 9600));
  682. sio_out(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSTL_MAX /* 15 */);
  683. spin_unlock_irqrestore(&up->port.lock, flags);
  684. }
  685. static int
  686. serial_txx9_verify_port(struct uart_port *port, struct serial_struct *ser)
  687. {
  688. unsigned long new_port = ser->port;
  689. if (HIGH_BITS_OFFSET)
  690. new_port += (unsigned long)ser->port_high << HIGH_BITS_OFFSET;
  691. if (ser->type != port->type ||
  692. ser->irq != port->irq ||
  693. ser->io_type != port->iotype ||
  694. new_port != port->iobase ||
  695. (unsigned long)ser->iomem_base != port->mapbase)
  696. return -EINVAL;
  697. return 0;
  698. }
  699. static const char *
  700. serial_txx9_type(struct uart_port *port)
  701. {
  702. return "txx9";
  703. }
  704. static struct uart_ops serial_txx9_pops = {
  705. .tx_empty = serial_txx9_tx_empty,
  706. .set_mctrl = serial_txx9_set_mctrl,
  707. .get_mctrl = serial_txx9_get_mctrl,
  708. .stop_tx = serial_txx9_stop_tx,
  709. .start_tx = serial_txx9_start_tx,
  710. .stop_rx = serial_txx9_stop_rx,
  711. .enable_ms = serial_txx9_enable_ms,
  712. .break_ctl = serial_txx9_break_ctl,
  713. .startup = serial_txx9_startup,
  714. .shutdown = serial_txx9_shutdown,
  715. .set_termios = serial_txx9_set_termios,
  716. .pm = serial_txx9_pm,
  717. .type = serial_txx9_type,
  718. .release_port = serial_txx9_release_port,
  719. .request_port = serial_txx9_request_port,
  720. .config_port = serial_txx9_config_port,
  721. .verify_port = serial_txx9_verify_port,
  722. };
  723. static struct uart_txx9_port serial_txx9_ports[UART_NR];
  724. static void __init serial_txx9_register_ports(struct uart_driver *drv)
  725. {
  726. int i;
  727. for (i = 0; i < UART_NR; i++) {
  728. struct uart_txx9_port *up = &serial_txx9_ports[i];
  729. up->port.line = i;
  730. up->port.ops = &serial_txx9_pops;
  731. if (up->port.iobase || up->port.mapbase)
  732. uart_add_one_port(drv, &up->port);
  733. }
  734. }
  735. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  736. /*
  737. * Wait for transmitter & holding register to empty
  738. */
  739. static inline void wait_for_xmitr(struct uart_txx9_port *up)
  740. {
  741. unsigned int tmout = 10000;
  742. /* Wait up to 10ms for the character(s) to be sent. */
  743. while (--tmout &&
  744. !(sio_in(up, TXX9_SICISR) & TXX9_SICISR_TXALS))
  745. udelay(1);
  746. /* Wait up to 1s for flow control if necessary */
  747. if (up->port.flags & UPF_CONS_FLOW) {
  748. tmout = 1000000;
  749. while (--tmout &&
  750. (sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS))
  751. udelay(1);
  752. }
  753. }
  754. static void serial_txx9_console_putchar(struct uart_port *port, int ch)
  755. {
  756. struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  757. wait_for_xmitr(up);
  758. sio_out(up, TXX9_SITFIFO, ch);
  759. }
  760. /*
  761. * Print a string to the serial port trying not to disturb
  762. * any possible real use of the port...
  763. *
  764. * The console_lock must be held when we get here.
  765. */
  766. static void
  767. serial_txx9_console_write(struct console *co, const char *s, unsigned int count)
  768. {
  769. struct uart_txx9_port *up = &serial_txx9_ports[co->index];
  770. unsigned int ier, flcr;
  771. /*
  772. * First save the UER then disable the interrupts
  773. */
  774. ier = sio_in(up, TXX9_SIDICR);
  775. sio_out(up, TXX9_SIDICR, 0);
  776. /*
  777. * Disable flow-control if enabled (and unnecessary)
  778. */
  779. flcr = sio_in(up, TXX9_SIFLCR);
  780. if (!(up->port.flags & UPF_CONS_FLOW) && (flcr & TXX9_SIFLCR_TES))
  781. sio_out(up, TXX9_SIFLCR, flcr & ~TXX9_SIFLCR_TES);
  782. uart_console_write(&up->port, s, count, serial_txx9_console_putchar);
  783. /*
  784. * Finally, wait for transmitter to become empty
  785. * and restore the IER
  786. */
  787. wait_for_xmitr(up);
  788. sio_out(up, TXX9_SIFLCR, flcr);
  789. sio_out(up, TXX9_SIDICR, ier);
  790. }
  791. static int serial_txx9_console_setup(struct console *co, char *options)
  792. {
  793. struct uart_port *port;
  794. struct uart_txx9_port *up;
  795. int baud = 9600;
  796. int bits = 8;
  797. int parity = 'n';
  798. int flow = 'n';
  799. /*
  800. * Check whether an invalid uart number has been specified, and
  801. * if so, search for the first available port that does have
  802. * console support.
  803. */
  804. if (co->index >= UART_NR)
  805. co->index = 0;
  806. up = &serial_txx9_ports[co->index];
  807. port = &up->port;
  808. if (!port->ops)
  809. return -ENODEV;
  810. /*
  811. * Disable UART interrupts, set DTR and RTS high
  812. * and set speed.
  813. */
  814. sio_out(up, TXX9_SIDICR, 0);
  815. /* initial settings */
  816. sio_out(up, TXX9_SILCR,
  817. TXX9_SILCR_UMODE_8BIT | TXX9_SILCR_USBL_1BIT |
  818. ((port->flags & UPF_TXX9_USE_SCLK) ?
  819. TXX9_SILCR_SCS_SCLK_BG : TXX9_SILCR_SCS_IMCLK_BG));
  820. sio_out(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSTL_MAX /* 15 */);
  821. if (options)
  822. uart_parse_options(options, &baud, &parity, &bits, &flow);
  823. return uart_set_options(port, co, baud, parity, bits, flow);
  824. }
  825. static struct uart_driver serial_txx9_reg;
  826. static struct console serial_txx9_console = {
  827. .name = TXX9_TTY_NAME,
  828. .write = serial_txx9_console_write,
  829. .device = uart_console_device,
  830. .setup = serial_txx9_console_setup,
  831. .flags = CON_PRINTBUFFER,
  832. .index = -1,
  833. .data = &serial_txx9_reg,
  834. };
  835. static int __init serial_txx9_console_init(void)
  836. {
  837. register_console(&serial_txx9_console);
  838. return 0;
  839. }
  840. console_initcall(serial_txx9_console_init);
  841. #define SERIAL_TXX9_CONSOLE &serial_txx9_console
  842. #else
  843. #define SERIAL_TXX9_CONSOLE NULL
  844. #endif
  845. static struct uart_driver serial_txx9_reg = {
  846. .owner = THIS_MODULE,
  847. .driver_name = "serial_txx9",
  848. .devfs_name = TXX9_TTY_DEVFS_NAME,
  849. .dev_name = TXX9_TTY_NAME,
  850. .major = TXX9_TTY_MAJOR,
  851. .minor = TXX9_TTY_MINOR_START,
  852. .nr = UART_NR,
  853. .cons = SERIAL_TXX9_CONSOLE,
  854. };
  855. int __init early_serial_txx9_setup(struct uart_port *port)
  856. {
  857. if (port->line >= ARRAY_SIZE(serial_txx9_ports))
  858. return -ENODEV;
  859. serial_txx9_ports[port->line].port = *port;
  860. serial_txx9_ports[port->line].port.ops = &serial_txx9_pops;
  861. serial_txx9_ports[port->line].port.flags |= UPF_BOOT_AUTOCONF;
  862. return 0;
  863. }
  864. #ifdef ENABLE_SERIAL_TXX9_PCI
  865. /**
  866. * serial_txx9_suspend_port - suspend one serial port
  867. * @line: serial line number
  868. * @level: the level of port suspension, as per uart_suspend_port
  869. *
  870. * Suspend one serial port.
  871. */
  872. static void serial_txx9_suspend_port(int line)
  873. {
  874. uart_suspend_port(&serial_txx9_reg, &serial_txx9_ports[line].port);
  875. }
  876. /**
  877. * serial_txx9_resume_port - resume one serial port
  878. * @line: serial line number
  879. * @level: the level of port resumption, as per uart_resume_port
  880. *
  881. * Resume one serial port.
  882. */
  883. static void serial_txx9_resume_port(int line)
  884. {
  885. uart_resume_port(&serial_txx9_reg, &serial_txx9_ports[line].port);
  886. }
  887. static DEFINE_MUTEX(serial_txx9_mutex);
  888. /**
  889. * serial_txx9_register_port - register a serial port
  890. * @port: serial port template
  891. *
  892. * Configure the serial port specified by the request.
  893. *
  894. * The port is then probed and if necessary the IRQ is autodetected
  895. * If this fails an error is returned.
  896. *
  897. * On success the port is ready to use and the line number is returned.
  898. */
  899. static int __devinit serial_txx9_register_port(struct uart_port *port)
  900. {
  901. int i;
  902. struct uart_txx9_port *uart;
  903. int ret = -ENOSPC;
  904. mutex_lock(&serial_txx9_mutex);
  905. for (i = 0; i < UART_NR; i++) {
  906. uart = &serial_txx9_ports[i];
  907. if (!(uart->port.iobase || uart->port.mapbase))
  908. break;
  909. }
  910. if (i < UART_NR) {
  911. uart->port.iobase = port->iobase;
  912. uart->port.membase = port->membase;
  913. uart->port.irq = port->irq;
  914. uart->port.uartclk = port->uartclk;
  915. uart->port.iotype = port->iotype;
  916. uart->port.flags = port->flags | UPF_BOOT_AUTOCONF;
  917. uart->port.mapbase = port->mapbase;
  918. if (port->dev)
  919. uart->port.dev = port->dev;
  920. ret = uart_add_one_port(&serial_txx9_reg, &uart->port);
  921. if (ret == 0)
  922. ret = uart->port.line;
  923. }
  924. mutex_unlock(&serial_txx9_mutex);
  925. return ret;
  926. }
  927. /**
  928. * serial_txx9_unregister_port - remove a txx9 serial port at runtime
  929. * @line: serial line number
  930. *
  931. * Remove one serial port. This may not be called from interrupt
  932. * context. We hand the port back to the our control.
  933. */
  934. static void __devexit serial_txx9_unregister_port(int line)
  935. {
  936. struct uart_txx9_port *uart = &serial_txx9_ports[line];
  937. mutex_lock(&serial_txx9_mutex);
  938. uart_remove_one_port(&serial_txx9_reg, &uart->port);
  939. uart->port.flags = 0;
  940. uart->port.type = PORT_UNKNOWN;
  941. uart->port.iobase = 0;
  942. uart->port.mapbase = 0;
  943. uart->port.membase = NULL;
  944. uart->port.dev = NULL;
  945. mutex_unlock(&serial_txx9_mutex);
  946. }
  947. /*
  948. * Probe one serial board. Unfortunately, there is no rhyme nor reason
  949. * to the arrangement of serial ports on a PCI card.
  950. */
  951. static int __devinit
  952. pciserial_txx9_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
  953. {
  954. struct uart_port port;
  955. int line;
  956. int rc;
  957. rc = pci_enable_device(dev);
  958. if (rc)
  959. return rc;
  960. memset(&port, 0, sizeof(port));
  961. port.ops = &serial_txx9_pops;
  962. port.flags |= UPF_TXX9_HAVE_CTS_LINE;
  963. port.uartclk = 66670000;
  964. port.irq = dev->irq;
  965. port.iotype = UPIO_PORT;
  966. port.iobase = pci_resource_start(dev, 1);
  967. port.dev = &dev->dev;
  968. line = serial_txx9_register_port(&port);
  969. if (line < 0) {
  970. printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), line);
  971. }
  972. pci_set_drvdata(dev, (void *)(long)line);
  973. return 0;
  974. }
  975. static void __devexit pciserial_txx9_remove_one(struct pci_dev *dev)
  976. {
  977. int line = (int)(long)pci_get_drvdata(dev);
  978. pci_set_drvdata(dev, NULL);
  979. if (line) {
  980. serial_txx9_unregister_port(line);
  981. pci_disable_device(dev);
  982. }
  983. }
  984. static int pciserial_txx9_suspend_one(struct pci_dev *dev, pm_message_t state)
  985. {
  986. int line = (int)(long)pci_get_drvdata(dev);
  987. if (line)
  988. serial_txx9_suspend_port(line);
  989. pci_save_state(dev);
  990. pci_set_power_state(dev, pci_choose_state(dev, state));
  991. return 0;
  992. }
  993. static int pciserial_txx9_resume_one(struct pci_dev *dev)
  994. {
  995. int line = (int)(long)pci_get_drvdata(dev);
  996. pci_set_power_state(dev, PCI_D0);
  997. pci_restore_state(dev);
  998. if (line) {
  999. pci_enable_device(dev);
  1000. serial_txx9_resume_port(line);
  1001. }
  1002. return 0;
  1003. }
  1004. static struct pci_device_id serial_txx9_pci_tbl[] = {
  1005. { PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_TC86C001_MISC,
  1006. PCI_ANY_ID, PCI_ANY_ID,
  1007. 0, 0, 0 },
  1008. { 0, }
  1009. };
  1010. static struct pci_driver serial_txx9_pci_driver = {
  1011. .name = "serial_txx9",
  1012. .probe = pciserial_txx9_init_one,
  1013. .remove = __devexit_p(pciserial_txx9_remove_one),
  1014. .suspend = pciserial_txx9_suspend_one,
  1015. .resume = pciserial_txx9_resume_one,
  1016. .id_table = serial_txx9_pci_tbl,
  1017. };
  1018. MODULE_DEVICE_TABLE(pci, serial_txx9_pci_tbl);
  1019. #endif /* ENABLE_SERIAL_TXX9_PCI */
  1020. static int __init serial_txx9_init(void)
  1021. {
  1022. int ret;
  1023. printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
  1024. ret = uart_register_driver(&serial_txx9_reg);
  1025. if (ret >= 0) {
  1026. serial_txx9_register_ports(&serial_txx9_reg);
  1027. #ifdef ENABLE_SERIAL_TXX9_PCI
  1028. ret = pci_register_driver(&serial_txx9_pci_driver);
  1029. #endif
  1030. }
  1031. return ret;
  1032. }
  1033. static void __exit serial_txx9_exit(void)
  1034. {
  1035. int i;
  1036. #ifdef ENABLE_SERIAL_TXX9_PCI
  1037. pci_unregister_driver(&serial_txx9_pci_driver);
  1038. #endif
  1039. for (i = 0; i < UART_NR; i++) {
  1040. struct uart_txx9_port *up = &serial_txx9_ports[i];
  1041. if (up->port.iobase || up->port.mapbase)
  1042. uart_remove_one_port(&serial_txx9_reg, &up->port);
  1043. }
  1044. uart_unregister_driver(&serial_txx9_reg);
  1045. }
  1046. module_init(serial_txx9_init);
  1047. module_exit(serial_txx9_exit);
  1048. MODULE_LICENSE("GPL");
  1049. MODULE_DESCRIPTION("TX39/49 serial driver");
  1050. MODULE_ALIAS_CHARDEV_MAJOR(TXX9_TTY_MAJOR);