Skip to content

Commit e676253

Browse files
ribaldagregkh
authored andcommitted
serial/8250: Add support for RS485 IOCTLs
This patch allow the users of the 8250 infrastructure to define a handler for RS485 configration. If no handler is defined the 8250 driver will work as usual. Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> Acked-by: Alan Cox <alan@linux.intel.com> -- v2:Change suggested by Alan "One Thousand Gnomes": - Move rs485 structure further down on the uart_8250_port structure drivers/tty/serial/8250/8250_core.c | 39 +++++++++++++++++++++++++++++++++++++ include/linux/serial_8250.h | 3 +++ 2 files changed, 42 insertions(+) Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 27d5775 commit e676253

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎drivers/tty/serial/8250/8250_core.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,6 +2843,42 @@ serial8250_verify_port(struct uart_port *port, struct serial_struct *ser)
28432843
return 0;
28442844
}
28452845

2846+
static int serial8250_ioctl(struct uart_port *port, unsigned int cmd,
2847+
unsigned long arg)
2848+
{
2849+
struct uart_8250_port *up =
2850+
container_of(port, struct uart_8250_port, port);
2851+
int ret;
2852+
struct serial_rs485 rs485_config;
2853+
2854+
if (!up->rs485_config)
2855+
return -ENOIOCTLCMD;
2856+
2857+
switch (cmd) {
2858+
case TIOCSRS485:
2859+
if (copy_from_user(&rs485_config, (void __user *)arg,
2860+
sizeof(rs485_config)))
2861+
return -EFAULT;
2862+
2863+
ret = up->rs485_config(up, &rs485_config);
2864+
if (ret)
2865+
return ret;
2866+
2867+
memcpy(&up->rs485, &rs485_config, sizeof(rs485_config));
2868+
2869+
return 0;
2870+
case TIOCGRS485:
2871+
if (copy_to_user((void __user *)arg, &up->rs485,
2872+
sizeof(up->rs485)))
2873+
return -EFAULT;
2874+
return 0;
2875+
default:
2876+
break;
2877+
}
2878+
2879+
return -ENOIOCTLCMD;
2880+
}
2881+
28462882
static const char *
28472883
serial8250_type(struct uart_port *port)
28482884
{
@@ -2872,6 +2908,7 @@ static struct uart_ops serial8250_pops = {
28722908
.request_port = serial8250_request_port,
28732909
.config_port = serial8250_config_port,
28742910
.verify_port = serial8250_verify_port,
2911+
.ioctl = serial8250_ioctl,
28752912
#ifdef CONFIG_CONSOLE_POLL
28762913
.poll_get_char = serial8250_get_poll_char,
28772914
.poll_put_char = serial8250_put_poll_char,
@@ -3388,6 +3425,8 @@ int serial8250_register_8250_port(struct uart_8250_port *up)
33883425
uart->port.fifosize = up->port.fifosize;
33893426
uart->tx_loadsz = up->tx_loadsz;
33903427
uart->capabilities = up->capabilities;
3428+
uart->rs485_config = up->rs485_config;
3429+
uart->rs485 = up->rs485;
33913430

33923431
/* Take tx_loadsz from fifosize if it wasn't set separately */
33933432
if (uart->port.fifosize && !uart->tx_loadsz)

‎include/linux/serial_8250.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,13 @@ struct uart_8250_port {
9696
unsigned char msr_saved_flags;
9797

9898
struct uart_8250_dma *dma;
99+
struct serial_rs485 rs485;
99100

100101
/* 8250 specific callbacks */
101102
int (*dl_read)(struct uart_8250_port *);
102103
void (*dl_write)(struct uart_8250_port *, int);
104+
int (*rs485_config)(struct uart_8250_port *,
105+
struct serial_rs485 *rs485);
103106
};
104107

105108
static inline struct uart_8250_port *up_to_u8250p(struct uart_port *up)

0 commit comments

Comments
 (0)