Commit 13bd3e6f authored by Ricardo Ribalda Delgado's avatar Ricardo Ribalda Delgado Committed by Greg Kroah-Hartman

serial/atmel: Use the rs485 functions on serial_core

In order to unify all the rs485 ioctl handling.
Use the implementation of TIOC[GS]RS485 ioctl handling on serial_core.
Reviewed-by: default avatarAlan Cox <alan@linux.intel.com>
Cc: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: default avatarRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Acked-by: default avatarNicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2fc0184d
...@@ -167,7 +167,6 @@ struct atmel_uart_port { ...@@ -167,7 +167,6 @@ struct atmel_uart_port {
struct circ_buf rx_ring; struct circ_buf rx_ring;
struct serial_rs485 rs485; /* rs485 settings */
struct mctrl_gpios *gpios; struct mctrl_gpios *gpios;
int gpio_irq[UART_GPIO_MAX]; int gpio_irq[UART_GPIO_MAX];
unsigned int tx_done_mask; unsigned int tx_done_mask;
...@@ -290,7 +289,8 @@ static unsigned int atmel_get_lines_status(struct uart_port *port) ...@@ -290,7 +289,8 @@ static unsigned int atmel_get_lines_status(struct uart_port *port)
} }
/* Enable or disable the rs485 support */ /* Enable or disable the rs485 support */
void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) static int atmel_config_rs485(struct uart_port *port,
struct serial_rs485 *rs485conf)
{ {
struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
unsigned int mode; unsigned int mode;
...@@ -306,7 +306,7 @@ void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) ...@@ -306,7 +306,7 @@ void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
/* Resetting serial mode to RS232 (0x0) */ /* Resetting serial mode to RS232 (0x0) */
mode &= ~ATMEL_US_USMODE; mode &= ~ATMEL_US_USMODE;
atmel_port->rs485 = *rs485conf; port->rs485 = *rs485conf;
if (rs485conf->flags & SER_RS485_ENABLED) { if (rs485conf->flags & SER_RS485_ENABLED) {
dev_dbg(port->dev, "Setting UART to RS485\n"); dev_dbg(port->dev, "Setting UART to RS485\n");
...@@ -329,6 +329,7 @@ void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) ...@@ -329,6 +329,7 @@ void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);
return 0;
} }
/* /*
...@@ -372,11 +373,10 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl) ...@@ -372,11 +373,10 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl)
/* Resetting serial mode to RS232 (0x0) */ /* Resetting serial mode to RS232 (0x0) */
mode &= ~ATMEL_US_USMODE; mode &= ~ATMEL_US_USMODE;
if (atmel_port->rs485.flags & SER_RS485_ENABLED) { if (port->rs485.flags & SER_RS485_ENABLED) {
dev_dbg(port->dev, "Setting UART to RS485\n"); dev_dbg(port->dev, "Setting UART to RS485\n");
if ((atmel_port->rs485.delay_rts_after_send) > 0) if ((port->rs485.delay_rts_after_send) > 0)
UART_PUT_TTGR(port, UART_PUT_TTGR(port, port->rs485.delay_rts_after_send);
atmel_port->rs485.delay_rts_after_send);
mode |= ATMEL_US_USMODE_RS485; mode |= ATMEL_US_USMODE_RS485;
} else { } else {
dev_dbg(port->dev, "Setting UART to RS232\n"); dev_dbg(port->dev, "Setting UART to RS232\n");
...@@ -423,8 +423,8 @@ static void atmel_stop_tx(struct uart_port *port) ...@@ -423,8 +423,8 @@ static void atmel_stop_tx(struct uart_port *port)
/* Disable interrupts */ /* Disable interrupts */
UART_PUT_IDR(port, atmel_port->tx_done_mask); UART_PUT_IDR(port, atmel_port->tx_done_mask);
if ((atmel_port->rs485.flags & SER_RS485_ENABLED) && if ((port->rs485.flags & SER_RS485_ENABLED) &&
!(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX)) !(port->rs485.flags & SER_RS485_RX_DURING_TX))
atmel_start_rx(port); atmel_start_rx(port);
} }
...@@ -441,8 +441,8 @@ static void atmel_start_tx(struct uart_port *port) ...@@ -441,8 +441,8 @@ static void atmel_start_tx(struct uart_port *port)
really need this.*/ really need this.*/
return; return;
if ((atmel_port->rs485.flags & SER_RS485_ENABLED) && if ((port->rs485.flags & SER_RS485_ENABLED) &&
!(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX)) !(port->rs485.flags & SER_RS485_RX_DURING_TX))
atmel_stop_rx(port); atmel_stop_rx(port);
/* re-enable PDC transmit */ /* re-enable PDC transmit */
...@@ -807,7 +807,7 @@ static void atmel_tx_dma(struct uart_port *port) ...@@ -807,7 +807,7 @@ static void atmel_tx_dma(struct uart_port *port)
atmel_port->cookie_tx = dmaengine_submit(desc); atmel_port->cookie_tx = dmaengine_submit(desc);
} else { } else {
if (atmel_port->rs485.flags & SER_RS485_ENABLED) { if (port->rs485.flags & SER_RS485_ENABLED) {
/* DMA done, stop TX, start RX for RS485 */ /* DMA done, stop TX, start RX for RS485 */
atmel_start_rx(port); atmel_start_rx(port);
} }
...@@ -1254,8 +1254,8 @@ static void atmel_tx_pdc(struct uart_port *port) ...@@ -1254,8 +1254,8 @@ static void atmel_tx_pdc(struct uart_port *port)
/* Enable interrupts */ /* Enable interrupts */
UART_PUT_IER(port, atmel_port->tx_done_mask); UART_PUT_IER(port, atmel_port->tx_done_mask);
} else { } else {
if ((atmel_port->rs485.flags & SER_RS485_ENABLED) && if ((port->rs485.flags & SER_RS485_ENABLED) &&
!(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX)) { !(port->rs485.flags & SER_RS485_RX_DURING_TX)) {
/* DMA done, stop TX, start RX for RS485 */ /* DMA done, stop TX, start RX for RS485 */
atmel_start_rx(port); atmel_start_rx(port);
} }
...@@ -1566,7 +1566,7 @@ static int atmel_init_property(struct atmel_uart_port *atmel_port, ...@@ -1566,7 +1566,7 @@ static int atmel_init_property(struct atmel_uart_port *atmel_port,
return 0; return 0;
} }
static void atmel_init_rs485(struct atmel_uart_port *atmel_port, static void atmel_init_rs485(struct uart_port *port,
struct platform_device *pdev) struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
...@@ -1577,7 +1577,7 @@ static void atmel_init_rs485(struct atmel_uart_port *atmel_port, ...@@ -1577,7 +1577,7 @@ static void atmel_init_rs485(struct atmel_uart_port *atmel_port,
/* rs485 properties */ /* rs485 properties */
if (of_property_read_u32_array(np, "rs485-rts-delay", if (of_property_read_u32_array(np, "rs485-rts-delay",
rs485_delay, 2) == 0) { rs485_delay, 2) == 0) {
struct serial_rs485 *rs485conf = &atmel_port->rs485; struct serial_rs485 *rs485conf = &port->rs485;
rs485conf->delay_rts_before_send = rs485_delay[0]; rs485conf->delay_rts_before_send = rs485_delay[0];
rs485conf->delay_rts_after_send = rs485_delay[1]; rs485conf->delay_rts_after_send = rs485_delay[1];
...@@ -1591,7 +1591,7 @@ static void atmel_init_rs485(struct atmel_uart_port *atmel_port, ...@@ -1591,7 +1591,7 @@ static void atmel_init_rs485(struct atmel_uart_port *atmel_port,
rs485conf->flags |= SER_RS485_ENABLED; rs485conf->flags |= SER_RS485_ENABLED;
} }
} else { } else {
atmel_port->rs485 = pdata->rs485; port->rs485 = pdata->rs485;
} }
} }
...@@ -1927,7 +1927,6 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, ...@@ -1927,7 +1927,6 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
{ {
unsigned long flags; unsigned long flags;
unsigned int mode, imr, quot, baud; unsigned int mode, imr, quot, baud;
struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
/* Get current mode register */ /* Get current mode register */
mode = UART_GET_MR(port) & ~(ATMEL_US_USCLKS | ATMEL_US_CHRL mode = UART_GET_MR(port) & ~(ATMEL_US_USCLKS | ATMEL_US_CHRL
...@@ -2029,10 +2028,9 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, ...@@ -2029,10 +2028,9 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
/* Resetting serial mode to RS232 (0x0) */ /* Resetting serial mode to RS232 (0x0) */
mode &= ~ATMEL_US_USMODE; mode &= ~ATMEL_US_USMODE;
if (atmel_port->rs485.flags & SER_RS485_ENABLED) { if (port->rs485.flags & SER_RS485_ENABLED) {
if ((atmel_port->rs485.delay_rts_after_send) > 0) if ((port->rs485.delay_rts_after_send) > 0)
UART_PUT_TTGR(port, UART_PUT_TTGR(port, port->rs485.delay_rts_after_send);
atmel_port->rs485.delay_rts_after_send);
mode |= ATMEL_US_USMODE_RS485; mode |= ATMEL_US_USMODE_RS485;
} }
...@@ -2171,35 +2169,6 @@ static void atmel_poll_put_char(struct uart_port *port, unsigned char ch) ...@@ -2171,35 +2169,6 @@ static void atmel_poll_put_char(struct uart_port *port, unsigned char ch)
} }
#endif #endif
static int
atmel_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg)
{
struct serial_rs485 rs485conf;
switch (cmd) {
case TIOCSRS485:
if (copy_from_user(&rs485conf, (struct serial_rs485 *) arg,
sizeof(rs485conf)))
return -EFAULT;
atmel_config_rs485(port, &rs485conf);
break;
case TIOCGRS485:
if (copy_to_user((struct serial_rs485 *) arg,
&(to_atmel_uart_port(port)->rs485),
sizeof(rs485conf)))
return -EFAULT;
break;
default:
return -ENOIOCTLCMD;
}
return 0;
}
static struct uart_ops atmel_pops = { static struct uart_ops atmel_pops = {
.tx_empty = atmel_tx_empty, .tx_empty = atmel_tx_empty,
.set_mctrl = atmel_set_mctrl, .set_mctrl = atmel_set_mctrl,
...@@ -2220,7 +2189,6 @@ static struct uart_ops atmel_pops = { ...@@ -2220,7 +2189,6 @@ static struct uart_ops atmel_pops = {
.config_port = atmel_config_port, .config_port = atmel_config_port,
.verify_port = atmel_verify_port, .verify_port = atmel_verify_port,
.pm = atmel_serial_pm, .pm = atmel_serial_pm,
.ioctl = atmel_ioctl,
#ifdef CONFIG_CONSOLE_POLL #ifdef CONFIG_CONSOLE_POLL
.poll_get_char = atmel_poll_get_char, .poll_get_char = atmel_poll_get_char,
.poll_put_char = atmel_poll_put_char, .poll_put_char = atmel_poll_put_char,
...@@ -2240,7 +2208,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port, ...@@ -2240,7 +2208,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,
if (!atmel_init_property(atmel_port, pdev)) if (!atmel_init_property(atmel_port, pdev))
atmel_set_ops(port); atmel_set_ops(port);
atmel_init_rs485(atmel_port, pdev); atmel_init_rs485(port, pdev);
port->iotype = UPIO_MEM; port->iotype = UPIO_MEM;
port->flags = UPF_BOOT_AUTOCONF; port->flags = UPF_BOOT_AUTOCONF;
...@@ -2249,6 +2217,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port, ...@@ -2249,6 +2217,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,
port->dev = &pdev->dev; port->dev = &pdev->dev;
port->mapbase = pdev->resource[0].start; port->mapbase = pdev->resource[0].start;
port->irq = pdev->resource[1].start; port->irq = pdev->resource[1].start;
port->rs485_config = atmel_config_rs485;
tasklet_init(&atmel_port->tasklet, atmel_tasklet_func, tasklet_init(&atmel_port->tasklet, atmel_tasklet_func,
(unsigned long)port); (unsigned long)port);
...@@ -2283,7 +2252,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port, ...@@ -2283,7 +2252,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,
} }
/* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */ /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
if (atmel_port->rs485.flags & SER_RS485_ENABLED) if (port->rs485.flags & SER_RS485_ENABLED)
atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
else if (atmel_use_pdc_tx(port)) { else if (atmel_use_pdc_tx(port)) {
port->fifosize = PDC_BUFFER_SIZE; port->fifosize = PDC_BUFFER_SIZE;
...@@ -2629,7 +2598,7 @@ static int atmel_serial_probe(struct platform_device *pdev) ...@@ -2629,7 +2598,7 @@ static int atmel_serial_probe(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
platform_set_drvdata(pdev, port); platform_set_drvdata(pdev, port);
if (port->rs485.flags & SER_RS485_ENABLED) { if (port->uart.rs485.flags & SER_RS485_ENABLED) {
UART_PUT_MR(&port->uart, ATMEL_US_USMODE_NORMAL); UART_PUT_MR(&port->uart, ATMEL_US_USMODE_NORMAL);
UART_PUT_CR(&port->uart, ATMEL_US_RTSEN); UART_PUT_CR(&port->uart, ATMEL_US_RTSEN);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment