bfin_5xx.c 31 KB

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