From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 30DE71863F for ; Tue, 14 Nov 2023 10:16:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="1VLhXwj3" Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4166FD56 for ; Tue, 14 Nov 2023 02:16:02 -0800 (PST) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c834c52b5aso50219601fa.1 for ; Tue, 14 Nov 2023 02:16:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1699956960; x=1700561760; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=S66K1VSLqdDY4G6GRPiKeVmO5YV98+bwwbj3xy8sc9k=; b=1VLhXwj3EOIruxOGDfwi8mkuNo8DbIUZ3e99bnBOXkKkB5GYKKcjnHn/0oHrNF1Uua T4NPzbQT2MS4AuVz8rdMQ0nwnExhXM+JFcKz5NAoCP7VP8HkaKsphJbG4bMg4A4NdP5/ 2hnS0GUjU4MsBpWLl3v63vfoRvVpqbIR3K/DFUukONZY4VHWUx5ffzcpCimC4EdVcoiQ /xs2l+bvQ0WiHQFnOAh0/wsvpQUSBmGz5VVHm4gcxhYHY0nUefMdh5ka/X4Lq4y8iA8G v1NbzzEp4OwURej0XOxm1qcrEYY7XuflA0CmEJKTuAtTz8LGtjEMc7CsBOpVLVrxO07/ 55Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699956960; x=1700561760; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S66K1VSLqdDY4G6GRPiKeVmO5YV98+bwwbj3xy8sc9k=; b=k6AiWk/5/YA3uckdJNULLWbblLExdXh882N2fwAkOu15O4OOIBED4D+Y3YaokIiwho T5F7Hl8org0BNO82GbrJ5yIXGQddO+35G3BtIpH3vvdi+FVl6IsLHz+/EPqUfGP3y56B Koc+N4WZsSd7do4zfU3iKjHsIygVMvlNl7GOit8v9SVfCGUv5H5vZSEwHnik2uohFKHP a7k8NG6KUyYsbJkgkQMDFAXHK4HhvLxGczYetl/MEBxAqDeeNKCGHsmKa+zNsaUqySgq 6L/q9vJVgaW9DoLIaeA2+teIISxXdQxmWFbO9mcSIANOuNSrPjfMQyH/2AoFMsE4IWSd 3VDw== X-Gm-Message-State: AOJu0Yzf8QQokiGqxvsdFwx2Bhv9b9xIhRoaKYVcgPIoW8JS4TyEyAEv GwL4vBasXTM1j7JHsE3CUNWppQ== X-Google-Smtp-Source: AGHT+IFpFePXPUj6r47XrvY+6vIyAtnVXiV3+sXFtpZsCWqUCGTVFu8vWiDXyJWPzaMTzGRi0imnzg== X-Received: by 2002:a2e:9d03:0:b0:2c5:2df8:d321 with SMTP id t3-20020a2e9d03000000b002c52df8d321mr1319633lji.36.1699956960430; Tue, 14 Nov 2023 02:16:00 -0800 (PST) Received: from blmsp ([2001:4091:a246:821e:4988:9c5:5b9:1020]) by smtp.gmail.com with ESMTPSA id v14-20020a05600c470e00b0040a47091602sm13109300wmo.31.2023.11.14.02.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 02:16:00 -0800 (PST) Date: Tue, 14 Nov 2023 11:15:59 +0100 From: Markus Schneider-Pargmann To: Martin =?utf-8?Q?Hundeb=C3=B8ll?= Cc: linux-can@vger.kernel.org, devicetree@vger.kernel.org, Chandrasekar Ramakrishnan , Wolfgang Grandegger , Marc Kleine-Budde , Rob Herring , Krzysztof Kozlowski , Conor Dooley Subject: Re: [PATCH v3 2/3] can: tcan4x5x: support resuming from rx interrupt signal Message-ID: <20231114101559.5wqnhdmklarr3lgv@blmsp> References: <20231113131452.214961-1-martin@geanix.com> <20231113131452.214961-3-martin@geanix.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231113131452.214961-3-martin@geanix.com> Hi Martin, On Mon, Nov 13, 2023 at 02:14:51PM +0100, Martin Hundebøll wrote: > Implement the "wakeup-source" device tree property, so the chip is left > running when suspending, and its rx interrupt is used as a wakeup source > to resume operation. > > Signed-off-by: Martin Hundebøll > --- > > Change in v3: > * Updated to use the property in struct m_can_classdev instead of > passing parameters to suspend/resume functions. > > Change in v2: > * Added `static` keyword to dev_pm_ops sturcture > > drivers/net/can/m_can/tcan4x5x-core.c | 34 +++++++++++++++++++++++++-- > 1 file changed, 32 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c > index 870ab4aef610..0f4c2ac7e4f6 100644 > --- a/drivers/net/can/m_can/tcan4x5x-core.c > +++ b/drivers/net/can/m_can/tcan4x5x-core.c > @@ -411,7 +411,7 @@ static int tcan4x5x_can_probe(struct spi_device *spi) > priv->spi = spi; > > mcan_class->pm_clock_support = 0; > - mcan_class->pm_wake_source = 0; > + mcan_class->pm_wake_source = device_property_read_bool(&spi->dev, "wakeup-source"); > mcan_class->can.clock.freq = freq; > mcan_class->dev = &spi->dev; > mcan_class->ops = &tcan4x5x_ops; > @@ -460,6 +460,9 @@ static int tcan4x5x_can_probe(struct spi_device *spi) > goto out_power; > } > > + if (mcan_class->pm_wake_source) > + device_init_wakeup(&spi->dev, true); > + You are automatically enabling the device for wakeup here. What do you think about using ethtool's wake-on-lan settings to actually enable tcan as a wakeup source? So the devicetree would describe if the hardware is capable of wakeups and the software (ethtool) can be used by the user to decide if CAN wakeups should be enabled. I am currently working on something similar for m_can, where m_can can be the wakeup source from very deep sleep states. However I can't keep the wakeup source always enabled. So this is a kind of a conflict for me in this patch. Also I would need to use the wakeup-source flag in m_can device nodes as well. I can share my work later as well, so we can find a good solution that works in both cases. Best, Markus > ret = m_can_class_register(mcan_class); > if (ret) { > dev_err(&spi->dev, "Failed registering m_can device %pe\n", > @@ -488,6 +491,29 @@ static void tcan4x5x_can_remove(struct spi_device *spi) > m_can_class_free_dev(priv->cdev.net); > } > > +static int __maybe_unused tcan4x5x_suspend(struct device *dev) > +{ > + struct m_can_classdev *cdev = dev_get_drvdata(dev); > + struct spi_device *spi = to_spi_device(dev); > + > + if (cdev->pm_wake_source) > + enable_irq_wake(spi->irq); > + > + return m_can_class_suspend(dev); > +} > + > +static int __maybe_unused tcan4x5x_resume(struct device *dev) > +{ > + struct m_can_classdev *cdev = dev_get_drvdata(dev); > + struct spi_device *spi = to_spi_device(dev); > + int ret = m_can_class_resume(dev); > + > + if (cdev->pm_wake_source) > + disable_irq_wake(spi->irq); > + > + return ret; > +} > + > static const struct of_device_id tcan4x5x_of_match[] = { > { > .compatible = "ti,tcan4x5x", > @@ -506,11 +532,15 @@ static const struct spi_device_id tcan4x5x_id_table[] = { > }; > MODULE_DEVICE_TABLE(spi, tcan4x5x_id_table); > > +static const struct dev_pm_ops tcan4x5x_pm_ops = { > + SET_SYSTEM_SLEEP_PM_OPS(tcan4x5x_suspend, tcan4x5x_resume) > +}; > + > static struct spi_driver tcan4x5x_can_driver = { > .driver = { > .name = KBUILD_MODNAME, > .of_match_table = tcan4x5x_of_match, > - .pm = NULL, > + .pm = &tcan4x5x_pm_ops, > }, > .id_table = tcan4x5x_id_table, > .probe = tcan4x5x_can_probe, > -- > 2.42.0 >