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