From patchwork Wed Oct 4 06:26:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 148154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp2558540vqb; Tue, 3 Oct 2023 23:27:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9ECx3CYEuJzD0RKHeJTzzWcXDZKgNUNAo88NRPlRChwGI1sBlGQitY5MQRqw+qk+jqFX2 X-Received: by 2002:a05:6a21:2703:b0:13d:17cc:5bca with SMTP id rm3-20020a056a21270300b0013d17cc5bcamr1150405pzb.18.1696400824435; Tue, 03 Oct 2023 23:27:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696400824; cv=none; d=google.com; s=arc-20160816; b=s+44uy2Sx7kVdelxYmSZO35ei8IRYgvU/zS4SyXasVQlpl0PyIsWEE1miMC36+fQzv 36TLlx2zxSTHjuYc9H6kgQW0A8wCtd9/IWYZBzX3+A5xOFs/YwKtuOfNCCeG4zm5kom3 snfknGZvA9J88DDTnNx+wK20TTNaiICewBgGtyiRKMJqJUslRPfyZlp1PrL5Bcy6otbk 9QFi6C4IsCjKAU2qtmuCUKoFJy5hlFzK35ybe7f2QVGwRb4g3ObvZoS9IPDAePYewBBy 1mUSRlTAfKhpgxwIPPhLYhGASHz9i6FCDV1HxwAfxIsJBv2yvDMT9sfjSzAENEStUJHC qpNA== 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 :message-id:date:subject:cc:to:from; bh=l1TwcSDIWh49UwurNPk++bOhY+A4otdhFsTftAvXi24=; fh=n7dM+f7LjYuLx+o4gzxXNkEWC9u7qeJi6cmcRDZcVew=; b=uaODxqA92x9wid4md/Fa5RiBh8PTT2aXXwmUgoVEfR9sGHpfWDhuczT4lgExg5lziP n3mglSN5+mw5SrgKq2Gibad5UWAHgjmJWmc184lsoBYSQSVjJ3nDL9O4aaO+t3k6jGua tRhLrKRvHLief0eShEiyzoUB47a9nl/1k8YawnLUAK0pJ6PpfbIsxZvOLG8G9pyen/9m WP6i1cDL9AzmIxTROmYNZqSYlTo+56TkZ87vJXbDcr0LTjDBbUMJoLvaWgK3D95VHAKi csFEfDbSs2ZPIlT7/eb6BgANtFN2/5osbADBwuELbhmcvK0wn++puR5QMhkxzd1bh3yc SHVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d9-20020a170902cec900b001bc5a4f56fcsi3280119plg.554.2023.10.03.23.27.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 23:27:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CEE1581CC85A; Tue, 3 Oct 2023 23:27:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241377AbjJDG1B (ORCPT + 17 others); Wed, 4 Oct 2023 02:27:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241384AbjJDG1A (ORCPT ); Wed, 4 Oct 2023 02:27:00 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 41B5EAF; Tue, 3 Oct 2023 23:26:57 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 1480F80BD; Wed, 4 Oct 2023 06:26:54 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , Dhruva Gole , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , John Ogness , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v2 1/1] serial: 8250_omap: Drop pm_runtime_irq_safe() Date: Wed, 4 Oct 2023 09:26:48 +0300 Message-ID: <20231004062650.64487-1-tony@atomide.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 03 Oct 2023 23:27:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778805191184768054 X-GMAIL-MSGID: 1778805191184768054 Let's drop the use of pm_runtime_irq_safe() for 8250_omap. The use of pm_runtime_irq_safe() is not nice as it takes a permanent usage count on the parent device. We can finally drop pm_runtime_irq_safe() safely as the kernel now knows when the uart port tx is active. This changed with commit 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM"). For serial port rx, we already use Linux generic wakeirqs for 8250_omap. To drop pm_runtime_irq_safe(), we need to add handling for shallow idle state where the port hardware may already be awake and an IO interrupt happens. We also need to replace the serial8250_rpm sync calls in the interrupt handlers with async runtime PM calls. Note that omap8250_irq() calls omap_8250_dma_handle_irq(), so we don't need separate runtime PM calls in omap_8250_dma_handle_irq(). While at it, let's also add the missing line break to the end of omap8250_runtime_resume() to group the calls. Signed-off-by: Tony Lindgren Reviewed-by: Andy Shevchenko --- Changes since v1: - Fix build warning if CONFIG_SERIAL_8250_DMA is not set as reported by kernel test robot --- drivers/tty/serial/8250/8250_omap.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -8,6 +8,7 @@ * */ +#include #include #include #include @@ -130,6 +131,7 @@ struct omap8250_priv { u8 tx_trigger; u8 rx_trigger; + atomic_t active; bool is_suspending; int wakeirq; int wakeups_enabled; @@ -632,14 +634,23 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id) unsigned int iir, lsr; int ret; + pm_runtime_get_noresume(port->dev); + + /* Shallow idle state wake-up to an IO interrupt? */ + if (atomic_add_unless(&priv->active, 1, 1)) { + priv->latency = priv->calc_latency; + schedule_work(&priv->qos_work); + } + #ifdef CONFIG_SERIAL_8250_DMA if (up->dma) { ret = omap_8250_dma_handle_irq(port); + pm_runtime_mark_last_busy(port->dev); + pm_runtime_put(port->dev); return IRQ_RETVAL(ret); } #endif - serial8250_rpm_get(up); lsr = serial_port_in(port, UART_LSR); iir = serial_port_in(port, UART_IIR); ret = serial8250_handle_irq(port, iir); @@ -676,7 +687,8 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id) schedule_delayed_work(&up->overrun_backoff, delay); } - serial8250_rpm_put(up); + pm_runtime_mark_last_busy(port->dev); + pm_runtime_put(port->dev); return IRQ_RETVAL(ret); } @@ -1270,11 +1282,8 @@ static int omap_8250_dma_handle_irq(struct uart_port *port) u16 status; u8 iir; - serial8250_rpm_get(up); - iir = serial_port_in(port, UART_IIR); if (iir & UART_IIR_NO_INT) { - serial8250_rpm_put(up); return IRQ_HANDLED; } @@ -1305,7 +1314,6 @@ static int omap_8250_dma_handle_irq(struct uart_port *port) uart_unlock_and_check_sysrq(port); - serial8250_rpm_put(up); return 1; } @@ -1503,8 +1511,6 @@ static int omap8250_probe(struct platform_device *pdev) if (!of_get_available_child_count(pdev->dev.of_node)) pm_runtime_set_autosuspend_delay(&pdev->dev, -1); - pm_runtime_irq_safe(&pdev->dev); - pm_runtime_get_sync(&pdev->dev); omap_serial_fill_features_erratas(&up, priv); @@ -1743,6 +1749,7 @@ static int omap8250_runtime_suspend(struct device *dev) priv->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; schedule_work(&priv->qos_work); + atomic_set(&priv->active, 0); return 0; } @@ -1752,6 +1759,10 @@ static int omap8250_runtime_resume(struct device *dev) struct omap8250_priv *priv = dev_get_drvdata(dev); struct uart_8250_port *up = NULL; + /* Did the hardware wake to a device IO interrupt before a wakeirq? */ + if (atomic_read(&priv->active)) + return 0; + if (priv->line >= 0) up = serial8250_get_port(priv->line); @@ -1767,8 +1778,10 @@ static int omap8250_runtime_resume(struct device *dev) uart_port_unlock_irq(&up->port); } + atomic_set(&priv->active, 1); priv->latency = priv->calc_latency; schedule_work(&priv->qos_work); + return 0; }