Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1267984 > unrolled thread
| Started by | "Matwey V. Kornilov" <matwey@sai.msu.ru> |
|---|---|
| First post | 2015-11-12 15:40 +0100 |
| Last post | 2015-11-12 15:40 +0100 |
| Articles | 6 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v3 0/5] tty: Introduce software RS485 direction control support "Matwey V. Kornilov" <matwey@sai.msu.ru> - 2015-11-12 15:40 +0100
[PATCH v3 4/5] tty: Move serial8250_stop_rx in front of serial8250_start_tx "Matwey V. Kornilov" <matwey@sai.msu.ru> - 2015-11-12 15:40 +0100
[PATCH v3 5/5] tty: Add software emulated RS485 support for 8250 "Matwey V. Kornilov" <matwey@sai.msu.ru> - 2015-11-12 15:40 +0100
Re: [PATCH v3 5/5] tty: Add software emulated RS485 support for 8250 Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-11-12 15:50 +0100
[PATCH v3 1/5] tty: Introduce UART_CAP_HW485 "Matwey V. Kornilov" <matwey@sai.msu.ru> - 2015-11-12 15:40 +0100
[PATCH v3 3/5] tty: Implement default fallback serial8250_rs485_config "Matwey V. Kornilov" <matwey@sai.msu.ru> - 2015-11-12 15:40 +0100
| From | "Matwey V. Kornilov" <matwey@sai.msu.ru> |
|---|---|
| Date | 2015-11-12 15:40 +0100 |
| Subject | [PATCH v3 0/5] tty: Introduce software RS485 direction control support |
| Message-ID | <qu1cC-1EX-7@gated-at.bofh.it> |
Changes from v2: - Introduced SER_RS485_SOFTWARE to show that software implementation is being used - serial8250_rs485_config is located as required - Timers are used to implement delay_before and delay_after timeouts -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | "Matwey V. Kornilov" <matwey@sai.msu.ru> |
|---|---|
| Date | 2015-11-12 15:40 +0100 |
| Subject | [PATCH v3 4/5] tty: Move serial8250_stop_rx in front of serial8250_start_tx |
| Message-ID | <qu1cC-1EX-21@gated-at.bofh.it> |
| In reply to | #1267984 |
Signed-off-by: Matwey V. Kornilov <matwey@sai.msu.ru>
---
drivers/tty/serial/8250/8250_port.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 067ef55..3f6d8a2 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -1286,6 +1286,19 @@ static void autoconfig_irq(struct uart_8250_port *up)
port->irq = (irq > 0) ? irq : 0;
}
+static void serial8250_stop_rx(struct uart_port *port)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+
+ serial8250_rpm_get(up);
+
+ up->ier &= ~(UART_IER_RLSI | UART_IER_RDI);
+ up->port.read_status_mask &= ~UART_LSR_DR;
+ serial_port_out(port, UART_IER, up->ier);
+
+ serial8250_rpm_put(up);
+}
+
static inline void __stop_tx(struct uart_8250_port *p)
{
if (p->ier & UART_IER_THRI) {
@@ -1353,19 +1366,6 @@ static void serial8250_unthrottle(struct uart_port *port)
port->unthrottle(port);
}
-static void serial8250_stop_rx(struct uart_port *port)
-{
- struct uart_8250_port *up = up_to_u8250p(port);
-
- serial8250_rpm_get(up);
-
- up->ier &= ~(UART_IER_RLSI | UART_IER_RDI);
- up->port.read_status_mask &= ~UART_LSR_DR;
- serial_port_out(port, UART_IER, up->ier);
-
- serial8250_rpm_put(up);
-}
-
static void serial8250_disable_ms(struct uart_port *port)
{
struct uart_8250_port *up =
--
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | "Matwey V. Kornilov" <matwey@sai.msu.ru> |
|---|---|
| Date | 2015-11-12 15:40 +0100 |
| Subject | [PATCH v3 5/5] tty: Add software emulated RS485 support for 8250 |
| Message-ID | <qu1cC-1EX-19@gated-at.bofh.it> |
| In reply to | #1267984 |
Implementation of software emulation of RS485 direction handling is based
on omap-serial driver.
Before and after transmission RTS is set to the appropriate value.
Signed-off-by: Matwey V. Kornilov <matwey@sai.msu.ru>
---
drivers/tty/serial/8250/8250_port.c | 152 ++++++++++++++++++++++++++++++++++--
include/linux/serial_8250.h | 2 +
2 files changed, 148 insertions(+), 6 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 3f6d8a2..b863a12 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -37,6 +37,7 @@
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/pm_runtime.h>
+#include <linux/timer.h>
#include <asm/io.h>
#include <asm/irq.h>
@@ -1299,7 +1300,75 @@ static void serial8250_stop_rx(struct uart_port *port)
serial8250_rpm_put(up);
}
-static inline void __stop_tx(struct uart_8250_port *p)
+static inline void serial8250_rs485_set_rts_on_send(struct uart_8250_port *p)
+{
+ if (p->port.rs485.flags & SER_RS485_RTS_ON_SEND)
+ p->mcr |= UART_MCR_RTS;
+ else
+ p->mcr &= ~UART_MCR_RTS;
+ serial_out(p, UART_MCR, p->mcr);
+}
+
+static inline void serial8250_rs485_set_rts_after_send(struct uart_8250_port *p)
+{
+ if (p->port.rs485.flags & SER_RS485_RTS_AFTER_SEND)
+ p->mcr |= UART_MCR_RTS;
+ else
+ p->mcr &= ~UART_MCR_RTS;
+ serial_out(p, UART_MCR, p->mcr);
+}
+
+static __u32 serial8250_rs485_start_tx(struct uart_8250_port *p)
+{
+ if (p->capabilities & UART_CAP_HW485 || !(p->port.rs485.flags & SER_RS485_ENABLED))
+ return 0;
+
+ if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX))
+ serial8250_stop_rx(&p->port);
+
+ del_timer_sync(&p->rs485_stop_tx_timer);
+
+ if (!!(p->port.rs485.flags & SER_RS485_RTS_ON_SEND) != !!(p->mcr & UART_MCR_RTS)) {
+ serial8250_rs485_set_rts_on_send(p);
+ return p->port.rs485.delay_rts_before_send;
+ }
+
+ return 0;
+}
+
+static inline void __do_stop_tx_rs485(struct uart_8250_port *p)
+{
+ serial8250_rs485_set_rts_after_send(p);
+ /*
+ * Empty the RX FIFO, we are not interested in anything
+ * received during the half-duplex transmission.
+ */
+ if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX))
+ serial8250_clear_fifos(p);
+}
+
+static void serial8250_handle_rs485_stop_tx_timer(unsigned long arg)
+{
+ struct uart_8250_port *p = (struct uart_8250_port*)arg;
+ __do_stop_tx_rs485(p);
+}
+
+static inline void __stop_tx_rs485(struct uart_8250_port *p)
+{
+ if (p->capabilities & UART_CAP_HW485 || !(p->port.rs485.flags & SER_RS485_ENABLED))
+ return;
+
+ del_timer_sync(&p->rs485_start_tx_timer);
+
+ /* __do_stop_tx_rs485 is going to set RTS according to config AND flush RX FIFO if required */
+ if (p->port.rs485.delay_rts_after_send > 0) {
+ mod_timer(&p->rs485_stop_tx_timer, jiffies + p->port.rs485.delay_rts_after_send * HZ / 1000);
+ } else {
+ __do_stop_tx_rs485(p);
+ }
+}
+
+static inline void __do_stop_tx(struct uart_8250_port *p)
{
if (p->ier & UART_IER_THRI) {
p->ier &= ~UART_IER_THRI;
@@ -1308,6 +1377,12 @@ static inline void __stop_tx(struct uart_8250_port *p)
}
}
+static inline void __stop_tx(struct uart_8250_port *p)
+{
+ __do_stop_tx(p);
+ __stop_tx_rs485(p);
+}
+
static void serial8250_stop_tx(struct uart_port *port)
{
struct uart_8250_port *up = up_to_u8250p(port);
@@ -1325,12 +1400,10 @@ static void serial8250_stop_tx(struct uart_port *port)
serial8250_rpm_put(up);
}
-static void serial8250_start_tx(struct uart_port *port)
+static inline void __start_tx(struct uart_port* port)
{
struct uart_8250_port *up = up_to_u8250p(port);
- serial8250_rpm_get_tx(up);
-
if (up->dma && !up->dma->tx_dma(up))
return;
@@ -1356,6 +1429,29 @@ static void serial8250_start_tx(struct uart_port *port)
}
}
+static void serial8250_handle_rs485_start_tx_timer(unsigned long arg)
+{
+ struct uart_port* port = (struct uart_port*)arg;
+ __start_tx(port);
+}
+
+static void serial8250_start_tx(struct uart_port *port)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+ __u32 delay;
+
+ serial8250_rpm_get_tx(up);
+
+ if (timer_pending(&up->rs485_start_tx_timer))
+ return;
+
+ if ((delay = serial8250_rs485_start_tx(up))) {
+ mod_timer(&up->rs485_start_tx_timer, jiffies + delay * HZ / 1000);
+ } else {
+ __start_tx(port);
+ }
+}
+
static void serial8250_throttle(struct uart_port *port)
{
port->throttle(port);
@@ -1806,6 +1902,16 @@ static void serial8250_put_poll_char(struct uart_port *port,
#endif /* CONFIG_CONSOLE_POLL */
+static inline void serial8250_startup_rs485(struct uart_port *port)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+
+ if (up->capabilities & UART_CAP_HW485 || !(up->port.rs485.flags & SER_RS485_ENABLED))
+ return;
+
+ serial8250_rs485_set_rts_after_send(up);
+}
+
int serial8250_do_startup(struct uart_port *port)
{
struct uart_8250_port *up = up_to_u8250p(port);
@@ -2044,6 +2150,8 @@ dont_test_tx_en:
inb_p(icp);
}
retval = 0;
+
+ serial8250_startup_rs485(port);
out:
serial8250_rpm_put(up);
return retval;
@@ -2057,12 +2165,24 @@ static int serial8250_startup(struct uart_port *port)
return serial8250_do_startup(port);
}
+static inline void serial8250_shutdown_rs485(struct uart_port *port)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+
+ if (up->capabilities & UART_CAP_HW485 || !(up->port.rs485.flags & SER_RS485_ENABLED))
+ return;
+
+ del_timer_sync(&up->rs485_start_tx_timer);
+ del_timer_sync(&up->rs485_stop_tx_timer);
+}
+
void serial8250_do_shutdown(struct uart_port *port)
{
struct uart_8250_port *up = up_to_u8250p(port);
unsigned long flags;
serial8250_rpm_get(up);
+ serial8250_shutdown_rs485(port);
/*
* Disable interrupts from this port
*/
@@ -2735,11 +2855,23 @@ serial8250_type(struct uart_port *port)
return uart_config[type].name;
}
-static int serial8250_rs485_config(struct uart_port *port,
- struct serial_rs485 *rs485)
+static int serial8250_rs485_config(struct uart_port *port, struct serial_rs485 *rs485)
{
+ bool need_startup = false;
+
+ if (!(port->rs485.flags & SER_RS485_ENABLED) && (rs485->flags & SER_RS485_ENABLED)) {
+ need_startup = true;
+ }
+ if ((port->rs485.flags & SER_RS485_ENABLED) && !(rs485->flags & SER_RS485_ENABLED)) {
+ serial8250_shutdown_rs485(port);
+ }
+
port->rs485 = *rs485;
port->rs485.flags |= SER_RS485_SOFTWARE;
+
+ if (need_startup)
+ serial8250_startup_rs485(port);
+
return 0;
}
@@ -2807,6 +2939,14 @@ void serial8250_set_defaults(struct uart_8250_port *up)
}
up->port.rs485_config = serial8250_rs485_config;
+ init_timer(&up->rs485_stop_tx_timer);
+ up->rs485_stop_tx_timer.function = serial8250_handle_rs485_stop_tx_timer;
+ up->rs485_stop_tx_timer.data = (unsigned long)up;
+ up->rs485_stop_tx_timer.flags |= TIMER_IRQSAFE;
+ init_timer(&up->rs485_start_tx_timer);
+ up->rs485_start_tx_timer.function = serial8250_handle_rs485_start_tx_timer;
+ up->rs485_start_tx_timer.data = (unsigned long)up;
+ up->rs485_start_tx_timer.flags |= TIMER_IRQSAFE;
}
EXPORT_SYMBOL_GPL(serial8250_set_defaults);
diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h
index faa0e03..c4905e7 100644
--- a/include/linux/serial_8250.h
+++ b/include/linux/serial_8250.h
@@ -86,6 +86,8 @@ struct uart_8250_ops {
struct uart_8250_port {
struct uart_port port;
struct timer_list timer; /* "no irq" timer */
+ struct timer_list rs485_start_tx_timer; /* "rs485 start tx" timer */
+ struct timer_list rs485_stop_tx_timer; /* "rs485 stop tx" timer */
struct list_head list; /* ports on this IRQ */
unsigned short capabilities; /* port capabilities */
unsigned short bugs; /* port bugs */
--
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Andy Shevchenko <andy.shevchenko@gmail.com> |
|---|---|
| Date | 2015-11-12 15:50 +0100 |
| Subject | Re: [PATCH v3 5/5] tty: Add software emulated RS485 support for 8250 |
| Message-ID | <qu1mi-1Ij-23@gated-at.bofh.it> |
| In reply to | #1267987 |
On Thu, Nov 12, 2015 at 4:33 PM, Matwey V. Kornilov <matwey@sai.msu.ru> wrote:
> Implementation of software emulation of RS485 direction handling is based
> on omap-serial driver.
> Before and after transmission RTS is set to the appropriate value.
>
One comment below.
> Signed-off-by: Matwey V. Kornilov <matwey@sai.msu.ru>
> ---
> drivers/tty/serial/8250/8250_port.c | 152 ++++++++++++++++++++++++++++++++++--
> include/linux/serial_8250.h | 2 +
> 2 files changed, 148 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 3f6d8a2..b863a12 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -37,6 +37,7 @@
> #include <linux/slab.h>
> #include <linux/uaccess.h>
> #include <linux/pm_runtime.h>
> +#include <linux/timer.h>
>
> #include <asm/io.h>
> #include <asm/irq.h>
> @@ -1299,7 +1300,75 @@ static void serial8250_stop_rx(struct uart_port *port)
> serial8250_rpm_put(up);
> }
>
> -static inline void __stop_tx(struct uart_8250_port *p)
> +static inline void serial8250_rs485_set_rts_on_send(struct uart_8250_port *p)
> +{
> + if (p->port.rs485.flags & SER_RS485_RTS_ON_SEND)
> + p->mcr |= UART_MCR_RTS;
> + else
> + p->mcr &= ~UART_MCR_RTS;
> + serial_out(p, UART_MCR, p->mcr);
> +}
> +
> +static inline void serial8250_rs485_set_rts_after_send(struct uart_8250_port *p)
> +{
> + if (p->port.rs485.flags & SER_RS485_RTS_AFTER_SEND)
> + p->mcr |= UART_MCR_RTS;
> + else
> + p->mcr &= ~UART_MCR_RTS;
> + serial_out(p, UART_MCR, p->mcr);
> +}
> +
> +static __u32 serial8250_rs485_start_tx(struct uart_8250_port *p)
> +{
> + if (p->capabilities & UART_CAP_HW485 || !(p->port.rs485.flags & SER_RS485_ENABLED))
> + return 0;
> +
> + if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX))
> + serial8250_stop_rx(&p->port);
> +
> + del_timer_sync(&p->rs485_stop_tx_timer);
> +
> + if (!!(p->port.rs485.flags & SER_RS485_RTS_ON_SEND) != !!(p->mcr & UART_MCR_RTS)) {
> + serial8250_rs485_set_rts_on_send(p);
> + return p->port.rs485.delay_rts_before_send;
> + }
> +
> + return 0;
> +}
> +
> +static inline void __do_stop_tx_rs485(struct uart_8250_port *p)
> +{
> + serial8250_rs485_set_rts_after_send(p);
> + /*
> + * Empty the RX FIFO, we are not interested in anything
> + * received during the half-duplex transmission.
> + */
> + if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX))
> + serial8250_clear_fifos(p);
> +}
> +
> +static void serial8250_handle_rs485_stop_tx_timer(unsigned long arg)
> +{
> + struct uart_8250_port *p = (struct uart_8250_port*)arg;
> + __do_stop_tx_rs485(p);
> +}
> +
> +static inline void __stop_tx_rs485(struct uart_8250_port *p)
> +{
> + if (p->capabilities & UART_CAP_HW485 || !(p->port.rs485.flags & SER_RS485_ENABLED))
> + return;
It seems you are using this pattern three times. What about
static inline bool is_rs485_sw_enabled(struct uart_8250_port *p)
{
return !(p->capabilities & UART_CAP_HW485) &&
(p->port.rs485.flags & SER_RS485_ENABLED);
}
> +
> + del_timer_sync(&p->rs485_start_tx_timer);
> +
> + /* __do_stop_tx_rs485 is going to set RTS according to config AND flush RX FIFO if required */
> + if (p->port.rs485.delay_rts_after_send > 0) {
> + mod_timer(&p->rs485_stop_tx_timer, jiffies + p->port.rs485.delay_rts_after_send * HZ / 1000);
> + } else {
> + __do_stop_tx_rs485(p);
> + }
> +}
> +
> +static inline void __do_stop_tx(struct uart_8250_port *p)
> {
> if (p->ier & UART_IER_THRI) {
> p->ier &= ~UART_IER_THRI;
> @@ -1308,6 +1377,12 @@ static inline void __stop_tx(struct uart_8250_port *p)
> }
> }
>
> +static inline void __stop_tx(struct uart_8250_port *p)
> +{
> + __do_stop_tx(p);
> + __stop_tx_rs485(p);
> +}
> +
> static void serial8250_stop_tx(struct uart_port *port)
> {
> struct uart_8250_port *up = up_to_u8250p(port);
> @@ -1325,12 +1400,10 @@ static void serial8250_stop_tx(struct uart_port *port)
> serial8250_rpm_put(up);
> }
>
> -static void serial8250_start_tx(struct uart_port *port)
> +static inline void __start_tx(struct uart_port* port)
> {
> struct uart_8250_port *up = up_to_u8250p(port);
>
> - serial8250_rpm_get_tx(up);
> -
> if (up->dma && !up->dma->tx_dma(up))
> return;
>
> @@ -1356,6 +1429,29 @@ static void serial8250_start_tx(struct uart_port *port)
> }
> }
>
> +static void serial8250_handle_rs485_start_tx_timer(unsigned long arg)
> +{
> + struct uart_port* port = (struct uart_port*)arg;
> + __start_tx(port);
> +}
> +
> +static void serial8250_start_tx(struct uart_port *port)
> +{
> + struct uart_8250_port *up = up_to_u8250p(port);
> + __u32 delay;
> +
> + serial8250_rpm_get_tx(up);
> +
> + if (timer_pending(&up->rs485_start_tx_timer))
> + return;
> +
> + if ((delay = serial8250_rs485_start_tx(up))) {
> + mod_timer(&up->rs485_start_tx_timer, jiffies + delay * HZ / 1000);
> + } else {
> + __start_tx(port);
> + }
> +}
> +
> static void serial8250_throttle(struct uart_port *port)
> {
> port->throttle(port);
> @@ -1806,6 +1902,16 @@ static void serial8250_put_poll_char(struct uart_port *port,
>
> #endif /* CONFIG_CONSOLE_POLL */
>
> +static inline void serial8250_startup_rs485(struct uart_port *port)
> +{
> + struct uart_8250_port *up = up_to_u8250p(port);
> +
> + if (up->capabilities & UART_CAP_HW485 || !(up->port.rs485.flags & SER_RS485_ENABLED))
> + return;
> +
> + serial8250_rs485_set_rts_after_send(up);
> +}
> +
> int serial8250_do_startup(struct uart_port *port)
> {
> struct uart_8250_port *up = up_to_u8250p(port);
> @@ -2044,6 +2150,8 @@ dont_test_tx_en:
> inb_p(icp);
> }
> retval = 0;
> +
> + serial8250_startup_rs485(port);
> out:
> serial8250_rpm_put(up);
> return retval;
> @@ -2057,12 +2165,24 @@ static int serial8250_startup(struct uart_port *port)
> return serial8250_do_startup(port);
> }
>
> +static inline void serial8250_shutdown_rs485(struct uart_port *port)
> +{
> + struct uart_8250_port *up = up_to_u8250p(port);
> +
> + if (up->capabilities & UART_CAP_HW485 || !(up->port.rs485.flags & SER_RS485_ENABLED))
> + return;
> +
> + del_timer_sync(&up->rs485_start_tx_timer);
> + del_timer_sync(&up->rs485_stop_tx_timer);
> +}
> +
> void serial8250_do_shutdown(struct uart_port *port)
> {
> struct uart_8250_port *up = up_to_u8250p(port);
> unsigned long flags;
>
> serial8250_rpm_get(up);
> + serial8250_shutdown_rs485(port);
> /*
> * Disable interrupts from this port
> */
> @@ -2735,11 +2855,23 @@ serial8250_type(struct uart_port *port)
> return uart_config[type].name;
> }
>
> -static int serial8250_rs485_config(struct uart_port *port,
> - struct serial_rs485 *rs485)
> +static int serial8250_rs485_config(struct uart_port *port, struct serial_rs485 *rs485)
> {
> + bool need_startup = false;
> +
> + if (!(port->rs485.flags & SER_RS485_ENABLED) && (rs485->flags & SER_RS485_ENABLED)) {
> + need_startup = true;
> + }
> + if ((port->rs485.flags & SER_RS485_ENABLED) && !(rs485->flags & SER_RS485_ENABLED)) {
> + serial8250_shutdown_rs485(port);
> + }
> +
> port->rs485 = *rs485;
> port->rs485.flags |= SER_RS485_SOFTWARE;
> +
> + if (need_startup)
> + serial8250_startup_rs485(port);
> +
> return 0;
> }
>
> @@ -2807,6 +2939,14 @@ void serial8250_set_defaults(struct uart_8250_port *up)
> }
>
> up->port.rs485_config = serial8250_rs485_config;
> + init_timer(&up->rs485_stop_tx_timer);
> + up->rs485_stop_tx_timer.function = serial8250_handle_rs485_stop_tx_timer;
> + up->rs485_stop_tx_timer.data = (unsigned long)up;
> + up->rs485_stop_tx_timer.flags |= TIMER_IRQSAFE;
> + init_timer(&up->rs485_start_tx_timer);
> + up->rs485_start_tx_timer.function = serial8250_handle_rs485_start_tx_timer;
> + up->rs485_start_tx_timer.data = (unsigned long)up;
> + up->rs485_start_tx_timer.flags |= TIMER_IRQSAFE;
> }
> EXPORT_SYMBOL_GPL(serial8250_set_defaults);
>
> diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h
> index faa0e03..c4905e7 100644
> --- a/include/linux/serial_8250.h
> +++ b/include/linux/serial_8250.h
> @@ -86,6 +86,8 @@ struct uart_8250_ops {
> struct uart_8250_port {
> struct uart_port port;
> struct timer_list timer; /* "no irq" timer */
> + struct timer_list rs485_start_tx_timer; /* "rs485 start tx" timer */
> + struct timer_list rs485_stop_tx_timer; /* "rs485 stop tx" timer */
> struct list_head list; /* ports on this IRQ */
> unsigned short capabilities; /* port capabilities */
> unsigned short bugs; /* port bugs */
> --
> 2.6.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | "Matwey V. Kornilov" <matwey@sai.msu.ru> |
|---|---|
| Date | 2015-11-12 15:40 +0100 |
| Subject | [PATCH v3 1/5] tty: Introduce UART_CAP_HW485 |
| Message-ID | <qu1cD-1EX-27@gated-at.bofh.it> |
| In reply to | #1267984 |
Introduce new capability UART_CAP_HW485 to mark 8250 UARTs which have
hardware support of line direction control.
Signed-off-by: Matwey V. Kornilov <matwey@sai.msu.ru>
---
drivers/tty/serial/8250/8250.h | 1 +
drivers/tty/serial/8250/8250_fintek.c | 1 +
drivers/tty/serial/8250/8250_lpc18xx.c | 1 +
drivers/tty/serial/8250/8250_pci.c | 1 +
4 files changed, 4 insertions(+)
diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
index d54dcd8..92a4f47 100644
--- a/drivers/tty/serial/8250/8250.h
+++ b/drivers/tty/serial/8250/8250.h
@@ -69,6 +69,7 @@ struct serial8250_config {
unsigned int flags;
};
+#define UART_CAP_HW485 (1 << 7) /* UART has hardware direction control for RS485 */
#define UART_CAP_FIFO (1 << 8) /* UART has FIFO */
#define UART_CAP_EFR (1 << 9) /* UART has EFR */
#define UART_CAP_SLEEP (1 << 10) /* UART has IER sleep */
diff --git a/drivers/tty/serial/8250/8250_fintek.c b/drivers/tty/serial/8250/8250_fintek.c
index 8947439..f2831a8 100644
--- a/drivers/tty/serial/8250/8250_fintek.c
+++ b/drivers/tty/serial/8250/8250_fintek.c
@@ -208,6 +208,7 @@ fintek_8250_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
uart.port.iobase = pnp_port_start(dev, 0);
uart.port.iotype = UPIO_PORT;
uart.port.rs485_config = fintek_8250_rs485_config;
+ uart.capabilities = UART_CAP_HW485;
uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE)
diff --git a/drivers/tty/serial/8250/8250_lpc18xx.c b/drivers/tty/serial/8250/8250_lpc18xx.c
index 99cd478..9d30276 100644
--- a/drivers/tty/serial/8250/8250_lpc18xx.c
+++ b/drivers/tty/serial/8250/8250_lpc18xx.c
@@ -175,6 +175,7 @@ static int lpc18xx_serial_probe(struct platform_device *pdev)
uart.port.private_data = data;
uart.port.rs485_config = lpc18xx_rs485_config;
uart.port.serial_out = lpc18xx_uart_serial_out;
+ uart.capabilities = UART_CAP_HW485;
uart.dma = &data->dma;
uart.dma->rxconf.src_maxburst = 1;
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 4097f3f..c7c0ae9 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1599,6 +1599,7 @@ static int pci_fintek_setup(struct serial_private *priv,
port->port.iotype = UPIO_PORT;
port->port.iobase = iobase;
port->port.rs485_config = pci_fintek_rs485_config;
+ port->capabilities = UART_CAP_HW485;
data = devm_kzalloc(&pdev->dev, sizeof(u8), GFP_KERNEL);
if (!data)
--
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | "Matwey V. Kornilov" <matwey@sai.msu.ru> |
|---|---|
| Date | 2015-11-12 15:40 +0100 |
| Subject | [PATCH v3 3/5] tty: Implement default fallback serial8250_rs485_config |
| Message-ID | <qu1cD-1EX-31@gated-at.bofh.it> |
| In reply to | #1267984 |
When 8250 driver doesn't have its own hardware RS485 support and doesn't
want to override rs485_config callback, then default
serial8250_rs485_config is used. It just stores supplied by user-space
config and sets SER_RS485_SOFTWARE
Signed-off-by: Matwey V. Kornilov <matwey@sai.msu.ru>
---
drivers/tty/serial/8250/8250_core.c | 3 ++-
drivers/tty/serial/8250/8250_port.c | 10 ++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 3912646..71fabb0 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -986,7 +986,6 @@ int serial8250_register_8250_port(struct uart_8250_port *up)
uart->capabilities = up->capabilities;
uart->port.throttle = up->port.throttle;
uart->port.unthrottle = up->port.unthrottle;
- uart->port.rs485_config = up->port.rs485_config;
uart->port.rs485 = up->port.rs485;
uart->dma = up->dma;
@@ -1025,6 +1024,8 @@ int serial8250_register_8250_port(struct uart_8250_port *up)
uart->port.pm = up->port.pm;
if (up->port.handle_break)
uart->port.handle_break = up->port.handle_break;
+ if (up->port.rs485_config)
+ uart->port.rs485_config = up->port.rs485_config;
if (up->dl_read)
uart->dl_read = up->dl_read;
if (up->dl_write)
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 52d82d2..067ef55 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2735,6 +2735,14 @@ serial8250_type(struct uart_port *port)
return uart_config[type].name;
}
+static int serial8250_rs485_config(struct uart_port *port,
+ struct serial_rs485 *rs485)
+{
+ port->rs485 = *rs485;
+ port->rs485.flags |= SER_RS485_SOFTWARE;
+ return 0;
+}
+
static const struct uart_ops serial8250_pops = {
.tx_empty = serial8250_tx_empty,
.set_mctrl = serial8250_set_mctrl,
@@ -2797,6 +2805,8 @@ void serial8250_set_defaults(struct uart_8250_port *up)
if (!up->dma->rx_dma)
up->dma->rx_dma = serial8250_rx_dma;
}
+
+ up->port.rs485_config = serial8250_rs485_config;
}
EXPORT_SYMBOL_GPL(serial8250_set_defaults);
--
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web