bfin_5xx.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. /*
  2. * Blackfin On-Chip Serial Driver
  3. *
  4. * Copyright 2006-2008 Analog Devices Inc.
  5. *
  6. * Enter bugs at http://blackfin.uclinux.org/
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #if defined(CONFIG_SERIAL_BFIN_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  11. #define SUPPORT_SYSRQ
  12. #endif
  13. #include <linux/module.h>
  14. #include <linux/ioport.h>
  15. #include <linux/init.h>
  16. #include <linux/console.h>
  17. #include <linux/sysrq.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/tty.h>
  20. #include <linux/tty_flip.h>
  21. #include <linux/serial_core.h>
  22. #ifdef CONFIG_KGDB_UART
  23. #include <linux/kgdb.h>
  24. #include <asm/irq_regs.h>
  25. #endif
  26. #include <asm/gpio.h>
  27. #include <mach/bfin_serial_5xx.h>
  28. #ifdef CONFIG_SERIAL_BFIN_DMA
  29. #include <linux/dma-mapping.h>
  30. #include <asm/io.h>
  31. #include <asm/irq.h>
  32. #include <asm/cacheflush.h>
  33. #endif
  34. /* UART name and device definitions */
  35. #define BFIN_SERIAL_NAME "ttyBF"
  36. #define BFIN_SERIAL_MAJOR 204
  37. #define BFIN_SERIAL_MINOR 64
  38. static struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS];
  39. static int nr_active_ports = ARRAY_SIZE(bfin_serial_resource);
  40. /*
  41. * Setup for console. Argument comes from the menuconfig
  42. */
  43. #define DMA_RX_XCOUNT 512
  44. #define DMA_RX_YCOUNT (PAGE_SIZE / DMA_RX_XCOUNT)
  45. #define DMA_RX_FLUSH_JIFFIES (HZ / 50)
  46. #define CTS_CHECK_JIFFIES (HZ / 50)
  47. #ifdef CONFIG_SERIAL_BFIN_DMA
  48. static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart);
  49. #else
  50. static void bfin_serial_tx_chars(struct bfin_serial_port *uart);
  51. #endif
  52. static void bfin_serial_mctrl_check(struct bfin_serial_port *uart);
  53. /*
  54. * interrupts are disabled on entry
  55. */
  56. static void bfin_serial_stop_tx(struct uart_port *port)
  57. {
  58. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  59. struct circ_buf *xmit = &uart->port.info->xmit;
  60. while (!(UART_GET_LSR(uart) & TEMT))
  61. cpu_relax();
  62. #ifdef CONFIG_SERIAL_BFIN_DMA
  63. disable_dma(uart->tx_dma_channel);
  64. xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1);
  65. uart->port.icount.tx += uart->tx_count;
  66. uart->tx_count = 0;
  67. uart->tx_done = 1;
  68. #else
  69. #ifdef CONFIG_BF54x
  70. /* Clear TFI bit */
  71. UART_PUT_LSR(uart, TFI);
  72. #endif
  73. UART_CLEAR_IER(uart, ETBEI);
  74. #endif
  75. }
  76. /*
  77. * port is locked and interrupts are disabled
  78. */
  79. static void bfin_serial_start_tx(struct uart_port *port)
  80. {
  81. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  82. #ifdef CONFIG_SERIAL_BFIN_DMA
  83. if (uart->tx_done)
  84. bfin_serial_dma_tx_chars(uart);
  85. #else
  86. UART_SET_IER(uart, ETBEI);
  87. bfin_serial_tx_chars(uart);
  88. #endif
  89. }
  90. /*
  91. * Interrupts are enabled
  92. */
  93. static void bfin_serial_stop_rx(struct uart_port *port)
  94. {
  95. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  96. #ifdef CONFIG_KGDB_UART
  97. if (uart->port.line != CONFIG_KGDB_UART_PORT)
  98. #endif
  99. UART_CLEAR_IER(uart, ERBFI);
  100. }
  101. /*
  102. * Set the modem control timer to fire immediately.
  103. */
  104. static void bfin_serial_enable_ms(struct uart_port *port)
  105. {
  106. }
  107. #ifdef CONFIG_KGDB_UART
  108. static int kgdb_entry_state;
  109. void kgdb_put_debug_char(int chr)
  110. {
  111. struct bfin_serial_port *uart;
  112. if (CONFIG_KGDB_UART_PORT < 0
  113. || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
  114. uart = &bfin_serial_ports[0];
  115. else
  116. uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
  117. while (!(UART_GET_LSR(uart) & THRE)) {
  118. SSYNC();
  119. }
  120. UART_CLEAR_DLAB(uart);
  121. UART_PUT_CHAR(uart, (unsigned char)chr);
  122. SSYNC();
  123. }
  124. int kgdb_get_debug_char(void)
  125. {
  126. struct bfin_serial_port *uart;
  127. unsigned char chr;
  128. if (CONFIG_KGDB_UART_PORT < 0
  129. || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
  130. uart = &bfin_serial_ports[0];
  131. else
  132. uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
  133. while(!(UART_GET_LSR(uart) & DR)) {
  134. SSYNC();
  135. }
  136. UART_CLEAR_DLAB(uart);
  137. chr = UART_GET_CHAR(uart);
  138. SSYNC();
  139. return chr;
  140. }
  141. #endif
  142. #if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO)
  143. # define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold)
  144. # define UART_SET_ANOMALY_THRESHOLD(uart, v) ((uart)->anomaly_threshold = (v))
  145. #else
  146. # define UART_GET_ANOMALY_THRESHOLD(uart) 0
  147. # define UART_SET_ANOMALY_THRESHOLD(uart, v)
  148. #endif
  149. #ifdef CONFIG_SERIAL_BFIN_PIO
  150. static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
  151. {
  152. struct tty_struct *tty = uart->port.info->port.tty;
  153. unsigned int status, ch, flg;
  154. static struct timeval anomaly_start = { .tv_sec = 0 };
  155. status = UART_GET_LSR(uart);
  156. UART_CLEAR_LSR(uart);
  157. ch = UART_GET_CHAR(uart);
  158. uart->port.icount.rx++;
  159. #ifdef CONFIG_KGDB_UART
  160. if (uart->port.line == CONFIG_KGDB_UART_PORT) {
  161. struct pt_regs *regs = get_irq_regs();
  162. if (uart->port.cons->index == CONFIG_KGDB_UART_PORT && ch == 0x1) { /* Ctrl + A */
  163. kgdb_breakkey_pressed(regs);
  164. return;
  165. } else if (kgdb_entry_state == 0 && ch == '$') {/* connection from KGDB */
  166. kgdb_entry_state = 1;
  167. } else if (kgdb_entry_state == 1 && ch == 'q') {
  168. kgdb_entry_state = 0;
  169. kgdb_breakkey_pressed(regs);
  170. return;
  171. } else if (ch == 0x3) {/* Ctrl + C */
  172. kgdb_entry_state = 0;
  173. kgdb_breakkey_pressed(regs);
  174. return;
  175. } else {
  176. kgdb_entry_state = 0;
  177. }
  178. }
  179. #endif
  180. if (ANOMALY_05000363) {
  181. /* The BF533 (and BF561) family of processors have a nice anomaly
  182. * where they continuously generate characters for a "single" break.
  183. * We have to basically ignore this flood until the "next" valid
  184. * character comes across. Due to the nature of the flood, it is
  185. * not possible to reliably catch bytes that are sent too quickly
  186. * after this break. So application code talking to the Blackfin
  187. * which sends a break signal must allow at least 1.5 character
  188. * times after the end of the break for things to stabilize. This
  189. * timeout was picked as it must absolutely be larger than 1
  190. * character time +/- some percent. So 1.5 sounds good. All other
  191. * Blackfin families operate properly. Woo.
  192. */
  193. if (anomaly_start.tv_sec) {
  194. struct timeval curr;
  195. suseconds_t usecs;
  196. if ((~ch & (~ch + 1)) & 0xff)
  197. goto known_good_char;
  198. do_gettimeofday(&curr);
  199. if (curr.tv_sec - anomaly_start.tv_sec > 1)
  200. goto known_good_char;
  201. usecs = 0;
  202. if (curr.tv_sec != anomaly_start.tv_sec)
  203. usecs += USEC_PER_SEC;
  204. usecs += curr.tv_usec - anomaly_start.tv_usec;
  205. if (usecs > UART_GET_ANOMALY_THRESHOLD(uart))
  206. goto known_good_char;
  207. if (ch)
  208. anomaly_start.tv_sec = 0;
  209. else
  210. anomaly_start = curr;
  211. return;
  212. known_good_char:
  213. anomaly_start.tv_sec = 0;
  214. }
  215. }
  216. if (status & BI) {
  217. if (ANOMALY_05000363)
  218. if (bfin_revid() < 5)
  219. do_gettimeofday(&anomaly_start);
  220. uart->port.icount.brk++;
  221. if (uart_handle_break(&uart->port))
  222. goto ignore_char;
  223. status &= ~(PE | FE);
  224. }
  225. if (status & PE)
  226. uart->port.icount.parity++;
  227. if (status & OE)
  228. uart->port.icount.overrun++;
  229. if (status & FE)
  230. uart->port.icount.frame++;
  231. status &= uart->port.read_status_mask;
  232. if (status & BI)
  233. flg = TTY_BREAK;
  234. else if (status & PE)
  235. flg = TTY_PARITY;
  236. else if (status & FE)
  237. flg = TTY_FRAME;
  238. else
  239. flg = TTY_NORMAL;
  240. if (uart_handle_sysrq_char(&uart->port, ch))
  241. goto ignore_char;
  242. uart_insert_char(&uart->port, status, OE, ch, flg);
  243. ignore_char:
  244. tty_flip_buffer_push(tty);
  245. }
  246. static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
  247. {
  248. struct circ_buf *xmit = &uart->port.info->xmit;
  249. /*
  250. * Check the modem control lines before
  251. * transmitting anything.
  252. */
  253. bfin_serial_mctrl_check(uart);
  254. if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) {
  255. #ifdef CONFIG_BF54x
  256. /* Clear TFI bit */
  257. UART_PUT_LSR(uart, TFI);
  258. #endif
  259. UART_CLEAR_IER(uart, ETBEI);
  260. return;
  261. }
  262. if (uart->port.x_char) {
  263. UART_PUT_CHAR(uart, uart->port.x_char);
  264. uart->port.icount.tx++;
  265. uart->port.x_char = 0;
  266. }
  267. while ((UART_GET_LSR(uart) & THRE) && xmit->tail != xmit->head) {
  268. UART_PUT_CHAR(uart, xmit->buf[xmit->tail]);
  269. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  270. uart->port.icount.tx++;
  271. SSYNC();
  272. }
  273. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  274. uart_write_wakeup(&uart->port);
  275. }
  276. static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id)
  277. {
  278. struct bfin_serial_port *uart = dev_id;
  279. spin_lock(&uart->port.lock);
  280. while (UART_GET_LSR(uart) & DR)
  281. bfin_serial_rx_chars(uart);
  282. spin_unlock(&uart->port.lock);
  283. return IRQ_HANDLED;
  284. }
  285. static irqreturn_t bfin_serial_tx_int(int irq, void *dev_id)
  286. {
  287. struct bfin_serial_port *uart = dev_id;
  288. spin_lock(&uart->port.lock);
  289. if (UART_GET_LSR(uart) & THRE)
  290. bfin_serial_tx_chars(uart);
  291. spin_unlock(&uart->port.lock);
  292. return IRQ_HANDLED;
  293. }
  294. #endif
  295. #ifdef CONFIG_SERIAL_BFIN_DMA
  296. static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart)
  297. {
  298. struct circ_buf *xmit = &uart->port.info->xmit;
  299. uart->tx_done = 0;
  300. /*
  301. * Check the modem control lines before
  302. * transmitting anything.
  303. */
  304. bfin_serial_mctrl_check(uart);
  305. if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) {
  306. uart->tx_count = 0;
  307. uart->tx_done = 1;
  308. return;
  309. }
  310. if (uart->port.x_char) {
  311. UART_PUT_CHAR(uart, uart->port.x_char);
  312. uart->port.icount.tx++;
  313. uart->port.x_char = 0;
  314. }
  315. uart->tx_count = CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE);
  316. if (uart->tx_count > (UART_XMIT_SIZE - xmit->tail))
  317. uart->tx_count = UART_XMIT_SIZE - xmit->tail;
  318. blackfin_dcache_flush_range((unsigned long)(xmit->buf+xmit->tail),
  319. (unsigned long)(xmit->buf+xmit->tail+uart->tx_count));
  320. set_dma_config(uart->tx_dma_channel,
  321. set_bfin_dma_config(DIR_READ, DMA_FLOW_STOP,
  322. INTR_ON_BUF,
  323. DIMENSION_LINEAR,
  324. DATA_SIZE_8,
  325. DMA_SYNC_RESTART));
  326. set_dma_start_addr(uart->tx_dma_channel, (unsigned long)(xmit->buf+xmit->tail));
  327. set_dma_x_count(uart->tx_dma_channel, uart->tx_count);
  328. set_dma_x_modify(uart->tx_dma_channel, 1);
  329. enable_dma(uart->tx_dma_channel);
  330. UART_SET_IER(uart, ETBEI);
  331. }
  332. static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
  333. {
  334. struct tty_struct *tty = uart->port.info->port.tty;
  335. int i, flg, status;
  336. status = UART_GET_LSR(uart);
  337. UART_CLEAR_LSR(uart);
  338. uart->port.icount.rx +=
  339. CIRC_CNT(uart->rx_dma_buf.head, uart->rx_dma_buf.tail,
  340. UART_XMIT_SIZE);
  341. if (status & BI) {
  342. uart->port.icount.brk++;
  343. if (uart_handle_break(&uart->port))
  344. goto dma_ignore_char;
  345. status &= ~(PE | FE);
  346. }
  347. if (status & PE)
  348. uart->port.icount.parity++;
  349. if (status & OE)
  350. uart->port.icount.overrun++;
  351. if (status & FE)
  352. uart->port.icount.frame++;
  353. status &= uart->port.read_status_mask;
  354. if (status & BI)
  355. flg = TTY_BREAK;
  356. else if (status & PE)
  357. flg = TTY_PARITY;
  358. else if (status & FE)
  359. flg = TTY_FRAME;
  360. else
  361. flg = TTY_NORMAL;
  362. for (i = uart->rx_dma_buf.tail; i != uart->rx_dma_buf.head; i++) {
  363. if (i >= UART_XMIT_SIZE)
  364. i = 0;
  365. if (!uart_handle_sysrq_char(&uart->port, uart->rx_dma_buf.buf[i]))
  366. uart_insert_char(&uart->port, status, OE,
  367. uart->rx_dma_buf.buf[i], flg);
  368. }
  369. dma_ignore_char:
  370. tty_flip_buffer_push(tty);
  371. }
  372. void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart)
  373. {
  374. int x_pos, pos;
  375. uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel);
  376. x_pos = get_dma_curr_xcount(uart->rx_dma_channel);
  377. uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows;
  378. if (uart->rx_dma_nrows == DMA_RX_YCOUNT)
  379. uart->rx_dma_nrows = 0;
  380. x_pos = DMA_RX_XCOUNT - x_pos;
  381. if (x_pos == DMA_RX_XCOUNT)
  382. x_pos = 0;
  383. pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos;
  384. if (pos != uart->rx_dma_buf.tail) {
  385. uart->rx_dma_buf.head = pos;
  386. bfin_serial_dma_rx_chars(uart);
  387. uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
  388. }
  389. mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES);
  390. }
  391. static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id)
  392. {
  393. struct bfin_serial_port *uart = dev_id;
  394. struct circ_buf *xmit = &uart->port.info->xmit;
  395. spin_lock(&uart->port.lock);
  396. if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) {
  397. disable_dma(uart->tx_dma_channel);
  398. clear_dma_irqstat(uart->tx_dma_channel);
  399. UART_CLEAR_IER(uart, ETBEI);
  400. xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1);
  401. uart->port.icount.tx += uart->tx_count;
  402. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  403. uart_write_wakeup(&uart->port);
  404. bfin_serial_dma_tx_chars(uart);
  405. }
  406. spin_unlock(&uart->port.lock);
  407. return IRQ_HANDLED;
  408. }
  409. static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id)
  410. {
  411. struct bfin_serial_port *uart = dev_id;
  412. unsigned short irqstat;
  413. spin_lock(&uart->port.lock);
  414. irqstat = get_dma_curr_irqstat(uart->rx_dma_channel);
  415. clear_dma_irqstat(uart->rx_dma_channel);
  416. spin_unlock(&uart->port.lock);
  417. mod_timer(&(uart->rx_dma_timer), jiffies);
  418. return IRQ_HANDLED;
  419. }
  420. #endif
  421. /*
  422. * Return TIOCSER_TEMT when transmitter is not busy.
  423. */
  424. static unsigned int bfin_serial_tx_empty(struct uart_port *port)
  425. {
  426. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  427. unsigned short lsr;
  428. lsr = UART_GET_LSR(uart);
  429. if (lsr & TEMT)
  430. return TIOCSER_TEMT;
  431. else
  432. return 0;
  433. }
  434. static unsigned int bfin_serial_get_mctrl(struct uart_port *port)
  435. {
  436. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  437. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  438. if (uart->cts_pin < 0)
  439. return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
  440. if (UART_GET_CTS(uart))
  441. return TIOCM_DSR | TIOCM_CAR;
  442. else
  443. #endif
  444. return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
  445. }
  446. static void bfin_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
  447. {
  448. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  449. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  450. if (uart->rts_pin < 0)
  451. return;
  452. if (mctrl & TIOCM_RTS)
  453. UART_CLEAR_RTS(uart);
  454. else
  455. UART_SET_RTS(uart);
  456. #endif
  457. }
  458. /*
  459. * Handle any change of modem status signal since we were last called.
  460. */
  461. static void bfin_serial_mctrl_check(struct bfin_serial_port *uart)
  462. {
  463. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  464. unsigned int status;
  465. struct uart_info *info = uart->port.info;
  466. struct tty_struct *tty = info->port.tty;
  467. status = bfin_serial_get_mctrl(&uart->port);
  468. uart_handle_cts_change(&uart->port, status & TIOCM_CTS);
  469. if (!(status & TIOCM_CTS)) {
  470. tty->hw_stopped = 1;
  471. uart->cts_timer.data = (unsigned long)(uart);
  472. uart->cts_timer.function = (void *)bfin_serial_mctrl_check;
  473. uart->cts_timer.expires = jiffies + CTS_CHECK_JIFFIES;
  474. add_timer(&(uart->cts_timer));
  475. } else {
  476. tty->hw_stopped = 0;
  477. }
  478. #endif
  479. }
  480. /*
  481. * Interrupts are always disabled.
  482. */
  483. static void bfin_serial_break_ctl(struct uart_port *port, int break_state)
  484. {
  485. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  486. u16 lcr = UART_GET_LCR(uart);
  487. if (break_state)
  488. lcr |= SB;
  489. else
  490. lcr &= ~SB;
  491. UART_PUT_LCR(uart, lcr);
  492. SSYNC();
  493. }
  494. static int bfin_serial_startup(struct uart_port *port)
  495. {
  496. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  497. #ifdef CONFIG_SERIAL_BFIN_DMA
  498. dma_addr_t dma_handle;
  499. if (request_dma(uart->rx_dma_channel, "BFIN_UART_RX") < 0) {
  500. printk(KERN_NOTICE "Unable to attach Blackfin UART RX DMA channel\n");
  501. return -EBUSY;
  502. }
  503. if (request_dma(uart->tx_dma_channel, "BFIN_UART_TX") < 0) {
  504. printk(KERN_NOTICE "Unable to attach Blackfin UART TX DMA channel\n");
  505. free_dma(uart->rx_dma_channel);
  506. return -EBUSY;
  507. }
  508. set_dma_callback(uart->rx_dma_channel, bfin_serial_dma_rx_int, uart);
  509. set_dma_callback(uart->tx_dma_channel, bfin_serial_dma_tx_int, uart);
  510. uart->rx_dma_buf.buf = (unsigned char *)dma_alloc_coherent(NULL, PAGE_SIZE, &dma_handle, GFP_DMA);
  511. uart->rx_dma_buf.head = 0;
  512. uart->rx_dma_buf.tail = 0;
  513. uart->rx_dma_nrows = 0;
  514. set_dma_config(uart->rx_dma_channel,
  515. set_bfin_dma_config(DIR_WRITE, DMA_FLOW_AUTO,
  516. INTR_ON_ROW, DIMENSION_2D,
  517. DATA_SIZE_8,
  518. DMA_SYNC_RESTART));
  519. set_dma_x_count(uart->rx_dma_channel, DMA_RX_XCOUNT);
  520. set_dma_x_modify(uart->rx_dma_channel, 1);
  521. set_dma_y_count(uart->rx_dma_channel, DMA_RX_YCOUNT);
  522. set_dma_y_modify(uart->rx_dma_channel, 1);
  523. set_dma_start_addr(uart->rx_dma_channel, (unsigned long)uart->rx_dma_buf.buf);
  524. enable_dma(uart->rx_dma_channel);
  525. uart->rx_dma_timer.data = (unsigned long)(uart);
  526. uart->rx_dma_timer.function = (void *)bfin_serial_rx_dma_timeout;
  527. uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES;
  528. add_timer(&(uart->rx_dma_timer));
  529. #else
  530. if (request_irq(uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED,
  531. "BFIN_UART_RX", uart)) {
  532. # ifdef CONFIG_KGDB_UART
  533. if (uart->port.line != CONFIG_KGDB_UART_PORT) {
  534. # endif
  535. printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n");
  536. return -EBUSY;
  537. # ifdef CONFIG_KGDB_UART
  538. }
  539. # endif
  540. }
  541. if (request_irq
  542. (uart->port.irq+1, bfin_serial_tx_int, IRQF_DISABLED,
  543. "BFIN_UART_TX", uart)) {
  544. printk(KERN_NOTICE "Unable to attach BlackFin UART TX interrupt\n");
  545. free_irq(uart->port.irq, uart);
  546. return -EBUSY;
  547. }
  548. # ifdef CONFIG_BF54x
  549. {
  550. unsigned uart_dma_ch_rx, uart_dma_ch_tx;
  551. switch (uart->port.irq) {
  552. case IRQ_UART3_RX:
  553. uart_dma_ch_rx = CH_UART3_RX;
  554. uart_dma_ch_tx = CH_UART3_TX;
  555. break;
  556. case IRQ_UART2_RX:
  557. uart_dma_ch_rx = CH_UART2_RX;
  558. uart_dma_ch_tx = CH_UART2_TX;
  559. break;
  560. default:
  561. uart_dma_ch_rx = uart_dma_ch_tx = 0;
  562. break;
  563. };
  564. if (uart_dma_ch_rx &&
  565. request_dma(uart_dma_ch_rx, "BFIN_UART_RX") < 0) {
  566. printk(KERN_NOTICE"Fail to attach UART interrupt\n");
  567. free_irq(uart->port.irq, uart);
  568. free_irq(uart->port.irq + 1, uart);
  569. return -EBUSY;
  570. }
  571. if (uart_dma_ch_tx &&
  572. request_dma(uart_dma_ch_tx, "BFIN_UART_TX") < 0) {
  573. printk(KERN_NOTICE "Fail to attach UART interrupt\n");
  574. free_dma(uart_dma_ch_rx);
  575. free_irq(uart->port.irq, uart);
  576. free_irq(uart->port.irq + 1, uart);
  577. return -EBUSY;
  578. }
  579. }
  580. # endif
  581. #endif
  582. UART_SET_IER(uart, ERBFI);
  583. return 0;
  584. }
  585. static void bfin_serial_shutdown(struct uart_port *port)
  586. {
  587. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  588. #ifdef CONFIG_SERIAL_BFIN_DMA
  589. disable_dma(uart->tx_dma_channel);
  590. free_dma(uart->tx_dma_channel);
  591. disable_dma(uart->rx_dma_channel);
  592. free_dma(uart->rx_dma_channel);
  593. del_timer(&(uart->rx_dma_timer));
  594. dma_free_coherent(NULL, PAGE_SIZE, uart->rx_dma_buf.buf, 0);
  595. #else
  596. #ifdef CONFIG_BF54x
  597. switch (uart->port.irq) {
  598. case IRQ_UART3_RX:
  599. free_dma(CH_UART3_RX);
  600. free_dma(CH_UART3_TX);
  601. break;
  602. case IRQ_UART2_RX:
  603. free_dma(CH_UART2_RX);
  604. free_dma(CH_UART2_TX);
  605. break;
  606. default:
  607. break;
  608. };
  609. #endif
  610. #ifdef CONFIG_KGDB_UART
  611. if (uart->port.line != CONFIG_KGDB_UART_PORT)
  612. #endif
  613. free_irq(uart->port.irq, uart);
  614. free_irq(uart->port.irq+1, uart);
  615. #endif
  616. }
  617. static void
  618. bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
  619. struct ktermios *old)
  620. {
  621. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  622. unsigned long flags;
  623. unsigned int baud, quot;
  624. unsigned short val, ier, lcr = 0;
  625. switch (termios->c_cflag & CSIZE) {
  626. case CS8:
  627. lcr = WLS(8);
  628. break;
  629. case CS7:
  630. lcr = WLS(7);
  631. break;
  632. case CS6:
  633. lcr = WLS(6);
  634. break;
  635. case CS5:
  636. lcr = WLS(5);
  637. break;
  638. default:
  639. printk(KERN_ERR "%s: word lengh not supported\n",
  640. __func__);
  641. }
  642. if (termios->c_cflag & CSTOPB)
  643. lcr |= STB;
  644. if (termios->c_cflag & PARENB)
  645. lcr |= PEN;
  646. if (!(termios->c_cflag & PARODD))
  647. lcr |= EPS;
  648. if (termios->c_cflag & CMSPAR)
  649. lcr |= STP;
  650. port->read_status_mask = OE;
  651. if (termios->c_iflag & INPCK)
  652. port->read_status_mask |= (FE | PE);
  653. if (termios->c_iflag & (BRKINT | PARMRK))
  654. port->read_status_mask |= BI;
  655. /*
  656. * Characters to ignore
  657. */
  658. port->ignore_status_mask = 0;
  659. if (termios->c_iflag & IGNPAR)
  660. port->ignore_status_mask |= FE | PE;
  661. if (termios->c_iflag & IGNBRK) {
  662. port->ignore_status_mask |= BI;
  663. /*
  664. * If we're ignoring parity and break indicators,
  665. * ignore overruns too (for real raw support).
  666. */
  667. if (termios->c_iflag & IGNPAR)
  668. port->ignore_status_mask |= OE;
  669. }
  670. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
  671. quot = uart_get_divisor(port, baud);
  672. spin_lock_irqsave(&uart->port.lock, flags);
  673. UART_SET_ANOMALY_THRESHOLD(uart, USEC_PER_SEC / baud * 15);
  674. /* Disable UART */
  675. ier = UART_GET_IER(uart);
  676. UART_DISABLE_INTS(uart);
  677. /* Set DLAB in LCR to Access DLL and DLH */
  678. UART_SET_DLAB(uart);
  679. UART_PUT_DLL(uart, quot & 0xFF);
  680. UART_PUT_DLH(uart, (quot >> 8) & 0xFF);
  681. SSYNC();
  682. /* Clear DLAB in LCR to Access THR RBR IER */
  683. UART_CLEAR_DLAB(uart);
  684. UART_PUT_LCR(uart, lcr);
  685. /* Enable UART */
  686. UART_ENABLE_INTS(uart, ier);
  687. val = UART_GET_GCTL(uart);
  688. val |= UCEN;
  689. UART_PUT_GCTL(uart, val);
  690. /* Port speed changed, update the per-port timeout. */
  691. uart_update_timeout(port, termios->c_cflag, baud);
  692. spin_unlock_irqrestore(&uart->port.lock, flags);
  693. }
  694. static const char *bfin_serial_type(struct uart_port *port)
  695. {
  696. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  697. return uart->port.type == PORT_BFIN ? "BFIN-UART" : NULL;
  698. }
  699. /*
  700. * Release the memory region(s) being used by 'port'.
  701. */
  702. static void bfin_serial_release_port(struct uart_port *port)
  703. {
  704. }
  705. /*
  706. * Request the memory region(s) being used by 'port'.
  707. */
  708. static int bfin_serial_request_port(struct uart_port *port)
  709. {
  710. return 0;
  711. }
  712. /*
  713. * Configure/autoconfigure the port.
  714. */
  715. static void bfin_serial_config_port(struct uart_port *port, int flags)
  716. {
  717. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  718. if (flags & UART_CONFIG_TYPE &&
  719. bfin_serial_request_port(&uart->port) == 0)
  720. uart->port.type = PORT_BFIN;
  721. }
  722. /*
  723. * Verify the new serial_struct (for TIOCSSERIAL).
  724. * The only change we allow are to the flags and type, and
  725. * even then only between PORT_BFIN and PORT_UNKNOWN
  726. */
  727. static int
  728. bfin_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
  729. {
  730. return 0;
  731. }
  732. /*
  733. * Enable the IrDA function if tty->ldisc.num is N_IRDA.
  734. * In other cases, disable IrDA function.
  735. */
  736. static void bfin_serial_set_ldisc(struct uart_port *port)
  737. {
  738. int line = port->line;
  739. unsigned short val;
  740. if (line >= port->info->port.tty->driver->num)
  741. return;
  742. switch (port->info->port.tty->termios->c_line) {
  743. case N_IRDA:
  744. val = UART_GET_GCTL(&bfin_serial_ports[line]);
  745. val |= (IREN | RPOLC);
  746. UART_PUT_GCTL(&bfin_serial_ports[line], val);
  747. break;
  748. default:
  749. val = UART_GET_GCTL(&bfin_serial_ports[line]);
  750. val &= ~(IREN | RPOLC);
  751. UART_PUT_GCTL(&bfin_serial_ports[line], val);
  752. }
  753. }
  754. static struct uart_ops bfin_serial_pops = {
  755. .tx_empty = bfin_serial_tx_empty,
  756. .set_mctrl = bfin_serial_set_mctrl,
  757. .get_mctrl = bfin_serial_get_mctrl,
  758. .stop_tx = bfin_serial_stop_tx,
  759. .start_tx = bfin_serial_start_tx,
  760. .stop_rx = bfin_serial_stop_rx,
  761. .enable_ms = bfin_serial_enable_ms,
  762. .break_ctl = bfin_serial_break_ctl,
  763. .startup = bfin_serial_startup,
  764. .shutdown = bfin_serial_shutdown,
  765. .set_termios = bfin_serial_set_termios,
  766. .set_ldisc = bfin_serial_set_ldisc,
  767. .type = bfin_serial_type,
  768. .release_port = bfin_serial_release_port,
  769. .request_port = bfin_serial_request_port,
  770. .config_port = bfin_serial_config_port,
  771. .verify_port = bfin_serial_verify_port,
  772. };
  773. static void __init bfin_serial_init_ports(void)
  774. {
  775. static int first = 1;
  776. int i;
  777. if (!first)
  778. return;
  779. first = 0;
  780. for (i = 0; i < nr_active_ports; i++) {
  781. bfin_serial_ports[i].port.uartclk = get_sclk();
  782. bfin_serial_ports[i].port.fifosize = BFIN_UART_TX_FIFO_SIZE;
  783. bfin_serial_ports[i].port.ops = &bfin_serial_pops;
  784. bfin_serial_ports[i].port.line = i;
  785. bfin_serial_ports[i].port.iotype = UPIO_MEM;
  786. bfin_serial_ports[i].port.membase =
  787. (void __iomem *)bfin_serial_resource[i].uart_base_addr;
  788. bfin_serial_ports[i].port.mapbase =
  789. bfin_serial_resource[i].uart_base_addr;
  790. bfin_serial_ports[i].port.irq =
  791. bfin_serial_resource[i].uart_irq;
  792. bfin_serial_ports[i].port.flags = UPF_BOOT_AUTOCONF;
  793. #ifdef CONFIG_SERIAL_BFIN_DMA
  794. bfin_serial_ports[i].tx_done = 1;
  795. bfin_serial_ports[i].tx_count = 0;
  796. bfin_serial_ports[i].tx_dma_channel =
  797. bfin_serial_resource[i].uart_tx_dma_channel;
  798. bfin_serial_ports[i].rx_dma_channel =
  799. bfin_serial_resource[i].uart_rx_dma_channel;
  800. init_timer(&(bfin_serial_ports[i].rx_dma_timer));
  801. #endif
  802. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  803. init_timer(&(bfin_serial_ports[i].cts_timer));
  804. bfin_serial_ports[i].cts_pin =
  805. bfin_serial_resource[i].uart_cts_pin;
  806. bfin_serial_ports[i].rts_pin =
  807. bfin_serial_resource[i].uart_rts_pin;
  808. #endif
  809. bfin_serial_hw_init(&bfin_serial_ports[i]);
  810. }
  811. }
  812. #ifdef CONFIG_SERIAL_BFIN_CONSOLE
  813. /*
  814. * If the port was already initialised (eg, by a boot loader),
  815. * try to determine the current setup.
  816. */
  817. static void __init
  818. bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
  819. int *parity, int *bits)
  820. {
  821. unsigned short status;
  822. status = UART_GET_IER(uart) & (ERBFI | ETBEI);
  823. if (status == (ERBFI | ETBEI)) {
  824. /* ok, the port was enabled */
  825. u16 lcr, dlh, dll;
  826. lcr = UART_GET_LCR(uart);
  827. *parity = 'n';
  828. if (lcr & PEN) {
  829. if (lcr & EPS)
  830. *parity = 'e';
  831. else
  832. *parity = 'o';
  833. }
  834. switch (lcr & 0x03) {
  835. case 0: *bits = 5; break;
  836. case 1: *bits = 6; break;
  837. case 2: *bits = 7; break;
  838. case 3: *bits = 8; break;
  839. }
  840. /* Set DLAB in LCR to Access DLL and DLH */
  841. UART_SET_DLAB(uart);
  842. dll = UART_GET_DLL(uart);
  843. dlh = UART_GET_DLH(uart);
  844. /* Clear DLAB in LCR to Access THR RBR IER */
  845. UART_CLEAR_DLAB(uart);
  846. *baud = get_sclk() / (16*(dll | dlh << 8));
  847. }
  848. pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits);
  849. }
  850. #endif
  851. #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
  852. static struct uart_driver bfin_serial_reg;
  853. static int __init
  854. bfin_serial_console_setup(struct console *co, char *options)
  855. {
  856. struct bfin_serial_port *uart;
  857. # ifdef CONFIG_SERIAL_BFIN_CONSOLE
  858. int baud = 57600;
  859. int bits = 8;
  860. int parity = 'n';
  861. # ifdef CONFIG_SERIAL_BFIN_CTSRTS
  862. int flow = 'r';
  863. # else
  864. int flow = 'n';
  865. # endif
  866. # endif
  867. /*
  868. * Check whether an invalid uart number has been specified, and
  869. * if so, search for the first available port that does have
  870. * console support.
  871. */
  872. if (co->index == -1 || co->index >= nr_active_ports)
  873. co->index = 0;
  874. uart = &bfin_serial_ports[co->index];
  875. # ifdef CONFIG_SERIAL_BFIN_CONSOLE
  876. if (options)
  877. uart_parse_options(options, &baud, &parity, &bits, &flow);
  878. else
  879. bfin_serial_console_get_options(uart, &baud, &parity, &bits);
  880. return uart_set_options(&uart->port, co, baud, parity, bits, flow);
  881. # else
  882. return 0;
  883. # endif
  884. }
  885. #endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) ||
  886. defined (CONFIG_EARLY_PRINTK) */
  887. #ifdef CONFIG_SERIAL_BFIN_CONSOLE
  888. static void bfin_serial_console_putchar(struct uart_port *port, int ch)
  889. {
  890. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  891. while (!(UART_GET_LSR(uart) & THRE))
  892. barrier();
  893. UART_PUT_CHAR(uart, ch);
  894. SSYNC();
  895. }
  896. /*
  897. * Interrupts are disabled on entering
  898. */
  899. static void
  900. bfin_serial_console_write(struct console *co, const char *s, unsigned int count)
  901. {
  902. struct bfin_serial_port *uart = &bfin_serial_ports[co->index];
  903. int flags = 0;
  904. spin_lock_irqsave(&uart->port.lock, flags);
  905. uart_console_write(&uart->port, s, count, bfin_serial_console_putchar);
  906. spin_unlock_irqrestore(&uart->port.lock, flags);
  907. }
  908. static struct console bfin_serial_console = {
  909. .name = BFIN_SERIAL_NAME,
  910. .write = bfin_serial_console_write,
  911. .device = uart_console_device,
  912. .setup = bfin_serial_console_setup,
  913. .flags = CON_PRINTBUFFER,
  914. .index = -1,
  915. .data = &bfin_serial_reg,
  916. };
  917. static int __init bfin_serial_rs_console_init(void)
  918. {
  919. bfin_serial_init_ports();
  920. register_console(&bfin_serial_console);
  921. #ifdef CONFIG_KGDB_UART
  922. kgdb_entry_state = 0;
  923. init_kgdb_uart();
  924. #endif
  925. return 0;
  926. }
  927. console_initcall(bfin_serial_rs_console_init);
  928. #define BFIN_SERIAL_CONSOLE &bfin_serial_console
  929. #else
  930. #define BFIN_SERIAL_CONSOLE NULL
  931. #endif /* CONFIG_SERIAL_BFIN_CONSOLE */
  932. #ifdef CONFIG_EARLY_PRINTK
  933. static __init void early_serial_putc(struct uart_port *port, int ch)
  934. {
  935. unsigned timeout = 0xffff;
  936. struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
  937. while ((!(UART_GET_LSR(uart) & THRE)) && --timeout)
  938. cpu_relax();
  939. UART_PUT_CHAR(uart, ch);
  940. }
  941. static __init void early_serial_write(struct console *con, const char *s,
  942. unsigned int n)
  943. {
  944. struct bfin_serial_port *uart = &bfin_serial_ports[con->index];
  945. unsigned int i;
  946. for (i = 0; i < n; i++, s++) {
  947. if (*s == '\n')
  948. early_serial_putc(&uart->port, '\r');
  949. early_serial_putc(&uart->port, *s);
  950. }
  951. }
  952. static struct __initdata console bfin_early_serial_console = {
  953. .name = "early_BFuart",
  954. .write = early_serial_write,
  955. .device = uart_console_device,
  956. .flags = CON_PRINTBUFFER,
  957. .setup = bfin_serial_console_setup,
  958. .index = -1,
  959. .data = &bfin_serial_reg,
  960. };
  961. struct console __init *bfin_earlyserial_init(unsigned int port,
  962. unsigned int cflag)
  963. {
  964. struct bfin_serial_port *uart;
  965. struct ktermios t;
  966. if (port == -1 || port >= nr_active_ports)
  967. port = 0;
  968. bfin_serial_init_ports();
  969. bfin_early_serial_console.index = port;
  970. uart = &bfin_serial_ports[port];
  971. t.c_cflag = cflag;
  972. t.c_iflag = 0;
  973. t.c_oflag = 0;
  974. t.c_lflag = ICANON;
  975. t.c_line = port;
  976. bfin_serial_set_termios(&uart->port, &t, &t);
  977. return &bfin_early_serial_console;
  978. }
  979. #endif /* CONFIG_SERIAL_BFIN_CONSOLE */
  980. static struct uart_driver bfin_serial_reg = {
  981. .owner = THIS_MODULE,
  982. .driver_name = "bfin-uart",
  983. .dev_name = BFIN_SERIAL_NAME,
  984. .major = BFIN_SERIAL_MAJOR,
  985. .minor = BFIN_SERIAL_MINOR,
  986. .nr = BFIN_UART_NR_PORTS,
  987. .cons = BFIN_SERIAL_CONSOLE,
  988. };
  989. static int bfin_serial_suspend(struct platform_device *dev, pm_message_t state)
  990. {
  991. int i;
  992. for (i = 0; i < nr_active_ports; i++) {
  993. if (bfin_serial_ports[i].port.dev != &dev->dev)
  994. continue;
  995. uart_suspend_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
  996. }
  997. return 0;
  998. }
  999. static int bfin_serial_resume(struct platform_device *dev)
  1000. {
  1001. int i;
  1002. for (i = 0; i < nr_active_ports; i++) {
  1003. if (bfin_serial_ports[i].port.dev != &dev->dev)
  1004. continue;
  1005. uart_resume_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
  1006. }
  1007. return 0;
  1008. }
  1009. static int bfin_serial_probe(struct platform_device *dev)
  1010. {
  1011. struct resource *res = dev->resource;
  1012. int i;
  1013. for (i = 0; i < dev->num_resources; i++, res++)
  1014. if (res->flags & IORESOURCE_MEM)
  1015. break;
  1016. if (i < dev->num_resources) {
  1017. for (i = 0; i < nr_active_ports; i++, res++) {
  1018. if (bfin_serial_ports[i].port.mapbase != res->start)
  1019. continue;
  1020. bfin_serial_ports[i].port.dev = &dev->dev;
  1021. uart_add_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
  1022. }
  1023. }
  1024. return 0;
  1025. }
  1026. static int bfin_serial_remove(struct platform_device *dev)
  1027. {
  1028. int i;
  1029. for (i = 0; i < nr_active_ports; i++) {
  1030. if (bfin_serial_ports[i].port.dev != &dev->dev)
  1031. continue;
  1032. uart_remove_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
  1033. bfin_serial_ports[i].port.dev = NULL;
  1034. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  1035. gpio_free(bfin_serial_ports[i].cts_pin);
  1036. gpio_free(bfin_serial_ports[i].rts_pin);
  1037. #endif
  1038. }
  1039. return 0;
  1040. }
  1041. static struct platform_driver bfin_serial_driver = {
  1042. .probe = bfin_serial_probe,
  1043. .remove = bfin_serial_remove,
  1044. .suspend = bfin_serial_suspend,
  1045. .resume = bfin_serial_resume,
  1046. .driver = {
  1047. .name = "bfin-uart",
  1048. .owner = THIS_MODULE,
  1049. },
  1050. };
  1051. static int __init bfin_serial_init(void)
  1052. {
  1053. int ret;
  1054. #ifdef CONFIG_KGDB_UART
  1055. struct bfin_serial_port *uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
  1056. struct ktermios t;
  1057. #endif
  1058. pr_info("Serial: Blackfin serial driver\n");
  1059. bfin_serial_init_ports();
  1060. ret = uart_register_driver(&bfin_serial_reg);
  1061. if (ret == 0) {
  1062. ret = platform_driver_register(&bfin_serial_driver);
  1063. if (ret) {
  1064. pr_debug("uart register failed\n");
  1065. uart_unregister_driver(&bfin_serial_reg);
  1066. }
  1067. }
  1068. #ifdef CONFIG_KGDB_UART
  1069. if (uart->port.cons->index != CONFIG_KGDB_UART_PORT) {
  1070. request_irq(uart->port.irq, bfin_serial_rx_int,
  1071. IRQF_DISABLED, "BFIN_UART_RX", uart);
  1072. pr_info("Request irq for kgdb uart port\n");
  1073. UART_SET_IER(uart, ERBFI);
  1074. SSYNC();
  1075. t.c_cflag = CS8|B57600;
  1076. t.c_iflag = 0;
  1077. t.c_oflag = 0;
  1078. t.c_lflag = ICANON;
  1079. t.c_line = CONFIG_KGDB_UART_PORT;
  1080. bfin_serial_set_termios(&uart->port, &t, &t);
  1081. }
  1082. #endif
  1083. return ret;
  1084. }
  1085. static void __exit bfin_serial_exit(void)
  1086. {
  1087. platform_driver_unregister(&bfin_serial_driver);
  1088. uart_unregister_driver(&bfin_serial_reg);
  1089. }
  1090. module_init(bfin_serial_init);
  1091. module_exit(bfin_serial_exit);
  1092. MODULE_AUTHOR("Aubrey.Li <aubrey.li@analog.com>");
  1093. MODULE_DESCRIPTION("Blackfin generic serial port driver");
  1094. MODULE_LICENSE("GPL");
  1095. MODULE_ALIAS_CHARDEV_MAJOR(BFIN_SERIAL_MAJOR);
  1096. MODULE_ALIAS("platform:bfin-uart");