bfin_5xx.c 31 KB

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