serial_txx9.c 31 KB

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