linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Johan Hovold <johan@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	Manivannan Sadhasivam <mani@kernel.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 04/12] USB: serial: xr: move pin configuration to probe
Date: Mon, 12 Apr 2021 11:55:49 +0200	[thread overview]
Message-ID: <20210412095557.1213-5-johan@kernel.org> (raw)
In-Reply-To: <20210412095557.1213-1-johan@kernel.org>

There's no need to configure the pins on every open and judging from the
vendor driver and datasheet it can be done before enabling the UART.

Move pin configuration from open() to port probe and make sure to
deassert DTR and RTS after configuring all pins as GPIO.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/xr_serial.c | 45 ++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c
index f5087a8b6c86..542c1dc060cc 100644
--- a/drivers/usb/serial/xr_serial.c
+++ b/drivers/usb/serial/xr_serial.c
@@ -532,7 +532,6 @@ static void xr_set_termios(struct tty_struct *tty,
 
 static int xr_open(struct tty_struct *tty, struct usb_serial_port *port)
 {
-	u8 gpio_dir;
 	int ret;
 
 	ret = xr_uart_enable(port);
@@ -541,13 +540,6 @@ static int xr_open(struct tty_struct *tty, struct usb_serial_port *port)
 		return ret;
 	}
 
-	/*
-	 * Configure DTR and RTS as outputs and RI, CD, DSR and CTS as
-	 * inputs.
-	 */
-	gpio_dir = XR21V141X_GPIO_DTR | XR21V141X_GPIO_RTS;
-	xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, gpio_dir);
-
 	/* Setup termios */
 	if (tty)
 		xr_set_termios(tty, port, NULL);
@@ -596,10 +588,38 @@ static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id)
 	return 0;
 }
 
+static int xr_gpio_init(struct usb_serial_port *port)
+{
+	u8 mask, mode;
+	int ret;
+
+	/* Configure all pins as GPIO. */
+	mode = 0;
+	ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_MODE, mode);
+	if (ret)
+		return ret;
+
+	/*
+	 * Configure DTR and RTS as outputs and make sure they are deasserted
+	 * (active low), and configure RI, CD, DSR and CTS as inputs.
+	 */
+	mask = XR21V141X_GPIO_DTR | XR21V141X_GPIO_RTS;
+	ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, mask);
+	if (ret)
+		return ret;
+
+	ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_SET, mask);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 static int xr_port_probe(struct usb_serial_port *port)
 {
 	struct usb_interface_descriptor *desc;
 	struct xr_data *data;
+	int ret;
 
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -610,7 +630,16 @@ static int xr_port_probe(struct usb_serial_port *port)
 
 	usb_set_serial_port_data(port, data);
 
+	ret = xr_gpio_init(port);
+	if (ret)
+		goto err_free;
+
 	return 0;
+
+err_free:
+	kfree(data);
+
+	return ret;
 }
 
 static void xr_port_remove(struct usb_serial_port *port)
-- 
2.26.3


  parent reply	other threads:[~2021-04-12 10:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12  9:55 [PATCH RESEND 00/12] USB: serial: xr: add support for more device types Johan Hovold
2021-04-12  9:55 ` [PATCH 01/12] USB: serial: xr: add support for XR21V1412 and XR21V1414 Johan Hovold
2021-04-12  9:55 ` [PATCH 02/12] USB: serial: xr: rename GPIO-mode defines Johan Hovold
2021-04-12  9:55 ` [PATCH 03/12] USB: serial: xr: rename GPIO-pin defines Johan Hovold
2021-04-12  9:55 ` Johan Hovold [this message]
2021-04-12  9:55 ` [PATCH 05/12] USB: serial: xr: drop type prefix from shared defines Johan Hovold
2021-04-12  9:55 ` [PATCH 06/12] USB: serial: xr: add type abstraction Johan Hovold
2021-04-12  9:55 ` [PATCH 07/12] USB: serial: xr: add support for XR21B1421, XR21B1422 and XR21B1424 Johan Hovold
2021-04-12  9:55 ` [PATCH 08/12] USB: serial: xr: add support for XR21B1411 Johan Hovold
2021-04-12  9:55 ` [PATCH 09/12] USB: serial: xr: add support for XR22801, XR22802, XR22804 Johan Hovold
2021-04-12  9:55 ` [PATCH 10/12] USB: serial: xr: reset FIFOs on open Johan Hovold
2021-04-12  9:55 ` [PATCH 11/12] USB: serial: xr: add copyright notice Johan Hovold
2021-04-12  9:55 ` [PATCH 12/12] USB: cdc-acm: add more Maxlinear/Exar models to ignore list Johan Hovold
2021-04-12 11:00   ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2021-03-30 14:39 [PATCH 00/12] USB: serial: xr: add support for more device types Johan Hovold
2021-03-30 14:39 ` [PATCH 04/12] USB: serial: xr: move pin configuration to probe Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210412095557.1213-5-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=mchehab+huawei@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).