max3107.c 30 KB

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