2 * Maxim (Dallas) MAX3107/8/9, MAX14830 serial driver
4 * Copyright (C) 2012-2016 Alexander Shiyan <shc_work@mail.ru>
6 * Based on max3100.c, by Christian Pellegrin <chripell@evolware.org>
7 * Based on max3110.c, by Feng Tang <feng.tang@intel.com>
8 * Based on max3107.c, by Aavamobile
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
16 #include <linux/bitops.h>
17 #include <linux/clk.h>
18 #include <linux/delay.h>
19 #include <linux/device.h>
20 #include <linux/gpio/driver.h>
21 #include <linux/module.h>
23 #include <linux/of_device.h>
24 #include <linux/regmap.h>
25 #include <linux/serial_core.h>
26 #include <linux/serial.h>
27 #include <linux/tty.h>
28 #include <linux/tty_flip.h>
29 #include <linux/spi/spi.h>
30 #include <linux/uaccess.h>
32 #define MAX310X_NAME "max310x"
33 #define MAX310X_MAJOR 204
34 #define MAX310X_MINOR 209
35 #define MAX310X_UART_NRMAX 16
37 /* MAX310X register definitions */
38 #define MAX310X_RHR_REG (0x00) /* RX FIFO */
39 #define MAX310X_THR_REG (0x00) /* TX FIFO */
40 #define MAX310X_IRQEN_REG (0x01) /* IRQ enable */
41 #define MAX310X_IRQSTS_REG (0x02) /* IRQ status */
42 #define MAX310X_LSR_IRQEN_REG (0x03) /* LSR IRQ enable */
43 #define MAX310X_LSR_IRQSTS_REG (0x04) /* LSR IRQ status */
44 #define MAX310X_REG_05 (0x05)
45 #define MAX310X_SPCHR_IRQEN_REG MAX310X_REG_05 /* Special char IRQ en */
46 #define MAX310X_SPCHR_IRQSTS_REG (0x06) /* Special char IRQ status */
47 #define MAX310X_STS_IRQEN_REG (0x07) /* Status IRQ enable */
48 #define MAX310X_STS_IRQSTS_REG (0x08) /* Status IRQ status */
49 #define MAX310X_MODE1_REG (0x09) /* MODE1 */
50 #define MAX310X_MODE2_REG (0x0a) /* MODE2 */
51 #define MAX310X_LCR_REG (0x0b) /* LCR */
52 #define MAX310X_RXTO_REG (0x0c) /* RX timeout */
53 #define MAX310X_HDPIXDELAY_REG (0x0d) /* Auto transceiver delays */
54 #define MAX310X_IRDA_REG (0x0e) /* IRDA settings */
55 #define MAX310X_FLOWLVL_REG (0x0f) /* Flow control levels */
56 #define MAX310X_FIFOTRIGLVL_REG (0x10) /* FIFO IRQ trigger levels */
57 #define MAX310X_TXFIFOLVL_REG (0x11) /* TX FIFO level */
58 #define MAX310X_RXFIFOLVL_REG (0x12) /* RX FIFO level */
59 #define MAX310X_FLOWCTRL_REG (0x13) /* Flow control */
60 #define MAX310X_XON1_REG (0x14) /* XON1 character */
61 #define MAX310X_XON2_REG (0x15) /* XON2 character */
62 #define MAX310X_XOFF1_REG (0x16) /* XOFF1 character */
63 #define MAX310X_XOFF2_REG (0x17) /* XOFF2 character */
64 #define MAX310X_GPIOCFG_REG (0x18) /* GPIO config */
65 #define MAX310X_GPIODATA_REG (0x19) /* GPIO data */
66 #define MAX310X_PLLCFG_REG (0x1a) /* PLL config */
67 #define MAX310X_BRGCFG_REG (0x1b) /* Baud rate generator conf */
68 #define MAX310X_BRGDIVLSB_REG (0x1c) /* Baud rate divisor LSB */
69 #define MAX310X_BRGDIVMSB_REG (0x1d) /* Baud rate divisor MSB */
70 #define MAX310X_CLKSRC_REG (0x1e) /* Clock source */
71 #define MAX310X_REG_1F (0x1f)
73 #define MAX310X_REVID_REG MAX310X_REG_1F /* Revision ID */
75 #define MAX310X_GLOBALIRQ_REG MAX310X_REG_1F /* Global IRQ (RO) */
76 #define MAX310X_GLOBALCMD_REG MAX310X_REG_1F /* Global Command (WO) */
78 /* Extended registers */
79 #define MAX310X_REVID_EXTREG MAX310X_REG_05 /* Revision ID */
81 /* IRQ register bits */
82 #define MAX310X_IRQ_LSR_BIT (1 << 0) /* LSR interrupt */
83 #define MAX310X_IRQ_SPCHR_BIT (1 << 1) /* Special char interrupt */
84 #define MAX310X_IRQ_STS_BIT (1 << 2) /* Status interrupt */
85 #define MAX310X_IRQ_RXFIFO_BIT (1 << 3) /* RX FIFO interrupt */
86 #define MAX310X_IRQ_TXFIFO_BIT (1 << 4) /* TX FIFO interrupt */
87 #define MAX310X_IRQ_TXEMPTY_BIT (1 << 5) /* TX FIFO empty interrupt */
88 #define MAX310X_IRQ_RXEMPTY_BIT (1 << 6) /* RX FIFO empty interrupt */
89 #define MAX310X_IRQ_CTS_BIT (1 << 7) /* CTS interrupt */
91 /* LSR register bits */
92 #define MAX310X_LSR_RXTO_BIT (1 << 0) /* RX timeout */
93 #define MAX310X_LSR_RXOVR_BIT (1 << 1) /* RX overrun */
94 #define MAX310X_LSR_RXPAR_BIT (1 << 2) /* RX parity error */
95 #define MAX310X_LSR_FRERR_BIT (1 << 3) /* Frame error */
96 #define MAX310X_LSR_RXBRK_BIT (1 << 4) /* RX break */
97 #define MAX310X_LSR_RXNOISE_BIT (1 << 5) /* RX noise */
98 #define MAX310X_LSR_CTS_BIT (1 << 7) /* CTS pin state */
100 /* Special character register bits */
101 #define MAX310X_SPCHR_XON1_BIT (1 << 0) /* XON1 character */
102 #define MAX310X_SPCHR_XON2_BIT (1 << 1) /* XON2 character */
103 #define MAX310X_SPCHR_XOFF1_BIT (1 << 2) /* XOFF1 character */
104 #define MAX310X_SPCHR_XOFF2_BIT (1 << 3) /* XOFF2 character */
105 #define MAX310X_SPCHR_BREAK_BIT (1 << 4) /* RX break */
106 #define MAX310X_SPCHR_MULTIDROP_BIT (1 << 5) /* 9-bit multidrop addr char */
108 /* Status register bits */
109 #define MAX310X_STS_GPIO0_BIT (1 << 0) /* GPIO 0 interrupt */
110 #define MAX310X_STS_GPIO1_BIT (1 << 1) /* GPIO 1 interrupt */
111 #define MAX310X_STS_GPIO2_BIT (1 << 2) /* GPIO 2 interrupt */
112 #define MAX310X_STS_GPIO3_BIT (1 << 3) /* GPIO 3 interrupt */
113 #define MAX310X_STS_CLKREADY_BIT (1 << 5) /* Clock ready */
114 #define MAX310X_STS_SLEEP_BIT (1 << 6) /* Sleep interrupt */
116 /* MODE1 register bits */
117 #define MAX310X_MODE1_RXDIS_BIT (1 << 0) /* RX disable */
118 #define MAX310X_MODE1_TXDIS_BIT (1 << 1) /* TX disable */
119 #define MAX310X_MODE1_TXHIZ_BIT (1 << 2) /* TX pin three-state */
120 #define MAX310X_MODE1_RTSHIZ_BIT (1 << 3) /* RTS pin three-state */
121 #define MAX310X_MODE1_TRNSCVCTRL_BIT (1 << 4) /* Transceiver ctrl enable */
122 #define MAX310X_MODE1_FORCESLEEP_BIT (1 << 5) /* Force sleep mode */
123 #define MAX310X_MODE1_AUTOSLEEP_BIT (1 << 6) /* Auto sleep enable */
124 #define MAX310X_MODE1_IRQSEL_BIT (1 << 7) /* IRQ pin enable */
126 /* MODE2 register bits */
127 #define MAX310X_MODE2_RST_BIT (1 << 0) /* Chip reset */
128 #define MAX310X_MODE2_FIFORST_BIT (1 << 1) /* FIFO reset */
129 #define MAX310X_MODE2_RXTRIGINV_BIT (1 << 2) /* RX FIFO INT invert */
130 #define MAX310X_MODE2_RXEMPTINV_BIT (1 << 3) /* RX FIFO empty INT invert */
131 #define MAX310X_MODE2_SPCHR_BIT (1 << 4) /* Special chr detect enable */
132 #define MAX310X_MODE2_LOOPBACK_BIT (1 << 5) /* Internal loopback enable */
133 #define MAX310X_MODE2_MULTIDROP_BIT (1 << 6) /* 9-bit multidrop enable */
134 #define MAX310X_MODE2_ECHOSUPR_BIT (1 << 7) /* ECHO suppression enable */
136 /* LCR register bits */
137 #define MAX310X_LCR_LENGTH0_BIT (1 << 0) /* Word length bit 0 */
138 #define MAX310X_LCR_LENGTH1_BIT (1 << 1) /* Word length bit 1
140 * Word length bits table:
146 #define MAX310X_LCR_STOPLEN_BIT (1 << 2) /* STOP length bit
148 * STOP length bit table:
150 * 1 -> 1-1.5 stop bits if
152 * 2 stop bits otherwise
154 #define MAX310X_LCR_PARITY_BIT (1 << 3) /* Parity bit enable */
155 #define MAX310X_LCR_EVENPARITY_BIT (1 << 4) /* Even parity bit enable */
156 #define MAX310X_LCR_FORCEPARITY_BIT (1 << 5) /* 9-bit multidrop parity */
157 #define MAX310X_LCR_TXBREAK_BIT (1 << 6) /* TX break enable */
158 #define MAX310X_LCR_RTS_BIT (1 << 7) /* RTS pin control */
160 /* IRDA register bits */
161 #define MAX310X_IRDA_IRDAEN_BIT (1 << 0) /* IRDA mode enable */
162 #define MAX310X_IRDA_SIR_BIT (1 << 1) /* SIR mode enable */
164 /* Flow control trigger level register masks */
165 #define MAX310X_FLOWLVL_HALT_MASK (0x000f) /* Flow control halt level */
166 #define MAX310X_FLOWLVL_RES_MASK (0x00f0) /* Flow control resume level */
167 #define MAX310X_FLOWLVL_HALT(words) ((words / 8) & 0x0f)
168 #define MAX310X_FLOWLVL_RES(words) (((words / 8) & 0x0f) << 4)
170 /* FIFO interrupt trigger level register masks */
171 #define MAX310X_FIFOTRIGLVL_TX_MASK (0x0f) /* TX FIFO trigger level */
172 #define MAX310X_FIFOTRIGLVL_RX_MASK (0xf0) /* RX FIFO trigger level */
173 #define MAX310X_FIFOTRIGLVL_TX(words) ((words / 8) & 0x0f)
174 #define MAX310X_FIFOTRIGLVL_RX(words) (((words / 8) & 0x0f) << 4)
176 /* Flow control register bits */
177 #define MAX310X_FLOWCTRL_AUTORTS_BIT (1 << 0) /* Auto RTS flow ctrl enable */
178 #define MAX310X_FLOWCTRL_AUTOCTS_BIT (1 << 1) /* Auto CTS flow ctrl enable */
179 #define MAX310X_FLOWCTRL_GPIADDR_BIT (1 << 2) /* Enables that GPIO inputs
180 * are used in conjunction with
181 * XOFF2 for definition of
182 * special character */
183 #define MAX310X_FLOWCTRL_SWFLOWEN_BIT (1 << 3) /* Auto SW flow ctrl enable */
184 #define MAX310X_FLOWCTRL_SWFLOW0_BIT (1 << 4) /* SWFLOW bit 0 */
185 #define MAX310X_FLOWCTRL_SWFLOW1_BIT (1 << 5) /* SWFLOW bit 1
187 * SWFLOW bits 1 & 0 table:
188 * 00 -> no transmitter flow
190 * 01 -> receiver compares
194 * 10 -> receiver compares
198 * 11 -> receiver compares
199 * XON1, XON2, XOFF1 and
203 #define MAX310X_FLOWCTRL_SWFLOW2_BIT (1 << 6) /* SWFLOW bit 2 */
204 #define MAX310X_FLOWCTRL_SWFLOW3_BIT (1 << 7) /* SWFLOW bit 3
206 * SWFLOW bits 3 & 2 table:
207 * 00 -> no received flow
209 * 01 -> transmitter generates
211 * 10 -> transmitter generates
213 * 11 -> transmitter generates
214 * XON1, XON2, XOFF1 and
218 /* PLL configuration register masks */
219 #define MAX310X_PLLCFG_PREDIV_MASK (0x3f) /* PLL predivision value */
220 #define MAX310X_PLLCFG_PLLFACTOR_MASK (0xc0) /* PLL multiplication factor */
222 /* Baud rate generator configuration register bits */
223 #define MAX310X_BRGCFG_2XMODE_BIT (1 << 4) /* Double baud rate */
224 #define MAX310X_BRGCFG_4XMODE_BIT (1 << 5) /* Quadruple baud rate */
226 /* Clock source register bits */
227 #define MAX310X_CLKSRC_CRYST_BIT (1 << 1) /* Crystal osc enable */
228 #define MAX310X_CLKSRC_PLL_BIT (1 << 2) /* PLL enable */
229 #define MAX310X_CLKSRC_PLLBYP_BIT (1 << 3) /* PLL bypass */
230 #define MAX310X_CLKSRC_EXTCLK_BIT (1 << 4) /* External clock enable */
231 #define MAX310X_CLKSRC_CLK2RTS_BIT (1 << 7) /* Baud clk to RTS pin */
233 /* Global commands */
234 #define MAX310X_EXTREG_ENBL (0xce)
235 #define MAX310X_EXTREG_DSBL (0xcd)
237 /* Misc definitions */
238 #define MAX310X_FIFO_SIZE (128)
239 #define MAX310x_REV_MASK (0xfc)
241 /* MAX3107 specific */
242 #define MAX3107_REV_ID (0xa0)
244 /* MAX3109 specific */
245 #define MAX3109_REV_ID (0xc0)
247 /* MAX14830 specific */
248 #define MAX14830_BRGCFG_CLKDIS_BIT (1 << 6) /* Clock Disable */
249 #define MAX14830_REV_ID (0xb0)
251 struct max310x_devtype {
254 int (*detect)(struct device *);
255 void (*power)(struct uart_port *, int);
259 struct uart_port port;
260 struct work_struct tx_work;
261 struct work_struct md_work;
262 struct work_struct rs_work;
265 struct max310x_port {
266 struct max310x_devtype *devtype;
267 struct regmap *regmap;
270 #ifdef CONFIG_GPIOLIB
271 struct gpio_chip gpio;
273 struct max310x_one p[0];
276 static struct uart_driver max310x_uart = {
277 .owner = THIS_MODULE,
278 .driver_name = MAX310X_NAME,
279 .dev_name = "ttyMAX",
280 .major = MAX310X_MAJOR,
281 .minor = MAX310X_MINOR,
282 .nr = MAX310X_UART_NRMAX,
285 static DECLARE_BITMAP(max310x_lines, MAX310X_UART_NRMAX);
287 static u8 max310x_port_read(struct uart_port *port, u8 reg)
289 struct max310x_port *s = dev_get_drvdata(port->dev);
290 unsigned int val = 0;
292 regmap_read(s->regmap, port->iobase + reg, &val);
297 static void max310x_port_write(struct uart_port *port, u8 reg, u8 val)
299 struct max310x_port *s = dev_get_drvdata(port->dev);
301 regmap_write(s->regmap, port->iobase + reg, val);
304 static void max310x_port_update(struct uart_port *port, u8 reg, u8 mask, u8 val)
306 struct max310x_port *s = dev_get_drvdata(port->dev);
308 regmap_update_bits(s->regmap, port->iobase + reg, mask, val);
311 static int max3107_detect(struct device *dev)
313 struct max310x_port *s = dev_get_drvdata(dev);
314 unsigned int val = 0;
317 ret = regmap_read(s->regmap, MAX310X_REVID_REG, &val);
321 if (((val & MAX310x_REV_MASK) != MAX3107_REV_ID)) {
323 "%s ID 0x%02x does not match\n", s->devtype->name, val);
330 static int max3108_detect(struct device *dev)
332 struct max310x_port *s = dev_get_drvdata(dev);
333 unsigned int val = 0;
336 /* MAX3108 have not REV ID register, we just check default value
337 * from clocksource register to make sure everything works.
339 ret = regmap_read(s->regmap, MAX310X_CLKSRC_REG, &val);
343 if (val != (MAX310X_CLKSRC_EXTCLK_BIT | MAX310X_CLKSRC_PLLBYP_BIT)) {
344 dev_err(dev, "%s not present\n", s->devtype->name);
351 static int max3109_detect(struct device *dev)
353 struct max310x_port *s = dev_get_drvdata(dev);
354 unsigned int val = 0;
357 ret = regmap_write(s->regmap, MAX310X_GLOBALCMD_REG,
358 MAX310X_EXTREG_ENBL);
362 regmap_read(s->regmap, MAX310X_REVID_EXTREG, &val);
363 regmap_write(s->regmap, MAX310X_GLOBALCMD_REG, MAX310X_EXTREG_DSBL);
364 if (((val & MAX310x_REV_MASK) != MAX3109_REV_ID)) {
366 "%s ID 0x%02x does not match\n", s->devtype->name, val);
373 static void max310x_power(struct uart_port *port, int on)
375 max310x_port_update(port, MAX310X_MODE1_REG,
376 MAX310X_MODE1_FORCESLEEP_BIT,
377 on ? 0 : MAX310X_MODE1_FORCESLEEP_BIT);
382 static int max14830_detect(struct device *dev)
384 struct max310x_port *s = dev_get_drvdata(dev);
385 unsigned int val = 0;
388 ret = regmap_write(s->regmap, MAX310X_GLOBALCMD_REG,
389 MAX310X_EXTREG_ENBL);
393 regmap_read(s->regmap, MAX310X_REVID_EXTREG, &val);
394 regmap_write(s->regmap, MAX310X_GLOBALCMD_REG, MAX310X_EXTREG_DSBL);
395 if (((val & MAX310x_REV_MASK) != MAX14830_REV_ID)) {
397 "%s ID 0x%02x does not match\n", s->devtype->name, val);
404 static void max14830_power(struct uart_port *port, int on)
406 max310x_port_update(port, MAX310X_BRGCFG_REG,
407 MAX14830_BRGCFG_CLKDIS_BIT,
408 on ? 0 : MAX14830_BRGCFG_CLKDIS_BIT);
413 static const struct max310x_devtype max3107_devtype = {
416 .detect = max3107_detect,
417 .power = max310x_power,
420 static const struct max310x_devtype max3108_devtype = {
423 .detect = max3108_detect,
424 .power = max310x_power,
427 static const struct max310x_devtype max3109_devtype = {
430 .detect = max3109_detect,
431 .power = max310x_power,
434 static const struct max310x_devtype max14830_devtype = {
437 .detect = max14830_detect,
438 .power = max14830_power,
441 static bool max310x_reg_writeable(struct device *dev, unsigned int reg)
443 switch (reg & 0x1f) {
444 case MAX310X_IRQSTS_REG:
445 case MAX310X_LSR_IRQSTS_REG:
446 case MAX310X_SPCHR_IRQSTS_REG:
447 case MAX310X_STS_IRQSTS_REG:
448 case MAX310X_TXFIFOLVL_REG:
449 case MAX310X_RXFIFOLVL_REG:
458 static bool max310x_reg_volatile(struct device *dev, unsigned int reg)
460 switch (reg & 0x1f) {
461 case MAX310X_RHR_REG:
462 case MAX310X_IRQSTS_REG:
463 case MAX310X_LSR_IRQSTS_REG:
464 case MAX310X_SPCHR_IRQSTS_REG:
465 case MAX310X_STS_IRQSTS_REG:
466 case MAX310X_TXFIFOLVL_REG:
467 case MAX310X_RXFIFOLVL_REG:
468 case MAX310X_GPIODATA_REG:
469 case MAX310X_BRGDIVLSB_REG:
480 static bool max310x_reg_precious(struct device *dev, unsigned int reg)
482 switch (reg & 0x1f) {
483 case MAX310X_RHR_REG:
484 case MAX310X_IRQSTS_REG:
485 case MAX310X_SPCHR_IRQSTS_REG:
486 case MAX310X_STS_IRQSTS_REG:
495 static int max310x_set_baud(struct uart_port *port, int baud)
497 unsigned int mode = 0, div = 0, frac = 0, c = 0, F = 0;
500 * Calculate the integer divisor first. Select a proper mode
501 * in case if the requested baud is too high for the pre-defined
504 div = port->uartclk / baud;
508 mode = MAX310X_BRGCFG_4XMODE_BIT;
509 } else if (div < 16) {
512 mode = MAX310X_BRGCFG_2XMODE_BIT;
517 /* Calculate the divisor in accordance with the fraction coefficient */
521 /* Calculate the baud rate fraction */
523 frac = (16*(port->uartclk % F)) / F;
527 max310x_port_write(port, MAX310X_BRGDIVMSB_REG, div >> 8);
528 max310x_port_write(port, MAX310X_BRGDIVLSB_REG, div);
529 max310x_port_write(port, MAX310X_BRGCFG_REG, frac | mode);
531 /* Return the actual baud rate we just programmed */
532 return (16*port->uartclk) / (c*(16*div + frac));
535 static int max310x_update_best_err(unsigned long f, long *besterr)
537 /* Use baudrate 115200 for calculate error */
538 long err = f % (460800 * 16);
540 if ((*besterr < 0) || (*besterr > err)) {
548 static int max310x_set_ref_clk(struct max310x_port *s, unsigned long freq,
551 unsigned int div, clksrc, pllcfg = 0;
553 unsigned long fdiv, fmul, bestfreq = freq;
555 /* First, update error without PLL */
556 max310x_update_best_err(freq, &besterr);
558 /* Try all possible PLL dividers */
559 for (div = 1; (div <= 63) && besterr; div++) {
560 fdiv = DIV_ROUND_CLOSEST(freq, div);
562 /* Try multiplier 6 */
564 if ((fdiv >= 500000) && (fdiv <= 800000))
565 if (!max310x_update_best_err(fmul, &besterr)) {
566 pllcfg = (0 << 6) | div;
569 /* Try multiplier 48 */
571 if ((fdiv >= 850000) && (fdiv <= 1200000))
572 if (!max310x_update_best_err(fmul, &besterr)) {
573 pllcfg = (1 << 6) | div;
576 /* Try multiplier 96 */
578 if ((fdiv >= 425000) && (fdiv <= 1000000))
579 if (!max310x_update_best_err(fmul, &besterr)) {
580 pllcfg = (2 << 6) | div;
583 /* Try multiplier 144 */
585 if ((fdiv >= 390000) && (fdiv <= 667000))
586 if (!max310x_update_best_err(fmul, &besterr)) {
587 pllcfg = (3 << 6) | div;
592 /* Configure clock source */
593 clksrc = MAX310X_CLKSRC_EXTCLK_BIT | (xtal ? MAX310X_CLKSRC_CRYST_BIT : 0);
597 clksrc |= MAX310X_CLKSRC_PLL_BIT;
598 regmap_write(s->regmap, MAX310X_PLLCFG_REG, pllcfg);
600 clksrc |= MAX310X_CLKSRC_PLLBYP_BIT;
602 regmap_write(s->regmap, MAX310X_CLKSRC_REG, clksrc);
604 /* Wait for crystal */
608 return (int)bestfreq;
611 static void max310x_handle_rx(struct uart_port *port, unsigned int rxlen)
613 unsigned int sts, ch, flag;
615 if (unlikely(rxlen >= port->fifosize)) {
616 dev_warn_ratelimited(port->dev, "Possible RX FIFO overrun\n");
617 port->icount.buf_overrun++;
618 /* Ensure sanity of RX level */
619 rxlen = port->fifosize;
623 ch = max310x_port_read(port, MAX310X_RHR_REG);
624 sts = max310x_port_read(port, MAX310X_LSR_IRQSTS_REG);
626 sts &= MAX310X_LSR_RXPAR_BIT | MAX310X_LSR_FRERR_BIT |
627 MAX310X_LSR_RXOVR_BIT | MAX310X_LSR_RXBRK_BIT;
633 if (sts & MAX310X_LSR_RXBRK_BIT) {
635 if (uart_handle_break(port))
637 } else if (sts & MAX310X_LSR_RXPAR_BIT)
638 port->icount.parity++;
639 else if (sts & MAX310X_LSR_FRERR_BIT)
640 port->icount.frame++;
641 else if (sts & MAX310X_LSR_RXOVR_BIT)
642 port->icount.overrun++;
644 sts &= port->read_status_mask;
645 if (sts & MAX310X_LSR_RXBRK_BIT)
647 else if (sts & MAX310X_LSR_RXPAR_BIT)
649 else if (sts & MAX310X_LSR_FRERR_BIT)
651 else if (sts & MAX310X_LSR_RXOVR_BIT)
655 if (uart_handle_sysrq_char(port, ch))
658 if (sts & port->ignore_status_mask)
661 uart_insert_char(port, sts, MAX310X_LSR_RXOVR_BIT, ch, flag);
664 tty_flip_buffer_push(&port->state->port);
667 static void max310x_handle_tx(struct uart_port *port)
669 struct circ_buf *xmit = &port->state->xmit;
670 unsigned int txlen, to_send;
672 if (unlikely(port->x_char)) {
673 max310x_port_write(port, MAX310X_THR_REG, port->x_char);
679 if (uart_circ_empty(xmit) || uart_tx_stopped(port))
682 /* Get length of data pending in circular buffer */
683 to_send = uart_circ_chars_pending(xmit);
684 if (likely(to_send)) {
685 /* Limit to size of TX FIFO */
686 txlen = max310x_port_read(port, MAX310X_TXFIFOLVL_REG);
687 txlen = port->fifosize - txlen;
688 to_send = (to_send > txlen) ? txlen : to_send;
690 /* Add data to send */
691 port->icount.tx += to_send;
693 max310x_port_write(port, MAX310X_THR_REG,
694 xmit->buf[xmit->tail]);
695 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
699 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
700 uart_write_wakeup(port);
703 static void max310x_port_irq(struct max310x_port *s, int portno)
705 struct uart_port *port = &s->p[portno].port;
708 unsigned int ists, lsr, rxlen;
710 /* Read IRQ status & RX FIFO level */
711 ists = max310x_port_read(port, MAX310X_IRQSTS_REG);
712 rxlen = max310x_port_read(port, MAX310X_RXFIFOLVL_REG);
716 if (ists & MAX310X_IRQ_CTS_BIT) {
717 lsr = max310x_port_read(port, MAX310X_LSR_IRQSTS_REG);
718 uart_handle_cts_change(port,
719 !!(lsr & MAX310X_LSR_CTS_BIT));
722 max310x_handle_rx(port, rxlen);
723 if (ists & MAX310X_IRQ_TXEMPTY_BIT) {
724 mutex_lock(&s->mutex);
725 max310x_handle_tx(port);
726 mutex_unlock(&s->mutex);
731 static irqreturn_t max310x_ist(int irq, void *dev_id)
733 struct max310x_port *s = (struct max310x_port *)dev_id;
735 if (s->devtype->nr > 1) {
737 unsigned int val = ~0;
739 WARN_ON_ONCE(regmap_read(s->regmap,
740 MAX310X_GLOBALIRQ_REG, &val));
741 val = ((1 << s->devtype->nr) - 1) & ~val;
744 max310x_port_irq(s, fls(val) - 1);
747 max310x_port_irq(s, 0);
752 static void max310x_wq_proc(struct work_struct *ws)
754 struct max310x_one *one = container_of(ws, struct max310x_one, tx_work);
755 struct max310x_port *s = dev_get_drvdata(one->port.dev);
757 mutex_lock(&s->mutex);
758 max310x_handle_tx(&one->port);
759 mutex_unlock(&s->mutex);
762 static void max310x_start_tx(struct uart_port *port)
764 struct max310x_one *one = container_of(port, struct max310x_one, port);
766 if (!work_pending(&one->tx_work))
767 schedule_work(&one->tx_work);
770 static unsigned int max310x_tx_empty(struct uart_port *port)
772 u8 lvl = max310x_port_read(port, MAX310X_TXFIFOLVL_REG);
774 return lvl ? 0 : TIOCSER_TEMT;
777 static unsigned int max310x_get_mctrl(struct uart_port *port)
779 /* DCD and DSR are not wired and CTS/RTS is handled automatically
780 * so just indicate DSR and CAR asserted
782 return TIOCM_DSR | TIOCM_CAR;
785 static void max310x_md_proc(struct work_struct *ws)
787 struct max310x_one *one = container_of(ws, struct max310x_one, md_work);
789 max310x_port_update(&one->port, MAX310X_MODE2_REG,
790 MAX310X_MODE2_LOOPBACK_BIT,
791 (one->port.mctrl & TIOCM_LOOP) ?
792 MAX310X_MODE2_LOOPBACK_BIT : 0);
795 static void max310x_set_mctrl(struct uart_port *port, unsigned int mctrl)
797 struct max310x_one *one = container_of(port, struct max310x_one, port);
799 schedule_work(&one->md_work);
802 static void max310x_break_ctl(struct uart_port *port, int break_state)
804 max310x_port_update(port, MAX310X_LCR_REG,
805 MAX310X_LCR_TXBREAK_BIT,
806 break_state ? MAX310X_LCR_TXBREAK_BIT : 0);
809 static void max310x_set_termios(struct uart_port *port,
810 struct ktermios *termios,
811 struct ktermios *old)
813 unsigned int lcr = 0, flow = 0;
816 /* Mask termios capabilities we don't support */
817 termios->c_cflag &= ~CMSPAR;
820 switch (termios->c_cflag & CSIZE) {
824 lcr = MAX310X_LCR_LENGTH0_BIT;
827 lcr = MAX310X_LCR_LENGTH1_BIT;
831 lcr = MAX310X_LCR_LENGTH1_BIT | MAX310X_LCR_LENGTH0_BIT;
836 if (termios->c_cflag & PARENB) {
837 lcr |= MAX310X_LCR_PARITY_BIT;
838 if (!(termios->c_cflag & PARODD))
839 lcr |= MAX310X_LCR_EVENPARITY_BIT;
843 if (termios->c_cflag & CSTOPB)
844 lcr |= MAX310X_LCR_STOPLEN_BIT; /* 2 stops */
846 /* Update LCR register */
847 max310x_port_write(port, MAX310X_LCR_REG, lcr);
849 /* Set read status mask */
850 port->read_status_mask = MAX310X_LSR_RXOVR_BIT;
851 if (termios->c_iflag & INPCK)
852 port->read_status_mask |= MAX310X_LSR_RXPAR_BIT |
853 MAX310X_LSR_FRERR_BIT;
854 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
855 port->read_status_mask |= MAX310X_LSR_RXBRK_BIT;
857 /* Set status ignore mask */
858 port->ignore_status_mask = 0;
859 if (termios->c_iflag & IGNBRK)
860 port->ignore_status_mask |= MAX310X_LSR_RXBRK_BIT;
861 if (!(termios->c_cflag & CREAD))
862 port->ignore_status_mask |= MAX310X_LSR_RXPAR_BIT |
863 MAX310X_LSR_RXOVR_BIT |
864 MAX310X_LSR_FRERR_BIT |
865 MAX310X_LSR_RXBRK_BIT;
867 /* Configure flow control */
868 max310x_port_write(port, MAX310X_XON1_REG, termios->c_cc[VSTART]);
869 max310x_port_write(port, MAX310X_XOFF1_REG, termios->c_cc[VSTOP]);
870 if (termios->c_cflag & CRTSCTS)
871 flow |= MAX310X_FLOWCTRL_AUTOCTS_BIT |
872 MAX310X_FLOWCTRL_AUTORTS_BIT;
873 if (termios->c_iflag & IXON)
874 flow |= MAX310X_FLOWCTRL_SWFLOW3_BIT |
875 MAX310X_FLOWCTRL_SWFLOWEN_BIT;
876 if (termios->c_iflag & IXOFF)
877 flow |= MAX310X_FLOWCTRL_SWFLOW1_BIT |
878 MAX310X_FLOWCTRL_SWFLOWEN_BIT;
879 max310x_port_write(port, MAX310X_FLOWCTRL_REG, flow);
881 /* Get baud rate generator configuration */
882 baud = uart_get_baud_rate(port, termios, old,
883 port->uartclk / 16 / 0xffff,
886 /* Setup baudrate generator */
887 baud = max310x_set_baud(port, baud);
889 /* Update timeout according to new baud rate */
890 uart_update_timeout(port, termios->c_cflag, baud);
893 static void max310x_rs_proc(struct work_struct *ws)
895 struct max310x_one *one = container_of(ws, struct max310x_one, rs_work);
898 val = (one->port.rs485.delay_rts_before_send << 4) |
899 one->port.rs485.delay_rts_after_send;
900 max310x_port_write(&one->port, MAX310X_HDPIXDELAY_REG, val);
902 if (one->port.rs485.flags & SER_RS485_ENABLED) {
903 max310x_port_update(&one->port, MAX310X_MODE1_REG,
904 MAX310X_MODE1_TRNSCVCTRL_BIT,
905 MAX310X_MODE1_TRNSCVCTRL_BIT);
906 max310x_port_update(&one->port, MAX310X_MODE2_REG,
907 MAX310X_MODE2_ECHOSUPR_BIT,
908 MAX310X_MODE2_ECHOSUPR_BIT);
910 max310x_port_update(&one->port, MAX310X_MODE1_REG,
911 MAX310X_MODE1_TRNSCVCTRL_BIT, 0);
912 max310x_port_update(&one->port, MAX310X_MODE2_REG,
913 MAX310X_MODE2_ECHOSUPR_BIT, 0);
917 static int max310x_rs485_config(struct uart_port *port,
918 struct serial_rs485 *rs485)
920 struct max310x_one *one = container_of(port, struct max310x_one, port);
922 if ((rs485->delay_rts_before_send > 0x0f) ||
923 (rs485->delay_rts_after_send > 0x0f))
926 rs485->flags &= SER_RS485_RTS_ON_SEND | SER_RS485_ENABLED;
927 memset(rs485->padding, 0, sizeof(rs485->padding));
928 port->rs485 = *rs485;
930 schedule_work(&one->rs_work);
935 static int max310x_startup(struct uart_port *port)
937 struct max310x_port *s = dev_get_drvdata(port->dev);
940 s->devtype->power(port, 1);
942 /* Configure MODE1 register */
943 max310x_port_update(port, MAX310X_MODE1_REG,
944 MAX310X_MODE1_TRNSCVCTRL_BIT, 0);
946 /* Configure MODE2 register & Reset FIFOs*/
947 val = MAX310X_MODE2_RXEMPTINV_BIT | MAX310X_MODE2_FIFORST_BIT;
948 max310x_port_write(port, MAX310X_MODE2_REG, val);
949 max310x_port_update(port, MAX310X_MODE2_REG,
950 MAX310X_MODE2_FIFORST_BIT, 0);
952 /* Configure flow control levels */
953 /* Flow control halt level 96, resume level 48 */
954 max310x_port_write(port, MAX310X_FLOWLVL_REG,
955 MAX310X_FLOWLVL_RES(48) | MAX310X_FLOWLVL_HALT(96));
957 /* Clear IRQ status register */
958 max310x_port_read(port, MAX310X_IRQSTS_REG);
960 /* Enable RX, TX, CTS change interrupts */
961 val = MAX310X_IRQ_RXEMPTY_BIT | MAX310X_IRQ_TXEMPTY_BIT;
962 max310x_port_write(port, MAX310X_IRQEN_REG, val | MAX310X_IRQ_CTS_BIT);
967 static void max310x_shutdown(struct uart_port *port)
969 struct max310x_port *s = dev_get_drvdata(port->dev);
971 /* Disable all interrupts */
972 max310x_port_write(port, MAX310X_IRQEN_REG, 0);
974 s->devtype->power(port, 0);
977 static const char *max310x_type(struct uart_port *port)
979 struct max310x_port *s = dev_get_drvdata(port->dev);
981 return (port->type == PORT_MAX310X) ? s->devtype->name : NULL;
984 static int max310x_request_port(struct uart_port *port)
990 static void max310x_config_port(struct uart_port *port, int flags)
992 if (flags & UART_CONFIG_TYPE)
993 port->type = PORT_MAX310X;
996 static int max310x_verify_port(struct uart_port *port, struct serial_struct *s)
998 if ((s->type != PORT_UNKNOWN) && (s->type != PORT_MAX310X))
1000 if (s->irq != port->irq)
1006 static void max310x_null_void(struct uart_port *port)
1011 static const struct uart_ops max310x_ops = {
1012 .tx_empty = max310x_tx_empty,
1013 .set_mctrl = max310x_set_mctrl,
1014 .get_mctrl = max310x_get_mctrl,
1015 .stop_tx = max310x_null_void,
1016 .start_tx = max310x_start_tx,
1017 .stop_rx = max310x_null_void,
1018 .break_ctl = max310x_break_ctl,
1019 .startup = max310x_startup,
1020 .shutdown = max310x_shutdown,
1021 .set_termios = max310x_set_termios,
1022 .type = max310x_type,
1023 .request_port = max310x_request_port,
1024 .release_port = max310x_null_void,
1025 .config_port = max310x_config_port,
1026 .verify_port = max310x_verify_port,
1029 static int __maybe_unused max310x_suspend(struct device *dev)
1031 struct max310x_port *s = dev_get_drvdata(dev);
1034 for (i = 0; i < s->devtype->nr; i++) {
1035 uart_suspend_port(&max310x_uart, &s->p[i].port);
1036 s->devtype->power(&s->p[i].port, 0);
1042 static int __maybe_unused max310x_resume(struct device *dev)
1044 struct max310x_port *s = dev_get_drvdata(dev);
1047 for (i = 0; i < s->devtype->nr; i++) {
1048 s->devtype->power(&s->p[i].port, 1);
1049 uart_resume_port(&max310x_uart, &s->p[i].port);
1055 static SIMPLE_DEV_PM_OPS(max310x_pm_ops, max310x_suspend, max310x_resume);
1057 #ifdef CONFIG_GPIOLIB
1058 static int max310x_gpio_get(struct gpio_chip *chip, unsigned offset)
1061 struct max310x_port *s = gpiochip_get_data(chip);
1062 struct uart_port *port = &s->p[offset / 4].port;
1064 val = max310x_port_read(port, MAX310X_GPIODATA_REG);
1066 return !!((val >> 4) & (1 << (offset % 4)));
1069 static void max310x_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1071 struct max310x_port *s = gpiochip_get_data(chip);
1072 struct uart_port *port = &s->p[offset / 4].port;
1074 max310x_port_update(port, MAX310X_GPIODATA_REG, 1 << (offset % 4),
1075 value ? 1 << (offset % 4) : 0);
1078 static int max310x_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
1080 struct max310x_port *s = gpiochip_get_data(chip);
1081 struct uart_port *port = &s->p[offset / 4].port;
1083 max310x_port_update(port, MAX310X_GPIOCFG_REG, 1 << (offset % 4), 0);
1088 static int max310x_gpio_direction_output(struct gpio_chip *chip,
1089 unsigned offset, int value)
1091 struct max310x_port *s = gpiochip_get_data(chip);
1092 struct uart_port *port = &s->p[offset / 4].port;
1094 max310x_port_update(port, MAX310X_GPIODATA_REG, 1 << (offset % 4),
1095 value ? 1 << (offset % 4) : 0);
1096 max310x_port_update(port, MAX310X_GPIOCFG_REG, 1 << (offset % 4),
1103 static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
1104 struct regmap *regmap, int irq, unsigned long flags)
1106 int i, ret, fmin, fmax, freq, uartclk;
1107 struct clk *clk_osc, *clk_xtal;
1108 struct max310x_port *s;
1112 return PTR_ERR(regmap);
1114 /* Alloc port structure */
1115 s = devm_kzalloc(dev, sizeof(*s) +
1116 sizeof(struct max310x_one) * devtype->nr, GFP_KERNEL);
1118 dev_err(dev, "Error allocating port structure\n");
1122 clk_osc = devm_clk_get(dev, "osc");
1123 clk_xtal = devm_clk_get(dev, "xtal");
1124 if (!IS_ERR(clk_osc)) {
1128 } else if (!IS_ERR(clk_xtal)) {
1133 } else if (PTR_ERR(clk_osc) == -EPROBE_DEFER ||
1134 PTR_ERR(clk_xtal) == -EPROBE_DEFER) {
1135 return -EPROBE_DEFER;
1137 dev_err(dev, "Cannot get clock\n");
1141 ret = clk_prepare_enable(s->clk);
1145 freq = clk_get_rate(s->clk);
1146 /* Check frequency limits */
1147 if (freq < fmin || freq > fmax) {
1153 s->devtype = devtype;
1154 dev_set_drvdata(dev, s);
1156 /* Check device to ensure we are talking to what we expect */
1157 ret = devtype->detect(dev);
1161 for (i = 0; i < devtype->nr; i++) {
1162 unsigned int offs = i << 5;
1165 regmap_write(s->regmap, MAX310X_MODE2_REG + offs,
1166 MAX310X_MODE2_RST_BIT);
1167 /* Clear port reset */
1168 regmap_write(s->regmap, MAX310X_MODE2_REG + offs, 0);
1170 /* Wait for port startup */
1172 regmap_read(s->regmap,
1173 MAX310X_BRGDIVLSB_REG + offs, &ret);
1174 } while (ret != 0x01);
1176 regmap_update_bits(s->regmap, MAX310X_MODE1_REG + offs,
1177 MAX310X_MODE1_AUTOSLEEP_BIT,
1178 MAX310X_MODE1_AUTOSLEEP_BIT);
1181 uartclk = max310x_set_ref_clk(s, freq, xtal);
1182 dev_dbg(dev, "Reference clock set to %i Hz\n", uartclk);
1184 #ifdef CONFIG_GPIOLIB
1185 /* Setup GPIO cotroller */
1186 s->gpio.owner = THIS_MODULE;
1187 s->gpio.parent = dev;
1188 s->gpio.label = dev_name(dev);
1189 s->gpio.direction_input = max310x_gpio_direction_input;
1190 s->gpio.get = max310x_gpio_get;
1191 s->gpio.direction_output= max310x_gpio_direction_output;
1192 s->gpio.set = max310x_gpio_set;
1194 s->gpio.ngpio = devtype->nr * 4;
1195 s->gpio.can_sleep = 1;
1196 ret = devm_gpiochip_add_data(dev, &s->gpio, s);
1201 mutex_init(&s->mutex);
1203 for (i = 0; i < devtype->nr; i++) {
1206 line = find_first_zero_bit(max310x_lines, MAX310X_UART_NRMAX);
1207 if (line == MAX310X_UART_NRMAX) {
1212 /* Initialize port data */
1213 s->p[i].port.line = line;
1214 s->p[i].port.dev = dev;
1215 s->p[i].port.irq = irq;
1216 s->p[i].port.type = PORT_MAX310X;
1217 s->p[i].port.fifosize = MAX310X_FIFO_SIZE;
1218 s->p[i].port.flags = UPF_FIXED_TYPE | UPF_LOW_LATENCY;
1219 s->p[i].port.iotype = UPIO_PORT;
1220 s->p[i].port.iobase = i * 0x20;
1221 s->p[i].port.membase = (void __iomem *)~0;
1222 s->p[i].port.uartclk = uartclk;
1223 s->p[i].port.rs485_config = max310x_rs485_config;
1224 s->p[i].port.ops = &max310x_ops;
1225 /* Disable all interrupts */
1226 max310x_port_write(&s->p[i].port, MAX310X_IRQEN_REG, 0);
1227 /* Clear IRQ status register */
1228 max310x_port_read(&s->p[i].port, MAX310X_IRQSTS_REG);
1229 /* Enable IRQ pin */
1230 max310x_port_update(&s->p[i].port, MAX310X_MODE1_REG,
1231 MAX310X_MODE1_IRQSEL_BIT,
1232 MAX310X_MODE1_IRQSEL_BIT);
1233 /* Initialize queue for start TX */
1234 INIT_WORK(&s->p[i].tx_work, max310x_wq_proc);
1235 /* Initialize queue for changing LOOPBACK mode */
1236 INIT_WORK(&s->p[i].md_work, max310x_md_proc);
1237 /* Initialize queue for changing RS485 mode */
1238 INIT_WORK(&s->p[i].rs_work, max310x_rs_proc);
1241 ret = uart_add_one_port(&max310x_uart, &s->p[i].port);
1243 s->p[i].port.dev = NULL;
1246 set_bit(line, max310x_lines);
1248 /* Go to suspend mode */
1249 devtype->power(&s->p[i].port, 0);
1252 /* Setup interrupt */
1253 ret = devm_request_threaded_irq(dev, irq, NULL, max310x_ist,
1254 IRQF_ONESHOT | flags, dev_name(dev), s);
1258 dev_err(dev, "Unable to reguest IRQ %i\n", irq);
1261 for (i = 0; i < devtype->nr; i++) {
1262 if (s->p[i].port.dev) {
1263 uart_remove_one_port(&max310x_uart, &s->p[i].port);
1264 clear_bit(s->p[i].port.line, max310x_lines);
1268 mutex_destroy(&s->mutex);
1271 clk_disable_unprepare(s->clk);
1276 static int max310x_remove(struct device *dev)
1278 struct max310x_port *s = dev_get_drvdata(dev);
1281 for (i = 0; i < s->devtype->nr; i++) {
1282 cancel_work_sync(&s->p[i].tx_work);
1283 cancel_work_sync(&s->p[i].md_work);
1284 cancel_work_sync(&s->p[i].rs_work);
1285 uart_remove_one_port(&max310x_uart, &s->p[i].port);
1286 clear_bit(s->p[i].port.line, max310x_lines);
1287 s->devtype->power(&s->p[i].port, 0);
1290 mutex_destroy(&s->mutex);
1291 clk_disable_unprepare(s->clk);
1296 static const struct of_device_id __maybe_unused max310x_dt_ids[] = {
1297 { .compatible = "maxim,max3107", .data = &max3107_devtype, },
1298 { .compatible = "maxim,max3108", .data = &max3108_devtype, },
1299 { .compatible = "maxim,max3109", .data = &max3109_devtype, },
1300 { .compatible = "maxim,max14830", .data = &max14830_devtype },
1303 MODULE_DEVICE_TABLE(of, max310x_dt_ids);
1305 static struct regmap_config regcfg = {
1308 .write_flag_mask = 0x80,
1309 .cache_type = REGCACHE_RBTREE,
1310 .writeable_reg = max310x_reg_writeable,
1311 .volatile_reg = max310x_reg_volatile,
1312 .precious_reg = max310x_reg_precious,
1315 #ifdef CONFIG_SPI_MASTER
1316 static int max310x_spi_probe(struct spi_device *spi)
1318 struct max310x_devtype *devtype;
1319 unsigned long flags = 0;
1320 struct regmap *regmap;
1324 spi->bits_per_word = 8;
1325 spi->mode = spi->mode ? : SPI_MODE_0;
1326 spi->max_speed_hz = spi->max_speed_hz ? : 26000000;
1327 ret = spi_setup(spi);
1331 if (spi->dev.of_node) {
1332 const struct of_device_id *of_id =
1333 of_match_device(max310x_dt_ids, &spi->dev);
1337 devtype = (struct max310x_devtype *)of_id->data;
1339 const struct spi_device_id *id_entry = spi_get_device_id(spi);
1341 devtype = (struct max310x_devtype *)id_entry->driver_data;
1344 flags = IRQF_TRIGGER_FALLING;
1345 regcfg.max_register = devtype->nr * 0x20 - 1;
1346 regmap = devm_regmap_init_spi(spi, ®cfg);
1348 return max310x_probe(&spi->dev, devtype, regmap, spi->irq, flags);
1351 static int max310x_spi_remove(struct spi_device *spi)
1353 return max310x_remove(&spi->dev);
1356 static const struct spi_device_id max310x_id_table[] = {
1357 { "max3107", (kernel_ulong_t)&max3107_devtype, },
1358 { "max3108", (kernel_ulong_t)&max3108_devtype, },
1359 { "max3109", (kernel_ulong_t)&max3109_devtype, },
1360 { "max14830", (kernel_ulong_t)&max14830_devtype, },
1363 MODULE_DEVICE_TABLE(spi, max310x_id_table);
1365 static struct spi_driver max310x_spi_driver = {
1367 .name = MAX310X_NAME,
1368 .of_match_table = of_match_ptr(max310x_dt_ids),
1369 .pm = &max310x_pm_ops,
1371 .probe = max310x_spi_probe,
1372 .remove = max310x_spi_remove,
1373 .id_table = max310x_id_table,
1377 static int __init max310x_uart_init(void)
1381 bitmap_zero(max310x_lines, MAX310X_UART_NRMAX);
1383 ret = uart_register_driver(&max310x_uart);
1387 #ifdef CONFIG_SPI_MASTER
1388 ret = spi_register_driver(&max310x_spi_driver);
1390 uart_unregister_driver(&max310x_uart);
1395 module_init(max310x_uart_init);
1397 static void __exit max310x_uart_exit(void)
1399 #ifdef CONFIG_SPI_MASTER
1400 spi_unregister_driver(&max310x_spi_driver);
1403 uart_unregister_driver(&max310x_uart);
1405 module_exit(max310x_uart_exit);
1407 MODULE_LICENSE("GPL");
1408 MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
1409 MODULE_DESCRIPTION("MAX310X serial driver");