Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4591914pxj; Wed, 12 May 2021 08:50:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwydFVTauIY1zjoTjN64/p7y+cwEYTdnAIuNEf6ShcNSxkG47ESz1xI878sKup+NxQ/SoRG X-Received: by 2002:aca:6109:: with SMTP id v9mr7760684oib.65.1620834658346; Wed, 12 May 2021 08:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620834658; cv=none; d=google.com; s=arc-20160816; b=B5SBQgwElISCdeQ8ndu5ajeI4UNFlGqnxRw91KTPTe/sovkugMxuKByAfqMobHqqc4 W/NsLrQbIKVgRdLWxYgcu7huO9XMS1TyXiTCDIDEyoVUhBDnjfmG2Fm/1tXUAmcuqoG1 ARtdlv+m3tnG0hcp4FyYKhmd8i8v7rYi3ATi3ehBh+YXXLF382S4FMmR8fWUR0ZDmzkz Wv8ZkCGBKlyqsqNTTakkmkrc2wtTY+5LiFE4TWKw/5/7uCkPIhjWrhdBcLDdSxMN/VnF CpQYloez/OCz5Uv8SCIY5uxg8fXa0ZpXunTOs6zwuYht2I/9Pweh3QBK2SBBAoeKZxQt rmwQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7TJFhRzqeXeN0NEd9yYM7HAOPoW0ewAHVnfVtR5JIgU=; b=qFjcVwelg3UpBDa8Gi8OItDvyJBv8UjvkF4g2HzSBrKYYxFCwYaqXEquWjt2hkb3cR Z3LKzRx9d4HRx2fhH3ZvtyDhxuWPKcj/YFqDGA6b94kY00wIW5BI2Q48DlnGF6Sn1Lh0 4ZDswiTkQ6Ojfpvh0SBuGOZJZXG7+Yl197GbHaHPhlszcq4Gu3cEcdtaKLU2T9VMuzCx 3I7eIFPv9DGB36eIVit1tVUDnvLccT40lNbkg2zUamY0fCCqSJ4bBxB/mmUSOYJmf0rJ 9JZedP6sSsM74Y0eXNaCP3X1h+hXBb/ywjVgybbXwwFAKN9Ma2K5Pvxf9AKvCQ+GLn6/ Ci0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Mdg8zu50; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b128si264439oif.208.2021.05.12.08.50.44; Wed, 12 May 2021 08:50:58 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Mdg8zu50; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235424AbhELPoz (ORCPT + 99 others); Wed, 12 May 2021 11:44:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:60086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234581AbhELPTz (ORCPT ); Wed, 12 May 2021 11:19:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1F3C961999; Wed, 12 May 2021 15:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832089; bh=tA9rM1j96RR6Wg2KTIrUJspWlz2TsQbVgxyUFm+J77g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mdg8zu50a7NDKG2N6Fb9cNmKlDpWFdeHfRvy+92W5aTcGS0OOpe5acCEQSh9FlAnK CwmN2CQCT+eRoP7XQLyUVqklkBD3F0JZDBmyldmG90nOLfd1vTKwGJHeN/Mmwpj0I+ V/pqDUiy3xHVODWTbhRRJkZer1UBbZRP0yAbFfBM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Erwan Le Ray , Sasha Levin Subject: [PATCH 5.10 136/530] serial: stm32: fix wake-up flag handling Date: Wed, 12 May 2021 16:44:06 +0200 Message-Id: <20210512144824.294928188@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Erwan Le Ray [ Upstream commit 12761869f0efa524348e2ae31827fd52eebf3f0d ] This patch fixes several issue with wake-up handling: - the WUF irq is handled several times at wake-up - the USART is disabled / enabled at suspend to set wake-up flag. It can cause glitches during RX. This patch fix those issues: - clear wake-up flag and disable wake-up irq in WUF irq handling - enable wake-up from low power on start bit detection at port configuration - Unmask the wake-up flag irq at suspend and mask it at resume In addition, pm_wakeup_event handling is moved from receice_chars to WUF irq handling. Fixes: 270e5a74fe4c ("serial: stm32: add wakeup mechanism") Signed-off-by: Erwan Le Ray Link: https://lore.kernel.org/r/20210304162308.8984-7-erwan.leray@foss.st.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/stm32-usart.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 5ae3841a4a08..85e9a4d4e91d 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -217,9 +217,6 @@ static void stm32_usart_receive_chars(struct uart_port *port, bool threaded) u32 sr; char flag; - if (irqd_is_wakeup_set(irq_get_irq_data(port->irq))) - pm_wakeup_event(tport->tty->dev, 0); - if (threaded) spin_lock_irqsave(&port->lock, flags); else @@ -462,6 +459,7 @@ static void stm32_usart_transmit_chars(struct uart_port *port) static irqreturn_t stm32_usart_interrupt(int irq, void *ptr) { struct uart_port *port = ptr; + struct tty_port *tport = &port->state->port; struct stm32_port *stm32_port = to_stm32_port(port); const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; u32 sr; @@ -472,9 +470,14 @@ static irqreturn_t stm32_usart_interrupt(int irq, void *ptr) writel_relaxed(USART_ICR_RTOCF, port->membase + ofs->icr); - if ((sr & USART_SR_WUF) && ofs->icr != UNDEF_REG) + if ((sr & USART_SR_WUF) && ofs->icr != UNDEF_REG) { + /* Clear wake up flag and disable wake up interrupt */ writel_relaxed(USART_ICR_WUCF, port->membase + ofs->icr); + stm32_usart_clr_bits(port, ofs->cr3, USART_CR3_WUFIE); + if (irqd_is_wakeup_set(irq_get_irq_data(port->irq))) + pm_wakeup_event(tport->tty->dev, 0); + } if ((sr & USART_SR_RXNE) && !(stm32_port->rx_ch)) stm32_usart_receive_chars(port, false); @@ -899,6 +902,12 @@ static void stm32_usart_set_termios(struct uart_port *port, cr1 &= ~(USART_CR1_DEDT_MASK | USART_CR1_DEAT_MASK); } + /* Configure wake up from low power on start bit detection */ + if (stm32_port->wakeirq > 0) { + cr3 &= ~USART_CR3_WUS_MASK; + cr3 |= USART_CR3_WUS_START_BIT; + } + writel_relaxed(cr3, port->membase + ofs->cr3); writel_relaxed(cr2, port->membase + ofs->cr2); writel_relaxed(cr1, port->membase + ofs->cr1); @@ -1466,23 +1475,20 @@ static void __maybe_unused stm32_usart_serial_en_wakeup(struct uart_port *port, { struct stm32_port *stm32_port = to_stm32_port(port); const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; - const struct stm32_usart_config *cfg = &stm32_port->info->cfg; - u32 val; if (stm32_port->wakeirq <= 0) return; + /* + * Enable low-power wake-up and wake-up irq if argument is set to + * "enable", disable low-power wake-up and wake-up irq otherwise + */ if (enable) { - stm32_usart_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit)); stm32_usart_set_bits(port, ofs->cr1, USART_CR1_UESM); - val = readl_relaxed(port->membase + ofs->cr3); - val &= ~USART_CR3_WUS_MASK; - /* Enable Wake up interrupt from low power on start bit */ - val |= USART_CR3_WUS_START_BIT | USART_CR3_WUFIE; - writel_relaxed(val, port->membase + ofs->cr3); - stm32_usart_set_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit)); + stm32_usart_set_bits(port, ofs->cr3, USART_CR3_WUFIE); } else { stm32_usart_clr_bits(port, ofs->cr1, USART_CR1_UESM); + stm32_usart_clr_bits(port, ofs->cr3, USART_CR3_WUFIE); } } -- 2.30.2