From patchwork Fri Oct 11 13:16:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 13832565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84DA9D0D78D for ; Fri, 11 Oct 2024 13:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GSdY/jWydsnh5WtGKd8S4In1q/EQUwCvNawFPtKHEzU=; b=CpqlvV+P+nlMmwE+3T3P4hG+Ol Y+h/ZDKRrqspIGyB/4CyGXRSGoR5uLXLcwx2s4h0XLWxgFsbe/YsGME/wL4lOMyU9AulJ3E+0Scu7 wzn7bZand3w1KRdLgaDIiocmi/rs2tajwpGDHTLUc5yBAHpQLPwox+h87tKhkRj5QARU2aAKSYPzj znVH/Ky1rT8J8Vm09pDD726Im9Lhb/bldc5i+yTYsDJooMNeiaNZnwvFP0mpcJQe8HaCfloAgF2nq RGKO/BU3zLKTW6SowVOI0ffKbVpIeXPJ1zTR0xTv4O3+MsNsyrGiwbra0r4DVS46StsolbMEz+DGT 0fdCJmGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1szFcF-0000000GRIi-3LTC; Fri, 11 Oct 2024 13:23:35 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1szFWu-0000000GQ4d-0heB for linux-arm-kernel@lists.infradead.org; Fri, 11 Oct 2024 13:18:05 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a9943897c07so281699266b.3 for ; Fri, 11 Oct 2024 06:18:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728652682; x=1729257482; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=GSdY/jWydsnh5WtGKd8S4In1q/EQUwCvNawFPtKHEzU=; b=Ior4VRgcCa4zpUeyRE0H78FLHBRJbPbDkz+ER1jdhzHxZkLJFxBep8FdIbUdhjlR6J Vu3i4RR5b1UBQfWlPBl2qoEs4CbWz0UT/Zx+06fBXWB0BsOGuI/wJ5iBEbZO+vCa9YO2 TQAkgBKX9DdS2EucAuAdTNvnfnl2nFzuCFTawipZABTjH/X3yuLw0OK2y3B7c3jekHae rgMnivfiPOW4DgLmu/I5YXbmXnoEz8Q4rIaN1mepOQxP+Gl7mkacEt1aR0r1CaqT64Ec GGUnGfLi4BFpGHYHjp9Q48JuzPxBXO+zA8im9BBMwEkApuwYuaaC0rVKdF9TWZNnqsdS E0qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728652682; x=1729257482; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GSdY/jWydsnh5WtGKd8S4In1q/EQUwCvNawFPtKHEzU=; b=Tnjp5yGl7cMnLI2awwkvMKpJdFjZrTeqz3UEpp01TmH9PNfVQJkxMR+gGJpp6QQv07 f9cdazybfgQYSPCONnUf1k6W3z8Qgn+ZIzWIDh9DFpKOV+qtithiWmz6Ad+BJweg+uvq fyNpQr4isH9VkEnF3pI+VUICEK44fYKwGv5eq5jjJbv8H/lBx+yHTNbWADAG5LlqMlhe t0r9hA7SAzMtk57IX2zRC4ZCcfbFcSrEVrjuleehSE12c3eaaJ75WJt5usX4E2qyfdAw Hx6RuIBhirCU5i3wW3N5GDZvE3GCM2/9uymHbpiwi8IRqjBmk5+Dnq/hfyEiF/w7Ivx9 tv9g== X-Forwarded-Encrypted: i=1; AJvYcCVVtcKfFcRSXdmIkmvM2IxS7RPHY5LyFUsBUW866oaI1ImzEQ0fWq3WzMHfq3jEpZIYXnegGnLQpYRCo4+ZAS/i@lists.infradead.org X-Gm-Message-State: AOJu0Yxg5kvnoxvl0TPXK8RgrsYKzfHPYZPg1tyTItp8UvSAQ09wFryI dyiVdhYKiyy+3ZCGkCa92rPuoO+1AC4ybA99igT2CWryRJPhmyYbv+ajMSkcg3Q= X-Google-Smtp-Source: AGHT+IEldii35e9PVlPZq7x1sIW5eSePwbQUs9Zkn2MXaSKHf3A/zUtyi0U68UtWtK/MFFkB8BzaRQ== X-Received: by 2002:a17:907:6d22:b0:a99:40e6:157c with SMTP id a640c23a62f3a-a99b930192dmr224582866b.4.1728652682272; Fri, 11 Oct 2024 06:18:02 -0700 (PDT) Received: from localhost ([2001:4090:a244:83ae:2517:2666:43c9:d0d3]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80df530sm212717066b.145.2024.10.11.06.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 06:18:01 -0700 (PDT) From: Markus Schneider-Pargmann Date: Fri, 11 Oct 2024 15:16:40 +0200 Subject: [PATCH v3 3/9] can: m_can: Map WoL to device_set_wakeup_enable MIME-Version: 1.0 Message-Id: <20241011-topic-mcan-wakeup-source-v6-12-v3-3-9752c714ad12@baylibre.com> References: <20241011-topic-mcan-wakeup-source-v6-12-v3-0-9752c714ad12@baylibre.com> In-Reply-To: <20241011-topic-mcan-wakeup-source-v6-12-v3-0-9752c714ad12@baylibre.com> To: Chandrasekar Ramakrishnan , Marc Kleine-Budde , Vincent Mailhol , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Matthias Schiffer , Vishal Mahaveer , Kevin Hilman , Dhruva Gole , Markus Schneider-Pargmann , Andrew Lunn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2838; i=msp@baylibre.com; h=from:subject:message-id; bh=cwyU19cQrq3CFX81zcGwso0Vwsxh5WskwRCVqlVQBpY=; b=owGbwMvMwCGm0rPl0RXRdfaMp9WSGNI5VRN01scys/0ROFZQ7ylmKfw1ZNPKvnsdr7es7vJJy 92oP/1YRykLgxgHg6yYIsvdDwvf1cldXxCx7pEjzBxWJpAhDFycAjCR3KsM/7RYmS5OuZNmd99Z LKHvwfFNQp3/g39di/+g4B4n5MKcW8Pwv6p/68TPjFx90aK3AxynV854Vr5yjWbI3x1Cb3bUnhM T5gMA X-Developer-Key: i=msp@baylibre.com; a=openpgp; fpr=BADD88DB889FDC3E8A3D5FE612FA6A01E0A45B41 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241011_061804_246571_CB208E86 X-CRM114-Status: GOOD ( 17.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In some devices the pins of the m_can module can act as a wakeup source. This patch helps do that by connecting the PHY_WAKE WoL option to device_set_wakeup_enable. By marking this device as being wakeup enabled, this setting can be used by platform code to decide which sleep or poweroff mode to use. Also this prepares the driver for the next patch in which the pinctrl settings are changed depending on the desired wakeup source. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Andrew Lunn --- drivers/net/can/m_can/m_can.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index a978b960f1f1e1e8273216ff330ab789d0fd6d51..29accadc20de7e9efa509f14209cc62e599f03bb 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -2185,6 +2185,36 @@ static int m_can_set_coalesce(struct net_device *dev, return 0; } +static void m_can_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) +{ + struct m_can_classdev *cdev = netdev_priv(dev); + + wol->supported = device_can_wakeup(cdev->dev) ? WAKE_PHY : 0; + wol->wolopts = device_may_wakeup(cdev->dev) ? WAKE_PHY : 0; +} + +static int m_can_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) +{ + struct m_can_classdev *cdev = netdev_priv(dev); + bool wol_enable = !!wol->wolopts & WAKE_PHY; + int ret; + + if ((wol->wolopts & WAKE_PHY) != wol->wolopts) + return -EINVAL; + + if (wol_enable == device_may_wakeup(cdev->dev)) + return 0; + + ret = device_set_wakeup_enable(cdev->dev, wol_enable); + if (ret) { + netdev_err(cdev->net, "Failed to set wakeup enable %pE\n", + ERR_PTR(ret)); + return ret; + } + + return 0; +} + static const struct ethtool_ops m_can_ethtool_ops_coalescing = { .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS_IRQ | ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ | @@ -2194,10 +2224,14 @@ static const struct ethtool_ops m_can_ethtool_ops_coalescing = { .get_ts_info = ethtool_op_get_ts_info, .get_coalesce = m_can_get_coalesce, .set_coalesce = m_can_set_coalesce, + .get_wol = m_can_get_wol, + .set_wol = m_can_set_wol, }; static const struct ethtool_ops m_can_ethtool_ops = { .get_ts_info = ethtool_op_get_ts_info, + .get_wol = m_can_get_wol, + .set_wol = m_can_set_wol, }; static int register_m_can_dev(struct m_can_classdev *cdev) @@ -2324,6 +2358,9 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, goto out; } + if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source")) + device_set_wakeup_capable(dev, true); + /* Get TX FIFO size * Defines the total amount of echo buffers for loopback */