bfin_5xx.c 31 KB

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