From patchwork Mon Nov 7 17:14:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel L. Somlo" X-Patchwork-Id: 16582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2181032wru; Mon, 7 Nov 2022 09:16:29 -0800 (PST) X-Google-Smtp-Source: AMsMyM4T0pah6D3NvZecHMjKymYvblO5bZvHpiDoCNnVaC/FPAXcgz5Erk+mQPJ6Ip8FYTnytZFZ X-Received: by 2002:a65:42c8:0:b0:41a:8138:f47f with SMTP id l8-20020a6542c8000000b0041a8138f47fmr44350705pgp.476.1667841389396; Mon, 07 Nov 2022 09:16:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667841389; cv=none; d=google.com; s=arc-20160816; b=EExRCpkn0luHXOfj2H2rUFw9vs1oHDDi86tA/kZJm2sCknsr5w2D+RspXyFXECDMIL RaYu59m6nEug5FrE+dMcA6DIAW6O5ibkox5gHg9yQDTflGrWdlf5tYr94VLQc4iavfZm pRVvMhsVyIBTMjtAmQAKU5tElAVvHbMzQRfREecQMu1yjvOmdJwh3PJxzNfPlM8jp2dy K+CgoJh+l9olK4TtRKLl0SZmipIFfGHZmPjfjzuymmDAJqmEyM14r6oxyJjLtoxxXG0k Hp+M/fFdWHXVUZ374oroYh3PvY8J8rIcqveFHO8aG1vYYj1yoHeQq8N9i9rMcOLYJwR3 rJIg== 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=ad8luJYSej7aw2mX5QDdm2q90JBkKxRfRuuN+1GfVOg=; b=Zh8Vl3R3GsN+nv0OdBGsKW+nu422itv8Vqh4WThGI5C1s5dZqhaSNUBwXz0OB6K1XH NIK0kB0agw4RwrZ/X1IIygstk5kjYRKobCc/ZI37OyZRuiDcHt5gbqKtvFT9WBDm05I3 DSqPo40YIqN4uaT00dL5dADfWLO0eXWstDEOV/386KaE+lrcqeWN3oMYewCX5ueqAI3P K9GfngQrJLiUNb45fDBnURpM8Efd221wsiMgrZ14sEQxy2m55T4LFYf/8u6YpdMa9G0Z h8ntS3/quod+owMiLXkzO6xwAMM4WvfM4wshOYKIuvaDlQevTE7C4jj9DwMeH72m+7W5 6Txw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iO1KP1sN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a170903405100b00186a06a3396si8663272pla.153.2022.11.07.09.16.14; Mon, 07 Nov 2022 09:16:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iO1KP1sN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232540AbiKGRPR (ORCPT + 99 others); Mon, 7 Nov 2022 12:15:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232302AbiKGRPL (ORCPT ); Mon, 7 Nov 2022 12:15:11 -0500 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F5421CB17; Mon, 7 Nov 2022 09:15:10 -0800 (PST) Received: by mail-qk1-x72e.google.com with SMTP id f8so7562135qkg.3; Mon, 07 Nov 2022 09:15:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ad8luJYSej7aw2mX5QDdm2q90JBkKxRfRuuN+1GfVOg=; b=iO1KP1sN9ONNmhVWElB/IPStlYoF/+sJKZXELeNvF57ki8OZKdN2vtv7LxIcGFOBTC D0qYKNSW4VctBK4su1IbcDI0nePTpZpPzUWZVyPTCi4oKjDEWj3RhoS/1bjOFRRGXz11 gihW4NhNDIo/zvrS3kl9mg5Wp4cUcDRMe6vIHzcSpx7Sfm4zC5FbR/DC3VONdmescEEc mqiDNAorWDcnSeDoTkbdzPivTnFk9GNw1UwPXJ7CP8WRdK2xQaqdDPx73QImStNPd33q ON6frvBKN0JP1qo6uB4vS2FPN2lC6/ooaokPvlxQliaW1tp/QZV9NIlTowK8V5ivL4GM 5CjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ad8luJYSej7aw2mX5QDdm2q90JBkKxRfRuuN+1GfVOg=; b=1foJbaOh4PhWCVIxiozzYlBhg4lh2UbDOKA+VNduZg6ZC5m862NMUTFKvbY6tgZ4xN cgSxjVeHetb4EcVJ93FXLJ0EsjszYHVKD1eE4DU7YAYcZvnY80JS1pNtfMjGZoqN6KY3 yCRd6HwMvte4JwoLsQvDBGugOF2nwpDDBZQjNQeLFXaZBHZc5Fh8ygrxvcuWR5MIXCWK CEWDg+XvHomRTXDQHaeCNmrwPVTX6TFEcU4FlGNQIUhK8WL1r/SAlD/c/UVwjFBFzOHg TuY/J0nkZs4+2ediKEfE0QHCEM+8tNC2tZah/phpfFRAh9Sp+oeHpwtWCsKy5G0YFWBF kp8g== X-Gm-Message-State: ACrzQf3ShMqqPgKCt4nRaNbksHW2j3IW0xgQUaRJwMi2wg/rKQwrIRyo AwTWH8ghHU+9fRJp24aIVqXpYqmKFZSBmQ== X-Received: by 2002:a37:ad18:0:b0:6fa:b07:9e8d with SMTP id f24-20020a37ad18000000b006fa0b079e8dmr35152948qkm.670.1667841309023; Mon, 07 Nov 2022 09:15:09 -0800 (PST) Received: from glsvmlin.ini.cmu.edu (GLSVMLIN.INI.CMU.EDU. [128.2.16.9]) by smtp.gmail.com with ESMTPSA id az36-20020a05620a172400b006ce9e880c6fsm7333611qkb.111.2022.11.07.09.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 09:15:08 -0800 (PST) From: Gabriel Somlo To: linux-kernel@vger.kernel.org Cc: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, kgugala@antmicro.com, mholenko@antmicro.com, joel@jms.id.au, david.abdurachmanov@sifive.com, florent@enjoy-digital.fr Subject: [PATCH v1 1/3] serial: liteuart: cosmetic changes Date: Mon, 7 Nov 2022 12:14:58 -0500 Message-Id: <20221107171500.2537938-2-gsomlo@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221107171500.2537938-1-gsomlo@gmail.com> References: <20221107171500.2537938-1-gsomlo@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748858452429950676?= X-GMAIL-MSGID: =?utf-8?q?1748858452429950676?= Make some cosmetic/stylistic (non-functional) improvements: 1. Use a DRV_NAME macro to avoid hard-coding "liteuart" in multiple locations throughout the source file 2. Use bit numbers instead of magic constants for event flags 3. Remove stub uart_ops methods that are not called unconditionally from serial_core; Document stubs that are required by serial_core 4. Don't set unused port->regshift and port->iobase fields gratuitously during probe() 5. Improve coding style in liteuart_init() Signed-off-by: Gabriel Somlo --- drivers/tty/serial/liteuart.c | 38 +++++++++-------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/drivers/tty/serial/liteuart.c b/drivers/tty/serial/liteuart.c index 4c0604325ee9..4b9cca249828 100644 --- a/drivers/tty/serial/liteuart.c +++ b/drivers/tty/serial/liteuart.c @@ -18,6 +18,8 @@ #include #include +#define DRV_NAME "liteuart" + /* * CSRs definitions (base address offsets + width) * @@ -38,8 +40,8 @@ #define OFF_EV_ENABLE 0x14 /* events */ -#define EV_TX 0x1 -#define EV_RX 0x2 +#define EV_TX BIT(0) +#define EV_RX BIT(1) struct liteuart_port { struct uart_port port; @@ -57,7 +59,7 @@ static struct console liteuart_console; static struct uart_driver liteuart_driver = { .owner = THIS_MODULE, - .driver_name = "liteuart", + .driver_name = DRV_NAME, .dev_name = "ttyLXU", .major = 0, .minor = 0, @@ -122,6 +124,7 @@ static unsigned int liteuart_get_mctrl(struct uart_port *port) static void liteuart_stop_tx(struct uart_port *port) { + /* not used in LiteUART, but called unconditionally from serial_core */ } static void liteuart_start_tx(struct uart_port *port) @@ -154,11 +157,6 @@ static void liteuart_stop_rx(struct uart_port *port) del_timer(&uart->timer); } -static void liteuart_break_ctl(struct uart_port *port, int break_state) -{ - /* LiteUART doesn't support sending break signal */ -} - static int liteuart_startup(struct uart_port *port) { struct liteuart_port *uart = to_liteuart_port(port); @@ -197,15 +195,6 @@ static const char *liteuart_type(struct uart_port *port) return "liteuart"; } -static void liteuart_release_port(struct uart_port *port) -{ -} - -static int liteuart_request_port(struct uart_port *port) -{ - return 0; -} - static void liteuart_config_port(struct uart_port *port, int flags) { /* @@ -232,13 +221,10 @@ static const struct uart_ops liteuart_ops = { .stop_tx = liteuart_stop_tx, .start_tx = liteuart_start_tx, .stop_rx = liteuart_stop_rx, - .break_ctl = liteuart_break_ctl, .startup = liteuart_startup, .shutdown = liteuart_shutdown, .set_termios = liteuart_set_termios, .type = liteuart_type, - .release_port = liteuart_release_port, - .request_port = liteuart_request_port, .config_port = liteuart_config_port, .verify_port = liteuart_verify_port, }; @@ -280,9 +266,7 @@ static int liteuart_probe(struct platform_device *pdev) port->iotype = UPIO_MEM; port->flags = UPF_BOOT_AUTOCONF; port->ops = &liteuart_ops; - port->regshift = 2; port->fifosize = 16; - port->iobase = 1; port->type = PORT_UNKNOWN; port->line = dev_id; spin_lock_init(&port->lock); @@ -322,7 +306,7 @@ static struct platform_driver liteuart_platform_driver = { .probe = liteuart_probe, .remove = liteuart_remove, .driver = { - .name = "liteuart", + .name = DRV_NAME, .of_match_table = liteuart_of_match, }, }; @@ -368,7 +352,7 @@ static int liteuart_console_setup(struct console *co, char *options) } static struct console liteuart_console = { - .name = "liteuart", + .name = DRV_NAME, .write = liteuart_console_write, .device = uart_console_device, .setup = liteuart_console_setup, @@ -416,12 +400,10 @@ static int __init liteuart_init(void) return res; res = platform_driver_register(&liteuart_platform_driver); - if (res) { + if (res) uart_unregister_driver(&liteuart_driver); - return res; - } - return 0; + return res; } static void __exit liteuart_exit(void) From patchwork Mon Nov 7 17:14:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel L. Somlo" X-Patchwork-Id: 16581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2180979wru; Mon, 7 Nov 2022 09:16:25 -0800 (PST) X-Google-Smtp-Source: AMsMyM4FRKh4OyWRi1ZpnypLmtvyHXgBnSgV7u7UN95oL5aiadja/21fZJ0LS4W+nJrWogsTJzN7 X-Received: by 2002:a17:903:11cd:b0:170:cde8:18b7 with SMTP id q13-20020a17090311cd00b00170cde818b7mr35281126plh.165.1667841384819; Mon, 07 Nov 2022 09:16:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667841384; cv=none; d=google.com; s=arc-20160816; b=cwxtLFBJOywgRhMbgadUCL5wiCbV7Ba8AhAlAl0edeBqiy6thlX3P98qnr64a27VRN i5LZUOPEmFrf9Ui8r2VsDuaA1ZR2e2VLNhdOQeLJkiOsFu8mt4WgB56/6eNfNkEKjZYS 4hY9lk9QVz9Qroz5W11qs3RHBAO+L8SMNvsAORMUtmhICuKUazsvCXGMfXs5+7y1t4GJ YuXkYuJaR+JKAqP1+nskhue61TSDe/ykT0tCu9ximO+vzpOtiyP4tW5Woa6G8UwN3R0r f4YdVBR6MNLHfSjpsaTRJS4xoy1B3SeA54y/jvAdHhGDYamaun2srPIyIZLAsms/+aif +3bg== 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=hjEUwtW5sL8GuJYm/+Q478PkR3HMmEg3Xukh/a9IkLc=; b=xgOQkhDVu2CuBPYs2F18JDaxR8Vgkk0unn127Jx/d3qGCjXVaUHJXgK+d9j2y3f5uh I1x/iVQgF/Wjp5SeJFt+LCVfp6Ws7xKR6OlxgLj7PIVNBzwgnMOyJQQ0xkaSMAFtlDxn zqaIMxH0EZSkkUDX+OSKAy/vrZnrlh7JNu0V+tNsHJFsCWsaNBycE62WoDatid1wuWkf a1Hckjv/C/lME5UT5gWRxoQ1a76D1UWrBUq0g49g+/EsV/TJaXvuEjRF2nfKiOlxGRBr /Q1mbMLhjA2Okkqbot7wBM8HLcJF1Py3OF+vuQEUfvF5GYyLQ5V4TW1tUvSjy7QwqeLV f7NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="L0wrRao/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u19-20020a63f653000000b0046086f8f5cfsi10641947pgj.383.2022.11.07.09.16.09; Mon, 07 Nov 2022 09:16:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="L0wrRao/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232568AbiKGRPV (ORCPT + 99 others); Mon, 7 Nov 2022 12:15:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232410AbiKGRPM (ORCPT ); Mon, 7 Nov 2022 12:15:12 -0500 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 600101C42C; Mon, 7 Nov 2022 09:15:11 -0800 (PST) Received: by mail-qk1-x72b.google.com with SMTP id x21so7585546qkj.0; Mon, 07 Nov 2022 09:15:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hjEUwtW5sL8GuJYm/+Q478PkR3HMmEg3Xukh/a9IkLc=; b=L0wrRao/Xut4IM2FaxKpjdKujuZ1Yf/LBQd1EzW1Cf9wkQFEhgfCW8YK6MlK3v61vR /3bv3OFywufm8UK0IVlu09o+MQj/1yuKMSKHe60jwYPpbbSd3qUDN5E49xmtt7e98Wag 58lb4NEWqLTpHccsT4IXzn0hCu1uYADu6SVKsaNP2Tvm8Emnphe0c1+eK9rWVn8IIkTl bDAdvB66h9WIX/BkwOFUMYO7NTPOGYoZF70dKMwVRqmv/e+V8Z94eIEFcoASri09l7y3 /iTJjoQwi5D8uvYidgsyseF6NjKjN1itj82bfdwOpeygbvOE6c0qXb9vMCRgtv6LEnvE BREQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hjEUwtW5sL8GuJYm/+Q478PkR3HMmEg3Xukh/a9IkLc=; b=kREje7zXbthYz+fzmvmzg9tluRVwAlUw8mgHpRtwWM98JaQfEV7qfAMKuDlOlhRNLe U9GyLRrpTlGhrXjuIesKWBuLoEtsendmE0RFzH/HDOgn5Fzmrg2Hj5ltBrQtmx1P9tc0 8ObDR1NSpiuCN7PJKnNBF50gFuiNqMx5Ggk4yTUUKysK5hyYKDE94eC7/vOLgtL+Ciw+ njVVOJONOaxGG+0OfWsJpFXuEwLZAqdAWUaPUQYdjm6P7SC5FObdlgMGbQfXBZBZmjC6 X9rSuMKBbSl/Z/JcUw4UnguSRJwsFdDYK4Mqa+q3kqWmUUlLZdVK2h/YSTsDi3PreCLv F3Mg== X-Gm-Message-State: ACrzQf2BJPpSoyv8RJEBQqy/b1rUEmZU/DiV4ztze3yobluH5Yg3TWl7 Udwd/8hBukG9gXwkXmEzv7NmjOkboVPNRA== X-Received: by 2002:a05:620a:12b5:b0:6fa:8a0c:ffd9 with SMTP id x21-20020a05620a12b500b006fa8a0cffd9mr13426265qki.518.1667841310142; Mon, 07 Nov 2022 09:15:10 -0800 (PST) Received: from glsvmlin.ini.cmu.edu (GLSVMLIN.INI.CMU.EDU. [128.2.16.9]) by smtp.gmail.com with ESMTPSA id az36-20020a05620a172400b006ce9e880c6fsm7333611qkb.111.2022.11.07.09.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 09:15:09 -0800 (PST) From: Gabriel Somlo To: linux-kernel@vger.kernel.org Cc: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, kgugala@antmicro.com, mholenko@antmicro.com, joel@jms.id.au, david.abdurachmanov@sifive.com, florent@enjoy-digital.fr Subject: [PATCH v1 2/3] serial: liteuart: separate RX loop from poll timer Date: Mon, 7 Nov 2022 12:14:59 -0500 Message-Id: <20221107171500.2537938-3-gsomlo@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221107171500.2537938-1-gsomlo@gmail.com> References: <20221107171500.2537938-1-gsomlo@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748858447630193988?= X-GMAIL-MSGID: =?utf-8?q?1748858447630193988?= Move the character-receive (RX) loop to its own dedicated function, and (for now) call that from the poll timer, liteuart_timer(). This is in preparation for adding IRQ support to the receive path. Signed-off-by: Gabriel Somlo --- drivers/tty/serial/liteuart.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/liteuart.c b/drivers/tty/serial/liteuart.c index 4b9cca249828..90a29ed79bff 100644 --- a/drivers/tty/serial/liteuart.c +++ b/drivers/tty/serial/liteuart.c @@ -69,29 +69,34 @@ static struct uart_driver liteuart_driver = { #endif }; -static void liteuart_timer(struct timer_list *t) +static void liteuart_rx_chars(struct uart_port *port) { - struct liteuart_port *uart = from_timer(uart, t, timer); - struct uart_port *port = &uart->port; unsigned char __iomem *membase = port->membase; - unsigned int flg = TTY_NORMAL; - int ch; - unsigned long status; + unsigned int status; + unsigned char ch; while ((status = !litex_read8(membase + OFF_RXEMPTY)) == 1) { ch = litex_read8(membase + OFF_RXTX); port->icount.rx++; /* necessary for RXEMPTY to refresh its value */ - litex_write8(membase + OFF_EV_PENDING, EV_TX | EV_RX); + litex_write8(membase + OFF_EV_PENDING, EV_RX); /* no overflow bits in status */ if (!(uart_handle_sysrq_char(port, ch))) - uart_insert_char(port, status, 0, ch, flg); - - tty_flip_buffer_push(&port->state->port); + uart_insert_char(port, status, 0, ch, TTY_NORMAL); } + tty_flip_buffer_push(&port->state->port); +} + +static void liteuart_timer(struct timer_list *t) +{ + struct liteuart_port *uart = from_timer(uart, t, timer); + struct uart_port *port = &uart->port; + + liteuart_rx_chars(port); + mod_timer(&uart->timer, jiffies + uart_poll_timeout(port)); } From patchwork Mon Nov 7 17:15:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel L. Somlo" X-Patchwork-Id: 16583 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2181179wru; Mon, 7 Nov 2022 09:16:45 -0800 (PST) X-Google-Smtp-Source: AMsMyM4nvmTvTl94MfEZ5k5Q9jKBcuE1M1bN79aHtrkNCet1r0K0923jm51r3inaoEJH8nmXNm2a X-Received: by 2002:a17:90a:f001:b0:213:bf4:ee29 with SMTP id bt1-20020a17090af00100b002130bf4ee29mr68752304pjb.98.1667841404823; Mon, 07 Nov 2022 09:16:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667841404; cv=none; d=google.com; s=arc-20160816; b=rRx4ZjuNh5KhsXWR/gyCG5N9fJyT0decKJH9Oi4S3J6pxbiryZcVLs0VhPjEBMaCfU HRHKS9hmux8pnB/xMPT4wNjw+HpDY1SmqPo312wys3DY+DQ5E4BEkF8b6QpFYSBnvTAC Dp/Z9vs/B2iJ7aZRg50La4iqYJwt/e58O+L64G0p7R159igcbsiawDre/uzE3dqVjJ/g WWFIUiBwLX3vEZoNHcqo4r/4Ra/qPNqXiyD9bzgtc9KZ/3rXgfoaSHYbbXb92AKum6tK KukDO3+O4xXFNk/9jp6X3iGa5yQdR+98UEQzbF9YaO2LwmuhW+V8zi5CavSKTXv5Ixo9 i0OA== 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=U5p80570qCVpx8wyPaQFV3qqLd7So3Af8EEHHd8G+ec=; b=Mu4ZyVrtQhnmcOje5mFnFgZHOeXJCfk2Fctr1IsuYyXncHya0k4Wjb69Qys0pHmNBu 0iP5k5BOEK7GVZv3vR+lJCOauor9rLDfTVOAHiMgkJVJMXN/MlYf/ICgFl42JxQgYCZq svTOLTerUgiqFzLaNdivbhmmjY6YhO4J5tmHbzNbXzAEvPiWTjtfKLQYnUvMrXjbxg3k hVrdFnUSMWOw30KUC7QaGMD0Q56w7eqkhDqAE54YCtqOictVlP8W2P8BvNBwmX8LeCGh U5686t5MMFdNrGO401fNTQG1V1AxKTgeeRZMM5Nf+jegMsrui9IMZW1pl1eofmjT/Fsk Mr6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g1n5ouBU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j22-20020aa78dd6000000b0056bc1d790ebsi9932747pfr.57.2022.11.07.09.16.32; Mon, 07 Nov 2022 09:16:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g1n5ouBU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232587AbiKGRPY (ORCPT + 99 others); Mon, 7 Nov 2022 12:15:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232075AbiKGRPO (ORCPT ); Mon, 7 Nov 2022 12:15:14 -0500 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 409BC220C9; Mon, 7 Nov 2022 09:15:13 -0800 (PST) Received: by mail-qk1-x732.google.com with SMTP id 8so7570008qka.1; Mon, 07 Nov 2022 09:15:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U5p80570qCVpx8wyPaQFV3qqLd7So3Af8EEHHd8G+ec=; b=g1n5ouBUfdzPqmzTo1aF2iinTR+GfBeVFFEgQhMtLO5h8ruxXyy5U1crM3BFJxWWv1 VOf3KKcBCvg4RmX/EpaHPD5V2OmYTroM7P1fRX68lKzwUiB61SdVc4e57PrhugminAHm Ogms5IDkF8M2raN0pblemV2DBoR9ZWOeBYKjziqFudJlBqkn/i/Q180IBEbpDrnpB/PF ILvzOPjLjl7xa3Em49vR3kF/RKevJl7DcQAxh4p6IVKmpCzqHQxFhlTezyDHBJHArpSQ z4biNg6nwayzIktBvMaFimFcEvrzn4N0X4mHTzjFAtB+uMCauuzY1ULy8a7uKPMqsTVi fWVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U5p80570qCVpx8wyPaQFV3qqLd7So3Af8EEHHd8G+ec=; b=pmrYQJanWODME+yindp2rNzZwmNN7h9eWBmFQY8fECYHyPhif26qdoxLKIeSbCy6A2 9704+Zr2rIUewdrACYtjw0O3mNp1vjnRyxj5zsDuijzGBcThxmXImBSchAXHIW4MVVKR 0JhfoH+pOfgvbiGH4gaOrg3DtmRQFZhnY5lMfbtmLcVKWynisx0/pLyq10dk2RDnos3T jYmct67zIK/CgboYSIpZKL1DVmo3EBHebbVg/y02Fl7Ylc+I3ESHOTG6aIKwzdLpkfTu 6GWq2H9PqMUbQNwBjZgXOOggjuEz030gFD64QciFVhQ9EUcleU52tAQQLYbCPWNna83n BZtA== X-Gm-Message-State: ACrzQf0Ko8FDMMnhrcTdeTM0vkqs7iAg2EcJC0/W+Wv+O8FWudWB1x94 IPClGEapzxIV9xFIBAM2o1jYNVj5Od67Bw== X-Received: by 2002:a05:620a:f15:b0:6cf:1efa:3705 with SMTP id v21-20020a05620a0f1500b006cf1efa3705mr36279978qkl.439.1667841311795; Mon, 07 Nov 2022 09:15:11 -0800 (PST) Received: from glsvmlin.ini.cmu.edu (GLSVMLIN.INI.CMU.EDU. [128.2.16.9]) by smtp.gmail.com with ESMTPSA id az36-20020a05620a172400b006ce9e880c6fsm7333611qkb.111.2022.11.07.09.15.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 09:15:11 -0800 (PST) From: Gabriel Somlo To: linux-kernel@vger.kernel.org Cc: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, kgugala@antmicro.com, mholenko@antmicro.com, joel@jms.id.au, david.abdurachmanov@sifive.com, florent@enjoy-digital.fr Subject: [PATCH v1 3/3] serial: liteuart: add IRQ support Date: Mon, 7 Nov 2022 12:15:00 -0500 Message-Id: <20221107171500.2537938-4-gsomlo@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221107171500.2537938-1-gsomlo@gmail.com> References: <20221107171500.2537938-1-gsomlo@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748858427175414270?= X-GMAIL-MSGID: =?utf-8?q?1748858468890423571?= Add support for IRQ-driven RX. The TX path remains "polling" based, which is fine since TX is synchronous. Signed-off-by: Gabriel Somlo --- drivers/tty/serial/liteuart.c | 65 +++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serial/liteuart.c b/drivers/tty/serial/liteuart.c index 90a29ed79bff..47ce3ecc50f2 100644 --- a/drivers/tty/serial/liteuart.c +++ b/drivers/tty/serial/liteuart.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -90,13 +91,27 @@ static void liteuart_rx_chars(struct uart_port *port) tty_flip_buffer_push(&port->state->port); } +static irqreturn_t liteuart_interrupt(int irq, void *data) +{ + struct uart_port *port = data; + unsigned int isr; + + isr = litex_read32(port->membase + OFF_EV_PENDING); + + spin_lock(&port->lock); + if (isr & EV_RX) + liteuart_rx_chars(port); + spin_unlock(&port->lock); + + return IRQ_RETVAL(isr); +} + static void liteuart_timer(struct timer_list *t) { struct liteuart_port *uart = from_timer(uart, t, timer); struct uart_port *port = &uart->port; - liteuart_rx_chars(port); - + liteuart_interrupt(0, port); mod_timer(&uart->timer, jiffies + uart_poll_timeout(port)); } @@ -165,19 +180,48 @@ static void liteuart_stop_rx(struct uart_port *port) static int liteuart_startup(struct uart_port *port) { struct liteuart_port *uart = to_liteuart_port(port); + unsigned long flags; + int ret; + u8 irq_mask = 0; - /* disable events */ - litex_write8(port->membase + OFF_EV_ENABLE, 0); + if (port->irq) { + ret = request_irq(port->irq, liteuart_interrupt, 0, + DRV_NAME, port); + if (ret == 0) { + /* we only need interrupts on the rx path! */ + irq_mask = EV_RX; + } else { + pr_err(DRV_NAME ": can't attach LiteUART %d irq=%d; " + "switching to polling\n", port->line, port->irq); + port->irq = 0; + } + } - /* prepare timer for polling */ - timer_setup(&uart->timer, liteuart_timer, 0); - mod_timer(&uart->timer, jiffies + uart_poll_timeout(port)); + if (!port->irq) { + timer_setup(&uart->timer, liteuart_timer, 0); + mod_timer(&uart->timer, jiffies + uart_poll_timeout(port)); + } + + spin_lock_irqsave(&port->lock, flags); + litex_write8(port->membase + OFF_EV_ENABLE, irq_mask); + spin_unlock_irqrestore(&port->lock, flags); return 0; } static void liteuart_shutdown(struct uart_port *port) { + struct liteuart_port *uart = to_liteuart_port(port); + unsigned long flags; + + spin_lock_irqsave(&port->lock, flags); + litex_write8(port->membase + OFF_EV_ENABLE, 0); + spin_unlock_irqrestore(&port->lock, flags); + + if (port->irq) + free_irq(port->irq, port); + else + del_timer_sync(&uart->timer); } static void liteuart_set_termios(struct uart_port *port, struct ktermios *new, @@ -266,6 +310,13 @@ static int liteuart_probe(struct platform_device *pdev) goto err_erase_id; } + /* get irq */ + ret = platform_get_irq_optional(pdev, 0); + if (ret < 0 && ret != -ENXIO) + return ret; + if (ret > 0) + port->irq = ret; + /* values not from device tree */ port->dev = &pdev->dev; port->iotype = UPIO_MEM;