serial_txx9.c 33 KB

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