serial_txx9.c 33 KB

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