From patchwork Mon Jul 29 07:41:32 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: 13744508 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 7A155C3DA61 for ; Mon, 29 Jul 2024 07:44:15 +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:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=euYaEmMVMSjTk2pj25N9i4771o+mJWDFmdSDcOKEIIY=; b=z4STXTObx2qIi0gkZ/g3i+bLPe tldf3gSUt2A4U15ugn8It6cWIBrIxqmSzg3s3gT30fLukVOe/f6eppAKw5N4JUjgrw6yOvLKmoPfz dAJ6dB+gts2/WwgpWY7C2D8MqmKycwXAYJORqKp36BZ+rPZP2uIJany6eXQGdlPASOYrK3ym5t7iP CecrBfY0CNMWf0nCg2zguv2H+X2LsbHaFqQu5/uh6IHqxpe/iGGk53yPzfOeVf6ezWTJTLAD0rxJR WUYYX6VONTTe+hxJZ77UzaxwlbqOXdaSTkvqy9JsWqHA3ysXr2I4sj28ixIfsLaaXjBMhCpafk8dr 0pNC4JCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYL36-0000000AOpm-0vmj; Mon, 29 Jul 2024 07:44:04 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYL1A-0000000AODz-065t for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 07:42:05 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4281ca54fd3so5612255e9.2 for ; Mon, 29 Jul 2024 00:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1722238922; x=1722843722; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=euYaEmMVMSjTk2pj25N9i4771o+mJWDFmdSDcOKEIIY=; b=dpns7nbaL9Brp70LMrOHnPt3nOwyortv+9jr1K2nxXVSdjS4sQd49okONntw8urLpb lUXr5Vj7fGLtuhZ1hzwRVx69KGkmUTY4kRzf3sSrI+qczE7a++bUsVU9qJVVbJUsZbY8 3NwKpc88UgSbW6abCgk1teI3SJ1RqKSkG0hoFAclSWhe31JsXk+9O5NiDiOjQvA2mOAf JnbBvwTKKv78/UMoUw1qpr8gvq8baQCGmXGzOff2OPDz+wFHEUncJJBAZOuL1iRk3vp2 3Pa85JCBegR3IqGyqj/G4Yh0S527xAan6bU+ZaMCnEZHfzsF8n1OkWLdd3Rw+D/rmA7Z C6wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722238922; x=1722843722; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=euYaEmMVMSjTk2pj25N9i4771o+mJWDFmdSDcOKEIIY=; b=LiqWL+3304GZp3kLHeG7PfpLxG8O41YxKsz7YkwCio/mkii0eAa+1zZ08yDTzPHgTf 2y/favKozA2j11MCaZh8MN3O5bql3602VSyjzkHsGZr3m7/hiOpZQp2EicbQ533y82RX 6bH069aP9qwD+tRL9pcJZvbuZHjI51HHBxcvb7fF9oOLGR26ELxf+tnot8QxW6wPSJQK 1SdN58DA5D8HuBS1WU2l22feKuL22w018IXC7h2K3AwM0naGB8gwdr1E5nIKhniDdTEE WD5k1V5uGDDW5GTIHgag9zRWkR+OSkdi1614pb+B6G9C1YhZ/92fvpRYocCmdUWAnrFX p08Q== X-Forwarded-Encrypted: i=1; AJvYcCXgwzOnrnvJn9OT0xgvHyctJ4pypwpI8cgZR2RPt5Eo+oX4vSqLoNPnZOrlpvAs2ZAcKE7qcDoIZ/FaZR/W/kudSYiGY3BtXM5HZXwQ5SI3DzW9/gM= X-Gm-Message-State: AOJu0YwRkJF0KetcefoCr51+VkHVh0CNwoWekQsnNVvNngb5O8fnZBkk dvr/xGbBkelDkktoY14ftdukQZQs7UA2K+0bDdmd1JnhqnmyCvav+Hs8wdUT2rU= X-Google-Smtp-Source: AGHT+IHlZDsneAUmpWQlVvOflGKEic5Rye1tKD/dzfIRoSAvJF4QRKJTN1ym1tr9RuFfvC7ACtRobg== X-Received: by 2002:a5d:6c68:0:b0:367:958e:9832 with SMTP id ffacd0b85a97d-36b5cee19c1mr5071133f8f.14.1722238922156; Mon, 29 Jul 2024 00:42:02 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a245:8609:c1c4:a4f8:94c8:31f2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36b36863aa7sm11460879f8f.109.2024.07.29.00.42.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 00:42:01 -0700 (PDT) From: Markus Schneider-Pargmann 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 , Markus Schneider-Pargmann , =?utf-8?q?Martin_Hundeb=C3=B8?= =?utf-8?q?ll?= , Christophe JAILLET , Michal Kubiak Cc: Vibhore Vardhan , Kevin Hilman , Dhruva Gole , Conor Dooley , linux-can@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 4/7] can: m_can: Support pinctrl wakeup state Date: Mon, 29 Jul 2024 09:41:32 +0200 Message-ID: <20240729074135.3850634-5-msp@baylibre.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240729074135.3850634-1-msp@baylibre.com> References: <20240729074135.3850634-1-msp@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_004204_203786_18AD778C X-CRM114-Status: GOOD ( 16.73 ) 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 | 57 +++++++++++++++++++++++++++++++++++ drivers/net/can/m_can/m_can.h | 4 +++ 2 files changed, 61 insertions(+) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 5b80a7d1f9a1..b71e7f8e9727 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -2193,6 +2193,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; @@ -2209,7 +2210,27 @@ 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)) { + 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 = { @@ -2377,7 +2398,43 @@ 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 92b2bd8628e6..b75b0dd6ccc9 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);