serial_txx9.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  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. unsigned char ch;
  250. unsigned int disr = *status;
  251. int max_count = 256;
  252. char flag;
  253. unsigned int next_ignore_status_mask;
  254. do {
  255. ch = sio_in(up, TXX9_SIRFIFO);
  256. flag = TTY_NORMAL;
  257. up->port.icount.rx++;
  258. /* mask out RFDN_MASK bit added by previous overrun */
  259. next_ignore_status_mask =
  260. up->port.ignore_status_mask & ~TXX9_SIDISR_RFDN_MASK;
  261. if (unlikely(disr & (TXX9_SIDISR_UBRK | TXX9_SIDISR_UPER |
  262. TXX9_SIDISR_UFER | TXX9_SIDISR_UOER))) {
  263. /*
  264. * For statistics only
  265. */
  266. if (disr & TXX9_SIDISR_UBRK) {
  267. disr &= ~(TXX9_SIDISR_UFER | TXX9_SIDISR_UPER);
  268. up->port.icount.brk++;
  269. /*
  270. * We do the SysRQ and SAK checking
  271. * here because otherwise the break
  272. * may get masked by ignore_status_mask
  273. * or read_status_mask.
  274. */
  275. if (uart_handle_break(&up->port))
  276. goto ignore_char;
  277. } else if (disr & TXX9_SIDISR_UPER)
  278. up->port.icount.parity++;
  279. else if (disr & TXX9_SIDISR_UFER)
  280. up->port.icount.frame++;
  281. if (disr & TXX9_SIDISR_UOER) {
  282. up->port.icount.overrun++;
  283. /*
  284. * The receiver read buffer still hold
  285. * a char which caused overrun.
  286. * Ignore next char by adding RFDN_MASK
  287. * to ignore_status_mask temporarily.
  288. */
  289. next_ignore_status_mask |=
  290. TXX9_SIDISR_RFDN_MASK;
  291. }
  292. /*
  293. * Mask off conditions which should be ingored.
  294. */
  295. disr &= up->port.read_status_mask;
  296. if (disr & TXX9_SIDISR_UBRK) {
  297. flag = TTY_BREAK;
  298. } else if (disr & TXX9_SIDISR_UPER)
  299. flag = TTY_PARITY;
  300. else if (disr & TXX9_SIDISR_UFER)
  301. flag = TTY_FRAME;
  302. }
  303. if (uart_handle_sysrq_char(&up->port, ch))
  304. goto ignore_char;
  305. uart_insert_char(&up->port, disr, TXX9_SIDISR_UOER, ch, flag);
  306. ignore_char:
  307. up->port.ignore_status_mask = next_ignore_status_mask;
  308. disr = sio_in(up, TXX9_SIDISR);
  309. } while (!(disr & TXX9_SIDISR_UVALID) && (max_count-- > 0));
  310. spin_unlock(&up->port.lock);
  311. tty_flip_buffer_push(&up->port.state->port);
  312. spin_lock(&up->port.lock);
  313. *status = disr;
  314. }
  315. static inline void transmit_chars(struct uart_txx9_port *up)
  316. {
  317. struct circ_buf *xmit = &up->port.state->xmit;
  318. int count;
  319. if (up->port.x_char) {
  320. sio_out(up, TXX9_SITFIFO, up->port.x_char);
  321. up->port.icount.tx++;
  322. up->port.x_char = 0;
  323. return;
  324. }
  325. if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
  326. serial_txx9_stop_tx(&up->port);
  327. return;
  328. }
  329. count = TXX9_SIO_TX_FIFO;
  330. do {
  331. sio_out(up, TXX9_SITFIFO, xmit->buf[xmit->tail]);
  332. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  333. up->port.icount.tx++;
  334. if (uart_circ_empty(xmit))
  335. break;
  336. } while (--count > 0);
  337. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  338. uart_write_wakeup(&up->port);
  339. if (uart_circ_empty(xmit))
  340. serial_txx9_stop_tx(&up->port);
  341. }
  342. static irqreturn_t serial_txx9_interrupt(int irq, void *dev_id)
  343. {
  344. int pass_counter = 0;
  345. struct uart_txx9_port *up = dev_id;
  346. unsigned int status;
  347. while (1) {
  348. spin_lock(&up->port.lock);
  349. status = sio_in(up, TXX9_SIDISR);
  350. if (!(sio_in(up, TXX9_SIDICR) & TXX9_SIDICR_TIE))
  351. status &= ~TXX9_SIDISR_TDIS;
  352. if (!(status & (TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS |
  353. TXX9_SIDISR_TOUT))) {
  354. spin_unlock(&up->port.lock);
  355. break;
  356. }
  357. if (status & TXX9_SIDISR_RDIS)
  358. receive_chars(up, &status);
  359. if (status & TXX9_SIDISR_TDIS)
  360. transmit_chars(up);
  361. /* Clear TX/RX Int. Status */
  362. sio_mask(up, TXX9_SIDISR,
  363. TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS |
  364. TXX9_SIDISR_TOUT);
  365. spin_unlock(&up->port.lock);
  366. if (pass_counter++ > PASS_LIMIT)
  367. break;
  368. }
  369. return pass_counter ? IRQ_HANDLED : IRQ_NONE;
  370. }
  371. static unsigned int serial_txx9_tx_empty(struct uart_port *port)
  372. {
  373. struct uart_txx9_port *up = to_uart_txx9_port(port);
  374. unsigned long flags;
  375. unsigned int ret;
  376. spin_lock_irqsave(&up->port.lock, flags);
  377. ret = (sio_in(up, TXX9_SICISR) & TXX9_SICISR_TXALS) ? TIOCSER_TEMT : 0;
  378. spin_unlock_irqrestore(&up->port.lock, flags);
  379. return ret;
  380. }
  381. static unsigned int serial_txx9_get_mctrl(struct uart_port *port)
  382. {
  383. struct uart_txx9_port *up = to_uart_txx9_port(port);
  384. unsigned int ret;
  385. /* no modem control lines */
  386. ret = TIOCM_CAR | TIOCM_DSR;
  387. ret |= (sio_in(up, TXX9_SIFLCR) & TXX9_SIFLCR_RTSSC) ? 0 : TIOCM_RTS;
  388. ret |= (sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS) ? 0 : TIOCM_CTS;
  389. return ret;
  390. }
  391. static void serial_txx9_set_mctrl(struct uart_port *port, unsigned int mctrl)
  392. {
  393. struct uart_txx9_port *up = to_uart_txx9_port(port);
  394. if (mctrl & TIOCM_RTS)
  395. sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSSC);
  396. else
  397. sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSSC);
  398. }
  399. static void serial_txx9_break_ctl(struct uart_port *port, int break_state)
  400. {
  401. struct uart_txx9_port *up = to_uart_txx9_port(port);
  402. unsigned long flags;
  403. spin_lock_irqsave(&up->port.lock, flags);
  404. if (break_state == -1)
  405. sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
  406. else
  407. sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
  408. spin_unlock_irqrestore(&up->port.lock, flags);
  409. }
  410. #if defined(CONFIG_SERIAL_TXX9_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
  411. /*
  412. * Wait for transmitter & holding register to empty
  413. */
  414. static void wait_for_xmitr(struct uart_txx9_port *up)
  415. {
  416. unsigned int tmout = 10000;
  417. /* Wait up to 10ms for the character(s) to be sent. */
  418. while (--tmout &&
  419. !(sio_in(up, TXX9_SICISR) & TXX9_SICISR_TXALS))
  420. udelay(1);
  421. /* Wait up to 1s for flow control if necessary */
  422. if (up->port.flags & UPF_CONS_FLOW) {
  423. tmout = 1000000;
  424. while (--tmout &&
  425. (sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS))
  426. udelay(1);
  427. }
  428. }
  429. #endif
  430. #ifdef CONFIG_CONSOLE_POLL
  431. /*
  432. * Console polling routines for writing and reading from the uart while
  433. * in an interrupt or debug context.
  434. */
  435. static int serial_txx9_get_poll_char(struct uart_port *port)
  436. {
  437. unsigned int ier;
  438. unsigned char c;
  439. struct uart_txx9_port *up = to_uart_txx9_port(port);
  440. /*
  441. * First save the IER then disable the interrupts
  442. */
  443. ier = sio_in(up, TXX9_SIDICR);
  444. sio_out(up, TXX9_SIDICR, 0);
  445. while (sio_in(up, TXX9_SIDISR) & TXX9_SIDISR_UVALID)
  446. ;
  447. c = sio_in(up, TXX9_SIRFIFO);
  448. /*
  449. * Finally, clear RX interrupt status
  450. * and restore the IER
  451. */
  452. sio_mask(up, TXX9_SIDISR, TXX9_SIDISR_RDIS);
  453. sio_out(up, TXX9_SIDICR, ier);
  454. return c;
  455. }
  456. static void serial_txx9_put_poll_char(struct uart_port *port, unsigned char c)
  457. {
  458. unsigned int ier;
  459. struct uart_txx9_port *up = to_uart_txx9_port(port);
  460. /*
  461. * First save the IER then disable the interrupts
  462. */
  463. ier = sio_in(up, TXX9_SIDICR);
  464. sio_out(up, TXX9_SIDICR, 0);
  465. wait_for_xmitr(up);
  466. /*
  467. * Send the character out.
  468. */
  469. sio_out(up, TXX9_SITFIFO, c);
  470. /*
  471. * Finally, wait for transmitter to become empty
  472. * and restore the IER
  473. */
  474. wait_for_xmitr(up);
  475. sio_out(up, TXX9_SIDICR, ier);
  476. }
  477. #endif /* CONFIG_CONSOLE_POLL */
  478. static int serial_txx9_startup(struct uart_port *port)
  479. {
  480. struct uart_txx9_port *up = to_uart_txx9_port(port);
  481. unsigned long flags;
  482. int retval;
  483. /*
  484. * Clear the FIFO buffers and disable them.
  485. * (they will be reenabled in set_termios())
  486. */
  487. sio_set(up, TXX9_SIFCR,
  488. TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  489. /* clear reset */
  490. sio_mask(up, TXX9_SIFCR,
  491. TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  492. sio_out(up, TXX9_SIDICR, 0);
  493. /*
  494. * Clear the interrupt registers.
  495. */
  496. sio_out(up, TXX9_SIDISR, 0);
  497. retval = request_irq(up->port.irq, serial_txx9_interrupt,
  498. IRQF_SHARED, "serial_txx9", up);
  499. if (retval)
  500. return retval;
  501. /*
  502. * Now, initialize the UART
  503. */
  504. spin_lock_irqsave(&up->port.lock, flags);
  505. serial_txx9_set_mctrl(&up->port, up->port.mctrl);
  506. spin_unlock_irqrestore(&up->port.lock, flags);
  507. /* Enable RX/TX */
  508. sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_RSDE | TXX9_SIFLCR_TSDE);
  509. /*
  510. * Finally, enable interrupts.
  511. */
  512. sio_set(up, TXX9_SIDICR, TXX9_SIDICR_RIE);
  513. return 0;
  514. }
  515. static void serial_txx9_shutdown(struct uart_port *port)
  516. {
  517. struct uart_txx9_port *up = to_uart_txx9_port(port);
  518. unsigned long flags;
  519. /*
  520. * Disable interrupts from this port
  521. */
  522. sio_out(up, TXX9_SIDICR, 0); /* disable all intrs */
  523. spin_lock_irqsave(&up->port.lock, flags);
  524. serial_txx9_set_mctrl(&up->port, up->port.mctrl);
  525. spin_unlock_irqrestore(&up->port.lock, flags);
  526. /*
  527. * Disable break condition
  528. */
  529. sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
  530. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  531. if (up->port.cons && up->port.line == up->port.cons->index) {
  532. free_irq(up->port.irq, up);
  533. return;
  534. }
  535. #endif
  536. /* reset FIFOs */
  537. sio_set(up, TXX9_SIFCR,
  538. TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  539. /* clear reset */
  540. sio_mask(up, TXX9_SIFCR,
  541. TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  542. /* Disable RX/TX */
  543. sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_RSDE | TXX9_SIFLCR_TSDE);
  544. free_irq(up->port.irq, up);
  545. }
  546. static void
  547. serial_txx9_set_termios(struct uart_port *port, struct ktermios *termios,
  548. struct ktermios *old)
  549. {
  550. struct uart_txx9_port *up = to_uart_txx9_port(port);
  551. unsigned int cval, fcr = 0;
  552. unsigned long flags;
  553. unsigned int baud, quot;
  554. /*
  555. * We don't support modem control lines.
  556. */
  557. termios->c_cflag &= ~(HUPCL | CMSPAR);
  558. termios->c_cflag |= CLOCAL;
  559. cval = sio_in(up, TXX9_SILCR);
  560. /* byte size and parity */
  561. cval &= ~TXX9_SILCR_UMODE_MASK;
  562. switch (termios->c_cflag & CSIZE) {
  563. case CS7:
  564. cval |= TXX9_SILCR_UMODE_7BIT;
  565. break;
  566. default:
  567. case CS5: /* not supported */
  568. case CS6: /* not supported */
  569. case CS8:
  570. cval |= TXX9_SILCR_UMODE_8BIT;
  571. break;
  572. }
  573. cval &= ~TXX9_SILCR_USBL_MASK;
  574. if (termios->c_cflag & CSTOPB)
  575. cval |= TXX9_SILCR_USBL_2BIT;
  576. else
  577. cval |= TXX9_SILCR_USBL_1BIT;
  578. cval &= ~(TXX9_SILCR_UPEN | TXX9_SILCR_UEPS);
  579. if (termios->c_cflag & PARENB)
  580. cval |= TXX9_SILCR_UPEN;
  581. if (!(termios->c_cflag & PARODD))
  582. cval |= TXX9_SILCR_UEPS;
  583. /*
  584. * Ask the core to calculate the divisor for us.
  585. */
  586. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16/2);
  587. quot = uart_get_divisor(port, baud);
  588. /* Set up FIFOs */
  589. /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
  590. fcr = TXX9_SIFCR_TDIL_MAX | TXX9_SIFCR_RDIL_1;
  591. /*
  592. * Ok, we're now changing the port state. Do it with
  593. * interrupts disabled.
  594. */
  595. spin_lock_irqsave(&up->port.lock, flags);
  596. /*
  597. * Update the per-port timeout.
  598. */
  599. uart_update_timeout(port, termios->c_cflag, baud);
  600. up->port.read_status_mask = TXX9_SIDISR_UOER |
  601. TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS;
  602. if (termios->c_iflag & INPCK)
  603. up->port.read_status_mask |= TXX9_SIDISR_UFER | TXX9_SIDISR_UPER;
  604. if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
  605. up->port.read_status_mask |= TXX9_SIDISR_UBRK;
  606. /*
  607. * Characteres to ignore
  608. */
  609. up->port.ignore_status_mask = 0;
  610. if (termios->c_iflag & IGNPAR)
  611. up->port.ignore_status_mask |= TXX9_SIDISR_UPER | TXX9_SIDISR_UFER;
  612. if (termios->c_iflag & IGNBRK) {
  613. up->port.ignore_status_mask |= TXX9_SIDISR_UBRK;
  614. /*
  615. * If we're ignoring parity and break indicators,
  616. * ignore overruns too (for real raw support).
  617. */
  618. if (termios->c_iflag & IGNPAR)
  619. up->port.ignore_status_mask |= TXX9_SIDISR_UOER;
  620. }
  621. /*
  622. * ignore all characters if CREAD is not set
  623. */
  624. if ((termios->c_cflag & CREAD) == 0)
  625. up->port.ignore_status_mask |= TXX9_SIDISR_RDIS;
  626. /* CTS flow control flag */
  627. if ((termios->c_cflag & CRTSCTS) &&
  628. (up->port.flags & UPF_TXX9_HAVE_CTS_LINE)) {
  629. sio_set(up, TXX9_SIFLCR,
  630. TXX9_SIFLCR_RCS | TXX9_SIFLCR_TES);
  631. } else {
  632. sio_mask(up, TXX9_SIFLCR,
  633. TXX9_SIFLCR_RCS | TXX9_SIFLCR_TES);
  634. }
  635. sio_out(up, TXX9_SILCR, cval);
  636. sio_quot_set(up, quot);
  637. sio_out(up, TXX9_SIFCR, fcr);
  638. serial_txx9_set_mctrl(&up->port, up->port.mctrl);
  639. spin_unlock_irqrestore(&up->port.lock, flags);
  640. }
  641. static void
  642. serial_txx9_pm(struct uart_port *port, unsigned int state,
  643. unsigned int oldstate)
  644. {
  645. /*
  646. * If oldstate was -1 this is called from
  647. * uart_configure_port(). In this case do not initialize the
  648. * port now, because the port was already initialized (for
  649. * non-console port) or should not be initialized here (for
  650. * console port). If we initialized the port here we lose
  651. * serial console settings.
  652. */
  653. if (state == 0 && oldstate != -1)
  654. serial_txx9_initialize(port);
  655. }
  656. static int serial_txx9_request_resource(struct uart_txx9_port *up)
  657. {
  658. unsigned int size = TXX9_REGION_SIZE;
  659. int ret = 0;
  660. switch (up->port.iotype) {
  661. default:
  662. if (!up->port.mapbase)
  663. break;
  664. if (!request_mem_region(up->port.mapbase, size, "serial_txx9")) {
  665. ret = -EBUSY;
  666. break;
  667. }
  668. if (up->port.flags & UPF_IOREMAP) {
  669. up->port.membase = ioremap(up->port.mapbase, size);
  670. if (!up->port.membase) {
  671. release_mem_region(up->port.mapbase, size);
  672. ret = -ENOMEM;
  673. }
  674. }
  675. break;
  676. case UPIO_PORT:
  677. if (!request_region(up->port.iobase, size, "serial_txx9"))
  678. ret = -EBUSY;
  679. break;
  680. }
  681. return ret;
  682. }
  683. static void serial_txx9_release_resource(struct uart_txx9_port *up)
  684. {
  685. unsigned int size = TXX9_REGION_SIZE;
  686. switch (up->port.iotype) {
  687. default:
  688. if (!up->port.mapbase)
  689. break;
  690. if (up->port.flags & UPF_IOREMAP) {
  691. iounmap(up->port.membase);
  692. up->port.membase = NULL;
  693. }
  694. release_mem_region(up->port.mapbase, size);
  695. break;
  696. case UPIO_PORT:
  697. release_region(up->port.iobase, size);
  698. break;
  699. }
  700. }
  701. static void serial_txx9_release_port(struct uart_port *port)
  702. {
  703. struct uart_txx9_port *up = to_uart_txx9_port(port);
  704. serial_txx9_release_resource(up);
  705. }
  706. static int serial_txx9_request_port(struct uart_port *port)
  707. {
  708. struct uart_txx9_port *up = to_uart_txx9_port(port);
  709. return serial_txx9_request_resource(up);
  710. }
  711. static void serial_txx9_config_port(struct uart_port *port, int uflags)
  712. {
  713. struct uart_txx9_port *up = to_uart_txx9_port(port);
  714. int ret;
  715. /*
  716. * Find the region that we can probe for. This in turn
  717. * tells us whether we can probe for the type of port.
  718. */
  719. ret = serial_txx9_request_resource(up);
  720. if (ret < 0)
  721. return;
  722. port->type = PORT_TXX9;
  723. up->port.fifosize = TXX9_SIO_TX_FIFO;
  724. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  725. if (up->port.line == up->port.cons->index)
  726. return;
  727. #endif
  728. serial_txx9_initialize(port);
  729. }
  730. static const char *
  731. serial_txx9_type(struct uart_port *port)
  732. {
  733. return "txx9";
  734. }
  735. static struct uart_ops serial_txx9_pops = {
  736. .tx_empty = serial_txx9_tx_empty,
  737. .set_mctrl = serial_txx9_set_mctrl,
  738. .get_mctrl = serial_txx9_get_mctrl,
  739. .stop_tx = serial_txx9_stop_tx,
  740. .start_tx = serial_txx9_start_tx,
  741. .stop_rx = serial_txx9_stop_rx,
  742. .enable_ms = serial_txx9_enable_ms,
  743. .break_ctl = serial_txx9_break_ctl,
  744. .startup = serial_txx9_startup,
  745. .shutdown = serial_txx9_shutdown,
  746. .set_termios = serial_txx9_set_termios,
  747. .pm = serial_txx9_pm,
  748. .type = serial_txx9_type,
  749. .release_port = serial_txx9_release_port,
  750. .request_port = serial_txx9_request_port,
  751. .config_port = serial_txx9_config_port,
  752. #ifdef CONFIG_CONSOLE_POLL
  753. .poll_get_char = serial_txx9_get_poll_char,
  754. .poll_put_char = serial_txx9_put_poll_char,
  755. #endif
  756. };
  757. static struct uart_txx9_port serial_txx9_ports[UART_NR];
  758. static void __init serial_txx9_register_ports(struct uart_driver *drv,
  759. struct device *dev)
  760. {
  761. int i;
  762. for (i = 0; i < UART_NR; i++) {
  763. struct uart_txx9_port *up = &serial_txx9_ports[i];
  764. up->port.line = i;
  765. up->port.ops = &serial_txx9_pops;
  766. up->port.dev = dev;
  767. if (up->port.iobase || up->port.mapbase)
  768. uart_add_one_port(drv, &up->port);
  769. }
  770. }
  771. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  772. static void serial_txx9_console_putchar(struct uart_port *port, int ch)
  773. {
  774. struct uart_txx9_port *up = to_uart_txx9_port(port);
  775. wait_for_xmitr(up);
  776. sio_out(up, TXX9_SITFIFO, ch);
  777. }
  778. /*
  779. * Print a string to the serial port trying not to disturb
  780. * any possible real use of the port...
  781. *
  782. * The console_lock must be held when we get here.
  783. */
  784. static void
  785. serial_txx9_console_write(struct console *co, const char *s, unsigned int count)
  786. {
  787. struct uart_txx9_port *up = &serial_txx9_ports[co->index];
  788. unsigned int ier, flcr;
  789. /*
  790. * First save the UER then disable the interrupts
  791. */
  792. ier = sio_in(up, TXX9_SIDICR);
  793. sio_out(up, TXX9_SIDICR, 0);
  794. /*
  795. * Disable flow-control if enabled (and unnecessary)
  796. */
  797. flcr = sio_in(up, TXX9_SIFLCR);
  798. if (!(up->port.flags & UPF_CONS_FLOW) && (flcr & TXX9_SIFLCR_TES))
  799. sio_out(up, TXX9_SIFLCR, flcr & ~TXX9_SIFLCR_TES);
  800. uart_console_write(&up->port, s, count, serial_txx9_console_putchar);
  801. /*
  802. * Finally, wait for transmitter to become empty
  803. * and restore the IER
  804. */
  805. wait_for_xmitr(up);
  806. sio_out(up, TXX9_SIFLCR, flcr);
  807. sio_out(up, TXX9_SIDICR, ier);
  808. }
  809. static int __init serial_txx9_console_setup(struct console *co, char *options)
  810. {
  811. struct uart_port *port;
  812. struct uart_txx9_port *up;
  813. int baud = 9600;
  814. int bits = 8;
  815. int parity = 'n';
  816. int flow = 'n';
  817. /*
  818. * Check whether an invalid uart number has been specified, and
  819. * if so, search for the first available port that does have
  820. * console support.
  821. */
  822. if (co->index >= UART_NR)
  823. co->index = 0;
  824. up = &serial_txx9_ports[co->index];
  825. port = &up->port;
  826. if (!port->ops)
  827. return -ENODEV;
  828. serial_txx9_initialize(&up->port);
  829. if (options)
  830. uart_parse_options(options, &baud, &parity, &bits, &flow);
  831. return uart_set_options(port, co, baud, parity, bits, flow);
  832. }
  833. static struct uart_driver serial_txx9_reg;
  834. static struct console serial_txx9_console = {
  835. .name = TXX9_TTY_NAME,
  836. .write = serial_txx9_console_write,
  837. .device = uart_console_device,
  838. .setup = serial_txx9_console_setup,
  839. .flags = CON_PRINTBUFFER,
  840. .index = -1,
  841. .data = &serial_txx9_reg,
  842. };
  843. static int __init serial_txx9_console_init(void)
  844. {
  845. register_console(&serial_txx9_console);
  846. return 0;
  847. }
  848. console_initcall(serial_txx9_console_init);
  849. #define SERIAL_TXX9_CONSOLE &serial_txx9_console
  850. #else
  851. #define SERIAL_TXX9_CONSOLE NULL
  852. #endif
  853. static struct uart_driver serial_txx9_reg = {
  854. .owner = THIS_MODULE,
  855. .driver_name = "serial_txx9",
  856. .dev_name = TXX9_TTY_NAME,
  857. .major = TXX9_TTY_MAJOR,
  858. .minor = TXX9_TTY_MINOR_START,
  859. .nr = UART_NR,
  860. .cons = SERIAL_TXX9_CONSOLE,
  861. };
  862. int __init early_serial_txx9_setup(struct uart_port *port)
  863. {
  864. if (port->line >= ARRAY_SIZE(serial_txx9_ports))
  865. return -ENODEV;
  866. serial_txx9_ports[port->line].port = *port;
  867. serial_txx9_ports[port->line].port.ops = &serial_txx9_pops;
  868. serial_txx9_ports[port->line].port.flags |=
  869. UPF_BOOT_AUTOCONF | UPF_FIXED_PORT;
  870. return 0;
  871. }
  872. static DEFINE_MUTEX(serial_txx9_mutex);
  873. /**
  874. * serial_txx9_register_port - register a serial port
  875. * @port: serial port template
  876. *
  877. * Configure the serial port specified by the request.
  878. *
  879. * The port is then probed and if necessary the IRQ is autodetected
  880. * If this fails an error is returned.
  881. *
  882. * On success the port is ready to use and the line number is returned.
  883. */
  884. static int serial_txx9_register_port(struct uart_port *port)
  885. {
  886. int i;
  887. struct uart_txx9_port *uart;
  888. int ret = -ENOSPC;
  889. mutex_lock(&serial_txx9_mutex);
  890. for (i = 0; i < UART_NR; i++) {
  891. uart = &serial_txx9_ports[i];
  892. if (uart_match_port(&uart->port, port)) {
  893. uart_remove_one_port(&serial_txx9_reg, &uart->port);
  894. break;
  895. }
  896. }
  897. if (i == UART_NR) {
  898. /* Find unused port */
  899. for (i = 0; i < UART_NR; i++) {
  900. uart = &serial_txx9_ports[i];
  901. if (!(uart->port.iobase || uart->port.mapbase))
  902. break;
  903. }
  904. }
  905. if (i < UART_NR) {
  906. uart->port.iobase = port->iobase;
  907. uart->port.membase = port->membase;
  908. uart->port.irq = port->irq;
  909. uart->port.uartclk = port->uartclk;
  910. uart->port.iotype = port->iotype;
  911. uart->port.flags = port->flags
  912. | UPF_BOOT_AUTOCONF | UPF_FIXED_PORT;
  913. uart->port.mapbase = port->mapbase;
  914. if (port->dev)
  915. uart->port.dev = port->dev;
  916. ret = uart_add_one_port(&serial_txx9_reg, &uart->port);
  917. if (ret == 0)
  918. ret = uart->port.line;
  919. }
  920. mutex_unlock(&serial_txx9_mutex);
  921. return ret;
  922. }
  923. /**
  924. * serial_txx9_unregister_port - remove a txx9 serial port at runtime
  925. * @line: serial line number
  926. *
  927. * Remove one serial port. This may not be called from interrupt
  928. * context. We hand the port back to the our control.
  929. */
  930. static void serial_txx9_unregister_port(int line)
  931. {
  932. struct uart_txx9_port *uart = &serial_txx9_ports[line];
  933. mutex_lock(&serial_txx9_mutex);
  934. uart_remove_one_port(&serial_txx9_reg, &uart->port);
  935. uart->port.flags = 0;
  936. uart->port.type = PORT_UNKNOWN;
  937. uart->port.iobase = 0;
  938. uart->port.mapbase = 0;
  939. uart->port.membase = NULL;
  940. uart->port.dev = NULL;
  941. mutex_unlock(&serial_txx9_mutex);
  942. }
  943. /*
  944. * Register a set of serial devices attached to a platform device.
  945. */
  946. static int serial_txx9_probe(struct platform_device *dev)
  947. {
  948. struct uart_port *p = dev_get_platdata(&dev->dev);
  949. struct uart_port port;
  950. int ret, i;
  951. memset(&port, 0, sizeof(struct uart_port));
  952. for (i = 0; p && p->uartclk != 0; p++, i++) {
  953. port.iobase = p->iobase;
  954. port.membase = p->membase;
  955. port.irq = p->irq;
  956. port.uartclk = p->uartclk;
  957. port.iotype = p->iotype;
  958. port.flags = p->flags;
  959. port.mapbase = p->mapbase;
  960. port.dev = &dev->dev;
  961. ret = serial_txx9_register_port(&port);
  962. if (ret < 0) {
  963. dev_err(&dev->dev, "unable to register port at index %d "
  964. "(IO%lx MEM%llx IRQ%d): %d\n", i,
  965. p->iobase, (unsigned long long)p->mapbase,
  966. p->irq, ret);
  967. }
  968. }
  969. return 0;
  970. }
  971. /*
  972. * Remove serial ports registered against a platform device.
  973. */
  974. static int serial_txx9_remove(struct platform_device *dev)
  975. {
  976. int i;
  977. for (i = 0; i < UART_NR; i++) {
  978. struct uart_txx9_port *up = &serial_txx9_ports[i];
  979. if (up->port.dev == &dev->dev)
  980. serial_txx9_unregister_port(i);
  981. }
  982. return 0;
  983. }
  984. #ifdef CONFIG_PM
  985. static int serial_txx9_suspend(struct platform_device *dev, pm_message_t state)
  986. {
  987. int i;
  988. for (i = 0; i < UART_NR; i++) {
  989. struct uart_txx9_port *up = &serial_txx9_ports[i];
  990. if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
  991. uart_suspend_port(&serial_txx9_reg, &up->port);
  992. }
  993. return 0;
  994. }
  995. static int serial_txx9_resume(struct platform_device *dev)
  996. {
  997. int i;
  998. for (i = 0; i < UART_NR; i++) {
  999. struct uart_txx9_port *up = &serial_txx9_ports[i];
  1000. if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
  1001. uart_resume_port(&serial_txx9_reg, &up->port);
  1002. }
  1003. return 0;
  1004. }
  1005. #endif
  1006. static struct platform_driver serial_txx9_plat_driver = {
  1007. .probe = serial_txx9_probe,
  1008. .remove = serial_txx9_remove,
  1009. #ifdef CONFIG_PM
  1010. .suspend = serial_txx9_suspend,
  1011. .resume = serial_txx9_resume,
  1012. #endif
  1013. .driver = {
  1014. .name = "serial_txx9",
  1015. .owner = THIS_MODULE,
  1016. },
  1017. };
  1018. #ifdef ENABLE_SERIAL_TXX9_PCI
  1019. /*
  1020. * Probe one serial board. Unfortunately, there is no rhyme nor reason
  1021. * to the arrangement of serial ports on a PCI card.
  1022. */
  1023. static int
  1024. pciserial_txx9_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
  1025. {
  1026. struct uart_port port;
  1027. int line;
  1028. int rc;
  1029. rc = pci_enable_device(dev);
  1030. if (rc)
  1031. return rc;
  1032. memset(&port, 0, sizeof(port));
  1033. port.ops = &serial_txx9_pops;
  1034. port.flags |= UPF_TXX9_HAVE_CTS_LINE;
  1035. port.uartclk = 66670000;
  1036. port.irq = dev->irq;
  1037. port.iotype = UPIO_PORT;
  1038. port.iobase = pci_resource_start(dev, 1);
  1039. port.dev = &dev->dev;
  1040. line = serial_txx9_register_port(&port);
  1041. if (line < 0) {
  1042. printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), line);
  1043. pci_disable_device(dev);
  1044. return line;
  1045. }
  1046. pci_set_drvdata(dev, &serial_txx9_ports[line]);
  1047. return 0;
  1048. }
  1049. static void pciserial_txx9_remove_one(struct pci_dev *dev)
  1050. {
  1051. struct uart_txx9_port *up = pci_get_drvdata(dev);
  1052. if (up) {
  1053. serial_txx9_unregister_port(up->port.line);
  1054. pci_disable_device(dev);
  1055. }
  1056. }
  1057. #ifdef CONFIG_PM
  1058. static int pciserial_txx9_suspend_one(struct pci_dev *dev, pm_message_t state)
  1059. {
  1060. struct uart_txx9_port *up = pci_get_drvdata(dev);
  1061. if (up)
  1062. uart_suspend_port(&serial_txx9_reg, &up->port);
  1063. pci_save_state(dev);
  1064. pci_set_power_state(dev, pci_choose_state(dev, state));
  1065. return 0;
  1066. }
  1067. static int pciserial_txx9_resume_one(struct pci_dev *dev)
  1068. {
  1069. struct uart_txx9_port *up = pci_get_drvdata(dev);
  1070. pci_set_power_state(dev, PCI_D0);
  1071. pci_restore_state(dev);
  1072. if (up)
  1073. uart_resume_port(&serial_txx9_reg, &up->port);
  1074. return 0;
  1075. }
  1076. #endif
  1077. static const struct pci_device_id serial_txx9_pci_tbl[] = {
  1078. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_TC86C001_MISC) },
  1079. { 0, }
  1080. };
  1081. static struct pci_driver serial_txx9_pci_driver = {
  1082. .name = "serial_txx9",
  1083. .probe = pciserial_txx9_init_one,
  1084. .remove = pciserial_txx9_remove_one,
  1085. #ifdef CONFIG_PM
  1086. .suspend = pciserial_txx9_suspend_one,
  1087. .resume = pciserial_txx9_resume_one,
  1088. #endif
  1089. .id_table = serial_txx9_pci_tbl,
  1090. };
  1091. MODULE_DEVICE_TABLE(pci, serial_txx9_pci_tbl);
  1092. #endif /* ENABLE_SERIAL_TXX9_PCI */
  1093. static struct platform_device *serial_txx9_plat_devs;
  1094. static int __init serial_txx9_init(void)
  1095. {
  1096. int ret;
  1097. printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
  1098. ret = uart_register_driver(&serial_txx9_reg);
  1099. if (ret)
  1100. goto out;
  1101. serial_txx9_plat_devs = platform_device_alloc("serial_txx9", -1);
  1102. if (!serial_txx9_plat_devs) {
  1103. ret = -ENOMEM;
  1104. goto unreg_uart_drv;
  1105. }
  1106. ret = platform_device_add(serial_txx9_plat_devs);
  1107. if (ret)
  1108. goto put_dev;
  1109. serial_txx9_register_ports(&serial_txx9_reg,
  1110. &serial_txx9_plat_devs->dev);
  1111. ret = platform_driver_register(&serial_txx9_plat_driver);
  1112. if (ret)
  1113. goto del_dev;
  1114. #ifdef ENABLE_SERIAL_TXX9_PCI
  1115. ret = pci_register_driver(&serial_txx9_pci_driver);
  1116. #endif
  1117. if (ret == 0)
  1118. goto out;
  1119. del_dev:
  1120. platform_device_del(serial_txx9_plat_devs);
  1121. put_dev:
  1122. platform_device_put(serial_txx9_plat_devs);
  1123. unreg_uart_drv:
  1124. uart_unregister_driver(&serial_txx9_reg);
  1125. out:
  1126. return ret;
  1127. }
  1128. static void __exit serial_txx9_exit(void)
  1129. {
  1130. int i;
  1131. #ifdef ENABLE_SERIAL_TXX9_PCI
  1132. pci_unregister_driver(&serial_txx9_pci_driver);
  1133. #endif
  1134. platform_driver_unregister(&serial_txx9_plat_driver);
  1135. platform_device_unregister(serial_txx9_plat_devs);
  1136. for (i = 0; i < UART_NR; i++) {
  1137. struct uart_txx9_port *up = &serial_txx9_ports[i];
  1138. if (up->port.iobase || up->port.mapbase)
  1139. uart_remove_one_port(&serial_txx9_reg, &up->port);
  1140. }
  1141. uart_unregister_driver(&serial_txx9_reg);
  1142. }
  1143. module_init(serial_txx9_init);
  1144. module_exit(serial_txx9_exit);
  1145. MODULE_LICENSE("GPL");
  1146. MODULE_DESCRIPTION("TX39/49 serial driver");
  1147. MODULE_ALIAS_CHARDEV_MAJOR(TXX9_TTY_MAJOR);