Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1636284pxb; Mon, 12 Apr 2021 03:04:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWTvfKhpgmPJod3ygBsWFBX7lYjvmfhisL45KucrTspimVE8YXeAU8uTHeznRB3Us/eXsU X-Received: by 2002:a17:906:d8cb:: with SMTP id re11mr6449503ejb.204.1618221860200; Mon, 12 Apr 2021 03:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618221860; cv=none; d=google.com; s=arc-20160816; b=edbY0K1+kPT53CVaYZ5rwa+xsiHg7lv4WZI1EjxphNjMuO1aky5WiBqQdKPyJo3r2f XXLoGLudZeRlSWwVwWKpMnyLZgF+x40AluOWEFGarU0ECRYG5NFc5XgNO0QiEQzdce8Z 8//sngDZ1E3bCDy0p4SWDwH4N0Ua/bRdmfNlF5H3nSWdClmdc4YshB/SSSdjvf6wfgAB 6hoGFDhbBlB4GwHp6Lna/EUG3E9tgbZqkx60kwLN9IsEY/bu+QKx+A0/jEof6yj0awk6 21Jp8VvdPZRCCPRkiNbsKbBMw1zeWaADDpxXYuAHUJaJE7aOU919jzX7PPEJoBfpb5p4 8+0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YPiCXkv1RyabaV+x9B19HoNHzQkrGPTDROYk6225EhU=; b=xDre+JnYF7elhebiGET2nk2VEWIh/AgL+155zvo8fCH7EIRQU3oLi5+PS1jL6X1HAb blhkVXETCmD9f8w9dOEzso8d6aQ5jZM5SIoeKfrddFZOF66fC/T59seGO40UmFDKMrdg xCeTCwTCSIe8aphgBlXF7fD0ClvV9c1Ai9ugsGnxgRvbr6fVEwPFbqY2QFc/8nPlKalf t4onBE3J/QyfOx3/hB0euqxVg4Wh0oNDxW4NmEnmFKMXoJb2pejU17orJzRi+2mA6W0S wPK8w/3i/Ul6qHshc0CACCg281n18TtUhQR4x4urCF+URckygoAoEwji3smB+duwZBdA 7vyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kOvaZmVb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si7632558edv.514.2021.04.12.03.03.53; Mon, 12 Apr 2021 03:04:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kOvaZmVb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241745AbhDLJ6k (ORCPT + 99 others); Mon, 12 Apr 2021 05:58:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:38456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244731AbhDLJ4g (ORCPT ); Mon, 12 Apr 2021 05:56:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7B35D61243; Mon, 12 Apr 2021 09:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618221378; bh=V9Az9SK1kudygBq678HHRwZCwk6BHQ3LDSAfFXCYOfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kOvaZmVbmGtybSGRu01KNviFEb5Ta5dDnwOv4JZ5d/z51c8TSOH7sv4ykblU/EGR2 sx2eB/LDXIn0YmHPmEGYGXmaYzFkEoYQEZTFRlVQ4GzlXUe3j3GqXi6ubEfXzQ6mUN 37+8+CCOwewOHvpFG5ybNO2BwHeGUeh+M3utKs6yoGOdDXxDGT4m4gu8MLCtlhca9K E3Pz6fw69uFEHGcyEHSh0QNVyEBKFv4ASeRQKZaagatY9m5QyfjmCERbhkeNTcvf8G qW/1edY+OgBZsZ77/U7qFF7sJ6NXcBLtuVFvrGL6QmmAPK8n80v6mMZFebW3kjkENP +uoz/HzdIJDqg== Received: from johan by xi with local (Exim 4.93.0.4) (envelope-from ) id 1lVtIi-0000Kg-PQ; Mon, 12 Apr 2021 11:56:12 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , Manivannan Sadhasivam , 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 Message-Id: <20210412095557.1213-5-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210412095557.1213-1-johan@kernel.org> References: <20210412095557.1213-1-johan@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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 --- 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