Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp650966pxb; Fri, 15 Oct 2021 13:04:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEnLFbdqjFVK2Xf1h5xrh3uQwexHN43lCvmRAATVDkycYlFk5ifgsv/jKzvD5+1P+N+bMw X-Received: by 2002:aa7:8609:0:b0:44b:346a:7404 with SMTP id p9-20020aa78609000000b0044b346a7404mr13857156pfn.86.1634328265998; Fri, 15 Oct 2021 13:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634328265; cv=none; d=google.com; s=arc-20160816; b=dutz9Orl1eEPI2/t3jUmOknhsDpK562Jr/xOuRlQZKBfwwjNO1xKxh/2rjhafEBea/ aN2V1y8SnYQqCgJUSRyQ3sOLYgtHoQrPVgzgtfdErTDY5Gow5XbM5oPxZBr3bE/t2lNB TVbVUW4BkKakQesw338kMHE+1A7Xf70fbV7ZIop2FxIUZ+ACH3y+luQQeAWwsLoA7vPx /m2QbPLlLkapJlQDC28nemorE7c+eeLVVuHla1xQ85Jc4ONzS2Lv1GGRD/8H9kzNVBC2 ZJ2nbj53u61zj3g0csIrTYO5Xux2yyvYAeSSyeiNmistZVp6HGQTV9SPxJ3KVaPTffXQ Qlew== 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; bh=3ItIS6tonKyJxuyILArX6aabCuYY3S8m+JZ9oJewJcI=; b=nhEvsHjurHE8vNVrtNGatddqFE5E7IKl5s1rCpqo9hGS3yr3oImHcu6xCEn+2lZv7q rAEcO4L/QkaxbESqMVvJ9eIG5Xcsj0gE/iZR2ovsjkU3NfzeuQMWFFDnRp9LNqP/IjpT M11u5hxWHsbx4PCmp/Jpy8fJ3WkbSa/RMCiqPEyZLaNdEx4oWJA9ORmyTDBlzJXS/25D aFzDt3eA9u9dwvHiK050DOQEOLv++PtI0mKT9JYyCArWhEVJuzWfzsgryvukzXyFx4oO eF7k1T4XvIhOjnh/fPSfBVHLcPUTCWb6uvIrYyf7YM12pkp4nkLE4tF8TqeOzxUJMtYU 1Rhg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si10048180plh.55.2021.10.15.13.03.49; Fri, 15 Oct 2021 13:04:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238517AbhJOL2v (ORCPT + 99 others); Fri, 15 Oct 2021 07:28:51 -0400 Received: from muru.com ([72.249.23.125]:44962 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238514AbhJOL2n (ORCPT ); Fri, 15 Oct 2021 07:28:43 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id DFA6380F1; Fri, 15 Oct 2021 11:27:07 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman Cc: Andy Shevchenko , Jiri Slaby , Johan Hovold , Vignesh Raghavendra , linux-serial@vger.kernel.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] serial: 8250: Implement wakeup for TX and use it for 8250_omap Date: Fri, 15 Oct 2021 14:26:24 +0300 Message-Id: <20211015112626.35359-3-tony@atomide.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211015112626.35359-1-tony@atomide.com> References: <20211015112626.35359-1-tony@atomide.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We can use the wakeup() and uart_start_pending_tx() calls to wake up an idle serial port and send out the pending TX buffer on runtime PM resume. This allows us to remove the dependency to pm_runtime_irq_safe() for 8250_omap driver in the following patches. We manage the port runtime_suspended flag in the serial port driver as only the driver knows when the hardware is runtime PM suspended. Note that The current flag for rpm_tx_active cannot be used as it is TX specific for 8250_port. We already have serial8250_start_tx() call serial8250_rpm_get_tx(), and serial8250_stop_tx() call serial8250_rpm_put_tx() to take care of the runtime PM usage count for TX. To have the serial port driver call uart_start_pending_tx() on runtime resume, we must now use just pm_runtime_get() for serial8250_start_tx() instead of the sync version. With these changes we must now also flip the 8250_omap driver over to call uart_start_pending_tx(). That's currently the only user of UART_CAP_RPM. Signed-off-by: Tony Lindgren --- drivers/tty/serial/8250/8250_omap.c | 19 ++++++++++++++ drivers/tty/serial/8250/8250_port.c | 39 ++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) 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 @@ -1593,12 +1593,16 @@ static int omap8250_runtime_suspend(struct device *dev) { struct omap8250_priv *priv = dev_get_drvdata(dev); struct uart_8250_port *up; + struct uart_port *port; + unsigned long flags; /* In case runtime-pm tries this before we are setup */ if (!priv) return 0; up = serial8250_get_port(priv->line); + port = &up->port; + /* * When using 'no_console_suspend', the console UART must not be * suspended. Since driver suspend is managed by runtime suspend, @@ -1610,6 +1614,10 @@ static int omap8250_runtime_suspend(struct device *dev) return -EBUSY; } + spin_lock_irqsave(&port->lock, flags); + port->runtime_suspended = 1; + spin_unlock_irqrestore(&port->lock, flags); + if (priv->habit & UART_ERRATA_CLOCK_DISABLE) { int ret; @@ -1636,13 +1644,18 @@ static int omap8250_runtime_resume(struct device *dev) { struct omap8250_priv *priv = dev_get_drvdata(dev); struct uart_8250_port *up; + struct uart_port *port; + unsigned long flags; /* In case runtime-pm tries this before we are setup */ if (!priv) return 0; up = serial8250_get_port(priv->line); + port = &up->port; + /* Restore state with interrupts disabled */ + spin_lock_irqsave(&port->lock, flags); if (omap8250_lost_context(up)) omap8250_restore_regs(up); @@ -1651,6 +1664,12 @@ static int omap8250_runtime_resume(struct device *dev) priv->latency = priv->calc_latency; schedule_work(&priv->qos_work); + + port->runtime_suspended = 0; + spin_unlock_irqrestore(&port->lock, flags); + + uart_start_pending_tx(port); + return 0; } #endif diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -724,7 +724,7 @@ void serial8250_rpm_get_tx(struct uart_8250_port *p) rpm_active = xchg(&p->rpm_tx_active, 1); if (rpm_active) return; - pm_runtime_get_sync(p->port.dev); + pm_runtime_get(p->port.dev); } EXPORT_SYMBOL_GPL(serial8250_rpm_get_tx); @@ -2507,6 +2507,42 @@ static void serial8250_shutdown(struct uart_port *port) serial8250_do_shutdown(port); } +/* + * Wakes up the serial port if it has been runtime PM suspended. + * + * Note that we rely on the serial8250_rpm functions to manage the + * runtime PM usage count. We also currently depend on the runtime + * PM autosuspend timeout to keep the port awake until start_tx(). + * Eventually we should just use runtime PM functions and not rely + * on the autosuspend timeout. + * + * Caller must hold port->lock for port->runtime_suspended status. + * Also the port drivers must hold port->lock when changing the + * state for port->runtime_suspended in runtime PM functions. + */ +static int serial8250_wakeup(struct uart_port *port) +{ + struct uart_8250_port *up = up_to_u8250p(port); + struct device *dev = up->port.dev; + int err; + + if (!(up->capabilities & UART_CAP_RPM)) + return 0; + + if (!port->runtime_suspended) { + pm_runtime_mark_last_busy(dev); + return 0; + } + + err = pm_request_resume(dev); + if (err < 0) { + dev_warn(dev, "wakeup failed: %d\n", err); + return err; + } + + return -EINPROGRESS; +} + /* Nuvoton NPCM UARTs have a custom divisor calculation */ static unsigned int npcm_get_divisor(struct uart_8250_port *up, unsigned int baud) @@ -3235,6 +3271,7 @@ static const struct uart_ops serial8250_pops = { .break_ctl = serial8250_break_ctl, .startup = serial8250_startup, .shutdown = serial8250_shutdown, + .wakeup = serial8250_wakeup, .set_termios = serial8250_set_termios, .set_ldisc = serial8250_set_ldisc, .pm = serial8250_pm, -- 2.33.0