serial_txx9.c 30 KB

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