serial_txx9.c 32 KB

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