Skip to contentSkip to conversation

serial: max310x: Improve driver. Part 1.

PATCH New Alexander Shiyan 1 participant 7 messages Feb 7, 2014 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

cover serial: max310x: Improve driver. Part 1.

This patchset provide various improvements/fixes for MAX310X serial driver.

Alexander Shiyan (6):
serial: max310x: Allow driver to be compiled as module
serial: max310x: Setup baud rate generator more precisely
serial: max310x: Remove init() and exit() callbacks
serial: max310x: Remove excess port configure at startup
serial: max310x: Add the loopback mode support
serial: max310x: Remove IRQ validation

 drivers/tty/serial/Kconfig            |  2 +-
 drivers/tty/serial/max310x.c          | 76 +++++++++++++++++------------------
 include/linux/platform_data/max310x.h |  5 ---
 3 files changed, 39 insertions(+), 44 deletions(-)
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/6 serial: max310x: Allow driver to be compiled as module

---
 drivers/tty/serial/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/Kconfig +1 -1
index a3815ea..d261d76 100644
@@ -289,7 +289,7 @@ config SERIAL_MAX3100
 	  MAX3100 chip support
 
 config SERIAL_MAX310X
-	bool "MAX310X support"
+	tristate "MAX310X support"
 	depends on SPI_MASTER
 	select SERIAL_CORE
 	select REGMAP_SPI if SPI_MASTER
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH 2/6 serial: max310x: Setup baud rate generator more precisely

In reply to Alexander Shiyan

This patch provide more precisely setup of baud rate generator. If the result of division has a remainder, we use the multiplier for the base frequency. Additionally, we report result baud rate back to serial core.

---
 drivers/tty/serial/max310x.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/tty/serial/max310x.c +20 -12
index 8d71e40..313bdf0 100644
@@ -1,7 +1,7 @@
 /*
  *  Maxim (Dallas) MAX3107/8/9, MAX14830 serial driver
  *
- *  Copyright (C) 2012-2013 Alexander Shiyan <[email protected]>
+ *  Copyright (C) 2012-2014 Alexander Shiyan <[email protected]>
  *
  *  Based on max3100.c, by Christian Pellegrin <[email protected]>
  *  Based on max3110.c, by Feng Tang <[email protected]>
@@ -504,25 +504,33 @@ static bool max310x_reg_precious(struct device *dev, unsigned int reg)
 	return false;
 }
 
-static void max310x_set_baud(struct uart_port *port, int baud)
+static int max310x_set_baud(struct uart_port *port, int baud)
 {
-	unsigned int mode = 0, div = port->uartclk / baud;
+	unsigned int mode = 0, clk = port->uartclk, div = clk / baud;
 
-	if (!(div / 16)) {
+	/* Check for minimal value for divider */
+	if (div < 16)
+		div = 16;
+
+	if (clk % baud && (div / 16) < 0x8000) {
 		/* Mode x2 */
 		mode = MAX310X_BRGCFG_2XMODE_BIT;
-		div = (port->uartclk * 2) / baud;
-	}
-
-	if (!(div / 16)) {
-		/* Mode x4 */
-		mode = MAX310X_BRGCFG_4XMODE_BIT;
-		div = (port->uartclk * 4) / baud;
+		clk = port->uartclk * 2;
+		div = clk / baud;
+
+		if (clk % baud && (div / 16) < 0x8000) {
+			/* Mode x4 */
+			mode = MAX310X_BRGCFG_4XMODE_BIT;
+			clk = port->uartclk * 4;
+			div = clk / baud;
+		}
 	}
 
 	max310x_port_write(port, MAX310X_BRGDIVMSB_REG, (div / 16) >> 8);
 	max310x_port_write(port, MAX310X_BRGDIVLSB_REG, div / 16);
 	max310x_port_write(port, MAX310X_BRGCFG_REG, (div % 16) | mode);
+
+	return DIV_ROUND_CLOSEST(clk, div);
 }
 
 static int max310x_update_best_err(unsigned long f, long *besterr)
@@ -875,7 +883,7 @@ static void max310x_set_termios(struct uart_port *port,
 				  port->uartclk / 4);
 
 	/* Setup baudrate generator */
-	max310x_set_baud(port, baud);
+	baud = max310x_set_baud(port, baud);
 
 	/* Update timeout according to new baud rate */
 	uart_update_timeout(port, termios->c_cflag, baud);
Signature · 1 line
1.8.3.2
#3 lore raw

PATCH 3/6 serial: max310x: Remove init() and exit() callbacks

In reply to Alexander Shiyan

These callbacks were previously used for the IC power initialization. If this initialization will be needed in the future, it should be implemented with the regulator API.

---
 drivers/tty/serial/max310x.c          | 7 -------
 include/linux/platform_data/max310x.h | 4 ----
 2 files changed, 11 deletions(-)
drivers/tty/serial/max310x.c +0 -7
index 313bdf0..202c1fb 100644
@@ -1135,10 +1135,6 @@ static int max310x_probe(struct device *dev, int is_spi,
 		return PTR_ERR(s->regmap);
 	}
 
-	/* Board specific configure */
-	if (s->pdata->init)
-		s->pdata->init();
-
 	/* Check device to ensure we are talking to what we expect */
 	ret = devtype->detect(dev);
 	if (ret)
@@ -1265,9 +1261,6 @@ static int max310x_remove(struct device *dev)
 		ret = gpiochip_remove(&s->gpio);
 #endif
 
-	if (s->pdata->exit)
-		s->pdata->exit();
-
 	return ret;
 }
 
include/linux/platform_data/max310x.h +0 -4
index dd11dcd..5f4b35d 100644
@@ -55,10 +55,6 @@ struct max310x_pdata {
 	const int		frequency;
 	/* GPIO base number (can be negative) */
 	const int		gpio_base;
-	/* Called during startup */
-	void (*init)(void);
-	/* Called before finish */
-	void (*exit)(void);
 };
 
 #endif
Signature · 1 line
1.8.3.2
#4 lore raw

PATCH 4/6 serial: max310x: Remove excess port configure at startup

In reply to Alexander Shiyan

Serial core calls set_termios() after port startup, so there are no reason to setup port twice.

---
 drivers/tty/serial/max310x.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/tty/serial/max310x.c +0 -6
index 202c1fb..1fb3895 100644
@@ -896,12 +896,6 @@ static int max310x_startup(struct uart_port *port)
 
 	s->devtype->power(port, 1);
 
-	/* Configure baud rate, 9600 as default */
-	max310x_set_baud(port, 9600);
-
-	/* Configure LCR register, 8N1 mode by default */
-	max310x_port_write(port, MAX310X_LCR_REG, MAX310X_LCR_WORD_LEN_8);
-
 	/* Configure MODE1 register */
 	max310x_port_update(port, MAX310X_MODE1_REG,
 			    MAX310X_MODE1_TRNSCVCTRL_BIT,
Signature · 1 line
1.8.3.2
#5 lore raw

PATCH 5/6 serial: max310x: Add the loopback mode support

In reply to Alexander Shiyan

This patch replaces loopback mode support from platform data to dynamic setup with TIOCMSET ioctl.

---
 drivers/tty/serial/max310x.c          | 25 ++++++++++++++++++-------
 include/linux/platform_data/max310x.h |  1 -
 2 files changed, 18 insertions(+), 8 deletions(-)
drivers/tty/serial/max310x.c +18 -7
index 1fb3895..3c93814 100644
@@ -283,6 +283,7 @@ struct max310x_devtype {
 struct max310x_one {
 	struct uart_port	port;
 	struct work_struct	tx_work;
+	struct work_struct	md_work;
 };
 
 struct max310x_port {
@@ -790,11 +791,21 @@ static unsigned int max310x_get_mctrl(struct uart_port *port)
 	return TIOCM_DSR | TIOCM_CAR;
 }
 
+static void max310x_md_proc(struct work_struct *ws)
+{
+	struct max310x_one *one = container_of(ws, struct max310x_one, md_work);
+
+	max310x_port_update(&one->port, MAX310X_MODE2_REG,
+			    MAX310X_MODE2_LOOPBACK_BIT,
+			    (one->port.mctrl & TIOCM_LOOP) ?
+			    MAX310X_MODE2_LOOPBACK_BIT : 0);
+}
+
 static void max310x_set_mctrl(struct uart_port *port, unsigned int mctrl)
 {
-	/* DCD and DSR are not wired and CTS/RTS is hadnled automatically
-	 * so do nothing
-	 */
+	struct max310x_one *one = container_of(port, struct max310x_one, port);
+
+	schedule_work(&one->md_work);
 }
 
 static void max310x_break_ctl(struct uart_port *port, int break_state)
@@ -904,8 +915,6 @@ static int max310x_startup(struct uart_port *port)
 
 	/* Configure MODE2 register */
 	val = MAX310X_MODE2_RXEMPTINV_BIT;
-	if (s->pdata->uart_flags[line] & MAX310X_LOOPBACK)
-		val |= MAX310X_MODE2_LOOPBACK_BIT;
 	if (s->pdata->uart_flags[line] & MAX310X_ECHO_SUPRESS)
 		val |= MAX310X_MODE2_ECHOSUPR_BIT;
 
@@ -1176,8 +1185,7 @@ static int max310x_probe(struct device *dev, int is_spi,
 		s->p[i].port.irq	= irq;
 		s->p[i].port.type	= PORT_MAX310X;
 		s->p[i].port.fifosize	= MAX310X_FIFO_SIZE;
-		s->p[i].port.flags	= UPF_SKIP_TEST | UPF_FIXED_TYPE |
-					  UPF_LOW_LATENCY;
+		s->p[i].port.flags	= UPF_FIXED_TYPE | UPF_LOW_LATENCY;
 		s->p[i].port.iotype	= UPIO_PORT;
 		s->p[i].port.iobase	= i * 0x20;
 		s->p[i].port.membase	= (void __iomem *)~0;
@@ -1193,6 +1201,8 @@ static int max310x_probe(struct device *dev, int is_spi,
 				    MAX310X_MODE1_IRQSEL_BIT);
 		/* Initialize queue for start TX */
 		INIT_WORK(&s->p[i].tx_work, max310x_wq_proc);
+		/* Initialize queue for changing mode */
+		INIT_WORK(&s->p[i].md_work, max310x_md_proc);
 		/* Register port */
 		uart_add_one_port(&s->uart, &s->p[i].port);
 		/* Go to suspend mode */
@@ -1244,6 +1254,7 @@ static int max310x_remove(struct device *dev)
 
 	for (i = 0; i < s->uart.nr; i++) {
 		cancel_work_sync(&s->p[i].tx_work);
+		cancel_work_sync(&s->p[i].md_work);
 		uart_remove_one_port(&s->uart, &s->p[i].port);
 		s->devtype->power(&s->p[i].port, 0);
 	}
include/linux/platform_data/max310x.h +0 -1
index 5f4b35d..9d5f69b 100644
@@ -46,7 +46,6 @@ struct max310x_pdata {
 #define MAX310X_EXT_CLK		(0x00000001)	/* External clock enable */
 	/* Flags global to UART port */
 	const u8		uart_flags[MAX310X_MAX_UARTS];
-#define MAX310X_LOOPBACK	(0x00000001)	/* Loopback mode enable */
 #define MAX310X_ECHO_SUPRESS	(0x00000002)	/* Enable echo supress */
 #define MAX310X_AUTO_DIR_CTRL	(0x00000004)	/* Enable Auto direction
 						 * control (RS-485)
Signature · 1 line
1.8.3.2
#6 lore raw

PATCH 6/6 serial: max310x: Remove IRQ validation

In reply to Alexander Shiyan

This patch removes excess IRQ checks at driver probe(). IRQ validation is already provided by request_threaded_irq().

---
 drivers/tty/serial/max310x.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/tty/serial/max310x.c +0 -6
index 3c93814..ac1d54c 100644
@@ -1081,12 +1081,6 @@ static int max310x_probe(struct device *dev, int is_spi,
 	struct max310x_pdata *pdata = dev_get_platdata(dev);
 	int i, ret, uartclk;
 
-	/* Check for IRQ */
-	if (irq <= 0) {
-		dev_err(dev, "No IRQ specified\n");
-		return -ENOTSUPP;
-	}
-
 	if (!pdata) {
 		dev_err(dev, "No platform data supplied\n");
 		return -EINVAL;
Signature · 1 line
1.8.3.2