bfin_5xx.c 31 KB

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