From patchwork Fri Oct 11 13:16:42 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: 13832568 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 CC965D0D78D for ; Fri, 11 Oct 2024 13:26:31 +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=Qi/qlics3jG9EexkXmJNmMTUpWskqoYCj2V24qVovxY=; b=GZArH7Ty6eUl9ZYMZNpE8xelgq hEoWIMw4/N8Db3VujZq+g42JZs/DRAue7LC5IdYjE7rBROYwx7VvTFeGs4GJ+KQs6yw/Bpwk/ebVj 1RFulpuBzu41gevwB4hwRMW+X0hh+W0rfLLncj/SNgCeMSWs8wI/rlRVAJUYpZkyxhtMFb5JETKh/ FcA/5JE3aaCbRRwKZLFsj89kylVz0QnQQmsbPhPOev9CR4LlEdjkNMM8JqtHLx6DipJVHissY6ejR ed0XePWL1OaY0IgI216v+2R/Q0gjh81NmMdUA427wf//Sqj1fdZA0lfJPAsY4/HDEO4/7Nf0zj6qA dEi4SDNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1szFev-0000000GRjq-1Pt6; Fri, 11 Oct 2024 13:26:21 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1szFWw-0000000GQ5c-3zyV for linux-arm-kernel@lists.infradead.org; Fri, 11 Oct 2024 13:18:08 +0000 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5c920611a86so2642099a12.0 for ; Fri, 11 Oct 2024 06:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1728652685; x=1729257485; 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=Qi/qlics3jG9EexkXmJNmMTUpWskqoYCj2V24qVovxY=; b=j/QA1LI3JZQKpfGNE58aj9lv2zh04//sSN++s4QHdqnXm+YwdehJaw7QspdkZ28hZL VcpPAn2gaWA8ewKVXFHXbTz7CFZ+65xTOL8nmf6iwMk28GLqUkCuSaIbWTwm06dVfK0A Y5TztyQGJWNHfVBFjs03vWabDuTZQyA4lPwgxa7FhGLw8dazceAK3zBUC/ArknVx4fEd 54ukszksADVDF6OYqyM5Wqum5SYNh1w7ASA2FGv9iV4PjdPxQGTImrqLqVS8g7JhDtCT Js+Wdappbq/NRJJRqMp7lF+ydvXHsyMUT7RtJFPpAhcBV4qD17XqKOuUGMmSZ4cJQJZX m7Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728652685; x=1729257485; 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=Qi/qlics3jG9EexkXmJNmMTUpWskqoYCj2V24qVovxY=; b=kcC1eRazKNYzcDIZ4ebVCrWP/BRhldkeNK9gulcGtjHKaKNkV1WJ1KzxpZ/QhZTBnD 6bXAdo30JkB70lW+xIuG45lPDL6a+zZ8MkOmIkSxXSYMcatETwUf79+iCW69v0TBzGAF mspV9yt4ORRZQV8dHFuE8/tYWDLwwJRNlc25l6vURNh6RkrJRDP6ZyIWgeAwLu9S0r5T 0l98C6LfhaelDB7hmBhYNBHuBNjqe6zCZr5aKxX6itklBOBtUs907R0m5LNpU4dd57P4 dsLLNWvZwz1r3/dtMt3HF/0/hAZcZZV/ShOk/GwEwceMCV3Zc1Qqfj15XbFOF2mauM5H 6R5w== X-Forwarded-Encrypted: i=1; AJvYcCUGVRM37i62eF+QQNVOagM7/8UU90px6hSVT4Rm9SlTi9tbS147vvNt0XM/VXXsM2McrGJyLM914tgW7DeBiApK@lists.infradead.org X-Gm-Message-State: AOJu0YxCOI/Jz2oIXbhiR3us7SkbWQ1PFU/ymG4AXIwyVwd0fkB2MKzC 52ZgHTeDESgTaKbbiEkzbkY1QVTjAFcYogEwmjViqE87FPiU2CEJ12U+bxgM0Fk= X-Google-Smtp-Source: AGHT+IHFHVZb0xFh7E/t9gOKFFFtdY640Gp4pHWzck9QzbrflS9WO8wY0rdkL08vnT39n2iJtnT/qg== X-Received: by 2002:a17:906:c14c:b0:a99:53cf:26bc with SMTP id a640c23a62f3a-a99b96b0c3emr256114266b.44.1728652685059; Fri, 11 Oct 2024 06:18:05 -0700 (PDT) Received: from localhost ([2001:4090:a244:83ae:2517:2666:43c9:d0d3]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7ede845sm214686166b.13.2024.10.11.06.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 06:18:04 -0700 (PDT) From: Markus Schneider-Pargmann Date: Fri, 11 Oct 2024 15:16:42 +0200 Subject: [PATCH v3 5/9] can: m_can: Support pinctrl wakeup state MIME-Version: 1.0 Message-Id: <20241011-topic-mcan-wakeup-source-v6-12-v3-5-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 X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3643; i=msp@baylibre.com; h=from:subject:message-id; bh=y4cyNWxW+AAMzsvEv+B5MML+u/SjeALajlpD0Ds81SU=; b=owGbwMvMwCGm0rPl0RXRdfaMp9WSGNI5VbN4Bc4uOvxl3u3Gs4oZS6ct2r0/8tr94zIv2l/q/ Su3U1pwrqOUhUGMg0FWTJHl7oeF7+rkri+IWPfIEWYOKxPIEAYuTgGYyMR3jAwL+xfm1jNcO3Jw ttKPR41P6j5MTDfYOr18s/6CV3lTO6eWMPwPXnzaTfVR6Tv3E48qjDevXZJ3afrEJO4NE4Iayk9 /vtzJAgA= 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_061807_035136_C45FF63F X-CRM114-Status: GOOD ( 16.96 ) 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 am62 requires a wakeup flag being set in pinctrl when mcan pins acts as a wakeup source. Add support to select the wakeup state if WOL is enabled. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 60 +++++++++++++++++++++++++++++++++++++++++++ drivers/net/can/m_can/m_can.h | 4 +++ 2 files changed, 64 insertions(+) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 5ab0bb3f1c71e7dc4d6144f7b9e8f58d0e0303fe..c56d61b0d20b05be36c95ec4a6651b0457883b66 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -2196,6 +2196,7 @@ static void m_can_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) static int m_can_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) { struct m_can_classdev *cdev = netdev_priv(dev); + struct pinctrl_state *new_pinctrl_state = NULL; bool wol_enable = !!wol->wolopts & WAKE_PHY; int ret; @@ -2212,7 +2213,28 @@ static int m_can_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) return ret; } + if (wol_enable) + new_pinctrl_state = cdev->pinctrl_state_wakeup; + else + new_pinctrl_state = cdev->pinctrl_state_default; + + if (IS_ERR_OR_NULL(new_pinctrl_state)) + return 0; + + ret = pinctrl_select_state(cdev->pinctrl, new_pinctrl_state); + if (ret) { + netdev_err(cdev->net, "Failed to select pinctrl state %pE\n", + ERR_PTR(ret)); + goto err_wakeup_enable; + } + return 0; + +err_wakeup_enable: + /* Revert wakeup enable */ + device_set_wakeup_enable(cdev->dev, !wol_enable); + + return ret; } static const struct ethtool_ops m_can_ethtool_ops_coalescing = { @@ -2380,7 +2402,45 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, m_can_of_parse_mram(class_dev, mram_config_vals); + class_dev->pinctrl = devm_pinctrl_get(dev); + if (IS_ERR(class_dev->pinctrl)) { + ret = PTR_ERR(class_dev->pinctrl); + + if (ret != -ENODEV) { + dev_err_probe(dev, ret, "Failed to get pinctrl\n"); + goto err_free_candev; + } + + class_dev->pinctrl = NULL; + } else { + class_dev->pinctrl_state_wakeup = + pinctrl_lookup_state(class_dev->pinctrl, "wakeup"); + if (IS_ERR(class_dev->pinctrl_state_wakeup)) { + ret = PTR_ERR(class_dev->pinctrl_state_wakeup); + ret = -EIO; + + if (ret != -ENODEV) { + dev_err_probe(dev, ret, "Failed to lookup pinctrl wakeup state\n"); + goto err_free_candev; + } + + class_dev->pinctrl_state_wakeup = NULL; + } else { + class_dev->pinctrl_state_default = + pinctrl_lookup_state(class_dev->pinctrl, "default"); + if (IS_ERR(class_dev->pinctrl_state_default)) { + ret = PTR_ERR(class_dev->pinctrl_state_default); + dev_err_probe(dev, ret, "Failed to lookup pinctrl default state\n"); + goto err_free_candev; + } + } + } + return class_dev; + +err_free_candev: + free_candev(net_dev); + return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(m_can_class_allocate_dev); diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index 92b2bd8628e6b31370f4accbc2e28f3b2257a71d..b75b0dd6ccc93973d0891daac07c92b61f81dc2a 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -126,6 +126,10 @@ struct m_can_classdev { struct mram_cfg mcfg[MRAM_CFG_NUM]; struct hrtimer hrtimer; + + struct pinctrl *pinctrl; + struct pinctrl_state *pinctrl_state_default; + struct pinctrl_state *pinctrl_state_wakeup; }; struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, int sizeof_priv);