Commit c150c0f3 authored by Lukas Wunner's avatar Lukas Wunner Committed by Greg Kroah-Hartman
Browse files

serial: Allow uart_get_rs485_mode() to return errno



We're about to amend uart_get_rs485_mode() to support a GPIO pin for
rs485 bus termination.  Retrieving the GPIO descriptor may fail, so
allow uart_get_rs485_mode() to return an errno and change all callers
to check for failure.

The GPIO descriptor is going to be stored in struct uart_port.  Pass
that struct to uart_get_rs485_mode() in lieu of a struct device and
struct serial_rs485, both of which are directly accessible from struct
uart_port.

A few drivers call uart_get_rs485_mode() before setting the struct
device pointer in struct uart_port.  Shuffle those calls around where
necessary.

[Heiko Stuebner did the ar933x_uart.c portion, hence his Signed-off-by.]

Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
Link: https://lore.kernel.org/r/271e814af4b0db3bffbbb74abf2b46b75add4516.1589285873.git.lukas@wunner.de


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e0a851fe
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -1026,7 +1026,9 @@ int serial8250_register_8250_port(struct uart_8250_port *up)

		if (up->port.dev) {
			uart->port.dev = up->port.dev;
			uart_get_rs485_mode(uart->port.dev, &uart->port.rs485);
			ret = uart_get_rs485_mode(&uart->port);
			if (ret)
				goto err;
		}

		if (up->port.flags & UPF_FIXED_TYPE)
+4 −2
Original line number Diff line number Diff line
@@ -766,8 +766,6 @@ static int ar933x_uart_probe(struct platform_device *pdev)
		goto err_disable_clk;
	}

	uart_get_rs485_mode(&pdev->dev, &port->rs485);

	port->mapbase = mem_res->start;
	port->line = id;
	port->irq = irq_res->start;
@@ -786,6 +784,10 @@ static int ar933x_uart_probe(struct platform_device *pdev)
	baud = ar933x_uart_get_baud(port->uartclk, 0, AR933X_UART_MAX_STEP);
	up->max_baud = min_t(unsigned int, baud, AR933X_UART_MAX_BAUD);

	ret = uart_get_rs485_mode(port);
	if (ret)
		goto err_disable_clk;

	up->gpios = mctrl_gpio_init(port, 0);
	if (IS_ERR(up->gpios) && PTR_ERR(up->gpios) != -ENOSYS)
		return PTR_ERR(up->gpios);
+4 −2
Original line number Diff line number Diff line
@@ -2491,8 +2491,6 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,
	atmel_init_property(atmel_port, pdev);
	atmel_set_ops(port);

	uart_get_rs485_mode(&mpdev->dev, &port->rs485);

	port->iotype		= UPIO_MEM;
	port->flags		= UPF_BOOT_AUTOCONF | UPF_IOREMAP;
	port->ops		= &atmel_pops;
@@ -2506,6 +2504,10 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,

	memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));

	ret = uart_get_rs485_mode(port);
	if (ret)
		return ret;

	/* for console, the clock could already be configured */
	if (!atmel_port->clk) {
		atmel_port->clk = clk_get(&mpdev->dev, "usart");
+4 −1
Original line number Diff line number Diff line
@@ -2619,7 +2619,9 @@ static int lpuart_probe(struct platform_device *pdev)
	if (ret)
		goto failed_attach_port;

	uart_get_rs485_mode(&pdev->dev, &sport->port.rs485);
	ret = uart_get_rs485_mode(&sport->port);
	if (ret)
		goto failed_get_rs485;

	if (sport->port.rs485.flags & SER_RS485_RX_DURING_TX)
		dev_err(&pdev->dev, "driver doesn't support RX during TX\n");
@@ -2632,6 +2634,7 @@ static int lpuart_probe(struct platform_device *pdev)

	return 0;

failed_get_rs485:
failed_attach_port:
failed_irq_request:
	lpuart_disable_clks(sport);
+5 −1
Original line number Diff line number Diff line
@@ -2304,7 +2304,11 @@ static int imx_uart_probe(struct platform_device *pdev)
	sport->ucr4 = readl(sport->port.membase + UCR4);
	sport->ufcr = readl(sport->port.membase + UFCR);

	uart_get_rs485_mode(&pdev->dev, &sport->port.rs485);
	ret = uart_get_rs485_mode(&sport->port);
	if (ret) {
		clk_disable_unprepare(sport->clk_ipg);
		return ret;
	}

	if (sport->port.rs485.flags & SER_RS485_ENABLED &&
	    (!sport->have_rtscts && !sport->have_rtsgpio))
Loading