bfin_5xx.c 32 KB

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