From patchwork Thu Feb 24 09:55:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 546130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3912CC433F5 for ; Thu, 24 Feb 2022 09:56:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232892AbiBXJ4a (ORCPT ); Thu, 24 Feb 2022 04:56:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232389AbiBXJ4a (ORCPT ); Thu, 24 Feb 2022 04:56:30 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FDE2285A9F; Thu, 24 Feb 2022 01:56:00 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 8B33E1F39D; Thu, 24 Feb 2022 09:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1645696559; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=18KgPXChIZvCcv99HC0TP296dhKANDC4RaJpwfonCJE=; b=f4GEZ7vaJCsHlvFY0stXGs5sVAY0sUNSRQ9l8Pvda0dk9EmNiebRTDeRbyhSXSoMsJb/mP r1u18mJsaPTvSSOH3QkPfhe6VbkXvVCl60M44cLWtlQ2GpuGEHfgLL+zk5ovvAwH4QvN7h 1JLjqKHD5Z0FtNS0xvvel/V1jdP2Ty0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1645696559; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=18KgPXChIZvCcv99HC0TP296dhKANDC4RaJpwfonCJE=; b=7OPEjogzUBrx+5Ue/w4Rq1859w782fuoFUEqYQSgQ590PcotXEExyJNUEPYSFFrGvE5hkk ZpnbWX+uA4JZpNBg== Received: from localhost.localdomain (unknown [10.100.208.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 62675A3B93; Thu, 24 Feb 2022 09:55:59 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 1/5] tty: serial: define UART_LCR_WLEN() macro Date: Thu, 24 Feb 2022 10:55:54 +0100 Message-Id: <20220224095558.30929-1-jslaby@suse.cz> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220224095517.30872-1-jslaby@suse.cz> References: <20220224095517.30872-1-jslaby@suse.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Define a generic UART_LCR_WLEN() macro with a size argument. It can be used to encode byte size into an LCR value. Therefore we can use it to simplify the drivers using tty_get_char_size() in the next patches. Signed-off-by: Jiri Slaby --- include/uapi/linux/serial_reg.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/uapi/linux/serial_reg.h b/include/uapi/linux/serial_reg.h index f51bc8f36813..c9d5ff6dd4c6 100644 --- a/include/uapi/linux/serial_reg.h +++ b/include/uapi/linux/serial_reg.h @@ -111,6 +111,7 @@ #define UART_LCR_WLEN6 0x01 /* Wordlength: 6 bits */ #define UART_LCR_WLEN7 0x02 /* Wordlength: 7 bits */ #define UART_LCR_WLEN8 0x03 /* Wordlength: 8 bits */ +#define UART_LCR_WLEN(x) ((x) - 5) /* * Access to some registers depends on register access / configuration From patchwork Thu Feb 24 09:55:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 546128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42FE9C4167D for ; Thu, 24 Feb 2022 09:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232389AbiBXJ4d (ORCPT ); Thu, 24 Feb 2022 04:56:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233069AbiBXJ4b (ORCPT ); Thu, 24 Feb 2022 04:56:31 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AD5A285AA0; Thu, 24 Feb 2022 01:56:01 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D2A0421110; Thu, 24 Feb 2022 09:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1645696559; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i5lREHa3mtX8u6rlzp2pDXxb2q4QB9XYD1KbBac2Ti0=; b=ephuaJ95xCG8H/EC29MkfMFQkfFWhXC87InWW8jE0hQ/aBWLefi+7rgr+OKcjB2K0YMv+e uy+YL3JluTsKhM2Re7cdmiX3FjvJ9NfFfTxSDMWRSGDByepR0gQ7jo4gyoPbH1dobuet+W XLE7WK21Y9461dGJxRJVL7m2yulDkq0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1645696559; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i5lREHa3mtX8u6rlzp2pDXxb2q4QB9XYD1KbBac2Ti0=; b=5Px6ROspi4uKW0FRmcpAyOalitNMNniRCwkiY/RLJFQk2m5iJMcysk637nxPRC1q2PIYU6 ddtw2GEy8evi44AQ== Received: from localhost.localdomain (unknown [10.100.208.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 99915A3B97; Thu, 24 Feb 2022 09:55:59 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby , Laxman Dewangan , Thierry Reding , Jonathan Hunter , linux-tegra@vger.kernel.org Subject: [PATCH 2/5] tty: serial: make use of UART_LCR_WLEN() + tty_get_char_size() Date: Thu, 24 Feb 2022 10:55:55 +0100 Message-Id: <20220224095558.30929-2-jslaby@suse.cz> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220224095558.30929-1-jslaby@suse.cz> References: <20220224095517.30872-1-jslaby@suse.cz> <20220224095558.30929-1-jslaby@suse.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Having a generic UART_LCR_WLEN() macro and the tty_get_char_size() helper, we can remove all those repeated switch-cases in drivers. Signed-off-by: Jiri Slaby Cc: Laxman Dewangan Cc: Thierry Reding Cc: Jonathan Hunter Cc: linux-tegra@vger.kernel.org --- drivers/tty/serial/8250/8250_omap.c | 16 +--------------- drivers/tty/serial/8250/8250_port.c | 16 +--------------- drivers/tty/serial/jsm/jsm_cls.c | 16 +--------------- drivers/tty/serial/jsm/jsm_neo.c | 16 +--------------- drivers/tty/serial/omap-serial.c | 16 +--------------- drivers/tty/serial/pxa.c | 16 +--------------- drivers/tty/serial/serial-tegra.c | 22 ++++------------------ drivers/tty/serial/vr41xx_siu.c | 15 +-------------- 8 files changed, 11 insertions(+), 122 deletions(-) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c index 73e5f1dbd075..ac8bfa042391 100644 --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -357,21 +357,7 @@ static void omap_8250_set_termios(struct uart_port *port, unsigned char cval = 0; unsigned int baud; - switch (termios->c_cflag & CSIZE) { - case CS5: - cval = UART_LCR_WLEN5; - break; - case CS6: - cval = UART_LCR_WLEN6; - break; - case CS7: - cval = UART_LCR_WLEN7; - break; - default: - case CS8: - cval = UART_LCR_WLEN8; - break; - } + cval = UART_LCR_WLEN(tty_get_char_size(termios->c_cflag)); if (termios->c_cflag & CSTOPB) cval |= UART_LCR_STOP; diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 863f38e036a7..8642f02e4f05 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -2590,21 +2590,7 @@ static unsigned char serial8250_compute_lcr(struct uart_8250_port *up, { unsigned char cval; - switch (c_cflag & CSIZE) { - case CS5: - cval = UART_LCR_WLEN5; - break; - case CS6: - cval = UART_LCR_WLEN6; - break; - case CS7: - cval = UART_LCR_WLEN7; - break; - default: - case CS8: - cval = UART_LCR_WLEN8; - break; - } + cval = UART_LCR_WLEN(tty_get_char_size(c_cflag)); if (c_cflag & CSTOPB) cval |= UART_LCR_STOP; diff --git a/drivers/tty/serial/jsm/jsm_cls.c b/drivers/tty/serial/jsm/jsm_cls.c index b507a2cec926..b280da50290c 100644 --- a/drivers/tty/serial/jsm/jsm_cls.c +++ b/drivers/tty/serial/jsm/jsm_cls.c @@ -737,21 +737,7 @@ static void cls_param(struct jsm_channel *ch) if (ch->ch_c_cflag & CSTOPB) lcr |= UART_LCR_STOP; - switch (ch->ch_c_cflag & CSIZE) { - case CS5: - lcr |= UART_LCR_WLEN5; - break; - case CS6: - lcr |= UART_LCR_WLEN6; - break; - case CS7: - lcr |= UART_LCR_WLEN7; - break; - case CS8: - default: - lcr |= UART_LCR_WLEN8; - break; - } + lcr |= UART_LCR_WLEN(tty_get_char_size(ch->ch_c_cflag)); ier = readb(&ch->ch_cls_uart->ier); uart_lcr = readb(&ch->ch_cls_uart->lcr); diff --git a/drivers/tty/serial/jsm/jsm_neo.c b/drivers/tty/serial/jsm/jsm_neo.c index c6f927a76c3b..c4fd31de04b4 100644 --- a/drivers/tty/serial/jsm/jsm_neo.c +++ b/drivers/tty/serial/jsm/jsm_neo.c @@ -1008,21 +1008,7 @@ static void neo_param(struct jsm_channel *ch) if (ch->ch_c_cflag & CSTOPB) lcr |= UART_LCR_STOP; - switch (ch->ch_c_cflag & CSIZE) { - case CS5: - lcr |= UART_LCR_WLEN5; - break; - case CS6: - lcr |= UART_LCR_WLEN6; - break; - case CS7: - lcr |= UART_LCR_WLEN7; - break; - case CS8: - default: - lcr |= UART_LCR_WLEN8; - break; - } + lcr |= UART_LCR_WLEN(tty_get_char_size(ch->ch_c_cflag)); ier = readb(&ch->ch_neo_uart->ier); uart_lcr = readb(&ch->ch_neo_uart->lcr); diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c index 7074670cf81d..8d5ffa196097 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -808,21 +808,7 @@ serial_omap_set_termios(struct uart_port *port, struct ktermios *termios, unsigned long flags; unsigned int baud, quot; - switch (termios->c_cflag & CSIZE) { - case CS5: - cval = UART_LCR_WLEN5; - break; - case CS6: - cval = UART_LCR_WLEN6; - break; - case CS7: - cval = UART_LCR_WLEN7; - break; - default: - case CS8: - cval = UART_LCR_WLEN8; - break; - } + cval = UART_LCR_WLEN(tty_get_char_size(termios->c_cflag)); if (termios->c_cflag & CSTOPB) cval |= UART_LCR_STOP; diff --git a/drivers/tty/serial/pxa.c b/drivers/tty/serial/pxa.c index 5d7b7e56661f..e80ba8e10407 100644 --- a/drivers/tty/serial/pxa.c +++ b/drivers/tty/serial/pxa.c @@ -430,21 +430,7 @@ serial_pxa_set_termios(struct uart_port *port, struct ktermios *termios, unsigned int baud, quot; unsigned int dll; - switch (termios->c_cflag & CSIZE) { - case CS5: - cval = UART_LCR_WLEN5; - break; - case CS6: - cval = UART_LCR_WLEN6; - break; - case CS7: - cval = UART_LCR_WLEN7; - break; - default: - case CS8: - cval = UART_LCR_WLEN8; - break; - } + cval = UART_LCR_WLEN(tty_get_char_size(termios->c_cflag)); if (termios->c_cflag & CSTOPB) cval |= UART_LCR_STOP; diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-tegra.c index b6223fab0687..d942ab152f5a 100644 --- a/drivers/tty/serial/serial-tegra.c +++ b/drivers/tty/serial/serial-tegra.c @@ -1277,6 +1277,7 @@ static void tegra_uart_set_termios(struct uart_port *u, unsigned int baud; unsigned long flags; unsigned int lcr; + unsigned char char_bits; int symb_bit = 1; struct clk *parent_clk = clk_get_parent(tup->uart_clk); unsigned long parent_clk_rate = clk_get_rate(parent_clk); @@ -1316,25 +1317,10 @@ static void tegra_uart_set_termios(struct uart_port *u, } } + char_bits = tty_get_char_size(termios->c_cflag); + symb_bit += char_bits; lcr &= ~UART_LCR_WLEN8; - switch (termios->c_cflag & CSIZE) { - case CS5: - lcr |= UART_LCR_WLEN5; - symb_bit += 5; - break; - case CS6: - lcr |= UART_LCR_WLEN6; - symb_bit += 6; - break; - case CS7: - lcr |= UART_LCR_WLEN7; - symb_bit += 7; - break; - default: - lcr |= UART_LCR_WLEN8; - symb_bit += 8; - break; - } + lcr |= UART_LCR_WLEN(char_bits); /* Stop bits */ if (termios->c_cflag & CSTOPB) { diff --git a/drivers/tty/serial/vr41xx_siu.c b/drivers/tty/serial/vr41xx_siu.c index 6b303af5ee54..e0bf003ca3a1 100644 --- a/drivers/tty/serial/vr41xx_siu.c +++ b/drivers/tty/serial/vr41xx_siu.c @@ -504,20 +504,7 @@ static void siu_set_termios(struct uart_port *port, struct ktermios *new, unsigned long flags; c_cflag = new->c_cflag; - switch (c_cflag & CSIZE) { - case CS5: - lcr = UART_LCR_WLEN5; - break; - case CS6: - lcr = UART_LCR_WLEN6; - break; - case CS7: - lcr = UART_LCR_WLEN7; - break; - default: - lcr = UART_LCR_WLEN8; - break; - } + lcr = UART_LCR_WLEN(tty_get_char_size(c_cflag)); if (c_cflag & CSTOPB) lcr |= UART_LCR_STOP; From patchwork Thu Feb 24 09:55:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 545835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 163E2C433FE for ; Thu, 24 Feb 2022 09:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233077AbiBXJ4b (ORCPT ); Thu, 24 Feb 2022 04:56:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232209AbiBXJ4a (ORCPT ); Thu, 24 Feb 2022 04:56:30 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6921C285AA2; Thu, 24 Feb 2022 01:56:01 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 26FEF1F44A; Thu, 24 Feb 2022 09:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1645696560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=757ZRRjpJoiVS489R5WI0W5vTxny+PNszy3i98nF14M=; b=Hx43IEhL5S0JH1QQPNvVsNkeyUHpp+Bxwc5FSojlyPhtozRZZnw+ZEiZuLoOyODUS38dlr Gf+cfNQTAl3PlE4PBEFU9lB9En0Moj3lQPSwq6qlnBxCLrfIHKFIuuomYafe9YugQ8PkZe VU1ZF4SSL2h8/lJ1I1APn/LjULzkZFk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1645696560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=757ZRRjpJoiVS489R5WI0W5vTxny+PNszy3i98nF14M=; b=AlX7aBWo4+ZvAqOobLGxC0gwEW2VZ/fgkvq9hNQHPa1JBtCMVyb9A3YdIKlO83J7On+TII nHXgrTk6ZvDopIAA== Received: from localhost.localdomain (unknown [10.100.208.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id D7B81A3B98; Thu, 24 Feb 2022 09:55:59 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby , Johan Hovold , linux-usb@vger.kernel.org Subject: [PATCH 3/5] USB: serial: make use of UART_LCR_WLEN() + tty_get_char_size() Date: Thu, 24 Feb 2022 10:55:56 +0100 Message-Id: <20220224095558.30929-3-jslaby@suse.cz> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220224095558.30929-1-jslaby@suse.cz> References: <20220224095517.30872-1-jslaby@suse.cz> <20220224095558.30929-1-jslaby@suse.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Having a generic UART_LCR_WLEN() macro and the tty_get_char_size() helper, we can remove all those repeated switch-cases in drivers. Signed-off-by: Jiri Slaby Cc: Johan Hovold Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org --- drivers/usb/serial/ark3116.c | 17 ++--------------- drivers/usb/serial/f81232.c | 16 +--------------- drivers/usb/serial/f81534.c | 16 +--------------- drivers/usb/serial/mos7720.c | 20 +------------------- drivers/usb/serial/quatech2.c | 16 +--------------- drivers/usb/serial/ssu100.c | 16 +--------------- 6 files changed, 7 insertions(+), 94 deletions(-) diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c index 5dd710e9fe7d..c0e4df87ff22 100644 --- a/drivers/usb/serial/ark3116.c +++ b/drivers/usb/serial/ark3116.c @@ -200,21 +200,8 @@ static void ark3116_set_termios(struct tty_struct *tty, __u8 lcr, hcr, eval; /* set data bit count */ - switch (cflag & CSIZE) { - case CS5: - lcr = UART_LCR_WLEN5; - break; - case CS6: - lcr = UART_LCR_WLEN6; - break; - case CS7: - lcr = UART_LCR_WLEN7; - break; - default: - case CS8: - lcr = UART_LCR_WLEN8; - break; - } + lcr = UART_LCR_WLEN(tty_get_char_size(cflag)); + if (cflag & CSTOPB) lcr |= UART_LCR_STOP; if (cflag & PARENB) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 3ad1f515fb68..d9f20256a6a8 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -643,21 +643,7 @@ static void f81232_set_termios(struct tty_struct *tty, if (C_CSTOPB(tty)) new_lcr |= UART_LCR_STOP; - switch (C_CSIZE(tty)) { - case CS5: - new_lcr |= UART_LCR_WLEN5; - break; - case CS6: - new_lcr |= UART_LCR_WLEN6; - break; - case CS7: - new_lcr |= UART_LCR_WLEN7; - break; - default: - case CS8: - new_lcr |= UART_LCR_WLEN8; - break; - } + new_lcr |= UART_LCR_WLEN(tty_get_char_size(tty->termios.c_cflag)); mutex_lock(&priv->lock); diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c index c0bca52ef92a..d789c1ec87b3 100644 --- a/drivers/usb/serial/f81534.c +++ b/drivers/usb/serial/f81534.c @@ -970,21 +970,7 @@ static void f81534_set_termios(struct tty_struct *tty, if (C_CSTOPB(tty)) new_lcr |= UART_LCR_STOP; - switch (C_CSIZE(tty)) { - case CS5: - new_lcr |= UART_LCR_WLEN5; - break; - case CS6: - new_lcr |= UART_LCR_WLEN6; - break; - case CS7: - new_lcr |= UART_LCR_WLEN7; - break; - default: - case CS8: - new_lcr |= UART_LCR_WLEN8; - break; - } + new_lcr |= UART_LCR_WLEN(tty_get_char_size(tty->termios.c_cflag)); baud = tty_get_baud_rate(tty); if (!baud) diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index 227f43d2bd56..1e12b5f30dcc 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c @@ -1380,30 +1380,12 @@ static void change_port_settings(struct tty_struct *tty, return; } - lData = UART_LCR_WLEN8; lStop = 0x00; /* 1 stop bit */ lParity = 0x00; /* No parity */ cflag = tty->termios.c_cflag; - /* Change the number of bits */ - switch (cflag & CSIZE) { - case CS5: - lData = UART_LCR_WLEN5; - break; - - case CS6: - lData = UART_LCR_WLEN6; - break; - - case CS7: - lData = UART_LCR_WLEN7; - break; - default: - case CS8: - lData = UART_LCR_WLEN8; - break; - } + lData = UART_LCR_WLEN(tty_get_char_size(cflag)); /* Change the Parity bit */ if (cflag & PARENB) { diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c index 971907f083a3..36b1e064e51f 100644 --- a/drivers/usb/serial/quatech2.c +++ b/drivers/usb/serial/quatech2.c @@ -281,21 +281,7 @@ static void qt2_set_termios(struct tty_struct *tty, new_lcr |= SERIAL_EVEN_PARITY; } - switch (cflag & CSIZE) { - case CS5: - new_lcr |= UART_LCR_WLEN5; - break; - case CS6: - new_lcr |= UART_LCR_WLEN6; - break; - case CS7: - new_lcr |= UART_LCR_WLEN7; - break; - default: - case CS8: - new_lcr |= UART_LCR_WLEN8; - break; - } + new_lcr |= UART_LCR_WLEN(tty_get_char_size(cflag)); baud = tty_get_baud_rate(tty); if (!baud) diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c index 3baf7c0f5a98..181e302136a5 100644 --- a/drivers/usb/serial/ssu100.c +++ b/drivers/usb/serial/ssu100.c @@ -231,21 +231,7 @@ static void ssu100_set_termios(struct tty_struct *tty, urb_value |= SERIAL_EVEN_PARITY; } - switch (cflag & CSIZE) { - case CS5: - urb_value |= UART_LCR_WLEN5; - break; - case CS6: - urb_value |= UART_LCR_WLEN6; - break; - case CS7: - urb_value |= UART_LCR_WLEN7; - break; - default: - case CS8: - urb_value |= UART_LCR_WLEN8; - break; - } + urb_value |= UART_LCR_WLEN(tty_get_char_size(cflag)); baud = tty_get_baud_rate(tty); if (!baud) From patchwork Thu Feb 24 09:55:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 545834 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7A38C4321E for ; Thu, 24 Feb 2022 09:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233092AbiBXJ4c (ORCPT ); Thu, 24 Feb 2022 04:56:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233072AbiBXJ4b (ORCPT ); Thu, 24 Feb 2022 04:56:31 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6B0D285AA3; Thu, 24 Feb 2022 01:56:01 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6325C212B8; Thu, 24 Feb 2022 09:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1645696560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mi7kRn8+80MSMtlJoq/glAA6uvH6O77jShLeUaAMftM=; b=Ld+6MGs1+cYUZ06k75aF5WtEQey1+qh3gW31FPPXM7XUJgc9JNtwVjG0XH5xWJV9LU5xLL 7AbU5tcOwSFSq8PddGs5NlH7S3YPH0gOaP0jKs1uNBY7YaQdY93jfJnCfPBpIhXi2eDzk3 Sgryb+HSyxyFxE7EJolJLUQpwo5B7Ak= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1645696560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mi7kRn8+80MSMtlJoq/glAA6uvH6O77jShLeUaAMftM=; b=9geI1vQuvIGVF6Vd3C0FZJerDi6chs0XQZMG8JvJpNoRfeDxZSTa/AmydCrrhfNHjquwQY qpO6DPXGhsC5m/AQ== Received: from localhost.localdomain (unknown [10.100.208.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 2CD29A3B83; Thu, 24 Feb 2022 09:56:00 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby , Ulf Hansson , linux-mmc@vger.kernel.org Subject: [PATCH 4/5] sdio_uart: make use of UART_LCR_WLEN() + tty_get_char_size() Date: Thu, 24 Feb 2022 10:55:57 +0100 Message-Id: <20220224095558.30929-4-jslaby@suse.cz> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220224095558.30929-1-jslaby@suse.cz> References: <20220224095517.30872-1-jslaby@suse.cz> <20220224095558.30929-1-jslaby@suse.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Having a generic UART_LCR_WLEN() macro and the tty_get_char_size() helper, we can remove all those repeated switch-cases in drivers. Signed-off-by: Jiri Slaby Cc: Ulf Hansson Cc: linux-mmc@vger.kernel.org --- drivers/mmc/core/sdio_uart.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/drivers/mmc/core/sdio_uart.c b/drivers/mmc/core/sdio_uart.c index 04c0823e0359..e6eb5bd6e440 100644 --- a/drivers/mmc/core/sdio_uart.c +++ b/drivers/mmc/core/sdio_uart.c @@ -250,21 +250,7 @@ static void sdio_uart_change_speed(struct sdio_uart_port *port, unsigned char cval, fcr = 0; unsigned int baud, quot; - switch (termios->c_cflag & CSIZE) { - case CS5: - cval = UART_LCR_WLEN5; - break; - case CS6: - cval = UART_LCR_WLEN6; - break; - case CS7: - cval = UART_LCR_WLEN7; - break; - default: - case CS8: - cval = UART_LCR_WLEN8; - break; - } + cval = UART_LCR_WLEN(tty_get_char_size(termios->c_cflag)); if (termios->c_cflag & CSTOPB) cval |= UART_LCR_STOP; From patchwork Thu Feb 24 09:55:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 546129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1A62C43219 for ; Thu, 24 Feb 2022 09:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233088AbiBXJ4c (ORCPT ); Thu, 24 Feb 2022 04:56:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233073AbiBXJ4b (ORCPT ); Thu, 24 Feb 2022 04:56:31 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCFFA285AA4; Thu, 24 Feb 2022 01:56:01 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 9B6EA1F44C; Thu, 24 Feb 2022 09:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1645696560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1yL3OrD93751tjdTWgqtYW3vZmFiVRVbclLaKF5e268=; b=dZPjGftc8DmBWAbVxU6MpC9JWpuJADlKpUXhT3+VziYC1Sr/U5W+kBX0Oibr+0qrRIXnoC 70kmWIy7XgaYCZ3LMdLxd68VF5Owk+Z6xwYN5R3bBB0u4jr2pVhvc3CoTxdMMCsyy4Fn0H kwI+xy/RCq2z87BKgPEFyHUIoEkiXKg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1645696560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1yL3OrD93751tjdTWgqtYW3vZmFiVRVbclLaKF5e268=; b=5eHk5bbCB/yNM/pwLcOCwRP1XGxtQaWU8YoAcTrSqhs8UnLlyxCMj/37N+Fs0vWtEVB+NO HpypL1XQYT0tgZDg== Received: from localhost.localdomain (unknown [10.100.208.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 729AFA3B97; Thu, 24 Feb 2022 09:56:00 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 5/5] mxser: make use of UART_LCR_WLEN() + tty_get_char_size() Date: Thu, 24 Feb 2022 10:55:58 +0100 Message-Id: <20220224095558.30929-5-jslaby@suse.cz> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220224095558.30929-1-jslaby@suse.cz> References: <20220224095517.30872-1-jslaby@suse.cz> <20220224095558.30929-1-jslaby@suse.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Having a generic UART_LCR_WLEN() macro and the tty_get_char_size() helper, we can remove all those repeated switch-cases in drivers. Signed-off-by: Jiri Slaby --- drivers/tty/mxser.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c index 836c9eca2946..6ebd3e4ed859 100644 --- a/drivers/tty/mxser.c +++ b/drivers/tty/mxser.c @@ -588,21 +588,7 @@ static void mxser_change_speed(struct tty_struct *tty, struct ktermios *old_term } /* byte size and parity */ - switch (cflag & CSIZE) { - default: - case CS5: - cval = UART_LCR_WLEN5; - break; - case CS6: - cval = UART_LCR_WLEN6; - break; - case CS7: - cval = UART_LCR_WLEN7; - break; - case CS8: - cval = UART_LCR_WLEN8; - break; - } + cval = UART_LCR_WLEN(tty_get_char_size(tty->termios.c_cflag)); if (cflag & CSTOPB) cval |= UART_LCR_STOP;