Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2168598pxb; Mon, 12 Apr 2021 16:44:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwy1VulfXlDxqZrJqjx4bXJJpqdHb6Eu853/7jVFIj64OBHQxluwiUDKRnRrdBMwK3otcgR X-Received: by 2002:aa7:d917:: with SMTP id a23mr22672863edr.80.1618271083384; Mon, 12 Apr 2021 16:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618271083; cv=none; d=google.com; s=arc-20160816; b=NA1uyahyA0BxbUyKKRVlZYIA11J0S6TjF8rGAVtZYJl7kKa+S/J65UGG2EGM/roGAL PquG3DwY1HCyQqwBRRAweoV7KjmW79LILs9cX29tjy6HXfdmChGEMOTXaGFEmjsW3M3K MTUenCiHZUvba829WSWQC3OT1K1/poGpLY7Luzk1Q1vP5ZUsvGGUYuQBhhZlNYrxvyjK Geyk1aHbKnR+rHs6lJNehsqZt3Cs4uNzojS+lAyNev4n4RqxQMXHgIfDRRHJvx2Pf2F1 H6JQZObhFB3JbH/gU/CUSGC9CMInVKW2r+Z/IxeKxw1FNuIJe6BdkdGS2Qp+lQNIyk47 RZQg== 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=VwRKRcmBK+jOzXTQjLcU6OFUvtNtOpSrNFaTw30LjNs=; b=jpL98WuvK/vds8ENg08Hz/NPPjdU4JUzZ/zWI7aDtlio6J674g4XD2T7LLDAuESp+p TxpF3zVmUdrIp1iflM1o/u9NFq4BuU12CSAdXRQzoJWq7nc35C6KmO9hQvuKq5SZODBh TF1V7N0MswY21/JLaKXmH+McLTzOIEeQfKeB1f1wt4JnXMDZHNEVjdPTSSIYRVZ1ffK0 KvU4Bqlpb0eMwF+0qFNaOJPM8Ko2ygBOSQbx3bChdyDiys/NXY1KDB4qxVXSH52gmHlB wwQpWROnOXpOMIEobWEcPHUBhTfB4J2Y2tLvp9Zvh6v7HR40OBWxidk2i3kJ2JlXDb7n 237A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NwFX4UbC; 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 v2si8665188edy.362.2021.04.12.16.44.20; Mon, 12 Apr 2021 16:44:43 -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=NwFX4UbC; 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 S243990AbhDLKAI (ORCPT + 99 others); Mon, 12 Apr 2021 06:00:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:38566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244813AbhDLJ4n (ORCPT ); Mon, 12 Apr 2021 05:56:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C250B61352; 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=93eu/ai965fIUGSREj8ExJtrJ3sNeihKwmSb0StfEPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NwFX4UbCJuvCLr9o8F1/GHWBeEtZhuPd6Wyewi+Rz/cz+V5Mr9tAcegh3RMPYdazy L4hEto/XTQSHihwMV+e8SRcLiQv/UTrrTIACknYyHi9zfxHl1yyZPGRoemymq4/wk8 pERZbiuXlNtHmIOOgWyNk9720uGyHU3ahclqaUGBl+NMKDzfz7JI3oH5CJ1ZGbZOiZ OqjXF2B/sj+A1As3txt8gYWiXw44zbU85bPQXUW0n4irLBcwUOpUaW2czfVHQI11UK K3Y+6pm0rwV4eQglj2A8De74db7xk7H/dtohtBXzkurtfWkj9mOZXSPJoJ8sBXzJ9U +KysoMN7nFGIQ== Received: from johan by xi with local (Exim 4.93.0.4) (envelope-from ) id 1lVtIj-0000Kz-BR; Mon, 12 Apr 2021 11:56:13 +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 10/12] USB: serial: xr: reset FIFOs on open Date: Mon, 12 Apr 2021 11:55:55 +0200 Message-Id: <20210412095557.1213-11-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 Reset the transmit and receive FIFOs before enabling the UARTs as part of open() in order to flush any stale data. Note that the XR21V141X needs a type-specific implementation due to its UART Manager registers. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 14dbda13ab4d..1b7b3c70a9b3 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -95,10 +95,13 @@ struct xr_txrx_clk_mask { #define XR_GPIO_MODE_TX_TOGGLE 0x100 #define XR_GPIO_MODE_RX_TOGGLE 0x200 +#define XR_FIFO_RESET 0x1 + #define XR_CUSTOM_DRIVER_ACTIVE 0x1 static int xr21v141x_uart_enable(struct usb_serial_port *port); static int xr21v141x_uart_disable(struct usb_serial_port *port); +static int xr21v141x_fifo_reset(struct usb_serial_port *port); static void xr21v141x_set_line_settings(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios); @@ -118,6 +121,8 @@ struct xr_type { u16 gpio_set; u16 gpio_clear; u16 gpio_status; + u16 tx_fifo_reset; + u16 rx_fifo_reset; u16 custom_driver; bool have_5_6_bit_mode; @@ -125,6 +130,7 @@ struct xr_type { int (*enable)(struct usb_serial_port *port); int (*disable)(struct usb_serial_port *port); + int (*fifo_reset)(struct usb_serial_port *port); void (*set_line_settings)(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios); @@ -158,6 +164,7 @@ static const struct xr_type xr_types[] = { .enable = xr21v141x_uart_enable, .disable = xr21v141x_uart_disable, + .fifo_reset = xr21v141x_fifo_reset, .set_line_settings = xr21v141x_set_line_settings, }, [XR21B142X] = { @@ -176,6 +183,8 @@ static const struct xr_type xr_types[] = { .gpio_set = 0x0e, .gpio_clear = 0x0f, .gpio_status = 0x10, + .tx_fifo_reset = 0x40, + .rx_fifo_reset = 0x43, .custom_driver = 0x60, .have_5_6_bit_mode = true, @@ -197,6 +206,8 @@ static const struct xr_type xr_types[] = { .gpio_set = 0xc0e, .gpio_clear = 0xc0f, .gpio_status = 0xc10, + .tx_fifo_reset = 0xc80, + .rx_fifo_reset = 0xcc0, .custom_driver = 0x20d, }, [XR2280X] = { @@ -215,6 +226,8 @@ static const struct xr_type xr_types[] = { .gpio_set = 0x4e, .gpio_clear = 0x4f, .gpio_status = 0x50, + .tx_fifo_reset = 0x60, + .rx_fifo_reset = 0x63, .custom_driver = 0x81, }, }; @@ -384,6 +397,40 @@ static int xr_uart_disable(struct usb_serial_port *port) return __xr_uart_disable(port); } +static int xr21v141x_fifo_reset(struct usb_serial_port *port) +{ + int ret; + + ret = xr_set_reg_um(port, XR21V141X_UM_TX_FIFO_RESET, XR_FIFO_RESET); + if (ret) + return ret; + + ret = xr_set_reg_um(port, XR21V141X_UM_RX_FIFO_RESET, XR_FIFO_RESET); + if (ret) + return ret; + + return 0; +} + +static int xr_fifo_reset(struct usb_serial_port *port) +{ + struct xr_data *data = usb_get_serial_port_data(port); + int ret; + + if (data->type->fifo_reset) + return data->type->fifo_reset(port); + + ret = xr_set_reg_uart(port, data->type->tx_fifo_reset, XR_FIFO_RESET); + if (ret) + return ret; + + ret = xr_set_reg_uart(port, data->type->rx_fifo_reset, XR_FIFO_RESET); + if (ret) + return ret; + + return 0; +} + static int xr_tiocmget(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; @@ -781,6 +828,10 @@ static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) { int ret; + ret = xr_fifo_reset(port); + if (ret) + return ret; + ret = xr_uart_enable(port); if (ret) { dev_err(&port->dev, "Failed to enable UART\n"); -- 2.26.3