serial_txx9.c 32 KB

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