max3107.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /*
  2. * max3107.c - spi uart protocol driver for Maxim 3107
  3. * Based on max3100.c
  4. * by Christian Pellegrin <chripell@evolware.org>
  5. * and max3110.c
  6. * by Feng Tang <feng.tang@intel.com>
  7. *
  8. * Copyright (C) Aavamobile 2009
  9. *
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. *
  28. */
  29. #include <linux/delay.h>
  30. #include <linux/device.h>
  31. #include <linux/serial_core.h>
  32. #include <linux/serial.h>
  33. #include <linux/tty.h>
  34. #include <linux/tty_flip.h>
  35. #include <linux/gpio.h>
  36. #include <linux/spi/spi.h>
  37. #include <linux/freezer.h>
  38. #include <linux/module.h>
  39. #include "max3107.h"
  40. static const struct baud_table brg26_ext[] = {
  41. { 300, MAX3107_BRG26_B300 },
  42. { 600, MAX3107_BRG26_B600 },
  43. { 1200, MAX3107_BRG26_B1200 },
  44. { 2400, MAX3107_BRG26_B2400 },
  45. { 4800, MAX3107_BRG26_B4800 },
  46. { 9600, MAX3107_BRG26_B9600 },
  47. { 19200, MAX3107_BRG26_B19200 },
  48. { 57600, MAX3107_BRG26_B57600 },
  49. { 115200, MAX3107_BRG26_B115200 },
  50. { 230400, MAX3107_BRG26_B230400 },
  51. { 460800, MAX3107_BRG26_B460800 },
  52. { 921600, MAX3107_BRG26_B921600 },
  53. { 0, 0 }
  54. };
  55. static const struct baud_table brg13_int[] = {
  56. { 300, MAX3107_BRG13_IB300 },
  57. { 600, MAX3107_BRG13_IB600 },
  58. { 1200, MAX3107_BRG13_IB1200 },
  59. { 2400, MAX3107_BRG13_IB2400 },
  60. { 4800, MAX3107_BRG13_IB4800 },
  61. { 9600, MAX3107_BRG13_IB9600 },
  62. { 19200, MAX3107_BRG13_IB19200 },
  63. { 57600, MAX3107_BRG13_IB57600 },
  64. { 115200, MAX3107_BRG13_IB115200 },
  65. { 230400, MAX3107_BRG13_IB230400 },
  66. { 460800, MAX3107_BRG13_IB460800 },
  67. { 921600, MAX3107_BRG13_IB921600 },
  68. { 0, 0 }
  69. };
  70. static u32 get_new_brg(int baud, struct max3107_port *s)
  71. {
  72. int i;
  73. const struct baud_table *baud_tbl = s->baud_tbl;
  74. for (i = 0; i < 13; i++) {
  75. if (baud == baud_tbl[i].baud)
  76. return baud_tbl[i].new_brg;
  77. }
  78. return 0;
  79. }
  80. /* Perform SPI transfer for write/read of device register(s) */
  81. int max3107_rw(struct max3107_port *s, u8 *tx, u8 *rx, int len)
  82. {
  83. struct spi_message spi_msg;
  84. struct spi_transfer spi_xfer;
  85. /* Initialize SPI ,message */
  86. spi_message_init(&spi_msg);
  87. /* Initialize SPI transfer */
  88. memset(&spi_xfer, 0, sizeof spi_xfer);
  89. spi_xfer.len = len;
  90. spi_xfer.tx_buf = tx;
  91. spi_xfer.rx_buf = rx;
  92. spi_xfer.speed_hz = MAX3107_SPI_SPEED;
  93. /* Add SPI transfer to SPI message */
  94. spi_message_add_tail(&spi_xfer, &spi_msg);
  95. #ifdef DBG_TRACE_SPI_DATA
  96. {
  97. int i;
  98. pr_info("tx len %d:\n", spi_xfer.len);
  99. for (i = 0 ; i < spi_xfer.len && i < 32 ; i++)
  100. pr_info(" %x", ((u8 *)spi_xfer.tx_buf)[i]);
  101. pr_info("\n");
  102. }
  103. #endif
  104. /* Perform synchronous SPI transfer */
  105. if (spi_sync(s->spi, &spi_msg)) {
  106. dev_err(&s->spi->dev, "spi_sync failure\n");
  107. return -EIO;
  108. }
  109. #ifdef DBG_TRACE_SPI_DATA
  110. if (spi_xfer.rx_buf) {
  111. int i;
  112. pr_info("rx len %d:\n", spi_xfer.len);
  113. for (i = 0 ; i < spi_xfer.len && i < 32 ; i++)
  114. pr_info(" %x", ((u8 *)spi_xfer.rx_buf)[i]);
  115. pr_info("\n");
  116. }
  117. #endif
  118. return 0;
  119. }
  120. EXPORT_SYMBOL_GPL(max3107_rw);
  121. /* Puts received data to circular buffer */
  122. static void put_data_to_circ_buf(struct max3107_port *s, unsigned char *data,
  123. int len)
  124. {
  125. struct uart_port *port = &s->port;
  126. struct tty_struct *tty;
  127. if (!port->state)
  128. return;
  129. tty = port->state->port.tty;
  130. if (!tty)
  131. return;
  132. /* Insert received data */
  133. tty_insert_flip_string(tty, data, len);
  134. /* Update RX counter */
  135. port->icount.rx += len;
  136. }
  137. /* Handle data receiving */
  138. static void max3107_handlerx(struct max3107_port *s, u16 rxlvl)
  139. {
  140. int i;
  141. int j;
  142. int len; /* SPI transfer buffer length */
  143. u16 *buf;
  144. u8 *valid_str;
  145. if (!s->rx_enabled)
  146. /* RX is disabled */
  147. return;
  148. if (rxlvl == 0) {
  149. /* RX fifo is empty */
  150. return;
  151. } else if (rxlvl >= MAX3107_RX_FIFO_SIZE) {
  152. dev_warn(&s->spi->dev, "Possible RX FIFO overrun %d\n", rxlvl);
  153. /* Ensure sanity of RX level */
  154. rxlvl = MAX3107_RX_FIFO_SIZE;
  155. }
  156. if ((s->rxbuf == 0) || (s->rxstr == 0)) {
  157. dev_warn(&s->spi->dev, "Rx buffer/str isn't ready\n");
  158. return;
  159. }
  160. buf = s->rxbuf;
  161. valid_str = s->rxstr;
  162. while (rxlvl) {
  163. pr_debug("rxlvl %d\n", rxlvl);
  164. /* Clear buffer */
  165. memset(buf, 0, sizeof(u16) * (MAX3107_RX_FIFO_SIZE + 2));
  166. len = 0;
  167. if (s->irqen_reg & MAX3107_IRQ_RXFIFO_BIT) {
  168. /* First disable RX FIFO interrupt */
  169. pr_debug("Disabling RX INT\n");
  170. buf[0] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG);
  171. s->irqen_reg &= ~MAX3107_IRQ_RXFIFO_BIT;
  172. buf[0] |= s->irqen_reg;
  173. len++;
  174. }
  175. /* Just increase the length by amount of words in FIFO since
  176. * buffer was zeroed and SPI transfer of 0x0000 means reading
  177. * from RX FIFO
  178. */
  179. len += rxlvl;
  180. /* Append RX level query */
  181. buf[len] = MAX3107_RXFIFOLVL_REG;
  182. len++;
  183. /* Perform the SPI transfer */
  184. if (max3107_rw(s, (u8 *)buf, (u8 *)buf, len * 2)) {
  185. dev_err(&s->spi->dev, "SPI transfer for RX h failed\n");
  186. return;
  187. }
  188. /* Skip RX FIFO interrupt disabling word if it was added */
  189. j = ((len - 1) - rxlvl);
  190. /* Read received words */
  191. for (i = 0; i < rxlvl; i++, j++)
  192. valid_str[i] = (u8)buf[j];
  193. put_data_to_circ_buf(s, valid_str, rxlvl);
  194. /* Get new RX level */
  195. rxlvl = (buf[len - 1] & MAX3107_SPI_RX_DATA_MASK);
  196. }
  197. if (s->rx_enabled) {
  198. /* RX still enabled, re-enable RX FIFO interrupt */
  199. pr_debug("Enabling RX INT\n");
  200. buf[0] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG);
  201. s->irqen_reg |= MAX3107_IRQ_RXFIFO_BIT;
  202. buf[0] |= s->irqen_reg;
  203. if (max3107_rw(s, (u8 *)buf, NULL, 2))
  204. dev_err(&s->spi->dev, "RX FIFO INT enabling failed\n");
  205. }
  206. /* Push the received data to receivers */
  207. if (s->port.state->port.tty)
  208. tty_flip_buffer_push(s->port.state->port.tty);
  209. }
  210. /* Handle data sending */
  211. static void max3107_handletx(struct max3107_port *s)
  212. {
  213. struct circ_buf *xmit = &s->port.state->xmit;
  214. int i;
  215. unsigned long flags;
  216. int len; /* SPI transfer buffer length */
  217. u16 *buf;
  218. if (!s->tx_fifo_empty)
  219. /* Don't send more data before previous data is sent */
  220. return;
  221. if (uart_circ_empty(xmit) || uart_tx_stopped(&s->port))
  222. /* No data to send or TX is stopped */
  223. return;
  224. if (!s->txbuf) {
  225. dev_warn(&s->spi->dev, "Txbuf isn't ready\n");
  226. return;
  227. }
  228. buf = s->txbuf;
  229. /* Get length of data pending in circular buffer */
  230. len = uart_circ_chars_pending(xmit);
  231. if (len) {
  232. /* Limit to size of TX FIFO */
  233. if (len > MAX3107_TX_FIFO_SIZE)
  234. len = MAX3107_TX_FIFO_SIZE;
  235. pr_debug("txlen %d\n", len);
  236. /* Update TX counter */
  237. s->port.icount.tx += len;
  238. /* TX FIFO will no longer be empty */
  239. s->tx_fifo_empty = 0;
  240. i = 0;
  241. if (s->irqen_reg & MAX3107_IRQ_TXEMPTY_BIT) {
  242. /* First disable TX empty interrupt */
  243. pr_debug("Disabling TE INT\n");
  244. buf[i] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG);
  245. s->irqen_reg &= ~MAX3107_IRQ_TXEMPTY_BIT;
  246. buf[i] |= s->irqen_reg;
  247. i++;
  248. len++;
  249. }
  250. /* Add data to send */
  251. spin_lock_irqsave(&s->port.lock, flags);
  252. for ( ; i < len ; i++) {
  253. buf[i] = (MAX3107_WRITE_BIT | MAX3107_THR_REG);
  254. buf[i] |= ((u16)xmit->buf[xmit->tail] &
  255. MAX3107_SPI_TX_DATA_MASK);
  256. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  257. }
  258. spin_unlock_irqrestore(&s->port.lock, flags);
  259. if (!(s->irqen_reg & MAX3107_IRQ_TXEMPTY_BIT)) {
  260. /* Enable TX empty interrupt */
  261. pr_debug("Enabling TE INT\n");
  262. buf[i] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG);
  263. s->irqen_reg |= MAX3107_IRQ_TXEMPTY_BIT;
  264. buf[i] |= s->irqen_reg;
  265. i++;
  266. len++;
  267. }
  268. if (!s->tx_enabled) {
  269. /* Enable TX */
  270. pr_debug("Enable TX\n");
  271. buf[i] = (MAX3107_WRITE_BIT | MAX3107_MODE1_REG);
  272. spin_lock_irqsave(&s->data_lock, flags);
  273. s->mode1_reg &= ~MAX3107_MODE1_TXDIS_BIT;
  274. buf[i] |= s->mode1_reg;
  275. spin_unlock_irqrestore(&s->data_lock, flags);
  276. s->tx_enabled = 1;
  277. i++;
  278. len++;
  279. }
  280. /* Perform the SPI transfer */
  281. if (max3107_rw(s, (u8 *)buf, NULL, len*2)) {
  282. dev_err(&s->spi->dev,
  283. "SPI transfer TX handling failed\n");
  284. return;
  285. }
  286. }
  287. /* Indicate wake up if circular buffer is getting low on data */
  288. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  289. uart_write_wakeup(&s->port);
  290. }
  291. /* Handle interrupts
  292. * Also reads and returns current RX FIFO level
  293. */
  294. static u16 handle_interrupt(struct max3107_port *s)
  295. {
  296. u16 buf[4]; /* Buffer for SPI transfers */
  297. u8 irq_status;
  298. u16 rx_level;
  299. unsigned long flags;
  300. /* Read IRQ status register */
  301. buf[0] = MAX3107_IRQSTS_REG;
  302. /* Read status IRQ status register */
  303. buf[1] = MAX3107_STS_IRQSTS_REG;
  304. /* Read LSR IRQ status register */
  305. buf[2] = MAX3107_LSR_IRQSTS_REG;
  306. /* Query RX level */
  307. buf[3] = MAX3107_RXFIFOLVL_REG;
  308. if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 8)) {
  309. dev_err(&s->spi->dev,
  310. "SPI transfer for INTR handling failed\n");
  311. return 0;
  312. }
  313. irq_status = (u8)buf[0];
  314. pr_debug("IRQSTS %x\n", irq_status);
  315. rx_level = (buf[3] & MAX3107_SPI_RX_DATA_MASK);
  316. if (irq_status & MAX3107_IRQ_LSR_BIT) {
  317. /* LSR interrupt */
  318. if (buf[2] & MAX3107_LSR_RXTO_BIT)
  319. /* RX timeout interrupt,
  320. * handled by normal RX handling
  321. */
  322. pr_debug("RX TO INT\n");
  323. }
  324. if (irq_status & MAX3107_IRQ_TXEMPTY_BIT) {
  325. /* Tx empty interrupt,
  326. * disable TX and set tx_fifo_empty flag
  327. */
  328. pr_debug("TE INT, disabling TX\n");
  329. buf[0] = (MAX3107_WRITE_BIT | MAX3107_MODE1_REG);
  330. spin_lock_irqsave(&s->data_lock, flags);
  331. s->mode1_reg |= MAX3107_MODE1_TXDIS_BIT;
  332. buf[0] |= s->mode1_reg;
  333. spin_unlock_irqrestore(&s->data_lock, flags);
  334. if (max3107_rw(s, (u8 *)buf, NULL, 2))
  335. dev_err(&s->spi->dev, "SPI transfer TX dis failed\n");
  336. s->tx_enabled = 0;
  337. s->tx_fifo_empty = 1;
  338. }
  339. if (irq_status & MAX3107_IRQ_RXFIFO_BIT)
  340. /* RX FIFO interrupt,
  341. * handled by normal RX handling
  342. */
  343. pr_debug("RFIFO INT\n");
  344. /* Return RX level */
  345. return rx_level;
  346. }
  347. /* Trigger work thread*/
  348. static void max3107_dowork(struct max3107_port *s)
  349. {
  350. if (!work_pending(&s->work) && !freezing(current) && !s->suspended)
  351. queue_work(s->workqueue, &s->work);
  352. else
  353. dev_warn(&s->spi->dev, "interrup isn't serviced normally!\n");
  354. }
  355. /* Work thread */
  356. static void max3107_work(struct work_struct *w)
  357. {
  358. struct max3107_port *s = container_of(w, struct max3107_port, work);
  359. u16 rxlvl = 0;
  360. int len; /* SPI transfer buffer length */
  361. u16 buf[5]; /* Buffer for SPI transfers */
  362. unsigned long flags;
  363. /* Start by reading current RX FIFO level */
  364. buf[0] = MAX3107_RXFIFOLVL_REG;
  365. if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) {
  366. dev_err(&s->spi->dev, "SPI transfer RX lev failed\n");
  367. rxlvl = 0;
  368. } else {
  369. rxlvl = (buf[0] & MAX3107_SPI_RX_DATA_MASK);
  370. }
  371. do {
  372. pr_debug("rxlvl %d\n", rxlvl);
  373. /* Handle RX */
  374. max3107_handlerx(s, rxlvl);
  375. rxlvl = 0;
  376. if (s->handle_irq) {
  377. /* Handle pending interrupts
  378. * We also get new RX FIFO level since new data may
  379. * have been received while pushing received data to
  380. * receivers
  381. */
  382. s->handle_irq = 0;
  383. rxlvl = handle_interrupt(s);
  384. }
  385. /* Handle TX */
  386. max3107_handletx(s);
  387. /* Handle configuration changes */
  388. len = 0;
  389. spin_lock_irqsave(&s->data_lock, flags);
  390. if (s->mode1_commit) {
  391. pr_debug("mode1_commit\n");
  392. buf[len] = (MAX3107_WRITE_BIT | MAX3107_MODE1_REG);
  393. buf[len++] |= s->mode1_reg;
  394. s->mode1_commit = 0;
  395. }
  396. if (s->lcr_commit) {
  397. pr_debug("lcr_commit\n");
  398. buf[len] = (MAX3107_WRITE_BIT | MAX3107_LCR_REG);
  399. buf[len++] |= s->lcr_reg;
  400. s->lcr_commit = 0;
  401. }
  402. if (s->brg_commit) {
  403. pr_debug("brg_commit\n");
  404. buf[len] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVMSB_REG);
  405. buf[len++] |= ((s->brg_cfg >> 16) &
  406. MAX3107_SPI_TX_DATA_MASK);
  407. buf[len] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVLSB_REG);
  408. buf[len++] |= ((s->brg_cfg >> 8) &
  409. MAX3107_SPI_TX_DATA_MASK);
  410. buf[len] = (MAX3107_WRITE_BIT | MAX3107_BRGCFG_REG);
  411. buf[len++] |= ((s->brg_cfg) & 0xff);
  412. s->brg_commit = 0;
  413. }
  414. spin_unlock_irqrestore(&s->data_lock, flags);
  415. if (len > 0) {
  416. if (max3107_rw(s, (u8 *)buf, NULL, len * 2))
  417. dev_err(&s->spi->dev,
  418. "SPI transfer config failed\n");
  419. }
  420. /* Reloop if interrupt handling indicated data in RX FIFO */
  421. } while (rxlvl);
  422. }
  423. /* Set sleep mode */
  424. static void max3107_set_sleep(struct max3107_port *s, int mode)
  425. {
  426. u16 buf[1]; /* Buffer for SPI transfer */
  427. unsigned long flags;
  428. pr_debug("enter, mode %d\n", mode);
  429. buf[0] = (MAX3107_WRITE_BIT | MAX3107_MODE1_REG);
  430. spin_lock_irqsave(&s->data_lock, flags);
  431. switch (mode) {
  432. case MAX3107_DISABLE_FORCED_SLEEP:
  433. s->mode1_reg &= ~MAX3107_MODE1_FORCESLEEP_BIT;
  434. break;
  435. case MAX3107_ENABLE_FORCED_SLEEP:
  436. s->mode1_reg |= MAX3107_MODE1_FORCESLEEP_BIT;
  437. break;
  438. case MAX3107_DISABLE_AUTOSLEEP:
  439. s->mode1_reg &= ~MAX3107_MODE1_AUTOSLEEP_BIT;
  440. break;
  441. case MAX3107_ENABLE_AUTOSLEEP:
  442. s->mode1_reg |= MAX3107_MODE1_AUTOSLEEP_BIT;
  443. break;
  444. default:
  445. spin_unlock_irqrestore(&s->data_lock, flags);
  446. dev_warn(&s->spi->dev, "invalid sleep mode\n");
  447. return;
  448. }
  449. buf[0] |= s->mode1_reg;
  450. spin_unlock_irqrestore(&s->data_lock, flags);
  451. if (max3107_rw(s, (u8 *)buf, NULL, 2))
  452. dev_err(&s->spi->dev, "SPI transfer sleep mode failed\n");
  453. if (mode == MAX3107_DISABLE_AUTOSLEEP ||
  454. mode == MAX3107_DISABLE_FORCED_SLEEP)
  455. msleep(MAX3107_WAKEUP_DELAY);
  456. }
  457. /* Perform full register initialization */
  458. static void max3107_register_init(struct max3107_port *s)
  459. {
  460. u16 buf[11]; /* Buffer for SPI transfers */
  461. /* 1. Configure baud rate, 9600 as default */
  462. s->baud = 9600;
  463. /* the below is default*/
  464. if (s->ext_clk) {
  465. s->brg_cfg = MAX3107_BRG26_B9600;
  466. s->baud_tbl = (struct baud_table *)brg26_ext;
  467. } else {
  468. s->brg_cfg = MAX3107_BRG13_IB9600;
  469. s->baud_tbl = (struct baud_table *)brg13_int;
  470. }
  471. if (s->pdata->init)
  472. s->pdata->init(s);
  473. buf[0] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVMSB_REG)
  474. | ((s->brg_cfg >> 16) & MAX3107_SPI_TX_DATA_MASK);
  475. buf[1] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVLSB_REG)
  476. | ((s->brg_cfg >> 8) & MAX3107_SPI_TX_DATA_MASK);
  477. buf[2] = (MAX3107_WRITE_BIT | MAX3107_BRGCFG_REG)
  478. | ((s->brg_cfg) & 0xff);
  479. /* 2. Configure LCR register, 8N1 mode by default */
  480. s->lcr_reg = MAX3107_LCR_WORD_LEN_8;
  481. buf[3] = (MAX3107_WRITE_BIT | MAX3107_LCR_REG)
  482. | s->lcr_reg;
  483. /* 3. Configure MODE 1 register */
  484. s->mode1_reg = 0;
  485. /* Enable IRQ pin */
  486. s->mode1_reg |= MAX3107_MODE1_IRQSEL_BIT;
  487. /* Disable TX */
  488. s->mode1_reg |= MAX3107_MODE1_TXDIS_BIT;
  489. s->tx_enabled = 0;
  490. /* RX is enabled */
  491. s->rx_enabled = 1;
  492. buf[4] = (MAX3107_WRITE_BIT | MAX3107_MODE1_REG)
  493. | s->mode1_reg;
  494. /* 4. Configure MODE 2 register */
  495. buf[5] = (MAX3107_WRITE_BIT | MAX3107_MODE2_REG);
  496. if (s->loopback) {
  497. /* Enable loopback */
  498. buf[5] |= MAX3107_MODE2_LOOPBACK_BIT;
  499. }
  500. /* Reset FIFOs */
  501. buf[5] |= MAX3107_MODE2_FIFORST_BIT;
  502. s->tx_fifo_empty = 1;
  503. /* 5. Configure FIFO trigger level register */
  504. buf[6] = (MAX3107_WRITE_BIT | MAX3107_FIFOTRIGLVL_REG);
  505. /* RX FIFO trigger for 16 words, TX FIFO trigger not used */
  506. buf[6] |= (MAX3107_FIFOTRIGLVL_RX(16) | MAX3107_FIFOTRIGLVL_TX(0));
  507. /* 6. Configure flow control levels */
  508. buf[7] = (MAX3107_WRITE_BIT | MAX3107_FLOWLVL_REG);
  509. /* Flow control halt level 96, resume level 48 */
  510. buf[7] |= (MAX3107_FLOWLVL_RES(48) | MAX3107_FLOWLVL_HALT(96));
  511. /* 7. Configure flow control */
  512. buf[8] = (MAX3107_WRITE_BIT | MAX3107_FLOWCTRL_REG);
  513. /* Enable auto CTS and auto RTS flow control */
  514. buf[8] |= (MAX3107_FLOWCTRL_AUTOCTS_BIT | MAX3107_FLOWCTRL_AUTORTS_BIT);
  515. /* 8. Configure RX timeout register */
  516. buf[9] = (MAX3107_WRITE_BIT | MAX3107_RXTO_REG);
  517. /* Timeout after 48 character intervals */
  518. buf[9] |= 0x0030;
  519. /* 9. Configure LSR interrupt enable register */
  520. buf[10] = (MAX3107_WRITE_BIT | MAX3107_LSR_IRQEN_REG);
  521. /* Enable RX timeout interrupt */
  522. buf[10] |= MAX3107_LSR_RXTO_BIT;
  523. /* Perform SPI transfer */
  524. if (max3107_rw(s, (u8 *)buf, NULL, 22))
  525. dev_err(&s->spi->dev, "SPI transfer for init failed\n");
  526. /* 10. Clear IRQ status register by reading it */
  527. buf[0] = MAX3107_IRQSTS_REG;
  528. /* 11. Configure interrupt enable register */
  529. /* Enable LSR interrupt */
  530. s->irqen_reg = MAX3107_IRQ_LSR_BIT;
  531. /* Enable RX FIFO interrupt */
  532. s->irqen_reg |= MAX3107_IRQ_RXFIFO_BIT;
  533. buf[1] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG)
  534. | s->irqen_reg;
  535. /* 12. Clear FIFO reset that was set in step 6 */
  536. buf[2] = (MAX3107_WRITE_BIT | MAX3107_MODE2_REG);
  537. if (s->loopback) {
  538. /* Keep loopback enabled */
  539. buf[2] |= MAX3107_MODE2_LOOPBACK_BIT;
  540. }
  541. /* Perform SPI transfer */
  542. if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 6))
  543. dev_err(&s->spi->dev, "SPI transfer for init failed\n");
  544. }
  545. /* IRQ handler */
  546. static irqreturn_t max3107_irq(int irqno, void *dev_id)
  547. {
  548. struct max3107_port *s = dev_id;
  549. if (irqno != s->spi->irq) {
  550. /* Unexpected IRQ */
  551. return IRQ_NONE;
  552. }
  553. /* Indicate irq */
  554. s->handle_irq = 1;
  555. /* Trigger work thread */
  556. max3107_dowork(s);
  557. return IRQ_HANDLED;
  558. }
  559. /* HW suspension function
  560. *
  561. * Currently autosleep is used to decrease current consumption, alternative
  562. * approach would be to set the chip to reset mode if UART is not being
  563. * used but that would mess the GPIOs
  564. *
  565. */
  566. void max3107_hw_susp(struct max3107_port *s, int suspend)
  567. {
  568. pr_debug("enter, suspend %d\n", suspend);
  569. if (suspend) {
  570. /* Suspend requested,
  571. * enable autosleep to decrease current consumption
  572. */
  573. s->suspended = 1;
  574. max3107_set_sleep(s, MAX3107_ENABLE_AUTOSLEEP);
  575. } else {
  576. /* Resume requested,
  577. * disable autosleep
  578. */
  579. s->suspended = 0;
  580. max3107_set_sleep(s, MAX3107_DISABLE_AUTOSLEEP);
  581. }
  582. }
  583. EXPORT_SYMBOL_GPL(max3107_hw_susp);
  584. /* Modem status IRQ enabling */
  585. static void max3107_enable_ms(struct uart_port *port)
  586. {
  587. /* Modem status not supported */
  588. }
  589. /* Data send function */
  590. static void max3107_start_tx(struct uart_port *port)
  591. {
  592. struct max3107_port *s = container_of(port, struct max3107_port, port);
  593. /* Trigger work thread for sending data */
  594. max3107_dowork(s);
  595. }
  596. /* Function for checking that there is no pending transfers */
  597. static unsigned int max3107_tx_empty(struct uart_port *port)
  598. {
  599. struct max3107_port *s = container_of(port, struct max3107_port, port);
  600. pr_debug("returning %d\n",
  601. (s->tx_fifo_empty && uart_circ_empty(&s->port.state->xmit)));
  602. return s->tx_fifo_empty && uart_circ_empty(&s->port.state->xmit);
  603. }
  604. /* Function for stopping RX */
  605. static void max3107_stop_rx(struct uart_port *port)
  606. {
  607. struct max3107_port *s = container_of(port, struct max3107_port, port);
  608. unsigned long flags;
  609. /* Set RX disabled in MODE 1 register */
  610. spin_lock_irqsave(&s->data_lock, flags);
  611. s->mode1_reg |= MAX3107_MODE1_RXDIS_BIT;
  612. s->mode1_commit = 1;
  613. spin_unlock_irqrestore(&s->data_lock, flags);
  614. /* Set RX disabled */
  615. s->rx_enabled = 0;
  616. /* Trigger work thread for doing the actual configuration change */
  617. max3107_dowork(s);
  618. }
  619. /* Function for returning control pin states */
  620. static unsigned int max3107_get_mctrl(struct uart_port *port)
  621. {
  622. /* DCD and DSR are not wired and CTS/RTS is handled automatically
  623. * so just indicate DSR and CAR asserted
  624. */
  625. return TIOCM_DSR | TIOCM_CAR;
  626. }
  627. /* Function for setting control pin states */
  628. static void max3107_set_mctrl(struct uart_port *port, unsigned int mctrl)
  629. {
  630. /* DCD and DSR are not wired and CTS/RTS is hadnled automatically
  631. * so do nothing
  632. */
  633. }
  634. /* Function for configuring UART parameters */
  635. static void max3107_set_termios(struct uart_port *port,
  636. struct ktermios *termios,
  637. struct ktermios *old)
  638. {
  639. struct max3107_port *s = container_of(port, struct max3107_port, port);
  640. struct tty_struct *tty;
  641. int baud;
  642. u16 new_lcr = 0;
  643. u32 new_brg = 0;
  644. unsigned long flags;
  645. if (!port->state)
  646. return;
  647. tty = port->state->port.tty;
  648. if (!tty)
  649. return;
  650. /* Get new LCR register values */
  651. /* Word size */
  652. if ((termios->c_cflag & CSIZE) == CS7)
  653. new_lcr |= MAX3107_LCR_WORD_LEN_7;
  654. else
  655. new_lcr |= MAX3107_LCR_WORD_LEN_8;
  656. /* Parity */
  657. if (termios->c_cflag & PARENB) {
  658. new_lcr |= MAX3107_LCR_PARITY_BIT;
  659. if (!(termios->c_cflag & PARODD))
  660. new_lcr |= MAX3107_LCR_EVENPARITY_BIT;
  661. }
  662. /* Stop bits */
  663. if (termios->c_cflag & CSTOPB) {
  664. /* 2 stop bits */
  665. new_lcr |= MAX3107_LCR_STOPLEN_BIT;
  666. }
  667. /* Mask termios capabilities we don't support */
  668. termios->c_cflag &= ~CMSPAR;
  669. /* Set status ignore mask */
  670. s->port.ignore_status_mask = 0;
  671. if (termios->c_iflag & IGNPAR)
  672. s->port.ignore_status_mask |= MAX3107_ALL_ERRORS;
  673. /* Set low latency to immediately handle pushed data */
  674. s->port.state->port.tty->low_latency = 1;
  675. /* Get new baud rate generator configuration */
  676. baud = tty_get_baud_rate(tty);
  677. spin_lock_irqsave(&s->data_lock, flags);
  678. new_brg = get_new_brg(baud, s);
  679. /* if can't find the corrent config, use previous */
  680. if (!new_brg) {
  681. baud = s->baud;
  682. new_brg = s->brg_cfg;
  683. }
  684. spin_unlock_irqrestore(&s->data_lock, flags);
  685. tty_termios_encode_baud_rate(termios, baud, baud);
  686. s->baud = baud;
  687. /* Update timeout according to new baud rate */
  688. uart_update_timeout(port, termios->c_cflag, baud);
  689. spin_lock_irqsave(&s->data_lock, flags);
  690. if (s->lcr_reg != new_lcr) {
  691. s->lcr_reg = new_lcr;
  692. s->lcr_commit = 1;
  693. }
  694. if (s->brg_cfg != new_brg) {
  695. s->brg_cfg = new_brg;
  696. s->brg_commit = 1;
  697. }
  698. spin_unlock_irqrestore(&s->data_lock, flags);
  699. /* Trigger work thread for doing the actual configuration change */
  700. max3107_dowork(s);
  701. }
  702. /* Port shutdown function */
  703. static void max3107_shutdown(struct uart_port *port)
  704. {
  705. struct max3107_port *s = container_of(port, struct max3107_port, port);
  706. if (s->suspended && s->pdata->hw_suspend)
  707. s->pdata->hw_suspend(s, 0);
  708. /* Free the interrupt */
  709. free_irq(s->spi->irq, s);
  710. if (s->workqueue) {
  711. /* Flush and destroy work queue */
  712. flush_workqueue(s->workqueue);
  713. destroy_workqueue(s->workqueue);
  714. s->workqueue = NULL;
  715. }
  716. /* Suspend HW */
  717. if (s->pdata->hw_suspend)
  718. s->pdata->hw_suspend(s, 1);
  719. }
  720. /* Port startup function */
  721. static int max3107_startup(struct uart_port *port)
  722. {
  723. struct max3107_port *s = container_of(port, struct max3107_port, port);
  724. /* Initialize work queue */
  725. s->workqueue = create_freezable_workqueue("max3107");
  726. if (!s->workqueue) {
  727. dev_err(&s->spi->dev, "Workqueue creation failed\n");
  728. return -EBUSY;
  729. }
  730. INIT_WORK(&s->work, max3107_work);
  731. /* Setup IRQ */
  732. if (request_irq(s->spi->irq, max3107_irq, IRQF_TRIGGER_FALLING,
  733. "max3107", s)) {
  734. dev_err(&s->spi->dev, "IRQ reguest failed\n");
  735. destroy_workqueue(s->workqueue);
  736. s->workqueue = NULL;
  737. return -EBUSY;
  738. }
  739. /* Resume HW */
  740. if (s->pdata->hw_suspend)
  741. s->pdata->hw_suspend(s, 0);
  742. /* Init registers */
  743. max3107_register_init(s);
  744. return 0;
  745. }
  746. /* Port type function */
  747. static const char *max3107_type(struct uart_port *port)
  748. {
  749. struct max3107_port *s = container_of(port, struct max3107_port, port);
  750. return s->spi->modalias;
  751. }
  752. /* Port release function */
  753. static void max3107_release_port(struct uart_port *port)
  754. {
  755. /* Do nothing */
  756. }
  757. /* Port request function */
  758. static int max3107_request_port(struct uart_port *port)
  759. {
  760. /* Do nothing */
  761. return 0;
  762. }
  763. /* Port config function */
  764. static void max3107_config_port(struct uart_port *port, int flags)
  765. {
  766. struct max3107_port *s = container_of(port, struct max3107_port, port);
  767. s->port.type = PORT_MAX3107;
  768. }
  769. /* Port verify function */
  770. static int max3107_verify_port(struct uart_port *port,
  771. struct serial_struct *ser)
  772. {
  773. if (ser->type == PORT_UNKNOWN || ser->type == PORT_MAX3107)
  774. return 0;
  775. return -EINVAL;
  776. }
  777. /* Port stop TX function */
  778. static void max3107_stop_tx(struct uart_port *port)
  779. {
  780. /* Do nothing */
  781. }
  782. /* Port break control function */
  783. static void max3107_break_ctl(struct uart_port *port, int break_state)
  784. {
  785. /* We don't support break control, do nothing */
  786. }
  787. /* Port functions */
  788. static struct uart_ops max3107_ops = {
  789. .tx_empty = max3107_tx_empty,
  790. .set_mctrl = max3107_set_mctrl,
  791. .get_mctrl = max3107_get_mctrl,
  792. .stop_tx = max3107_stop_tx,
  793. .start_tx = max3107_start_tx,
  794. .stop_rx = max3107_stop_rx,
  795. .enable_ms = max3107_enable_ms,
  796. .break_ctl = max3107_break_ctl,
  797. .startup = max3107_startup,
  798. .shutdown = max3107_shutdown,
  799. .set_termios = max3107_set_termios,
  800. .type = max3107_type,
  801. .release_port = max3107_release_port,
  802. .request_port = max3107_request_port,
  803. .config_port = max3107_config_port,
  804. .verify_port = max3107_verify_port,
  805. };
  806. /* UART driver data */
  807. static struct uart_driver max3107_uart_driver = {
  808. .owner = THIS_MODULE,
  809. .driver_name = "ttyMAX",
  810. .dev_name = "ttyMAX",
  811. .nr = 1,
  812. };
  813. static int driver_registered = 0;
  814. /* 'Generic' platform data */
  815. static struct max3107_plat generic_plat_data = {
  816. .loopback = 0,
  817. .ext_clk = 1,
  818. .hw_suspend = max3107_hw_susp,
  819. .polled_mode = 0,
  820. .poll_time = 0,
  821. };
  822. /*******************************************************************/
  823. /**
  824. * max3107_probe - SPI bus probe entry point
  825. * @spi: the spi device
  826. *
  827. * SPI wants us to probe this device and if appropriate claim it.
  828. * Perform any platform specific requirements and then initialise
  829. * the device.
  830. */
  831. int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata)
  832. {
  833. struct max3107_port *s;
  834. u16 buf[2]; /* Buffer for SPI transfers */
  835. int retval;
  836. pr_info("enter max3107 probe\n");
  837. /* Allocate port structure */
  838. s = kzalloc(sizeof(*s), GFP_KERNEL);
  839. if (!s) {
  840. pr_err("Allocating port structure failed\n");
  841. return -ENOMEM;
  842. }
  843. s->pdata = pdata;
  844. /* SPI Rx buffer
  845. * +2 for RX FIFO interrupt
  846. * disabling and RX level query
  847. */
  848. s->rxbuf = kzalloc(sizeof(u16) * (MAX3107_RX_FIFO_SIZE+2), GFP_KERNEL);
  849. if (!s->rxbuf) {
  850. pr_err("Allocating RX buffer failed\n");
  851. retval = -ENOMEM;
  852. goto err_free4;
  853. }
  854. s->rxstr = kzalloc(sizeof(u8) * MAX3107_RX_FIFO_SIZE, GFP_KERNEL);
  855. if (!s->rxstr) {
  856. pr_err("Allocating RX buffer failed\n");
  857. retval = -ENOMEM;
  858. goto err_free3;
  859. }
  860. /* SPI Tx buffer
  861. * SPI transfer buffer
  862. * +3 for TX FIFO empty
  863. * interrupt disabling and
  864. * enabling and TX enabling
  865. */
  866. s->txbuf = kzalloc(sizeof(u16) * MAX3107_TX_FIFO_SIZE + 3, GFP_KERNEL);
  867. if (!s->txbuf) {
  868. pr_err("Allocating TX buffer failed\n");
  869. retval = -ENOMEM;
  870. goto err_free2;
  871. }
  872. /* Initialize shared data lock */
  873. spin_lock_init(&s->data_lock);
  874. /* SPI intializations */
  875. dev_set_drvdata(&spi->dev, s);
  876. spi->mode = SPI_MODE_0;
  877. spi->dev.platform_data = pdata;
  878. spi->bits_per_word = 16;
  879. s->ext_clk = pdata->ext_clk;
  880. s->loopback = pdata->loopback;
  881. spi_setup(spi);
  882. s->spi = spi;
  883. /* Check REV ID to ensure we are talking to what we expect */
  884. buf[0] = MAX3107_REVID_REG;
  885. if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) {
  886. dev_err(&s->spi->dev, "SPI transfer for REVID read failed\n");
  887. retval = -EIO;
  888. goto err_free1;
  889. }
  890. if ((buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID1 &&
  891. (buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID2) {
  892. dev_err(&s->spi->dev, "REVID %x does not match\n",
  893. (buf[0] & MAX3107_SPI_RX_DATA_MASK));
  894. retval = -ENODEV;
  895. goto err_free1;
  896. }
  897. /* Disable all interrupts */
  898. buf[0] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG | 0x0000);
  899. buf[0] |= 0x0000;
  900. /* Configure clock source */
  901. buf[1] = (MAX3107_WRITE_BIT | MAX3107_CLKSRC_REG);
  902. if (s->ext_clk) {
  903. /* External clock */
  904. buf[1] |= MAX3107_CLKSRC_EXTCLK_BIT;
  905. }
  906. /* PLL bypass ON */
  907. buf[1] |= MAX3107_CLKSRC_PLLBYP_BIT;
  908. /* Perform SPI transfer */
  909. if (max3107_rw(s, (u8 *)buf, NULL, 4)) {
  910. dev_err(&s->spi->dev, "SPI transfer for init failed\n");
  911. retval = -EIO;
  912. goto err_free1;
  913. }
  914. /* Register UART driver */
  915. if (!driver_registered) {
  916. retval = uart_register_driver(&max3107_uart_driver);
  917. if (retval) {
  918. dev_err(&s->spi->dev, "Registering UART driver failed\n");
  919. goto err_free1;
  920. }
  921. driver_registered = 1;
  922. }
  923. /* Initialize UART port data */
  924. s->port.fifosize = 128;
  925. s->port.ops = &max3107_ops;
  926. s->port.line = 0;
  927. s->port.dev = &spi->dev;
  928. s->port.uartclk = 9600;
  929. s->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
  930. s->port.irq = s->spi->irq;
  931. s->port.type = PORT_MAX3107;
  932. /* Add UART port */
  933. retval = uart_add_one_port(&max3107_uart_driver, &s->port);
  934. if (retval < 0) {
  935. dev_err(&s->spi->dev, "Adding UART port failed\n");
  936. goto err_free1;
  937. }
  938. if (pdata->configure) {
  939. retval = pdata->configure(s);
  940. if (retval < 0)
  941. goto err_free1;
  942. }
  943. /* Go to suspend mode */
  944. if (pdata->hw_suspend)
  945. pdata->hw_suspend(s, 1);
  946. return 0;
  947. err_free1:
  948. kfree(s->txbuf);
  949. err_free2:
  950. kfree(s->rxstr);
  951. err_free3:
  952. kfree(s->rxbuf);
  953. err_free4:
  954. kfree(s);
  955. return retval;
  956. }
  957. EXPORT_SYMBOL_GPL(max3107_probe);
  958. /* Driver remove function */
  959. int max3107_remove(struct spi_device *spi)
  960. {
  961. struct max3107_port *s = dev_get_drvdata(&spi->dev);
  962. pr_info("enter max3107 remove\n");
  963. /* Remove port */
  964. if (uart_remove_one_port(&max3107_uart_driver, &s->port))
  965. dev_warn(&s->spi->dev, "Removing UART port failed\n");
  966. /* Free TxRx buffer */
  967. kfree(s->rxbuf);
  968. kfree(s->rxstr);
  969. kfree(s->txbuf);
  970. /* Free port structure */
  971. kfree(s);
  972. return 0;
  973. }
  974. EXPORT_SYMBOL_GPL(max3107_remove);
  975. /* Driver suspend function */
  976. int max3107_suspend(struct spi_device *spi, pm_message_t state)
  977. {
  978. #ifdef CONFIG_PM
  979. struct max3107_port *s = dev_get_drvdata(&spi->dev);
  980. pr_debug("enter suspend\n");
  981. /* Suspend UART port */
  982. uart_suspend_port(&max3107_uart_driver, &s->port);
  983. /* Go to suspend mode */
  984. if (s->pdata->hw_suspend)
  985. s->pdata->hw_suspend(s, 1);
  986. #endif /* CONFIG_PM */
  987. return 0;
  988. }
  989. EXPORT_SYMBOL_GPL(max3107_suspend);
  990. /* Driver resume function */
  991. int max3107_resume(struct spi_device *spi)
  992. {
  993. #ifdef CONFIG_PM
  994. struct max3107_port *s = dev_get_drvdata(&spi->dev);
  995. pr_debug("enter resume\n");
  996. /* Resume from suspend */
  997. if (s->pdata->hw_suspend)
  998. s->pdata->hw_suspend(s, 0);
  999. /* Resume UART port */
  1000. uart_resume_port(&max3107_uart_driver, &s->port);
  1001. #endif /* CONFIG_PM */
  1002. return 0;
  1003. }
  1004. EXPORT_SYMBOL_GPL(max3107_resume);
  1005. static int max3107_probe_generic(struct spi_device *spi)
  1006. {
  1007. return max3107_probe(spi, &generic_plat_data);
  1008. }
  1009. /* Spi driver data */
  1010. static struct spi_driver max3107_driver = {
  1011. .driver = {
  1012. .name = "max3107",
  1013. .owner = THIS_MODULE,
  1014. },
  1015. .probe = max3107_probe_generic,
  1016. .remove = __devexit_p(max3107_remove),
  1017. .suspend = max3107_suspend,
  1018. .resume = max3107_resume,
  1019. };
  1020. /* Driver init function */
  1021. static int __init max3107_init(void)
  1022. {
  1023. pr_info("enter max3107 init\n");
  1024. return spi_register_driver(&max3107_driver);
  1025. }
  1026. /* Driver exit function */
  1027. static void __exit max3107_exit(void)
  1028. {
  1029. pr_info("enter max3107 exit\n");
  1030. /* Unregister UART driver */
  1031. if (driver_registered)
  1032. uart_unregister_driver(&max3107_uart_driver);
  1033. spi_unregister_driver(&max3107_driver);
  1034. }
  1035. module_init(max3107_init);
  1036. module_exit(max3107_exit);
  1037. MODULE_DESCRIPTION("MAX3107 driver");
  1038. MODULE_AUTHOR("Aavamobile");
  1039. MODULE_ALIAS("spi:max3107");
  1040. MODULE_LICENSE("GPL v2");