bfin_5xx.c 30 KB

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