drivers: tty: serial: omap-serial-rtu: switch to using gpiod API
Signed-off-by: Oleg Karfich <oleg.karfich@wago.com>
This commit is contained in:
@@ -229,7 +229,7 @@ static inline void serial_omap_update_rts(struct uart_omap_port *up)
|
||||
|
||||
static void serial_omap_config_rs485(struct uart_omap_port *up, struct serial_rs485 *rs485conf)
|
||||
{
|
||||
if (gpio_is_valid(up->rs485en_gpio)) {
|
||||
if (up->rs485en_gpio) {
|
||||
int val;
|
||||
|
||||
/* way from uart_port to tty_port: ugly :( */
|
||||
@@ -259,7 +259,7 @@ static void serial_omap_config_rs485(struct uart_omap_port *up, struct serial_rs
|
||||
tty->driver->flags &= ~TTY_DRIVER_IGNORE_FLUSH;
|
||||
}
|
||||
|
||||
gpio_set_value(up->rs485en_gpio, up->rs485en_alow ? !val : val);
|
||||
gpiod_set_value_cansleep(up->rs485en_gpio, up->rs485en_alow ? !val : val);
|
||||
|
||||
#ifdef CONFIG_SERIAL_OMAP_MODBUS
|
||||
/*
|
||||
@@ -1718,12 +1718,11 @@ static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev)
|
||||
}
|
||||
|
||||
static int of_probe_rs485(struct uart_omap_port *up,
|
||||
struct device_node *np)
|
||||
struct device *dev)
|
||||
{
|
||||
struct serial_rs485 *rs485conf = &up->rs485;
|
||||
struct device_node *np = dev->of_node;
|
||||
u32 rs485_delay[2];
|
||||
enum of_gpio_flags flags;
|
||||
int ret;
|
||||
|
||||
rs485conf->flags = 0;
|
||||
up->rts_gpio = -EINVAL;
|
||||
@@ -1737,15 +1736,12 @@ static int of_probe_rs485(struct uart_omap_port *up,
|
||||
rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
|
||||
|
||||
/* check for tx enable gpio */
|
||||
up->rs485en_gpio = of_get_named_gpio_flags(np, "rs485en-gpio", 0, &flags);
|
||||
if (gpio_is_valid(up->rs485en_gpio)) {
|
||||
ret = gpio_request(up->rs485en_gpio, "omap-serial-rtu-rs485en");
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
} else if (up->rs485en_gpio == -EPROBE_DEFER) {
|
||||
return -EPROBE_DEFER;
|
||||
} else {
|
||||
up->rs485en_gpio = -EINVAL;
|
||||
up->rs485en_gpio = devm_gpiod_get(dev, "rs485en", GPIOD_OUT_HIGH);
|
||||
if (IS_ERR(up->rs485en_gpio)) {
|
||||
dev_err(dev, "failed to find rs485en gpio signal! %ld\n",
|
||||
PTR_ERR(up->rs485en_gpio));
|
||||
|
||||
return PTR_ERR(up->rs485en_gpio);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1764,18 +1760,17 @@ static int of_probe_rs485(struct uart_omap_port *up,
|
||||
if (of_property_read_bool(np, "linux,rs485-enabled-at-boot-time"))
|
||||
rs485conf->flags |= SER_RS485_ENABLED;
|
||||
|
||||
if (gpio_is_valid(up->rs485en_gpio)) {
|
||||
if (up->rs485en_gpio) {
|
||||
int val = rs485conf->flags & SER_RS485_ENABLED;
|
||||
|
||||
up->rs485en_alow = flags & OF_GPIO_ACTIVE_LOW;
|
||||
up->rs485en_alow = gpiod_is_active_low(up->rs485en_gpio);
|
||||
|
||||
pr_info("%s: rs485en-gpio is %s\n", __func__,
|
||||
up->rs485en_alow ? "active_low" : "active_high");
|
||||
|
||||
/* turn on or off rs485 hw path */
|
||||
ret = gpio_direction_output(up->rs485en_gpio, up->rs485en_alow ? !val : val);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
gpiod_set_value_cansleep(up->rs485en_gpio,
|
||||
up->rs485en_alow ? !val : val);
|
||||
|
||||
pr_info("%s: %s mode enabled\n", __func__, val ? "rs485" : "rs232");
|
||||
}
|
||||
@@ -1820,7 +1815,7 @@ static int serial_omap_probe(struct platform_device *pdev)
|
||||
return -ENOMEM;
|
||||
|
||||
if (pdev->dev.of_node) {
|
||||
ret = of_probe_rs485(up, pdev->dev.of_node);
|
||||
ret = of_probe_rs485(up, &pdev->dev);
|
||||
if (ret == -EPROBE_DEFER) {
|
||||
devm_kfree(&pdev->dev, up);
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
@@ -185,7 +185,7 @@ struct uart_omap_port {
|
||||
struct serial_rs485 rs485;
|
||||
unsigned int tx_in_progress:1, tx_wait_end:1;
|
||||
int rts_gpio;
|
||||
int rs485en_gpio;
|
||||
struct gpio_desc *rs485en_gpio;
|
||||
u8 rs485en_alow;
|
||||
|
||||
int context_loss_cnt;
|
||||
|
||||
Reference in New Issue
Block a user