* [PATCH] serial: mxs-auart: use mctrl_gpio helpers for handling modem signals (v2)
@ 2014-09-12 16:49 Janusz Uzycki
2014-09-12 17:05 ` Fabio Estevam
0 siblings, 1 reply; 3+ messages in thread
From: Janusz Uzycki @ 2014-09-12 16:49 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-serial, devicetree, Janusz Uzycki
Dedicated CTS and RTS pins are unusable together with a lot of other
peripherals because they share the same line. Pinctrl is limited.
Moreover, the USART controller doesn't handle DTR/DSR/DCD/RI signals,
so we have to control them via GPIO.
This patch permits to use GPIOs to control the CTS/RTS/DTR/DSR/DCD/RI
signals.
Signed-off-by: Janusz Uzycki <j.uzycki@elproma.com.pl>
---
.../devicetree/bindings/serial/fsl-mxs-auart.txt | 10 +++-
drivers/tty/serial/Kconfig | 1 +
drivers/tty/serial/mxs-auart.c | 66 +++++++++++++++++++++-
3 files changed, 73 insertions(+), 4 deletions(-)
diff --git a/Documentation/devicetree/bindings/serial/fsl-mxs-auart.txt b/Documentation/devicetree/bindings/serial/fsl-mxs-auart.txt
index 59a40f1..7c408c8 100644
--- a/Documentation/devicetree/bindings/serial/fsl-mxs-auart.txt
+++ b/Documentation/devicetree/bindings/serial/fsl-mxs-auart.txt
@@ -11,8 +11,13 @@ Required properties:
- dma-names: "rx" for RX channel, "tx" for TX channel.
Optional properties:
-- fsl,uart-has-rtscts : Indicate the UART has RTS and CTS lines,
+- fsl,uart-has-rtscts : Indicate the UART has RTS and CTS lines
+ for hardware flow control,
it also means you enable the DMA support for this UART.
+- {rts,cts,dtr,dsr,rng,dcd}-gpios: specify a GPIO for RTS/CTS/DTR/DSR/RI/DCD
+ line respectively. It will use specified PIO instead of the peripheral
+ function pin for the USART feature.
+ If unsure, don't specify this property.
Example:
auart0: serial@8006a000 {
@@ -21,6 +26,9 @@ auart0: serial@8006a000 {
interrupts = <112>;
dmas = <&dma_apbx 8>, <&dma_apbx 9>;
dma-names = "rx", "tx";
+ cts-gpios = <&gpio1 15 GPIO_ACTIVE_LOW>;
+ dsr-gpios = <&gpio1 16 GPIO_ACTIVE_LOW>;
+ dcd-gpios = <&gpio1 17 GPIO_ACTIVE_LOW>;
};
Note: Each auart port should have an alias correctly numbered in "aliases"
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 4fe8ca1..90e8516 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1357,6 +1357,7 @@ config SERIAL_MXS_AUART
depends on ARCH_MXS
tristate "MXS AUART support"
select SERIAL_CORE
+ select SERIAL_MCTRL_GPIO if GPIOLIB
help
This driver supports the MXS Application UART (AUART) port.
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index 024e54f..e32ffb5 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -38,6 +38,18 @@
#include <asm/cacheflush.h>
+/* based on clps711x.c from linux-next:
+ * serial: clps711x: Use mctrl_gpio helpers for handling modem signals
+ * serial: clps711x: Fix COMPILE_TEST build for target without GPIOLIB support
+ * based on Documentation/devicetree/bindings/serial/cirrus,clps711x-uart.txt from linux-next:
+ * serial: clps711x: Use mctrl_gpio helpers for handling modem signals
+ * based on atmel_serial.c from linux-next:
+ * tty/serial: at91: use mctrl_gpio helpers
+ * TODO: tty/serial: at91: add interrupts for modem control lines
+ * */
+#include <linux/err.h>
+#include "serial_mctrl_gpio.h"
+
#define MXS_AUART_MAJOR 242
#define MXS_AUART_PORTS 5
#define MXS_AUART_FIFO_SIZE 16
@@ -156,6 +168,8 @@ struct mxs_auart_port {
struct scatterlist rx_sgl;
struct dma_chan *rx_dma_chan;
void *rx_dma_buf;
+
+ struct mctrl_gpios *gpios;
};
static struct platform_device_id mxs_auart_devtype[] = {
@@ -417,6 +431,34 @@ static void mxs_auart_set_mctrl(struct uart_port *u, unsigned mctrl)
s->ctrl = mctrl;
writel(ctrl, u->membase + AUART_CTRL2);
+
+ mctrl_gpio_set(s->gpios, mctrl);
+}
+
+/* mxs_auart_modem_status() based on 8250.c,
+ * similar function should be in a serial's helper! */
+#define MCTRL_ANY_DELTA (TIOCM_RI | TIOCM_DSR | TIOCM_CD | TIOCM_CTS)
+static u32 mxs_auart_modem_status(struct mxs_auart_port *s, u32 mctrl)
+{
+ u32 mctrl_diff;
+
+ mctrl_diff = mctrl ^ s->ctrl;
+ s->ctrl = mctrl;
+ if (mctrl_diff & MCTRL_ANY_DELTA &&
+ /*interrupt_enabled &&*/
+ s->port.state != NULL) {
+ if (mctrl_diff & TIOCM_RI)
+ s->port.icount.rng++;
+ if (mctrl_diff & TIOCM_DSR)
+ s->port.icount.dsr++;
+ if (mctrl_diff & TIOCM_CD)
+ uart_handle_dcd_change(&s->port, mctrl & TIOCM_CD);
+ if (mctrl_diff & TIOCM_CTS)
+ uart_handle_cts_change(&s->port, mctrl & TIOCM_CTS);
+
+ wake_up_interruptible(&s->port.state->port.delta_msr_wait);
+ }
+ return mctrl;
}
static u32 mxs_auart_get_mctrl(struct uart_port *u)
@@ -433,7 +475,9 @@ static u32 mxs_auart_get_mctrl(struct uart_port *u)
if (ctrl2 & AUART_CTRL2_RTS)
mctrl |= TIOCM_RTS;
- return mctrl;
+ /* should mxs_auart_modem_status() be in interrupt only? */
+ return mxs_auart_modem_status(s,
+ mctrl_gpio_get(s->gpios, &mctrl));
}
static int mxs_auart_dma_prep_rx(struct mxs_auart_port *s);
@@ -637,7 +681,12 @@ static void mxs_auart_settermios(struct uart_port *u,
ctrl |= AUART_LINECTRL_STP2;
/* figure out the hardware flow control settings */
- if (cflag & CRTSCTS) {
+ /*FIXME: DMA for hardware flow control only? */
+ if (cflag & CRTSCTS &&
+ (IS_ERR_OR_NULL(mctrl_gpio_to_gpiod(s->gpios,
+ UART_GPIO_RTS)) ||
+ IS_ERR_OR_NULL(mctrl_gpio_to_gpiod(s->gpios,
+ UART_GPIO_CTS)))) {
/*
* The DMA has a bug(see errata:2836) in mx23.
* So we can not implement the DMA for auart in mx23,
@@ -696,8 +745,14 @@ static irqreturn_t mxs_auart_irq_handle(int irq, void *context)
| AUART_INTR_CTSMIS),
s->port.membase + AUART_INTR_CLR);
+ mxs_auart_modem_status(s,
+ mctrl_gpio_get(s->gpios, &s->ctrl));
+
if (istat & AUART_INTR_CTSMIS) {
- uart_handle_cts_change(&s->port, stat & AUART_STAT_CTS);
+ if (IS_ERR_OR_NULL(mctrl_gpio_to_gpiod(s->gpios,
+ UART_GPIO_CTS)))
+ uart_handle_cts_change(&s->port,
+ stat & AUART_STAT_CTS);
writel(AUART_INTR_CTSMIS,
s->port.membase + AUART_INTR_CLR);
istat &= ~AUART_INTR_CTSMIS;
@@ -1084,6 +1139,8 @@ static int mxs_auart_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, s);
+ s->gpios = mctrl_gpio_init(&pdev->dev, 0);
+
auart_port[s->port.line] = s;
mxs_auart_reset(&s->port);
@@ -1100,6 +1157,7 @@ static int mxs_auart_probe(struct platform_device *pdev)
return 0;
out_free_irq:
+ mctrl_gpio_free(&pdev->dev, s->gpios); /*useless?*/
auart_port[pdev->id] = NULL;
free_irq(s->irq, s);
out_free_clk:
@@ -1118,6 +1176,8 @@ static int mxs_auart_remove(struct platform_device *pdev)
auart_port[pdev->id] = NULL;
+ mctrl_gpio_free(&pdev->dev, s->gpios); /*useless?*/
+
clk_put(s->clk);
free_irq(s->irq, s);
kfree(s);
--
1.7.11.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] serial: mxs-auart: use mctrl_gpio helpers for handling modem signals (v2)
2014-09-12 16:49 [PATCH] serial: mxs-auart: use mctrl_gpio helpers for handling modem signals (v2) Janusz Uzycki
@ 2014-09-12 17:05 ` Fabio Estevam
2014-09-12 18:16 ` Janusz Użycki
0 siblings, 1 reply; 3+ messages in thread
From: Fabio Estevam @ 2014-09-12 17:05 UTC (permalink / raw)
To: Janusz Uzycki
Cc: Greg Kroah-Hartman, linux-serial@vger.kernel.org,
devicetree@vger.kernel.org
On Fri, Sep 12, 2014 at 1:49 PM, Janusz Uzycki <j.uzycki@elproma.com.pl> wrote:
> Dedicated CTS and RTS pins are unusable together with a lot of other
> peripherals because they share the same line. Pinctrl is limited.
>
> Moreover, the USART controller doesn't handle DTR/DSR/DCD/RI signals,
You meant "AUART controller"
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] serial: mxs-auart: use mctrl_gpio helpers for handling modem signals (v2)
2014-09-12 17:05 ` Fabio Estevam
@ 2014-09-12 18:16 ` Janusz Użycki
0 siblings, 0 replies; 3+ messages in thread
From: Janusz Użycki @ 2014-09-12 18:16 UTC (permalink / raw)
To: Fabio Estevam
Cc: Greg Kroah-Hartman, linux-serial@vger.kernel.org,
devicetree@vger.kernel.org
> On Fri, Sep 12, 2014 at 1:49 PM, Janusz Uzycki <j.uzycki@elproma.com.pl> wrote:
>> Dedicated CTS and RTS pins are unusable together with a lot of other
>> peripherals because they share the same line. Pinctrl is limited.
>>
>> Moreover, the USART controller doesn't handle DTR/DSR/DCD/RI signals,
> You meant "AUART controller"
Thanks Fabio. I wait for more comments, especially to comments-questions
in the code.
best regards
Janusz
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-09-12 18:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-12 16:49 [PATCH] serial: mxs-auart: use mctrl_gpio helpers for handling modem signals (v2) Janusz Uzycki
2014-09-12 17:05 ` Fabio Estevam
2014-09-12 18:16 ` Janusz Użycki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.