bfin_sport_uart.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * File: linux/drivers/serial/bfin_sport_uart.c
  3. *
  4. * Based on: drivers/serial/bfin_5xx.c by Aubrey Li.
  5. * Author: Roy Huang <roy.huang@analog.com>
  6. *
  7. * Created: Nov 22, 2006
  8. * Copyright: (c) 2006-2007 Analog Devices Inc.
  9. * Description: this driver enable SPORTs on Blackfin emulate UART.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, see the file COPYING, or write
  23. * to the Free Software Foundation, Inc.,
  24. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  25. */
  26. /*
  27. * This driver and the hardware supported are in term of EE-191 of ADI.
  28. * http://www.analog.com/UploadedFiles/Application_Notes/399447663EE191.pdf
  29. * This application note describe how to implement a UART on a Sharc DSP,
  30. * but this driver is implemented on Blackfin Processor.
  31. */
  32. /* After reset, there is a prelude of low level pulse when transmit data first
  33. * time. No addtional pulse in following transmit.
  34. * According to document:
  35. * The SPORTs are ready to start transmitting or receiving data no later than
  36. * three serial clock cycles after they are enabled in the SPORTx_TCR1 or
  37. * SPORTx_RCR1 register. No serial clock cycles are lost from this point on.
  38. * The first internal frame sync will occur one frame sync delay after the
  39. * SPORTs are ready. External frame syncs can occur as soon as the SPORT is
  40. * ready.
  41. */
  42. /* Thanks to Axel Alatalo <axel@rubico.se> for fixing sport rx bug. Sometimes
  43. * sport receives data incorrectly. The following is Axel's words.
  44. * As EE-191, sport rx samples 3 times of the UART baudrate and takes the
  45. * middle smaple of every 3 samples as the data bit. For a 8-N-1 UART setting,
  46. * 30 samples will be required for a byte. If transmitter sends a 1/3 bit short
  47. * byte due to buadrate drift, then the 30th sample of a byte, this sample is
  48. * also the third sample of the stop bit, will happens on the immediately
  49. * following start bit which will be thrown away and missed. Thus since parts
  50. * of the startbit will be missed and the receiver will begin to drift, the
  51. * effect accumulates over time until synchronization is lost.
  52. * If only require 2 samples of the stopbit (by sampling in total 29 samples),
  53. * then a to short byte as in the case above will be tolerated. Then the 1/3
  54. * early startbit will trigger a framesync since the last read is complete
  55. * after only 2/3 stopbit and framesync is active during the last 1/3 looking
  56. * for a possible early startbit. */
  57. //#define DEBUG
  58. #include <linux/module.h>
  59. #include <linux/ioport.h>
  60. #include <linux/init.h>
  61. #include <linux/console.h>
  62. #include <linux/sysrq.h>
  63. #include <linux/platform_device.h>
  64. #include <linux/tty.h>
  65. #include <linux/tty_flip.h>
  66. #include <linux/serial_core.h>
  67. #include <asm/delay.h>
  68. #include <asm/portmux.h>
  69. #include "bfin_sport_uart.h"
  70. unsigned short bfin_uart_pin_req_sport0[] =
  71. {P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS, \
  72. P_SPORT0_DRPRI, P_SPORT0_RSCLK, P_SPORT0_DRSEC, P_SPORT0_DTSEC, 0};
  73. unsigned short bfin_uart_pin_req_sport1[] =
  74. {P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS, \
  75. P_SPORT1_DRPRI, P_SPORT1_RSCLK, P_SPORT1_DRSEC, P_SPORT1_DTSEC, 0};
  76. #define DRV_NAME "bfin-sport-uart"
  77. struct sport_uart_port {
  78. struct uart_port port;
  79. char *name;
  80. int tx_irq;
  81. int rx_irq;
  82. int err_irq;
  83. };
  84. static void sport_uart_tx_chars(struct sport_uart_port *up);
  85. static void sport_stop_tx(struct uart_port *port);
  86. static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value)
  87. {
  88. pr_debug("%s value:%x\n", __FUNCTION__, value);
  89. /* Place a Start and Stop bit */
  90. __asm__ volatile (
  91. "R2 = b#01111111100;\n\t"
  92. "R3 = b#10000000001;\n\t"
  93. "%0 <<= 2;\n\t"
  94. "%0 = %0 & R2;\n\t"
  95. "%0 = %0 | R3;\n\t"
  96. :"=r"(value)
  97. :"0"(value)
  98. :"R2", "R3");
  99. pr_debug("%s value:%x\n", __FUNCTION__, value);
  100. SPORT_PUT_TX(up, value);
  101. }
  102. static inline unsigned int rx_one_byte(struct sport_uart_port *up)
  103. {
  104. unsigned int value, extract;
  105. value = SPORT_GET_RX32(up);
  106. pr_debug("%s value:%x\n", __FUNCTION__, value);
  107. /* Extract 8 bits data */
  108. __asm__ volatile (
  109. "R5 = 0;\n\t"
  110. "P0 = 8;\n\t"
  111. "R1 = 0x1801(Z);\n\t"
  112. "R3 = 0x0300(Z);\n\t"
  113. "R4 = 0;\n\t"
  114. "LSETUP(loop_s, loop_e) LC0 = P0;\nloop_s:\t"
  115. "R2 = extract(%1, R1.L)(Z);\n\t"
  116. "R2 <<= R4;\n\t"
  117. "R5 = R5 | R2;\n\t"
  118. "R1 = R1 - R3;\nloop_e:\t"
  119. "R4 += 1;\n\t"
  120. "%0 = R5;\n\t"
  121. :"=r"(extract)
  122. :"r"(value)
  123. :"P0", "R1", "R2","R3","R4", "R5");
  124. pr_debug(" extract:%x\n", extract);
  125. return extract;
  126. }
  127. static int sport_uart_setup(struct sport_uart_port *up, int sclk, int baud_rate)
  128. {
  129. int tclkdiv, tfsdiv, rclkdiv;
  130. /* Set TCR1 and TCR2 */
  131. SPORT_PUT_TCR1(up, (LTFS | ITFS | TFSR | TLSBIT | ITCLK));
  132. SPORT_PUT_TCR2(up, 10);
  133. pr_debug("%s TCR1:%x, TCR2:%x\n", __FUNCTION__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up));
  134. /* Set RCR1 and RCR2 */
  135. SPORT_PUT_RCR1(up, (RCKFE | LARFS | LRFS | RFSR | IRCLK));
  136. SPORT_PUT_RCR2(up, 28);
  137. pr_debug("%s RCR1:%x, RCR2:%x\n", __FUNCTION__, SPORT_GET_RCR1(up), SPORT_GET_RCR2(up));
  138. tclkdiv = sclk/(2 * baud_rate) - 1;
  139. tfsdiv = 12;
  140. rclkdiv = sclk/(2 * baud_rate * 3) - 1;
  141. SPORT_PUT_TCLKDIV(up, tclkdiv);
  142. SPORT_PUT_TFSDIV(up, tfsdiv);
  143. SPORT_PUT_RCLKDIV(up, rclkdiv);
  144. SSYNC();
  145. pr_debug("%s sclk:%d, baud_rate:%d, tclkdiv:%d, tfsdiv:%d, rclkdiv:%d\n",
  146. __FUNCTION__, sclk, baud_rate, tclkdiv, tfsdiv, rclkdiv);
  147. return 0;
  148. }
  149. static irqreturn_t sport_uart_rx_irq(int irq, void *dev_id)
  150. {
  151. struct sport_uart_port *up = dev_id;
  152. struct tty_struct *tty = up->port.info->port.tty;
  153. unsigned int ch;
  154. do {
  155. ch = rx_one_byte(up);
  156. up->port.icount.rx++;
  157. if (uart_handle_sysrq_char(&up->port, ch))
  158. ;
  159. else
  160. tty_insert_flip_char(tty, ch, TTY_NORMAL);
  161. } while (SPORT_GET_STAT(up) & RXNE);
  162. tty_flip_buffer_push(tty);
  163. return IRQ_HANDLED;
  164. }
  165. static irqreturn_t sport_uart_tx_irq(int irq, void *dev_id)
  166. {
  167. sport_uart_tx_chars(dev_id);
  168. return IRQ_HANDLED;
  169. }
  170. static irqreturn_t sport_uart_err_irq(int irq, void *dev_id)
  171. {
  172. struct sport_uart_port *up = dev_id;
  173. struct tty_struct *tty = up->port.info->port.tty;
  174. unsigned int stat = SPORT_GET_STAT(up);
  175. /* Overflow in RX FIFO */
  176. if (stat & ROVF) {
  177. up->port.icount.overrun++;
  178. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  179. SPORT_PUT_STAT(up, ROVF); /* Clear ROVF bit */
  180. }
  181. /* These should not happen */
  182. if (stat & (TOVF | TUVF | RUVF)) {
  183. printk(KERN_ERR "SPORT Error:%s %s %s\n",
  184. (stat & TOVF)?"TX overflow":"",
  185. (stat & TUVF)?"TX underflow":"",
  186. (stat & RUVF)?"RX underflow":"");
  187. SPORT_PUT_TCR1(up, SPORT_GET_TCR1(up) & ~TSPEN);
  188. SPORT_PUT_RCR1(up, SPORT_GET_RCR1(up) & ~RSPEN);
  189. }
  190. SSYNC();
  191. return IRQ_HANDLED;
  192. }
  193. /* Reqeust IRQ, Setup clock */
  194. static int sport_startup(struct uart_port *port)
  195. {
  196. struct sport_uart_port *up = (struct sport_uart_port *)port;
  197. char buffer[20];
  198. int retval;
  199. pr_debug("%s enter\n", __FUNCTION__);
  200. memset(buffer, 20, '\0');
  201. snprintf(buffer, 20, "%s rx", up->name);
  202. retval = request_irq(up->rx_irq, sport_uart_rx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
  203. if (retval) {
  204. printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
  205. return retval;
  206. }
  207. snprintf(buffer, 20, "%s tx", up->name);
  208. retval = request_irq(up->tx_irq, sport_uart_tx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
  209. if (retval) {
  210. printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
  211. goto fail1;
  212. }
  213. snprintf(buffer, 20, "%s err", up->name);
  214. retval = request_irq(up->err_irq, sport_uart_err_irq, IRQF_SAMPLE_RANDOM, buffer, up);
  215. if (retval) {
  216. printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
  217. goto fail2;
  218. }
  219. if (port->line) {
  220. if (peripheral_request_list(bfin_uart_pin_req_sport1, DRV_NAME))
  221. goto fail3;
  222. } else {
  223. if (peripheral_request_list(bfin_uart_pin_req_sport0, DRV_NAME))
  224. goto fail3;
  225. }
  226. sport_uart_setup(up, get_sclk(), port->uartclk);
  227. /* Enable receive interrupt */
  228. SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) | RSPEN));
  229. SSYNC();
  230. return 0;
  231. fail3:
  232. printk(KERN_ERR DRV_NAME
  233. ": Requesting Peripherals failed\n");
  234. free_irq(up->err_irq, up);
  235. fail2:
  236. free_irq(up->tx_irq, up);
  237. fail1:
  238. free_irq(up->rx_irq, up);
  239. return retval;
  240. }
  241. static void sport_uart_tx_chars(struct sport_uart_port *up)
  242. {
  243. struct circ_buf *xmit = &up->port.info->xmit;
  244. if (SPORT_GET_STAT(up) & TXF)
  245. return;
  246. if (up->port.x_char) {
  247. tx_one_byte(up, up->port.x_char);
  248. up->port.icount.tx++;
  249. up->port.x_char = 0;
  250. return;
  251. }
  252. if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
  253. sport_stop_tx(&up->port);
  254. return;
  255. }
  256. while(!(SPORT_GET_STAT(up) & TXF) && !uart_circ_empty(xmit)) {
  257. tx_one_byte(up, xmit->buf[xmit->tail]);
  258. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE -1);
  259. up->port.icount.tx++;
  260. }
  261. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  262. uart_write_wakeup(&up->port);
  263. }
  264. static unsigned int sport_tx_empty(struct uart_port *port)
  265. {
  266. struct sport_uart_port *up = (struct sport_uart_port *)port;
  267. unsigned int stat;
  268. stat = SPORT_GET_STAT(up);
  269. pr_debug("%s stat:%04x\n", __FUNCTION__, stat);
  270. if (stat & TXHRE) {
  271. return TIOCSER_TEMT;
  272. } else
  273. return 0;
  274. }
  275. static unsigned int sport_get_mctrl(struct uart_port *port)
  276. {
  277. pr_debug("%s enter\n", __FUNCTION__);
  278. return (TIOCM_CTS | TIOCM_CD | TIOCM_DSR);
  279. }
  280. static void sport_set_mctrl(struct uart_port *port, unsigned int mctrl)
  281. {
  282. pr_debug("%s enter\n", __FUNCTION__);
  283. }
  284. static void sport_stop_tx(struct uart_port *port)
  285. {
  286. struct sport_uart_port *up = (struct sport_uart_port *)port;
  287. unsigned int stat;
  288. pr_debug("%s enter\n", __FUNCTION__);
  289. stat = SPORT_GET_STAT(up);
  290. while(!(stat & TXHRE)) {
  291. udelay(1);
  292. stat = SPORT_GET_STAT(up);
  293. }
  294. /* Although the hold register is empty, last byte is still in shift
  295. * register and not sent out yet. If baud rate is lower than default,
  296. * delay should be longer. For example, if the baud rate is 9600,
  297. * the delay must be at least 2ms by experience */
  298. udelay(500);
  299. SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) & ~TSPEN));
  300. SSYNC();
  301. return;
  302. }
  303. static void sport_start_tx(struct uart_port *port)
  304. {
  305. struct sport_uart_port *up = (struct sport_uart_port *)port;
  306. pr_debug("%s enter\n", __FUNCTION__);
  307. /* Write data into SPORT FIFO before enable SPROT to transmit */
  308. sport_uart_tx_chars(up);
  309. /* Enable transmit, then an interrupt will generated */
  310. SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) | TSPEN));
  311. SSYNC();
  312. pr_debug("%s exit\n", __FUNCTION__);
  313. }
  314. static void sport_stop_rx(struct uart_port *port)
  315. {
  316. struct sport_uart_port *up = (struct sport_uart_port *)port;
  317. pr_debug("%s enter\n", __FUNCTION__);
  318. /* Disable sport to stop rx */
  319. SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) & ~RSPEN));
  320. SSYNC();
  321. }
  322. static void sport_enable_ms(struct uart_port *port)
  323. {
  324. pr_debug("%s enter\n", __FUNCTION__);
  325. }
  326. static void sport_break_ctl(struct uart_port *port, int break_state)
  327. {
  328. pr_debug("%s enter\n", __FUNCTION__);
  329. }
  330. static void sport_shutdown(struct uart_port *port)
  331. {
  332. struct sport_uart_port *up = (struct sport_uart_port *)port;
  333. pr_debug("%s enter\n", __FUNCTION__);
  334. /* Disable sport */
  335. SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) & ~TSPEN));
  336. SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) & ~RSPEN));
  337. SSYNC();
  338. if (port->line) {
  339. peripheral_free_list(bfin_uart_pin_req_sport1);
  340. } else {
  341. peripheral_free_list(bfin_uart_pin_req_sport0);
  342. }
  343. free_irq(up->rx_irq, up);
  344. free_irq(up->tx_irq, up);
  345. free_irq(up->err_irq, up);
  346. }
  347. static void sport_set_termios(struct uart_port *port,
  348. struct termios *termios, struct termios *old)
  349. {
  350. pr_debug("%s enter, c_cflag:%08x\n", __FUNCTION__, termios->c_cflag);
  351. uart_update_timeout(port, CS8 ,port->uartclk);
  352. }
  353. static const char *sport_type(struct uart_port *port)
  354. {
  355. struct sport_uart_port *up = (struct sport_uart_port *)port;
  356. pr_debug("%s enter\n", __FUNCTION__);
  357. return up->name;
  358. }
  359. static void sport_release_port(struct uart_port *port)
  360. {
  361. pr_debug("%s enter\n", __FUNCTION__);
  362. }
  363. static int sport_request_port(struct uart_port *port)
  364. {
  365. pr_debug("%s enter\n", __FUNCTION__);
  366. return 0;
  367. }
  368. static void sport_config_port(struct uart_port *port, int flags)
  369. {
  370. struct sport_uart_port *up = (struct sport_uart_port *)port;
  371. pr_debug("%s enter\n", __FUNCTION__);
  372. up->port.type = PORT_BFIN_SPORT;
  373. }
  374. static int sport_verify_port(struct uart_port *port, struct serial_struct *ser)
  375. {
  376. pr_debug("%s enter\n", __FUNCTION__);
  377. return 0;
  378. }
  379. struct uart_ops sport_uart_ops = {
  380. .tx_empty = sport_tx_empty,
  381. .set_mctrl = sport_set_mctrl,
  382. .get_mctrl = sport_get_mctrl,
  383. .stop_tx = sport_stop_tx,
  384. .start_tx = sport_start_tx,
  385. .stop_rx = sport_stop_rx,
  386. .enable_ms = sport_enable_ms,
  387. .break_ctl = sport_break_ctl,
  388. .startup = sport_startup,
  389. .shutdown = sport_shutdown,
  390. .set_termios = sport_set_termios,
  391. .type = sport_type,
  392. .release_port = sport_release_port,
  393. .request_port = sport_request_port,
  394. .config_port = sport_config_port,
  395. .verify_port = sport_verify_port,
  396. };
  397. static struct sport_uart_port sport_uart_ports[] = {
  398. { /* SPORT 0 */
  399. .name = "SPORT0",
  400. .tx_irq = IRQ_SPORT0_TX,
  401. .rx_irq = IRQ_SPORT0_RX,
  402. .err_irq= IRQ_SPORT0_ERROR,
  403. .port = {
  404. .type = PORT_BFIN_SPORT,
  405. .iotype = UPIO_MEM,
  406. .membase = (void __iomem *)SPORT0_TCR1,
  407. .mapbase = SPORT0_TCR1,
  408. .irq = IRQ_SPORT0_RX,
  409. .uartclk = CONFIG_SPORT_BAUD_RATE,
  410. .fifosize = 8,
  411. .ops = &sport_uart_ops,
  412. .line = 0,
  413. },
  414. }, { /* SPORT 1 */
  415. .name = "SPORT1",
  416. .tx_irq = IRQ_SPORT1_TX,
  417. .rx_irq = IRQ_SPORT1_RX,
  418. .err_irq= IRQ_SPORT1_ERROR,
  419. .port = {
  420. .type = PORT_BFIN_SPORT,
  421. .iotype = UPIO_MEM,
  422. .membase = (void __iomem *)SPORT1_TCR1,
  423. .mapbase = SPORT1_TCR1,
  424. .irq = IRQ_SPORT1_RX,
  425. .uartclk = CONFIG_SPORT_BAUD_RATE,
  426. .fifosize = 8,
  427. .ops = &sport_uart_ops,
  428. .line = 1,
  429. },
  430. }
  431. };
  432. static struct uart_driver sport_uart_reg = {
  433. .owner = THIS_MODULE,
  434. .driver_name = "SPORT-UART",
  435. .dev_name = "ttySS",
  436. .major = 204,
  437. .minor = 84,
  438. .nr = ARRAY_SIZE(sport_uart_ports),
  439. .cons = NULL,
  440. };
  441. static int sport_uart_suspend(struct platform_device *dev, pm_message_t state)
  442. {
  443. struct sport_uart_port *sport = platform_get_drvdata(dev);
  444. pr_debug("%s enter\n", __FUNCTION__);
  445. if (sport)
  446. uart_suspend_port(&sport_uart_reg, &sport->port);
  447. return 0;
  448. }
  449. static int sport_uart_resume(struct platform_device *dev)
  450. {
  451. struct sport_uart_port *sport = platform_get_drvdata(dev);
  452. pr_debug("%s enter\n", __FUNCTION__);
  453. if (sport)
  454. uart_resume_port(&sport_uart_reg, &sport->port);
  455. return 0;
  456. }
  457. static int sport_uart_probe(struct platform_device *dev)
  458. {
  459. pr_debug("%s enter\n", __FUNCTION__);
  460. sport_uart_ports[dev->id].port.dev = &dev->dev;
  461. uart_add_one_port(&sport_uart_reg, &sport_uart_ports[dev->id].port);
  462. platform_set_drvdata(dev, &sport_uart_ports[dev->id]);
  463. return 0;
  464. }
  465. static int sport_uart_remove(struct platform_device *dev)
  466. {
  467. struct sport_uart_port *sport = platform_get_drvdata(dev);
  468. pr_debug("%s enter\n", __FUNCTION__);
  469. platform_set_drvdata(dev, NULL);
  470. if (sport)
  471. uart_remove_one_port(&sport_uart_reg, &sport->port);
  472. return 0;
  473. }
  474. static struct platform_driver sport_uart_driver = {
  475. .probe = sport_uart_probe,
  476. .remove = sport_uart_remove,
  477. .suspend = sport_uart_suspend,
  478. .resume = sport_uart_resume,
  479. .driver = {
  480. .name = DRV_NAME,
  481. },
  482. };
  483. static int __init sport_uart_init(void)
  484. {
  485. int ret;
  486. pr_debug("%s enter\n", __FUNCTION__);
  487. ret = uart_register_driver(&sport_uart_reg);
  488. if (ret != 0) {
  489. printk(KERN_ERR "Failed to register %s:%d\n",
  490. sport_uart_reg.driver_name, ret);
  491. return ret;
  492. }
  493. ret = platform_driver_register(&sport_uart_driver);
  494. if (ret != 0) {
  495. printk(KERN_ERR "Failed to register sport uart driver:%d\n", ret);
  496. uart_unregister_driver(&sport_uart_reg);
  497. }
  498. pr_debug("%s exit\n", __FUNCTION__);
  499. return ret;
  500. }
  501. static void __exit sport_uart_exit(void)
  502. {
  503. pr_debug("%s enter\n", __FUNCTION__);
  504. platform_driver_unregister(&sport_uart_driver);
  505. uart_unregister_driver(&sport_uart_reg);
  506. }
  507. module_init(sport_uart_init);
  508. module_exit(sport_uart_exit);
  509. MODULE_LICENSE("GPL");