serial_txx9.c 33 KB

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