bfin_sport_uart.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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", __func__, value);
  89. /* Place a Start and Stop bit */
  90. __asm__ __volatile__ (
  91. "R2 = b#01111111100;"
  92. "R3 = b#10000000001;"
  93. "%0 <<= 2;"
  94. "%0 = %0 & R2;"
  95. "%0 = %0 | R3;"
  96. : "=d"(value)
  97. : "d"(value)
  98. : "ASTAT", "R2", "R3"
  99. );
  100. pr_debug("%s value:%x\n", __func__, value);
  101. SPORT_PUT_TX(up, value);
  102. }
  103. static inline unsigned int rx_one_byte(struct sport_uart_port *up)
  104. {
  105. unsigned int value, extract;
  106. u32 tmp_mask1, tmp_mask2, tmp_shift, tmp;
  107. value = SPORT_GET_RX32(up);
  108. pr_debug("%s value:%x\n", __func__, value);
  109. /* Extract 8 bits data */
  110. __asm__ __volatile__ (
  111. "%[extr] = 0;"
  112. "%[mask1] = 0x1801(Z);"
  113. "%[mask2] = 0x0300(Z);"
  114. "%[shift] = 0;"
  115. "LSETUP(.Lloop_s, .Lloop_e) LC0 = %[lc];"
  116. ".Lloop_s:"
  117. "%[tmp] = extract(%[val], %[mask1].L)(Z);"
  118. "%[tmp] <<= %[shift];"
  119. "%[extr] = %[extr] | %[tmp];"
  120. "%[mask1] = %[mask1] - %[mask2];"
  121. ".Lloop_e:"
  122. "%[shift] += 1;"
  123. : [val]"=d"(value), [extr]"=d"(extract), [shift]"=d"(tmp_shift), [tmp]"=d"(tmp),
  124. [mask1]"=d"(tmp_mask1), [mask2]"=d"(tmp_mask2)
  125. : "d"(value), [lc]"a"(8)
  126. : "ASTAT", "LB0", "LC0", "LT0"
  127. );
  128. pr_debug(" extract:%x\n", extract);
  129. return extract;
  130. }
  131. static int sport_uart_setup(struct sport_uart_port *up, int sclk, int baud_rate)
  132. {
  133. int tclkdiv, tfsdiv, rclkdiv;
  134. /* Set TCR1 and TCR2 */
  135. SPORT_PUT_TCR1(up, (LATFS | ITFS | TFSR | TLSBIT | ITCLK));
  136. SPORT_PUT_TCR2(up, 10);
  137. pr_debug("%s TCR1:%x, TCR2:%x\n", __func__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up));
  138. /* Set RCR1 and RCR2 */
  139. SPORT_PUT_RCR1(up, (RCKFE | LARFS | LRFS | RFSR | IRCLK));
  140. SPORT_PUT_RCR2(up, 28);
  141. pr_debug("%s RCR1:%x, RCR2:%x\n", __func__, SPORT_GET_RCR1(up), SPORT_GET_RCR2(up));
  142. tclkdiv = sclk/(2 * baud_rate) - 1;
  143. tfsdiv = 12;
  144. rclkdiv = sclk/(2 * baud_rate * 3) - 1;
  145. SPORT_PUT_TCLKDIV(up, tclkdiv);
  146. SPORT_PUT_TFSDIV(up, tfsdiv);
  147. SPORT_PUT_RCLKDIV(up, rclkdiv);
  148. SSYNC();
  149. pr_debug("%s sclk:%d, baud_rate:%d, tclkdiv:%d, tfsdiv:%d, rclkdiv:%d\n",
  150. __func__, sclk, baud_rate, tclkdiv, tfsdiv, rclkdiv);
  151. return 0;
  152. }
  153. static irqreturn_t sport_uart_rx_irq(int irq, void *dev_id)
  154. {
  155. struct sport_uart_port *up = dev_id;
  156. struct tty_struct *tty = up->port.info->port.tty;
  157. unsigned int ch;
  158. do {
  159. ch = rx_one_byte(up);
  160. up->port.icount.rx++;
  161. if (uart_handle_sysrq_char(&up->port, ch))
  162. ;
  163. else
  164. tty_insert_flip_char(tty, ch, TTY_NORMAL);
  165. } while (SPORT_GET_STAT(up) & RXNE);
  166. tty_flip_buffer_push(tty);
  167. return IRQ_HANDLED;
  168. }
  169. static irqreturn_t sport_uart_tx_irq(int irq, void *dev_id)
  170. {
  171. sport_uart_tx_chars(dev_id);
  172. return IRQ_HANDLED;
  173. }
  174. static irqreturn_t sport_uart_err_irq(int irq, void *dev_id)
  175. {
  176. struct sport_uart_port *up = dev_id;
  177. struct tty_struct *tty = up->port.info->port.tty;
  178. unsigned int stat = SPORT_GET_STAT(up);
  179. /* Overflow in RX FIFO */
  180. if (stat & ROVF) {
  181. up->port.icount.overrun++;
  182. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  183. SPORT_PUT_STAT(up, ROVF); /* Clear ROVF bit */
  184. }
  185. /* These should not happen */
  186. if (stat & (TOVF | TUVF | RUVF)) {
  187. printk(KERN_ERR "SPORT Error:%s %s %s\n",
  188. (stat & TOVF)?"TX overflow":"",
  189. (stat & TUVF)?"TX underflow":"",
  190. (stat & RUVF)?"RX underflow":"");
  191. SPORT_PUT_TCR1(up, SPORT_GET_TCR1(up) & ~TSPEN);
  192. SPORT_PUT_RCR1(up, SPORT_GET_RCR1(up) & ~RSPEN);
  193. }
  194. SSYNC();
  195. return IRQ_HANDLED;
  196. }
  197. /* Reqeust IRQ, Setup clock */
  198. static int sport_startup(struct uart_port *port)
  199. {
  200. struct sport_uart_port *up = (struct sport_uart_port *)port;
  201. char buffer[20];
  202. int retval;
  203. pr_debug("%s enter\n", __func__);
  204. memset(buffer, 20, '\0');
  205. snprintf(buffer, 20, "%s rx", up->name);
  206. retval = request_irq(up->rx_irq, sport_uart_rx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
  207. if (retval) {
  208. printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
  209. return retval;
  210. }
  211. snprintf(buffer, 20, "%s tx", up->name);
  212. retval = request_irq(up->tx_irq, sport_uart_tx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
  213. if (retval) {
  214. printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
  215. goto fail1;
  216. }
  217. snprintf(buffer, 20, "%s err", up->name);
  218. retval = request_irq(up->err_irq, sport_uart_err_irq, IRQF_SAMPLE_RANDOM, buffer, up);
  219. if (retval) {
  220. printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
  221. goto fail2;
  222. }
  223. if (port->line) {
  224. if (peripheral_request_list(bfin_uart_pin_req_sport1, DRV_NAME))
  225. goto fail3;
  226. } else {
  227. if (peripheral_request_list(bfin_uart_pin_req_sport0, DRV_NAME))
  228. goto fail3;
  229. }
  230. sport_uart_setup(up, get_sclk(), port->uartclk);
  231. /* Enable receive interrupt */
  232. SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) | RSPEN));
  233. SSYNC();
  234. return 0;
  235. fail3:
  236. printk(KERN_ERR DRV_NAME
  237. ": Requesting Peripherals failed\n");
  238. free_irq(up->err_irq, up);
  239. fail2:
  240. free_irq(up->tx_irq, up);
  241. fail1:
  242. free_irq(up->rx_irq, up);
  243. return retval;
  244. }
  245. static void sport_uart_tx_chars(struct sport_uart_port *up)
  246. {
  247. struct circ_buf *xmit = &up->port.info->xmit;
  248. if (SPORT_GET_STAT(up) & TXF)
  249. return;
  250. if (up->port.x_char) {
  251. tx_one_byte(up, up->port.x_char);
  252. up->port.icount.tx++;
  253. up->port.x_char = 0;
  254. return;
  255. }
  256. if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
  257. sport_stop_tx(&up->port);
  258. return;
  259. }
  260. while(!(SPORT_GET_STAT(up) & TXF) && !uart_circ_empty(xmit)) {
  261. tx_one_byte(up, xmit->buf[xmit->tail]);
  262. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE -1);
  263. up->port.icount.tx++;
  264. }
  265. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  266. uart_write_wakeup(&up->port);
  267. }
  268. static unsigned int sport_tx_empty(struct uart_port *port)
  269. {
  270. struct sport_uart_port *up = (struct sport_uart_port *)port;
  271. unsigned int stat;
  272. stat = SPORT_GET_STAT(up);
  273. pr_debug("%s stat:%04x\n", __func__, stat);
  274. if (stat & TXHRE) {
  275. return TIOCSER_TEMT;
  276. } else
  277. return 0;
  278. }
  279. static unsigned int sport_get_mctrl(struct uart_port *port)
  280. {
  281. pr_debug("%s enter\n", __func__);
  282. return (TIOCM_CTS | TIOCM_CD | TIOCM_DSR);
  283. }
  284. static void sport_set_mctrl(struct uart_port *port, unsigned int mctrl)
  285. {
  286. pr_debug("%s enter\n", __func__);
  287. }
  288. static void sport_stop_tx(struct uart_port *port)
  289. {
  290. struct sport_uart_port *up = (struct sport_uart_port *)port;
  291. unsigned int stat;
  292. pr_debug("%s enter\n", __func__);
  293. stat = SPORT_GET_STAT(up);
  294. while(!(stat & TXHRE)) {
  295. udelay(1);
  296. stat = SPORT_GET_STAT(up);
  297. }
  298. /* Although the hold register is empty, last byte is still in shift
  299. * register and not sent out yet. If baud rate is lower than default,
  300. * delay should be longer. For example, if the baud rate is 9600,
  301. * the delay must be at least 2ms by experience */
  302. udelay(500);
  303. SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) & ~TSPEN));
  304. SSYNC();
  305. return;
  306. }
  307. static void sport_start_tx(struct uart_port *port)
  308. {
  309. struct sport_uart_port *up = (struct sport_uart_port *)port;
  310. pr_debug("%s enter\n", __func__);
  311. /* Write data into SPORT FIFO before enable SPROT to transmit */
  312. sport_uart_tx_chars(up);
  313. /* Enable transmit, then an interrupt will generated */
  314. SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) | TSPEN));
  315. SSYNC();
  316. pr_debug("%s exit\n", __func__);
  317. }
  318. static void sport_stop_rx(struct uart_port *port)
  319. {
  320. struct sport_uart_port *up = (struct sport_uart_port *)port;
  321. pr_debug("%s enter\n", __func__);
  322. /* Disable sport to stop rx */
  323. SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) & ~RSPEN));
  324. SSYNC();
  325. }
  326. static void sport_enable_ms(struct uart_port *port)
  327. {
  328. pr_debug("%s enter\n", __func__);
  329. }
  330. static void sport_break_ctl(struct uart_port *port, int break_state)
  331. {
  332. pr_debug("%s enter\n", __func__);
  333. }
  334. static void sport_shutdown(struct uart_port *port)
  335. {
  336. struct sport_uart_port *up = (struct sport_uart_port *)port;
  337. pr_debug("%s enter\n", __func__);
  338. /* Disable sport */
  339. SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) & ~TSPEN));
  340. SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) & ~RSPEN));
  341. SSYNC();
  342. if (port->line) {
  343. peripheral_free_list(bfin_uart_pin_req_sport1);
  344. } else {
  345. peripheral_free_list(bfin_uart_pin_req_sport0);
  346. }
  347. free_irq(up->rx_irq, up);
  348. free_irq(up->tx_irq, up);
  349. free_irq(up->err_irq, up);
  350. }
  351. static void sport_set_termios(struct uart_port *port,
  352. struct ktermios *termios, struct ktermios *old)
  353. {
  354. pr_debug("%s enter, c_cflag:%08x\n", __func__, termios->c_cflag);
  355. uart_update_timeout(port, CS8 ,port->uartclk);
  356. }
  357. static const char *sport_type(struct uart_port *port)
  358. {
  359. struct sport_uart_port *up = (struct sport_uart_port *)port;
  360. pr_debug("%s enter\n", __func__);
  361. return up->name;
  362. }
  363. static void sport_release_port(struct uart_port *port)
  364. {
  365. pr_debug("%s enter\n", __func__);
  366. }
  367. static int sport_request_port(struct uart_port *port)
  368. {
  369. pr_debug("%s enter\n", __func__);
  370. return 0;
  371. }
  372. static void sport_config_port(struct uart_port *port, int flags)
  373. {
  374. struct sport_uart_port *up = (struct sport_uart_port *)port;
  375. pr_debug("%s enter\n", __func__);
  376. up->port.type = PORT_BFIN_SPORT;
  377. }
  378. static int sport_verify_port(struct uart_port *port, struct serial_struct *ser)
  379. {
  380. pr_debug("%s enter\n", __func__);
  381. return 0;
  382. }
  383. struct uart_ops sport_uart_ops = {
  384. .tx_empty = sport_tx_empty,
  385. .set_mctrl = sport_set_mctrl,
  386. .get_mctrl = sport_get_mctrl,
  387. .stop_tx = sport_stop_tx,
  388. .start_tx = sport_start_tx,
  389. .stop_rx = sport_stop_rx,
  390. .enable_ms = sport_enable_ms,
  391. .break_ctl = sport_break_ctl,
  392. .startup = sport_startup,
  393. .shutdown = sport_shutdown,
  394. .set_termios = sport_set_termios,
  395. .type = sport_type,
  396. .release_port = sport_release_port,
  397. .request_port = sport_request_port,
  398. .config_port = sport_config_port,
  399. .verify_port = sport_verify_port,
  400. };
  401. static struct sport_uart_port sport_uart_ports[] = {
  402. { /* SPORT 0 */
  403. .name = "SPORT0",
  404. .tx_irq = IRQ_SPORT0_TX,
  405. .rx_irq = IRQ_SPORT0_RX,
  406. .err_irq= IRQ_SPORT0_ERROR,
  407. .port = {
  408. .type = PORT_BFIN_SPORT,
  409. .iotype = UPIO_MEM,
  410. .membase = (void __iomem *)SPORT0_TCR1,
  411. .mapbase = SPORT0_TCR1,
  412. .irq = IRQ_SPORT0_RX,
  413. .uartclk = CONFIG_SPORT_BAUD_RATE,
  414. .fifosize = 8,
  415. .ops = &sport_uart_ops,
  416. .line = 0,
  417. },
  418. }, { /* SPORT 1 */
  419. .name = "SPORT1",
  420. .tx_irq = IRQ_SPORT1_TX,
  421. .rx_irq = IRQ_SPORT1_RX,
  422. .err_irq= IRQ_SPORT1_ERROR,
  423. .port = {
  424. .type = PORT_BFIN_SPORT,
  425. .iotype = UPIO_MEM,
  426. .membase = (void __iomem *)SPORT1_TCR1,
  427. .mapbase = SPORT1_TCR1,
  428. .irq = IRQ_SPORT1_RX,
  429. .uartclk = CONFIG_SPORT_BAUD_RATE,
  430. .fifosize = 8,
  431. .ops = &sport_uart_ops,
  432. .line = 1,
  433. },
  434. }
  435. };
  436. static struct uart_driver sport_uart_reg = {
  437. .owner = THIS_MODULE,
  438. .driver_name = "SPORT-UART",
  439. .dev_name = "ttySS",
  440. .major = 204,
  441. .minor = 84,
  442. .nr = ARRAY_SIZE(sport_uart_ports),
  443. .cons = NULL,
  444. };
  445. static int sport_uart_suspend(struct platform_device *dev, pm_message_t state)
  446. {
  447. struct sport_uart_port *sport = platform_get_drvdata(dev);
  448. pr_debug("%s enter\n", __func__);
  449. if (sport)
  450. uart_suspend_port(&sport_uart_reg, &sport->port);
  451. return 0;
  452. }
  453. static int sport_uart_resume(struct platform_device *dev)
  454. {
  455. struct sport_uart_port *sport = platform_get_drvdata(dev);
  456. pr_debug("%s enter\n", __func__);
  457. if (sport)
  458. uart_resume_port(&sport_uart_reg, &sport->port);
  459. return 0;
  460. }
  461. static int sport_uart_probe(struct platform_device *dev)
  462. {
  463. pr_debug("%s enter\n", __func__);
  464. sport_uart_ports[dev->id].port.dev = &dev->dev;
  465. uart_add_one_port(&sport_uart_reg, &sport_uart_ports[dev->id].port);
  466. platform_set_drvdata(dev, &sport_uart_ports[dev->id]);
  467. return 0;
  468. }
  469. static int sport_uart_remove(struct platform_device *dev)
  470. {
  471. struct sport_uart_port *sport = platform_get_drvdata(dev);
  472. pr_debug("%s enter\n", __func__);
  473. platform_set_drvdata(dev, NULL);
  474. if (sport)
  475. uart_remove_one_port(&sport_uart_reg, &sport->port);
  476. return 0;
  477. }
  478. static struct platform_driver sport_uart_driver = {
  479. .probe = sport_uart_probe,
  480. .remove = sport_uart_remove,
  481. .suspend = sport_uart_suspend,
  482. .resume = sport_uart_resume,
  483. .driver = {
  484. .name = DRV_NAME,
  485. },
  486. };
  487. static int __init sport_uart_init(void)
  488. {
  489. int ret;
  490. pr_debug("%s enter\n", __func__);
  491. ret = uart_register_driver(&sport_uart_reg);
  492. if (ret != 0) {
  493. printk(KERN_ERR "Failed to register %s:%d\n",
  494. sport_uart_reg.driver_name, ret);
  495. return ret;
  496. }
  497. ret = platform_driver_register(&sport_uart_driver);
  498. if (ret != 0) {
  499. printk(KERN_ERR "Failed to register sport uart driver:%d\n", ret);
  500. uart_unregister_driver(&sport_uart_reg);
  501. }
  502. pr_debug("%s exit\n", __func__);
  503. return ret;
  504. }
  505. static void __exit sport_uart_exit(void)
  506. {
  507. pr_debug("%s enter\n", __func__);
  508. platform_driver_unregister(&sport_uart_driver);
  509. uart_unregister_driver(&sport_uart_reg);
  510. }
  511. module_init(sport_uart_init);
  512. module_exit(sport_uart_exit);
  513. MODULE_LICENSE("GPL");