max3107.c 30 KB

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