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

serial/omap: 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: default avatarRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 13bd3e6f
...@@ -163,7 +163,6 @@ struct uart_omap_port { ...@@ -163,7 +163,6 @@ struct uart_omap_port {
u8 wakeups_enabled; u8 wakeups_enabled;
u32 features; u32 features;
struct serial_rs485 rs485;
int rts_gpio; int rts_gpio;
struct pm_qos_request pm_qos_request; struct pm_qos_request pm_qos_request;
...@@ -316,7 +315,7 @@ static void serial_omap_stop_tx(struct uart_port *port) ...@@ -316,7 +315,7 @@ static void serial_omap_stop_tx(struct uart_port *port)
pm_runtime_get_sync(up->dev); pm_runtime_get_sync(up->dev);
/* Handle RS-485 */ /* Handle RS-485 */
if (up->rs485.flags & SER_RS485_ENABLED) { if (port->rs485.flags & SER_RS485_ENABLED) {
if (up->scr & OMAP_UART_SCR_TX_EMPTY) { if (up->scr & OMAP_UART_SCR_TX_EMPTY) {
/* THR interrupt is fired when both TX FIFO and TX /* THR interrupt is fired when both TX FIFO and TX
* shift register are empty. This means there's nothing * shift register are empty. This means there's nothing
...@@ -327,10 +326,12 @@ static void serial_omap_stop_tx(struct uart_port *port) ...@@ -327,10 +326,12 @@ static void serial_omap_stop_tx(struct uart_port *port)
*/ */
up->scr &= ~OMAP_UART_SCR_TX_EMPTY; up->scr &= ~OMAP_UART_SCR_TX_EMPTY;
serial_out(up, UART_OMAP_SCR, up->scr); serial_out(up, UART_OMAP_SCR, up->scr);
res = (up->rs485.flags & SER_RS485_RTS_AFTER_SEND) ? 1 : 0; res = (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) ?
1 : 0;
if (gpio_get_value(up->rts_gpio) != res) { if (gpio_get_value(up->rts_gpio) != res) {
if (up->rs485.delay_rts_after_send > 0) if (port->rs485.delay_rts_after_send > 0)
mdelay(up->rs485.delay_rts_after_send); mdelay(
port->rs485.delay_rts_after_send);
gpio_set_value(up->rts_gpio, res); gpio_set_value(up->rts_gpio, res);
} }
} else { } else {
...@@ -353,8 +354,8 @@ static void serial_omap_stop_tx(struct uart_port *port) ...@@ -353,8 +354,8 @@ static void serial_omap_stop_tx(struct uart_port *port)
serial_out(up, UART_IER, up->ier); serial_out(up, UART_IER, up->ier);
} }
if ((up->rs485.flags & SER_RS485_ENABLED) && if ((port->rs485.flags & SER_RS485_ENABLED) &&
!(up->rs485.flags & SER_RS485_RX_DURING_TX)) { !(port->rs485.flags & SER_RS485_RX_DURING_TX)) {
/* /*
* Empty the RX FIFO, we are not interested in anything * Empty the RX FIFO, we are not interested in anything
* received during the half-duplex transmission. * received during the half-duplex transmission.
...@@ -429,22 +430,22 @@ static void serial_omap_start_tx(struct uart_port *port) ...@@ -429,22 +430,22 @@ static void serial_omap_start_tx(struct uart_port *port)
pm_runtime_get_sync(up->dev); pm_runtime_get_sync(up->dev);
/* Handle RS-485 */ /* Handle RS-485 */
if (up->rs485.flags & SER_RS485_ENABLED) { if (port->rs485.flags & SER_RS485_ENABLED) {
/* Fire THR interrupts when FIFO is below trigger level */ /* Fire THR interrupts when FIFO is below trigger level */
up->scr &= ~OMAP_UART_SCR_TX_EMPTY; up->scr &= ~OMAP_UART_SCR_TX_EMPTY;
serial_out(up, UART_OMAP_SCR, up->scr); serial_out(up, UART_OMAP_SCR, up->scr);
/* if rts not already enabled */ /* if rts not already enabled */
res = (up->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0; res = (port->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0;
if (gpio_get_value(up->rts_gpio) != res) { if (gpio_get_value(up->rts_gpio) != res) {
gpio_set_value(up->rts_gpio, res); gpio_set_value(up->rts_gpio, res);
if (up->rs485.delay_rts_before_send > 0) if (port->rs485.delay_rts_before_send > 0)
mdelay(up->rs485.delay_rts_before_send); mdelay(port->rs485.delay_rts_before_send);
} }
} }
if ((up->rs485.flags & SER_RS485_ENABLED) && if ((port->rs485.flags & SER_RS485_ENABLED) &&
!(up->rs485.flags & SER_RS485_RX_DURING_TX)) !(port->rs485.flags & SER_RS485_RX_DURING_TX))
serial_omap_stop_rx(port); serial_omap_stop_rx(port);
serial_omap_enable_ier_thri(up); serial_omap_enable_ier_thri(up);
...@@ -1355,7 +1356,7 @@ static inline void serial_omap_add_console_port(struct uart_omap_port *up) ...@@ -1355,7 +1356,7 @@ static inline void serial_omap_add_console_port(struct uart_omap_port *up)
#endif #endif
/* Enable or disable the rs485 support */ /* Enable or disable the rs485 support */
static void static int
serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
{ {
struct uart_omap_port *up = to_uart_omap_port(port); struct uart_omap_port *up = to_uart_omap_port(port);
...@@ -1372,7 +1373,7 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) ...@@ -1372,7 +1373,7 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
serial_out(up, UART_IER, 0); serial_out(up, UART_IER, 0);
/* store new config */ /* store new config */
up->rs485 = *rs485conf; port->rs485 = *rs485conf;
/* /*
* Just as a precaution, only allow rs485 * Just as a precaution, only allow rs485
...@@ -1380,12 +1381,12 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) ...@@ -1380,12 +1381,12 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
*/ */
if (gpio_is_valid(up->rts_gpio)) { if (gpio_is_valid(up->rts_gpio)) {
/* enable / disable rts */ /* enable / disable rts */
val = (up->rs485.flags & SER_RS485_ENABLED) ? val = (port->rs485.flags & SER_RS485_ENABLED) ?
SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND; SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND;
val = (up->rs485.flags & val) ? 1 : 0; val = (port->rs485.flags & val) ? 1 : 0;
gpio_set_value(up->rts_gpio, val); gpio_set_value(up->rts_gpio, val);
} else } else
up->rs485.flags &= ~SER_RS485_ENABLED; port->rs485.flags &= ~SER_RS485_ENABLED;
/* Enable interrupts */ /* Enable interrupts */
up->ier = mode; up->ier = mode;
...@@ -1394,7 +1395,7 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) ...@@ -1394,7 +1395,7 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
/* If RS-485 is disabled, make sure the THR interrupt is fired when /* If RS-485 is disabled, make sure the THR interrupt is fired when
* TX FIFO is below the trigger level. * TX FIFO is below the trigger level.
*/ */
if (!(up->rs485.flags & SER_RS485_ENABLED) && if (!(port->rs485.flags & SER_RS485_ENABLED) &&
(up->scr & OMAP_UART_SCR_TX_EMPTY)) { (up->scr & OMAP_UART_SCR_TX_EMPTY)) {
up->scr &= ~OMAP_UART_SCR_TX_EMPTY; up->scr &= ~OMAP_UART_SCR_TX_EMPTY;
serial_out(up, UART_OMAP_SCR, up->scr); serial_out(up, UART_OMAP_SCR, up->scr);
...@@ -1403,36 +1404,10 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) ...@@ -1403,36 +1404,10 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
spin_unlock_irqrestore(&up->port.lock, flags); spin_unlock_irqrestore(&up->port.lock, flags);
pm_runtime_mark_last_busy(up->dev); pm_runtime_mark_last_busy(up->dev);
pm_runtime_put_autosuspend(up->dev); pm_runtime_put_autosuspend(up->dev);
}
static int
serial_omap_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg)
{
struct serial_rs485 rs485conf;
switch (cmd) {
case TIOCSRS485:
if (copy_from_user(&rs485conf, (void __user *) arg,
sizeof(rs485conf)))
return -EFAULT;
serial_omap_config_rs485(port, &rs485conf);
break;
case TIOCGRS485:
if (copy_to_user((void __user *) arg,
&(to_uart_omap_port(port)->rs485),
sizeof(rs485conf)))
return -EFAULT;
break;
default:
return -ENOIOCTLCMD;
}
return 0; return 0;
} }
static struct uart_ops serial_omap_pops = { static struct uart_ops serial_omap_pops = {
.tx_empty = serial_omap_tx_empty, .tx_empty = serial_omap_tx_empty,
.set_mctrl = serial_omap_set_mctrl, .set_mctrl = serial_omap_set_mctrl,
...@@ -1453,7 +1428,6 @@ static struct uart_ops serial_omap_pops = { ...@@ -1453,7 +1428,6 @@ static struct uart_ops serial_omap_pops = {
.request_port = serial_omap_request_port, .request_port = serial_omap_request_port,
.config_port = serial_omap_config_port, .config_port = serial_omap_config_port,
.verify_port = serial_omap_verify_port, .verify_port = serial_omap_verify_port,
.ioctl = serial_omap_ioctl,
#ifdef CONFIG_CONSOLE_POLL #ifdef CONFIG_CONSOLE_POLL
.poll_put_char = serial_omap_poll_put_char, .poll_put_char = serial_omap_poll_put_char,
.poll_get_char = serial_omap_poll_get_char, .poll_get_char = serial_omap_poll_get_char,
...@@ -1587,7 +1561,7 @@ static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev) ...@@ -1587,7 +1561,7 @@ static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev)
static int serial_omap_probe_rs485(struct uart_omap_port *up, static int serial_omap_probe_rs485(struct uart_omap_port *up,
struct device_node *np) struct device_node *np)
{ {
struct serial_rs485 *rs485conf = &up->rs485; struct serial_rs485 *rs485conf = &up->port.rs485;
u32 rs485_delay[2]; u32 rs485_delay[2];
enum of_gpio_flags flags; enum of_gpio_flags flags;
int ret; int ret;
...@@ -1709,6 +1683,7 @@ static int serial_omap_probe(struct platform_device *pdev) ...@@ -1709,6 +1683,7 @@ static int serial_omap_probe(struct platform_device *pdev)
up->port.membase = base; up->port.membase = base;
up->port.flags = omap_up_info->flags; up->port.flags = omap_up_info->flags;
up->port.uartclk = omap_up_info->uartclk; up->port.uartclk = omap_up_info->uartclk;
up->port.rs485_config = serial_omap_config_rs485;
if (!up->port.uartclk) { if (!up->port.uartclk) {
up->port.uartclk = DEFAULT_CLK_SPEED; up->port.uartclk = DEFAULT_CLK_SPEED;
dev_warn(&pdev->dev, dev_warn(&pdev->dev,
......
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