serial_txx9.c 32 KB

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