* [PATCH 0/6] serial: max310x: Improve driver. Part 1.
@ 2014-02-07 14:16 Alexander Shiyan
2014-02-07 14:16 ` [PATCH 1/6] serial: max310x: Allow driver to be compiled as module Alexander Shiyan
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Alexander Shiyan @ 2014-02-07 14:16 UTC (permalink / raw)
To: linux-serial; +Cc: Greg Kroah-Hartman, Jiri Slaby, Alexander Shiyan
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(-)
--
1.8.3.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] serial: max310x: Allow driver to be compiled as module
2014-02-07 14:16 [PATCH 0/6] serial: max310x: Improve driver. Part 1 Alexander Shiyan
@ 2014-02-07 14:16 ` Alexander Shiyan
2014-02-07 14:16 ` [PATCH 2/6] serial: max310x: Setup baud rate generator more precisely Alexander Shiyan
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Alexander Shiyan @ 2014-02-07 14:16 UTC (permalink / raw)
To: linux-serial; +Cc: Greg Kroah-Hartman, Jiri Slaby, Alexander Shiyan
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
drivers/tty/serial/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index a3815ea..d261d76 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -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
--
1.8.3.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/6] serial: max310x: Setup baud rate generator more precisely
2014-02-07 14:16 [PATCH 0/6] serial: max310x: Improve driver. Part 1 Alexander Shiyan
2014-02-07 14:16 ` [PATCH 1/6] serial: max310x: Allow driver to be compiled as module Alexander Shiyan
@ 2014-02-07 14:16 ` Alexander Shiyan
2014-02-07 14:16 ` [PATCH 3/6] serial: max310x: Remove init() and exit() callbacks Alexander Shiyan
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Alexander Shiyan @ 2014-02-07 14:16 UTC (permalink / raw)
To: linux-serial; +Cc: Greg Kroah-Hartman, Jiri Slaby, 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.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
drivers/tty/serial/max310x.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 8d71e40..313bdf0 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -1,7 +1,7 @@
/*
* Maxim (Dallas) MAX3107/8/9, MAX14830 serial driver
*
- * Copyright (C) 2012-2013 Alexander Shiyan <shc_work@mail.ru>
+ * Copyright (C) 2012-2014 Alexander Shiyan <shc_work@mail.ru>
*
* Based on max3100.c, by Christian Pellegrin <chripell@evolware.org>
* Based on max3110.c, by Feng Tang <feng.tang@intel.com>
@@ -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);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/6] serial: max310x: Remove init() and exit() callbacks
2014-02-07 14:16 [PATCH 0/6] serial: max310x: Improve driver. Part 1 Alexander Shiyan
2014-02-07 14:16 ` [PATCH 1/6] serial: max310x: Allow driver to be compiled as module Alexander Shiyan
2014-02-07 14:16 ` [PATCH 2/6] serial: max310x: Setup baud rate generator more precisely Alexander Shiyan
@ 2014-02-07 14:16 ` Alexander Shiyan
2014-02-07 14:16 ` [PATCH 4/6] serial: max310x: Remove excess port configure at startup Alexander Shiyan
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Alexander Shiyan @ 2014-02-07 14:16 UTC (permalink / raw)
To: linux-serial; +Cc: Greg Kroah-Hartman, Jiri Slaby, 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.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
drivers/tty/serial/max310x.c | 7 -------
include/linux/platform_data/max310x.h | 4 ----
2 files changed, 11 deletions(-)
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 313bdf0..202c1fb 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -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;
}
diff --git a/include/linux/platform_data/max310x.h b/include/linux/platform_data/max310x.h
index dd11dcd..5f4b35d 100644
--- a/include/linux/platform_data/max310x.h
+++ b/include/linux/platform_data/max310x.h
@@ -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
--
1.8.3.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/6] serial: max310x: Remove excess port configure at startup
2014-02-07 14:16 [PATCH 0/6] serial: max310x: Improve driver. Part 1 Alexander Shiyan
` (2 preceding siblings ...)
2014-02-07 14:16 ` [PATCH 3/6] serial: max310x: Remove init() and exit() callbacks Alexander Shiyan
@ 2014-02-07 14:16 ` Alexander Shiyan
2014-02-07 14:16 ` [PATCH 5/6] serial: max310x: Add the loopback mode support Alexander Shiyan
2014-02-07 14:16 ` [PATCH 6/6] serial: max310x: Remove IRQ validation Alexander Shiyan
5 siblings, 0 replies; 7+ messages in thread
From: Alexander Shiyan @ 2014-02-07 14:16 UTC (permalink / raw)
To: linux-serial; +Cc: Greg Kroah-Hartman, Jiri Slaby, Alexander Shiyan
Serial core calls set_termios() after port startup, so there are
no reason to setup port twice.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
drivers/tty/serial/max310x.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 202c1fb..1fb3895 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -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,
--
1.8.3.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/6] serial: max310x: Add the loopback mode support
2014-02-07 14:16 [PATCH 0/6] serial: max310x: Improve driver. Part 1 Alexander Shiyan
` (3 preceding siblings ...)
2014-02-07 14:16 ` [PATCH 4/6] serial: max310x: Remove excess port configure at startup Alexander Shiyan
@ 2014-02-07 14:16 ` Alexander Shiyan
2014-02-07 14:16 ` [PATCH 6/6] serial: max310x: Remove IRQ validation Alexander Shiyan
5 siblings, 0 replies; 7+ messages in thread
From: Alexander Shiyan @ 2014-02-07 14:16 UTC (permalink / raw)
To: linux-serial; +Cc: Greg Kroah-Hartman, Jiri Slaby, Alexander Shiyan
This patch replaces loopback mode support from platform data to
dynamic setup with TIOCMSET ioctl.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
drivers/tty/serial/max310x.c | 25 ++++++++++++++++++-------
include/linux/platform_data/max310x.h | 1 -
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 1fb3895..3c93814 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -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);
}
diff --git a/include/linux/platform_data/max310x.h b/include/linux/platform_data/max310x.h
index 5f4b35d..9d5f69b 100644
--- a/include/linux/platform_data/max310x.h
+++ b/include/linux/platform_data/max310x.h
@@ -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)
--
1.8.3.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/6] serial: max310x: Remove IRQ validation
2014-02-07 14:16 [PATCH 0/6] serial: max310x: Improve driver. Part 1 Alexander Shiyan
` (4 preceding siblings ...)
2014-02-07 14:16 ` [PATCH 5/6] serial: max310x: Add the loopback mode support Alexander Shiyan
@ 2014-02-07 14:16 ` Alexander Shiyan
5 siblings, 0 replies; 7+ messages in thread
From: Alexander Shiyan @ 2014-02-07 14:16 UTC (permalink / raw)
To: linux-serial; +Cc: Greg Kroah-Hartman, Jiri Slaby, Alexander Shiyan
This patch removes excess IRQ checks at driver probe().
IRQ validation is already provided by request_threaded_irq().
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
drivers/tty/serial/max310x.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 3c93814..ac1d54c 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -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;
--
1.8.3.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-02-07 14:20 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-07 14:16 [PATCH 0/6] serial: max310x: Improve driver. Part 1 Alexander Shiyan
2014-02-07 14:16 ` [PATCH 1/6] serial: max310x: Allow driver to be compiled as module Alexander Shiyan
2014-02-07 14:16 ` [PATCH 2/6] serial: max310x: Setup baud rate generator more precisely Alexander Shiyan
2014-02-07 14:16 ` [PATCH 3/6] serial: max310x: Remove init() and exit() callbacks Alexander Shiyan
2014-02-07 14:16 ` [PATCH 4/6] serial: max310x: Remove excess port configure at startup Alexander Shiyan
2014-02-07 14:16 ` [PATCH 5/6] serial: max310x: Add the loopback mode support Alexander Shiyan
2014-02-07 14:16 ` [PATCH 6/6] serial: max310x: Remove IRQ validation Alexander Shiyan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).