From patchwork Tue Sep 21 10:33:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 12507557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A678C433FE for ; Tue, 21 Sep 2021 10:33:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 410FE6112F for ; Tue, 21 Sep 2021 10:33:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231887AbhIUKfY (ORCPT ); Tue, 21 Sep 2021 06:35:24 -0400 Received: from muru.com ([72.249.23.125]:35518 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231823AbhIUKfY (ORCPT ); Tue, 21 Sep 2021 06:35:24 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 3FF7E8127; Tue, 21 Sep 2021 10:34:22 +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 1/6] n_tty: Start making use of -EAGAIN returned from process_output_block() Date: Tue, 21 Sep 2021 13:33:41 +0300 Message-Id: <20210921103346.64824-2-tony@atomide.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210921103346.64824-1-tony@atomide.com> References: <20210921103346.64824-1-tony@atomide.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org We check for -EAGAIN in n_tty_write() but never currently get it from process_output_block(). Let's add -EAGAIN handling and break out with 0 bytes processed. Note that if we return -EAGAIN from n_tty_write(), it will be treated as error by the caller rather than a retry. Looking at the patch description for commit 9ef8927f45f2 ("n_tty: check for negative and zero space return from tty_write_room") it looks like we have not made use of -EGAIN from process_output_block() so far, so this does not seem like it's currently needed as a fix. We can use -EAGAIN for serial layer power management changes as we now will make use of write_room() returning 0 for an idled serial port. Signed-off-by: Tony Lindgren --- drivers/tty/n_tty.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -549,6 +549,8 @@ static ssize_t process_output_block(struct tty_struct *tty, space = tty_write_room(tty); if (space <= 0) { mutex_unlock(&ldata->output_lock); + if (!space) + space = -EAGAIN; return space; } if (nr > space) @@ -2287,8 +2289,10 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, while (nr > 0) { ssize_t num = process_output_block(tty, b, nr); if (num < 0) { - if (num == -EAGAIN) - break; + if (num == -EAGAIN) { + retval = 0; + goto break_out; + } retval = num; goto break_out; } From patchwork Tue Sep 21 10:33:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 12507559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3315C433FE for ; Tue, 21 Sep 2021 10:34:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B3C160FC1 for ; Tue, 21 Sep 2021 10:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231939AbhIUKf1 (ORCPT ); Tue, 21 Sep 2021 06:35:27 -0400 Received: from muru.com ([72.249.23.125]:35522 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231823AbhIUKf0 (ORCPT ); Tue, 21 Sep 2021 06:35:26 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 37951812F; Tue, 21 Sep 2021 10:34:24 +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/6] tty: n_gsm: Don't ignore write return value in gsmld_output() Date: Tue, 21 Sep 2021 13:33:42 +0300 Message-Id: <20210921103346.64824-3-tony@atomide.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210921103346.64824-1-tony@atomide.com> References: <20210921103346.64824-1-tony@atomide.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org We currently have gsmld_output() ignore the return value from device write. This means we will lose packets if device write returns 0 or an error. Signed-off-by: Tony Lindgren --- drivers/tty/n_gsm.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -687,7 +687,7 @@ static void gsm_data_kick(struct gsm_mux *gsm, struct gsm_dlci *dlci) print_hex_dump_bytes("gsm_data_kick: ", DUMP_PREFIX_OFFSET, gsm->txframe, len); - if (gsmld_output(gsm, gsm->txframe, len) < 0) + if (gsmld_output(gsm, gsm->txframe, len) <= 0) break; /* FIXME: Can eliminate one SOF in many more cases */ gsm->tx_bytes -= msg->len; @@ -2358,8 +2358,7 @@ static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len) if (debug & 4) print_hex_dump_bytes("gsmld_output: ", DUMP_PREFIX_OFFSET, data, len); - gsm->tty->ops->write(gsm->tty, data, len); - return len; + return gsm->tty->ops->write(gsm->tty, data, len); } /** From patchwork Tue Sep 21 10:33:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 12507561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 182B5C4332F for ; Tue, 21 Sep 2021 10:34:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 017E661038 for ; Tue, 21 Sep 2021 10:34:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231986AbhIUKf2 (ORCPT ); Tue, 21 Sep 2021 06:35:28 -0400 Received: from muru.com ([72.249.23.125]:35532 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231927AbhIUKf2 (ORCPT ); Tue, 21 Sep 2021 06:35:28 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 0B4F380A8; Tue, 21 Sep 2021 10:34:25 +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 3/6] serial: core: Add new prep_tx for power management Date: Tue, 21 Sep 2021 13:33:43 +0300 Message-Id: <20210921103346.64824-4-tony@atomide.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210921103346.64824-1-tony@atomide.com> References: <20210921103346.64824-1-tony@atomide.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org If the serial driver implements PM runtime with autosuspend, the port may be powered off for TX. To wake up the port, let's add new prep_tx() call for serial drivers to implement as needed. We call it from serial write_room() and write() functions. If the serial port is not enabled, we just return 0. Signed-off-by: Tony Lindgren --- Documentation/driver-api/serial/driver.rst | 9 +++++++++ drivers/tty/serial/serial_core.c | 23 ++++++++++++++++++++++ include/linux/serial_core.h | 1 + 3 files changed, 33 insertions(+) diff --git a/Documentation/driver-api/serial/driver.rst b/Documentation/driver-api/serial/driver.rst --- a/Documentation/driver-api/serial/driver.rst +++ b/Documentation/driver-api/serial/driver.rst @@ -136,6 +136,15 @@ hardware. This call must not sleep + prep_tx(port) + Prepare port for transmitting characters. + + Locking: port->lock taken. + + Interrupts: locally disabled. + + This call must not sleep + start_tx(port) Start transmitting characters. diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -118,6 +118,17 @@ static void uart_stop(struct tty_struct *tty) uart_port_unlock(port, flags); } +static int __uart_prep_tx(struct tty_struct *tty) +{ + struct uart_state *state = tty->driver_data; + struct uart_port *port = state->uart_port; + + if (port && !uart_tx_stopped(port) && port->ops->prep_tx) + return port->ops->prep_tx(port); + + return 0; +} + static void __uart_start(struct tty_struct *tty) { struct uart_state *state = tty->driver_data; @@ -574,6 +585,12 @@ static int uart_write(struct tty_struct *tty, return 0; } + ret = __uart_prep_tx(tty); + if (ret < 0) { + uart_port_unlock(port, flags); + return 0; + } + while (port) { c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE); if (count < c) @@ -600,6 +617,12 @@ static unsigned int uart_write_room(struct tty_struct *tty) unsigned int ret; port = uart_port_lock(state, flags); + ret = __uart_prep_tx(tty); + if (ret < 0) { + uart_port_unlock(port, flags); + return 0; + } + ret = uart_circ_chars_free(&state->xmit); uart_port_unlock(port, flags); return ret; diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -40,6 +40,7 @@ struct uart_ops { void (*set_mctrl)(struct uart_port *, unsigned int mctrl); unsigned int (*get_mctrl)(struct uart_port *); void (*stop_tx)(struct uart_port *); + int (*prep_tx)(struct uart_port *); void (*start_tx)(struct uart_port *); void (*throttle)(struct uart_port *); void (*unthrottle)(struct uart_port *); From patchwork Tue Sep 21 10:33:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 12507563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ADFFC433FE for ; Tue, 21 Sep 2021 10:34:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22C5661038 for ; Tue, 21 Sep 2021 10:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232130AbhIUKfg (ORCPT ); Tue, 21 Sep 2021 06:35:36 -0400 Received: from muru.com ([72.249.23.125]:35542 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232000AbhIUKfa (ORCPT ); Tue, 21 Sep 2021 06:35:30 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 118A38127; Tue, 21 Sep 2021 10:34:27 +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 4/6] serial: 8250: Implement prep_tx for power management Date: Tue, 21 Sep 2021 13:33:44 +0300 Message-Id: <20210921103346.64824-5-tony@atomide.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210921103346.64824-1-tony@atomide.com> References: <20210921103346.64824-1-tony@atomide.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org We can use the prep_tx() call to wake up an idle serial port. This allows ust to remove the depedency to pm_runtime_irq_safe() for 8250_omap driver in the following patches. Signed-off-by: Tony Lindgren --- drivers/tty/serial/8250/8250_port.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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 @@ -1650,6 +1650,29 @@ static enum hrtimer_restart serial8250_em485_handle_start_tx(struct hrtimer *t) return HRTIMER_NORESTART; } +static int serial8250_prep_tx(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 (!pm_runtime_suspended(dev)) { + pm_runtime_mark_last_busy(dev); + return 0; + } + + err = pm_request_resume(dev); + if (err < 0) { + dev_warn(dev, "prep_tx wakeup failed: %d\n", err); + return err; + } + + return -EINPROGRESS; +} + static void serial8250_start_tx(struct uart_port *port) { struct uart_8250_port *up = up_to_u8250p(port); @@ -3227,6 +3250,7 @@ static const struct uart_ops serial8250_pops = { .set_mctrl = serial8250_set_mctrl, .get_mctrl = serial8250_get_mctrl, .stop_tx = serial8250_stop_tx, + .prep_tx = serial8250_prep_tx, .start_tx = serial8250_start_tx, .throttle = serial8250_throttle, .unthrottle = serial8250_unthrottle, From patchwork Tue Sep 21 10:33:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 12507565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F674C4332F for ; Tue, 21 Sep 2021 10:34:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BE7E61038 for ; Tue, 21 Sep 2021 10:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232029AbhIUKfh (ORCPT ); Tue, 21 Sep 2021 06:35:37 -0400 Received: from muru.com ([72.249.23.125]:35554 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231799AbhIUKfc (ORCPT ); Tue, 21 Sep 2021 06:35:32 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 052B68132; Tue, 21 Sep 2021 10:34:29 +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 5/6] serial: 8250_omap: Require a valid wakeirq for deeper idle states Date: Tue, 21 Sep 2021 13:33:45 +0300 Message-Id: <20210921103346.64824-6-tony@atomide.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210921103346.64824-1-tony@atomide.com> References: <20210921103346.64824-1-tony@atomide.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org For deeper idle states the 8250 device gets powered off. The wakeup is handled with a separate wakeirq controller monitoring the RX pin. Let's check for a valid wakeirq before enabling deeper idle states. Signed-off-by: Tony Lindgren --- drivers/tty/serial/8250/8250_omap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 @@ -133,6 +133,7 @@ struct omap8250_priv { spinlock_t rx_dma_lock; bool rx_dma_broken; bool throttled; + unsigned int allow_rpm:1; }; struct omap8250_dma_params { @@ -676,6 +677,7 @@ static int omap_8250_startup(struct uart_port *port) ret = dev_pm_set_dedicated_wake_irq(port->dev, priv->wakeirq); if (ret) return ret; + priv->allow_rpm = 1; } pm_runtime_get_sync(port->dev); @@ -722,6 +724,10 @@ static int omap_8250_startup(struct uart_port *port) if (up->dma && !(priv->habit & UART_HAS_EFR2)) up->dma->rx_dma(up); + /* Block runtime PM if no wakeirq, paired with shutdown */ + if (!priv->allow_rpm) + pm_runtime_get(port->dev); + pm_runtime_mark_last_busy(port->dev); pm_runtime_put_autosuspend(port->dev); return 0; @@ -760,6 +766,10 @@ static void omap_8250_shutdown(struct uart_port *port) serial_out(up, UART_LCR, up->lcr & ~UART_LCR_SBC); serial_out(up, UART_FCR, UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); + /* Clear possible PM runtime block to pair with startup */ + if (!priv->allow_rpm) + pm_runtime_put(port->dev); + pm_runtime_mark_last_busy(port->dev); pm_runtime_put_autosuspend(port->dev); free_irq(port->irq, port); From patchwork Tue Sep 21 10:33:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 12507567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 382D8C433F5 for ; Tue, 21 Sep 2021 10:34:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24C8161038 for ; Tue, 21 Sep 2021 10:34:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232060AbhIUKfi (ORCPT ); Tue, 21 Sep 2021 06:35:38 -0400 Received: from muru.com ([72.249.23.125]:35568 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232076AbhIUKfe (ORCPT ); Tue, 21 Sep 2021 06:35:34 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 11D6E812F; Tue, 21 Sep 2021 10:34:31 +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 6/6] serial: 8250_omap: Drop the use of pm_runtime_irq_safe() Date: Tue, 21 Sep 2021 13:33:46 +0300 Message-Id: <20210921103346.64824-7-tony@atomide.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210921103346.64824-1-tony@atomide.com> References: <20210921103346.64824-1-tony@atomide.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org We already have the serial layer RX wake path fixed for power management. We no longer allow deeper idle states unless the kernel console has been detached, and we require that the RX wakeirq is configured. For TX path, we may have the serial port autoidled, and need to wake it up before writing to it. With the serial_core prep_tx() changes, we can finally drop the dependency to pm_runtime_irq_safe() for 8250_omap driver. To drop pm_runtime_irq_safe(), we remove all PM runtime calls from the interrupt context. If we ever see an interrupt for an idled port, we just bail out. We now also need to restore the port context with interrupts disabled to prevent interrupts from happening while restoring the port. Signed-off-by: Tony Lindgren --- drivers/tty/serial/8250/8250_omap.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 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 @@ -134,6 +134,7 @@ struct omap8250_priv { bool rx_dma_broken; bool throttled; unsigned int allow_rpm:1; + unsigned int clocks_off:1; }; struct omap8250_dma_params { @@ -621,6 +622,9 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id) unsigned int iir, lsr; int ret; + if (priv->clocks_off) + return IRQ_NONE; + #ifdef CONFIG_SERIAL_8250_DMA if (up->dma) { ret = omap_8250_dma_handle_irq(port); @@ -628,7 +632,6 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id) } #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); @@ -662,8 +665,6 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id) schedule_delayed_work(&up->overrun_backoff, delay); } - serial8250_rpm_put(up); - return IRQ_RETVAL(ret); } @@ -1191,13 +1192,9 @@ static int omap_8250_dma_handle_irq(struct uart_port *port) unsigned char status; u8 iir; - serial8250_rpm_get(up); - iir = serial_port_in(port, UART_IIR); - if (iir & UART_IIR_NO_INT) { - serial8250_rpm_put(up); + if (iir & UART_IIR_NO_INT) return IRQ_HANDLED; - } spin_lock(&port->lock); @@ -1226,7 +1223,6 @@ static int omap_8250_dma_handle_irq(struct uart_port *port) uart_unlock_and_check_sysrq(port); - serial8250_rpm_put(up); return 1; } @@ -1420,8 +1416,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); @@ -1637,6 +1631,8 @@ static int omap8250_runtime_suspend(struct device *dev) omap_8250_rx_dma_flush(up); priv->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; + priv->clocks_off = 1; + schedule_work(&priv->qos_work); return 0; @@ -1646,13 +1642,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); @@ -1660,6 +1661,9 @@ static int omap8250_runtime_resume(struct device *dev) omap_8250_rx_dma(up); priv->latency = priv->calc_latency; + priv->clocks_off = 0; + spin_unlock_irqrestore(&port->lock, flags); + schedule_work(&priv->qos_work); return 0; }