[PATCH 4/7] can: m_can: Support pinctrl wakeup state
Markus Schneider-Pargmann
msp at baylibre.com
Thu May 23 00:53:44 PDT 2024
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 <msp at baylibre.com>
---
drivers/net/can/m_can/m_can.c | 20 +++++++++++++++++++-
drivers/net/can/m_can/m_can.h | 4 ++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 80964e403a5e..c5585dc68f2f 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -2140,11 +2140,21 @@ 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;
if ((wol->wolopts & WAKE_PHY) != wol->wolopts)
return -EINVAL;
- device_set_wakeup_enable(cdev->dev, !!wol->wolopts & WAKE_PHY);
+ 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))
+ pinctrl_select_state(cdev->pinctrl, new_pinctrl_state);
+
+ device_set_wakeup_enable(cdev->dev, wol_enable);
return 0;
}
@@ -2309,6 +2319,14 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev,
SET_NETDEV_DEV(net_dev, dev);
m_can_of_parse_mram(class_dev, mram_config_vals);
+
+ class_dev->pinctrl = devm_pinctrl_get(dev);
+ if (!IS_ERR_OR_NULL(class_dev->pinctrl)) {
+ class_dev->pinctrl_state_default =
+ pinctrl_lookup_state(class_dev->pinctrl, "default");
+ class_dev->pinctrl_state_wakeup =
+ pinctrl_lookup_state(class_dev->pinctrl, "wakeup");
+ }
out:
return class_dev;
}
diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h
index 3a9edc292593..bdfbba67b336 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);
--
2.43.0
More information about the linux-arm-kernel
mailing list