From patchwork Mon May 6 05:59:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Herburger X-Patchwork-Id: 13654970 X-Patchwork-Delegate: kuba@kernel.org Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9C224AEE6; Mon, 6 May 2024 06:00:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.104.207.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714975212; cv=none; b=fFWfJ4Zx7cxdT/kGchjwZ7fapEKs+5jIGzuRxZpSaJrlxH7U0JsG0wn/Qt5+UYrxsEgcjwFxhHJHdRSIR1K3AuU3XyJ4/nwct7c9Az0YzGxP2S8d6EiXfInDpyC2ct9IkQu0cW8tbiSsrcAZrkbmL9vylnEjjGHFuIFbYN6d/Ww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714975212; c=relaxed/simple; bh=+Qveyuu1v4FvIUSFlIEA/3OG3zhEu/ongopJVNgfTKs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jnHwuSF+FIBfKmxr2BCGLmE+N0Qxwh6HbkCJ3QHFG+qL03F0HhrwY2kO6rNxTi654TyT/8xHFT+4YcAs+IGUDSF9NiAdMSCEhq5Vz63XuEr9k9nt5Qr10gPd7UmfQQqHoJDP5Pz//LMrnyom+GdtD7I+/9+DLv/R7GfbMdFFlOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com; spf=pass smtp.mailfrom=ew.tq-group.com; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b=dn1OdOHy; dkim=fail (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b=ZaKSeGAg reason="key not found in DNS"; arc=none smtp.client-ip=93.104.207.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="dn1OdOHy"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b="ZaKSeGAg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1714975209; x=1746511209; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=OBGFkZtBUY6CLcCH997A3eA6xZRxVGzOp58tM2v/Y8w=; b=dn1OdOHyO65A63YXB7qGFNDtf7mXerqDCtfh0eVikAeClB5aYQHTfbVw tJ1ikZLFZY9AR1dbvd6vkmhPda2UFWreVukwwxWVr4JpIrkaXwTTwIKls A8dFfQ+HofE4Zv/U0AjP0PEtxZKnMmiZmusU/gHIdxi4XJXIWlIoWXlfC 64rKfQFGl3TZ9ZUz2UWCW+Zd/weEh1v8za42lupjf07hsryCYuWps0PVv dR9NqogQZ9qcXFPVg8P2YP9dpuSokWyR5bbbaExvhyRw7QgEU7IcWrcGn NmNGyTZ/o+L35+m2Egufnx0VdnfsuNASN45nnoTaFePQ8+aT9eEuaF3NU w==; X-CSE-ConnectionGUID: sgBXbvymT4y4igDa5k0Jyw== X-CSE-MsgGUID: V/d2EelCSA6NHRq6xiLK3w== X-IronPort-AV: E=Sophos;i="6.07,257,1708383600"; d="scan'208";a="36751423" Received: from vmailcow01.tq-net.de ([10.150.86.48]) by mx1.tq-group.com with ESMTP; 06 May 2024 08:00:04 +0200 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7BA0A173CC9; Mon, 6 May 2024 07:59:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ew.tq-group.com; s=dkim; t=1714975200; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=OBGFkZtBUY6CLcCH997A3eA6xZRxVGzOp58tM2v/Y8w=; b=ZaKSeGAgjc16OMLdTm8ytJj47Vn3ZQHARvmtURcBEdpq3fYcKJzzUtWPjp8rwgilKnTlY8 pSBRcgIHl//GbCrd3+ndX/QytXC+CGaf9vamwX0BoD5q6aQQJHQE2h4zmD3rGVeHRJ203R whq9V5dt6sOIPSg9rkke6dRuoOdeALdHPdk2YPqLTMAHZtKbfg+q2HIBqc88ZUxeGef+EC WwP0PgZTCYYWb8alg7ClkicNHbPQiCHFkQqKDMgMVHCwNF+aaJCl0x/OKz1XBre5Vx39// ytwI3YTn46u9ZHlBcmxH8JHtONsJO76BAwIrpngNjgnqPGkaxYyDSs0IkUVZ+g== From: Gregor Herburger Date: Mon, 06 May 2024 07:59:44 +0200 Subject: [PATCH v2 2/6] can: mcp251xfd: move mcp251xfd_timestamp_start()/stop() into mcp251xfd_chip_start/stop() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240506-mcp251xfd-gpio-feature-v2-2-615b16fa8789@ew.tq-group.com> References: <20240506-mcp251xfd-gpio-feature-v2-0-615b16fa8789@ew.tq-group.com> In-Reply-To: <20240506-mcp251xfd-gpio-feature-v2-0-615b16fa8789@ew.tq-group.com> To: Marc Kleine-Budde , Manivannan Sadhasivam , Thomas Kopp , Vincent Mailhol , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux@ew.tq-group.com, gregor.herburger@ew.tq-group.com X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1714975188; l=4143; i=gregor.herburger@ew.tq-group.com; s=20230829; h=from:subject:message-id; bh=5MNSUMJdhUcvqjyxAlN8mXO8gFpKVp+awDVJ/95Fxcc=; b=IhuWCKnDnD8tF2eOnbfbBclnTuuXZ8LjNKc1iuG79DCBOyX+R1jlJfhqj7z28uHpgsIRTUr5Q XO6Gy/YRZBFBYFSAvMlYXthbMb0+jkH161g2W11+LPVysM6UPV9FFGd X-Developer-Key: i=gregor.herburger@ew.tq-group.com; a=ed25519; pk=+eRxwX7ikXwazcRjlOjj2/tbDmfVZdDLoW+xLZbQ4h4= X-Last-TLS-Session-Version: TLSv1.3 X-Patchwork-Delegate: kuba@kernel.org From: Marc Kleine-Budde The mcp251xfd wakes up from Low Power or Sleep Mode when SPI activity is detected. To avoid this, make sure that the timestamp worker is stopped before shutting down the chip. Split the starting of the timestamp worker out of mcp251xfd_timestamp_init() into the separate function mcp251xfd_timestamp_start(). Call mcp251xfd_timestamp_init() before mcp251xfd_chip_start(), move mcp251xfd_timestamp_start() to mcp251xfd_chip_start(). In this way, mcp251xfd_timestamp_stop() can be called unconditionally by mcp251xfd_chip_stop(). Signed-off-by: Marc Kleine-Budde --- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 8 +++++--- drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c | 7 +++++-- drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c index e3c791f562d2..4ae201426a46 100644 --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c @@ -744,6 +744,7 @@ static void mcp251xfd_chip_stop(struct mcp251xfd_priv *priv, mcp251xfd_chip_interrupts_disable(priv); mcp251xfd_chip_rx_int_disable(priv); + mcp251xfd_timestamp_stop(priv); mcp251xfd_chip_sleep(priv); } @@ -763,6 +764,8 @@ static int mcp251xfd_chip_start(struct mcp251xfd_priv *priv) if (err) goto out_chip_stop; + mcp251xfd_timestamp_start(priv); + err = mcp251xfd_set_bittiming(priv); if (err) goto out_chip_stop; @@ -1610,11 +1613,12 @@ static int mcp251xfd_open(struct net_device *ndev) if (err) goto out_mcp251xfd_ring_free; + mcp251xfd_timestamp_init(priv); + err = mcp251xfd_chip_start(priv); if (err) goto out_transceiver_disable; - mcp251xfd_timestamp_init(priv); clear_bit(MCP251XFD_FLAGS_DOWN, priv->flags); can_rx_offload_enable(&priv->offload); @@ -1637,7 +1641,6 @@ static int mcp251xfd_open(struct net_device *ndev) out_can_rx_offload_disable: can_rx_offload_disable(&priv->offload); set_bit(MCP251XFD_FLAGS_DOWN, priv->flags); - mcp251xfd_timestamp_stop(priv); out_transceiver_disable: mcp251xfd_transceiver_disable(priv); out_mcp251xfd_ring_free: @@ -1662,7 +1665,6 @@ static int mcp251xfd_stop(struct net_device *ndev) mcp251xfd_chip_interrupts_disable(priv); free_irq(ndev->irq, priv); can_rx_offload_disable(&priv->offload); - mcp251xfd_timestamp_stop(priv); mcp251xfd_chip_stop(priv, CAN_STATE_STOPPED); mcp251xfd_transceiver_disable(priv); mcp251xfd_ring_free(priv); diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c index 712e09186987..7bbf4603038b 100644 --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c @@ -58,9 +58,12 @@ void mcp251xfd_timestamp_init(struct mcp251xfd_priv *priv) cc->shift = 1; cc->mult = clocksource_hz2mult(priv->can.clock.freq, cc->shift); - timecounter_init(&priv->tc, &priv->cc, ktime_get_real_ns()); - INIT_DELAYED_WORK(&priv->timestamp, mcp251xfd_timestamp_work); +} + +void mcp251xfd_timestamp_start(struct mcp251xfd_priv *priv) +{ + timecounter_init(&priv->tc, &priv->cc, ktime_get_real_ns()); schedule_delayed_work(&priv->timestamp, MCP251XFD_TIMESTAMP_WORK_DELAY_SEC * HZ); } diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd.h b/drivers/net/can/spi/mcp251xfd/mcp251xfd.h index 24510b3b8020..75d5a8a25415 100644 --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd.h +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd.h @@ -950,6 +950,7 @@ int mcp251xfd_handle_tefif(struct mcp251xfd_priv *priv); void mcp251xfd_skb_set_timestamp(const struct mcp251xfd_priv *priv, struct sk_buff *skb, u32 timestamp); void mcp251xfd_timestamp_init(struct mcp251xfd_priv *priv); +void mcp251xfd_timestamp_start(struct mcp251xfd_priv *priv); void mcp251xfd_timestamp_stop(struct mcp251xfd_priv *priv); netdev_tx_t mcp251xfd_start_xmit(struct sk_buff *skb,