Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1199020lqh; Sun, 5 May 2024 23:01:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpI5XUGCZMn8kHtIn8j4pFdaa27SyO4Kf+/ppnSbkGrDHY7TlScMNy55luS3buNgGaUpAvoHwbvMm4ok2EPTZ10J4inpBJksp6aVmb0w== X-Google-Smtp-Source: AGHT+IEtVXsUJA2l8oJVbe4oGEfkIpthcWfyT4lhvFMt+cXBmGPW063zYFpbKXs9HxpBCVSypWoE X-Received: by 2002:a05:622a:1787:b0:437:a0fb:cffe with SMTP id s7-20020a05622a178700b00437a0fbcffemr12049091qtk.30.1714975277785; Sun, 05 May 2024 23:01:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714975277; cv=pass; d=google.com; s=arc-20160816; b=roAaHD8fkFsQ0HFrYyK4anZz07n9Q6DF+uXgyG9fmAxPlTC7FKiSbgcdnZ5nCSDcpK nmw7+V093ZVOl76q19sUCMoOipiQQzhSGQSehF6lNBxv4/e9n9dksCrIYixRYWYCbrxI RryuLExBqbSUGce5wwrRy6xh5ae9g1B/vYZflBSZz6o5/l2k8rBxP8YvN6gFlrK3yHBT bRbFr8c2K5TUrQsN0ZLslhtrAbJOHCTwuWVkRT2DizIHkGBHt3+FgX8WuHzxhYNG0f1K Obio3yyl3ekZc7G3d+BQK2/vcMcmVp+Rz6ojFaTSZldArWMMXHTWGdkHqoD4ddtDbn1e bA5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature:dkim-signature; bh=6uFIYNjLjgqsV+0RlynG6403IRJSRImrwePI2LAt+58=; fh=Ck0fOcHdhRzgBaHwp6SaSYBo0j21rhywV4MXv2yQ9aM=; b=fgi0n277v34I8VeDZoe+/p5oJ2GCMiV89TG6pJhA6sLI5vt6Q0ogm0KZkSWV33gzir nW1XYQ13kda3qaC+Lk3T/aj4yvf641sRdSu2ylaabSakMRH4aPNlJ+lN45QUvQwlG2ZD cjsDxdmVL22J7HAwQ1yqyXFDWx4LlTayDH95tkqsD6h6Nwn4ZvTBX4TFLXu7iMJ6tqPs sAUFYnCZFWQqBQqJKIxnNqMxltExTGnv7tY0aUwKw1v2cU5dFyCmqID/lVK67cxhILb6 w227DRoPwXqdrUS1TiWAETWQI4zbiJEXP2qqS1mz5aQq9NT3Ub0r4LGEaIGAQL8/wVIt 9eAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=n2gwXd7V; dkim=temperror (no key for signature) header.i=@ew.tq-group.com header.s=dkim header.b=HJYQwDy1; arc=pass (i=1 spf=pass spfdomain=ew.tq-group.com dkim=pass dkdomain=tq-group.com dmarc=pass fromdomain=ew.tq-group.com); spf=pass (google.com: domain of linux-kernel+bounces-169339-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169339-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tq-group.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e5-20020a05622a110500b0043aee69eeb9si9236690qty.683.2024.05.05.23.01.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 23:01:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169339-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=n2gwXd7V; dkim=temperror (no key for signature) header.i=@ew.tq-group.com header.s=dkim header.b=HJYQwDy1; arc=pass (i=1 spf=pass spfdomain=ew.tq-group.com dkim=pass dkdomain=tq-group.com dmarc=pass fromdomain=ew.tq-group.com); spf=pass (google.com: domain of linux-kernel+bounces-169339-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169339-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tq-group.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 744B41C20FEF for ; Mon, 6 May 2024 06:01:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DAF331411C6; Mon, 6 May 2024 06:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="n2gwXd7V"; 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="HJYQwDy1" 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 C5B9F4EB4C; Mon, 6 May 2024 06:00:10 +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=1714975213; cv=none; b=Dkjc2jgFMHkdeJIFXdkb3GAsqkrOHnMv4UCjV7x6U3I5ar1HbILbhgStp2wPkoPn/+FTqeUhsb6f+hBVX/ofoP1boCkYUbvjbACxgQD+FLY+NP1Ezosb8gHaWSyA45LGUYKVMH5iEGFX2KxwlwbHtsRw3H7St9RXE92Db/NGo/0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714975213; c=relaxed/simple; bh=u0TscTqRVB+PaARLJJf9VxgcmIZJt6T9GhtInOa1pmE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PQQ8tIZZdttx2swNEkPCQzz/q/yVr2ImiUbwm/Bz1+wXeV+Qve5wicYrme7MgXiat3m3mn7L9VppCJsmYD0xc+cYKIKB8noKakLunxzg1XBCatan8o/QaPflvY3LTRvYmdq85aItuzmYQxkfKEP/5+yqNzW8W3naB3hGM2xlCzI= 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=n2gwXd7V; dkim=fail (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b=HJYQwDy1 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1714975211; x=1746511211; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=6uFIYNjLjgqsV+0RlynG6403IRJSRImrwePI2LAt+58=; b=n2gwXd7VsKWbcXjMl1fTTmgtOGH3p1/8N+sBPgrGn6cgYc3LjmisDmgW o0lAnbtZamin2CVM5T+TKuC/KxPsISv1Sc8uTELhH52SMADHLElbIqmOG Z93AoEbm8guv6OxqGH9VJLDQu0k1lnlpldFxXOD1dWKRIuTn+0g/YF/Ny PQxnVioH4RaDSFx9rJpkzEF3PRZ5NUnIOk8CxmHtIAnn8l12sG9LBMYlt YlUmI/fSJHP38DcA5dZFNnuiCncOtKoeDF4+K2VNIZ2zgrFEAbBRt2+5E GUCQp3o6PqFEg3OHK6bKPpaE3EUjscyDBRlluM9a3biGVIyCnJiZ3VdpS A==; X-CSE-ConnectionGUID: tDB/3IjRQs+MI0zQEFaaLQ== X-CSE-MsgGUID: fvFBUf2nTmGXsEO1AJ+N9w== X-IronPort-AV: E=Sophos;i="6.07,257,1708383600"; d="scan'208";a="36751428" Received: from vmailcow01.tq-net.de ([10.150.86.48]) by mx1.tq-group.com with ESMTP; 06 May 2024 08:00:09 +0200 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 4249B1760EA; Mon, 6 May 2024 08:00:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ew.tq-group.com; s=dkim; t=1714975204; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=6uFIYNjLjgqsV+0RlynG6403IRJSRImrwePI2LAt+58=; b=HJYQwDy1TwkRQey7qqkBin5GWd2ftWauvXT93E70SvptGxNqSW/qiGBWRiHpFbuOs0Tf8N hRh965mF/w9+IruMGSN7CLmZ7hv9j54Sy5aPBvDe3AKMhnF8Ms+N7CpDBMxxvd4plkFvgL 914FytGuYZIg7Zwp+B6rl0hzAgw23Hc/+m9pvneTCHGZws7kfdgabH39txqp8Kvu3v6bCt W+8lACr1Ahix+ESnzX7ODJr5SttYbKOYlHV61r3OPyDEdLy0usENlgxur86/IuM3L2r/nP sqOh+wiofnZp4GGO73pDB+tcvYkRs9wD5P2//J30WBAqDkJgAC4gY96tP2xFbQ== From: Gregor Herburger Date: Mon, 06 May 2024 07:59:45 +0200 Subject: [PATCH v2 3/6] can: mcp251xfd: move chip sleep mode into runtime pm Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240506-mcp251xfd-gpio-feature-v2-3-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=6388; i=gregor.herburger@ew.tq-group.com; s=20230829; h=from:subject:message-id; bh=DRB9jsz/bqQMPMBVtSXa2ZhvPJdm2qGH29HGCGexllI=; b=eMElllRfKEDqO6OBtiNWH00apyDw0sjZ0YHBxYmhMoLkVR9r2DFo5l1uZk9XWXZ/sxjKbIBrT Y0C7kS1oB0sCqxIFKqibipQNPd38rc9cmFuHWn//NIcZKeEm3hihOd+ X-Developer-Key: i=gregor.herburger@ew.tq-group.com; a=ed25519; pk=+eRxwX7ikXwazcRjlOjj2/tbDmfVZdDLoW+xLZbQ4h4= X-Last-TLS-Session-Version: TLSv1.3 From: Marc Kleine-Budde This is a preparation patch to add GPIO support. Up to now, the Vdd regulator and the clocks have been managed by Runtime-PM (on systems without CONFIG_PM these remain permanently switched on). During the mcp251xfd_open() callback the mcp251xfd is powered, soft-reset and configured. In mcp251xfd_stop() the chip is shut down again. To support the on-chip GPIOs, the chip must be supplied with power while GPIOs are being requested, even if the networking interface ist down. To support this, move the functions mcp251xfd_chip_softreset() and mcp251xfd_chip_clock_init() from mcp251xfd_chip_start() to mcp251xfd_runtime_resume(). Instead of setting the controller to sleep mode in mcp251xfd_chip_stop(), bring it into configuration mode. This way it doesn't take part in bus activity and doesn't enter sleep mode. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 99 ++++++++++++++++---------- 1 file changed, 61 insertions(+), 38 deletions(-) diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c index 4ae201426a46..4739ad80ef2a 100644 --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c @@ -745,21 +745,13 @@ 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); + mcp251xfd_chip_set_mode(priv, MCP251XFD_REG_CON_MODE_CONFIG); } static int mcp251xfd_chip_start(struct mcp251xfd_priv *priv) { int err; - err = mcp251xfd_chip_softreset(priv); - if (err) - goto out_chip_stop; - - err = mcp251xfd_chip_clock_init(priv); - if (err) - goto out_chip_stop; - err = mcp251xfd_chip_timestamp_init(priv); if (err) goto out_chip_stop; @@ -1602,8 +1594,11 @@ static int mcp251xfd_open(struct net_device *ndev) return err; err = pm_runtime_resume_and_get(ndev->dev.parent); - if (err) + if (err) { + if (err == -ETIMEDOUT || err == -ENODEV) + pm_runtime_set_suspended(ndev->dev.parent); goto out_close_candev; + } err = mcp251xfd_ring_alloc(priv); if (err) @@ -1872,53 +1867,53 @@ static int mcp251xfd_register(struct mcp251xfd_priv *priv) struct net_device *ndev = priv->ndev; int err; + mcp251xfd_register_quirks(priv); + err = mcp251xfd_clks_and_vdd_enable(priv); if (err) return err; + err = mcp251xfd_chip_softreset(priv); + if (err == -ENODEV) + goto out_clks_and_vdd_disable; + if (err) + goto out_chip_sleep; + + err = mcp251xfd_chip_clock_init(priv); + if (err == -ENODEV) + goto out_clks_and_vdd_disable; + if (err) + goto out_chip_sleep; + pm_runtime_get_noresume(ndev->dev.parent); err = pm_runtime_set_active(ndev->dev.parent); if (err) goto out_runtime_put_noidle; pm_runtime_enable(ndev->dev.parent); - mcp251xfd_register_quirks(priv); - - err = mcp251xfd_chip_softreset(priv); - if (err == -ENODEV) - goto out_runtime_disable; - if (err) - goto out_chip_sleep; - - err = mcp251xfd_chip_clock_init(priv); - if (err == -ENODEV) - goto out_runtime_disable; - if (err) - goto out_chip_sleep; - err = mcp251xfd_register_chip_detect(priv); if (err) - goto out_chip_sleep; + goto out_runtime_disable; err = mcp251xfd_register_check_rx_int(priv); if (err) - goto out_chip_sleep; + goto out_runtime_disable; mcp251xfd_ethtool_init(priv); err = register_candev(ndev); if (err) - goto out_chip_sleep; + goto out_runtime_disable; err = mcp251xfd_register_done(priv); if (err) goto out_unregister_candev; - /* Put controller into sleep mode and let pm_runtime_put() - * disable the clocks and vdd. If CONFIG_PM is not enabled, - * the clocks and vdd will stay powered. + /* Put controller into Config mode and let pm_runtime_put() + * put in sleep mode, disable the clocks and vdd. If CONFIG_PM + * is not enabled, the clocks and vdd will stay powered. */ - err = mcp251xfd_chip_sleep(priv); + err = mcp251xfd_chip_set_mode(priv, MCP251XFD_REG_CON_MODE_CONFIG); if (err) goto out_unregister_candev; @@ -1928,12 +1923,13 @@ static int mcp251xfd_register(struct mcp251xfd_priv *priv) out_unregister_candev: unregister_candev(ndev); -out_chip_sleep: - mcp251xfd_chip_sleep(priv); out_runtime_disable: pm_runtime_disable(ndev->dev.parent); out_runtime_put_noidle: pm_runtime_put_noidle(ndev->dev.parent); +out_chip_sleep: + mcp251xfd_chip_sleep(priv); +out_clks_and_vdd_disable: mcp251xfd_clks_and_vdd_disable(priv); return err; @@ -1945,10 +1941,12 @@ static inline void mcp251xfd_unregister(struct mcp251xfd_priv *priv) unregister_candev(ndev); - if (pm_runtime_enabled(ndev->dev.parent)) + if (pm_runtime_enabled(ndev->dev.parent)) { pm_runtime_disable(ndev->dev.parent); - else + } else { + mcp251xfd_chip_sleep(priv); mcp251xfd_clks_and_vdd_disable(priv); + } } static const struct of_device_id mcp251xfd_of_match[] = { @@ -2175,16 +2173,41 @@ static void mcp251xfd_remove(struct spi_device *spi) static int __maybe_unused mcp251xfd_runtime_suspend(struct device *device) { - const struct mcp251xfd_priv *priv = dev_get_drvdata(device); + struct mcp251xfd_priv *priv = dev_get_drvdata(device); + mcp251xfd_chip_sleep(priv); return mcp251xfd_clks_and_vdd_disable(priv); } static int __maybe_unused mcp251xfd_runtime_resume(struct device *device) { - const struct mcp251xfd_priv *priv = dev_get_drvdata(device); + struct mcp251xfd_priv *priv = dev_get_drvdata(device); + int err; - return mcp251xfd_clks_and_vdd_enable(priv); + err = mcp251xfd_clks_and_vdd_enable(priv); + if (err) + return err; + + err = mcp251xfd_chip_softreset(priv); + if (err == -ENODEV) + goto out_clks_and_vdd_disable; + if (err) + goto out_chip_sleep; + + err = mcp251xfd_chip_clock_init(priv); + if (err == -ENODEV) + goto out_clks_and_vdd_disable; + if (err) + goto out_chip_sleep; + + return 0; + +out_chip_sleep: + mcp251xfd_chip_sleep(priv); +out_clks_and_vdd_disable: + mcp251xfd_clks_and_vdd_disable(priv); + + return err; } static const struct dev_pm_ops mcp251xfd_pm_ops = { -- 2.34.1