Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13476416ybl; Sun, 29 Dec 2019 12:49:58 -0800 (PST) X-Google-Smtp-Source: APXvYqyCDV3pgmjQd9aqbekx0A9RADrPS8JKbeHFdW7AmK/0nIQUNe59hnwRywR7zk1Z6SiYg0AX X-Received: by 2002:a05:6830:9a:: with SMTP id a26mr60216454oto.131.1577652598409; Sun, 29 Dec 2019 12:49:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652598; cv=none; d=google.com; s=arc-20160816; b=m+eng+teTM5hRY0t4VUOFmcDI3qARwCy1rC4hQWiReO4DaIlGFQeFl1eKe/MN1/oRs SiYCo0hzMV4A5YUF68CAtrabs+FnZhQ/tv95QTlGQldU3mJLPX7ktYvC5yNp8FRb85EC l+c7kr9zKqW49PXnKvb0P2JobX3J2kD8T2XNjTC26t/F8R4np9HbPPdOfDzXXPcO35tc sLU9S0cZREa3Gf+DSqQgs9Rt4UrkNYUrGwwUTumdnrFCdJqqf+NAljJ7lX/R6beRyli4 nolq52cFmh+wGqDMwpVg/QIm/s0yPq9EtixCIlpi1vZbGDX/T/3NKug50f8yWqUs79Ux EsCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5h+dnFFvWWBBa4KsFX9K+0peFAsMRbFl81Ggz6Q+MNs=; b=Hzqb9P8aTaA2on1/Jgl4xsP2DtUwt4E0erhgp5iDgfcs5eQHr5V+JtnF+2+C1RJbbE myijopWAGdzCxmYmsf3xGOdHZ0W/aJ0UBPNa2a2IFOm1VXpXzQn8a7SuQ7BJLkeIwbS/ 5K21hCZcVuAYaOdlb+AzPfwuFpXeD78O2UdnPyzyOCdoS6r6MtGvVxo+UzR6jKJeK83x tdDHArxMNwphVJDSN4vtuMShj4U/NxGY9gxTOAX8TbAZtg7wARpRk+ZZXbrSpMlfFlhK e+ZKjm6tx37J+9Q3K8w+7ML10pO3wfQgBLvLacfHTnuVWpAwtWkH1wNzzwwzJEkAv5zE F5jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Lzivx37G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10si6178125oid.84.2019.12.29.12.49.47; Sun, 29 Dec 2019 12:49:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Lzivx37G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733139AbfL2R4x (ORCPT + 99 others); Sun, 29 Dec 2019 12:56:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:46784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733123AbfL2R4t (ORCPT ); Sun, 29 Dec 2019 12:56:49 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2BF04222C3; Sun, 29 Dec 2019 17:56:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577642208; bh=c1FQrMMv8I7o3y+VLYP45P+pAFjvh2uqwH/WJErZ/Eo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lzivx37GoMPZxbE83qMDm7WyhL7NbjTleRsm+YdflGjUscCQcEM3KAHystoRcyP7q HA5QVrZwl7YqFknwPOQ+l2vdpYXhkqFk41S0oikhgaCxxMwBzWKqKjBhkD/W0irq16 HRwoNwJIubQGTBMYL1wAiLceQuaE2ftaCkCG0hwI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Nyekjaer , Joakim Zhang , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.4 388/434] can: flexcan: add low power enter/exit acknowledgment helper Date: Sun, 29 Dec 2019 18:27:21 +0100 Message-Id: <20191229172728.013499830@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joakim Zhang [ Upstream commit b7603d080ffcf8689ec91ca300caf84d8dbed317 ] The MCR[LPMACK] read-only bit indicates that FlexCAN is in a lower-power mode (Disabled mode, Doze mode, Stop mode). The CPU can poll this bit to know when FlexCAN has actually entered low power mode. The low power enter/exit acknowledgment helper will reduce code duplication for disabled mode, doze mode and stop mode. Tested-by: Sean Nyekjaer Signed-off-by: Joakim Zhang Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- drivers/net/can/flexcan.c | 46 +++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index 99b3492ea130..e5c207ad3c77 100644 --- a/drivers/net/can/flexcan.c +++ b/drivers/net/can/flexcan.c @@ -389,6 +389,34 @@ static struct flexcan_mb __iomem *flexcan_get_mb(const struct flexcan_priv *priv (&priv->regs->mb[bank][priv->mb_size * mb_index]); } +static int flexcan_low_power_enter_ack(struct flexcan_priv *priv) +{ + struct flexcan_regs __iomem *regs = priv->regs; + unsigned int timeout = FLEXCAN_TIMEOUT_US / 10; + + while (timeout-- && !(priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK)) + udelay(10); + + if (!(priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK)) + return -ETIMEDOUT; + + return 0; +} + +static int flexcan_low_power_exit_ack(struct flexcan_priv *priv) +{ + struct flexcan_regs __iomem *regs = priv->regs; + unsigned int timeout = FLEXCAN_TIMEOUT_US / 10; + + while (timeout-- && (priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK)) + udelay(10); + + if (priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK) + return -ETIMEDOUT; + + return 0; +} + static void flexcan_enable_wakeup_irq(struct flexcan_priv *priv, bool enable) { struct flexcan_regs __iomem *regs = priv->regs; @@ -493,39 +521,25 @@ static inline int flexcan_transceiver_disable(const struct flexcan_priv *priv) static int flexcan_chip_enable(struct flexcan_priv *priv) { struct flexcan_regs __iomem *regs = priv->regs; - unsigned int timeout = FLEXCAN_TIMEOUT_US / 10; u32 reg; reg = priv->read(®s->mcr); reg &= ~FLEXCAN_MCR_MDIS; priv->write(reg, ®s->mcr); - while (timeout-- && (priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK)) - udelay(10); - - if (priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK) - return -ETIMEDOUT; - - return 0; + return flexcan_low_power_exit_ack(priv); } static int flexcan_chip_disable(struct flexcan_priv *priv) { struct flexcan_regs __iomem *regs = priv->regs; - unsigned int timeout = FLEXCAN_TIMEOUT_US / 10; u32 reg; reg = priv->read(®s->mcr); reg |= FLEXCAN_MCR_MDIS; priv->write(reg, ®s->mcr); - while (timeout-- && !(priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK)) - udelay(10); - - if (!(priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK)) - return -ETIMEDOUT; - - return 0; + return flexcan_low_power_enter_ack(priv); } static int flexcan_chip_freeze(struct flexcan_priv *priv) -- 2.20.1