Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: m_can: Map WoL to device_set_wakeup_enable

In some devices the pins of the m_can module can act as a wakeup source.
This patch helps do that by connecting the PHY_WAKE WoL option to
device_set_wakeup_enable. By marking this device as being wakeup
enabled, this setting can be used by platform code to decide which
sleep or poweroff mode to use.

Also this prepares the driver for the next patch in which the pinctrl
settings are changed depending on the desired wakeup source.

Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Reviewed-by: Kendall Willis <k-willis@ti.com>
Signed-off-by: Markus Schneider-Pargmann (TI.com) <msp@baylibre.com>
Link: https://patch.msgid.link/20251001-topic-mcan-wakeup-source-v6-12-v10-2-4ab508ac5d1e@baylibre.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Markus Schneider-Pargmann (TI.com) and committed by
Marc Kleine-Budde
04d5826b 73cc2882

+37
+37
drivers/net/can/m_can/m_can.c
··· 2238 2238 return 0; 2239 2239 } 2240 2240 2241 + static void m_can_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 2242 + { 2243 + struct m_can_classdev *cdev = netdev_priv(dev); 2244 + 2245 + wol->supported = device_can_wakeup(cdev->dev) ? WAKE_PHY : 0; 2246 + wol->wolopts = device_may_wakeup(cdev->dev) ? WAKE_PHY : 0; 2247 + } 2248 + 2249 + static int m_can_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 2250 + { 2251 + struct m_can_classdev *cdev = netdev_priv(dev); 2252 + bool wol_enable = !!(wol->wolopts & WAKE_PHY); 2253 + int ret; 2254 + 2255 + if (wol->wolopts & ~WAKE_PHY) 2256 + return -EINVAL; 2257 + 2258 + if (wol_enable == device_may_wakeup(cdev->dev)) 2259 + return 0; 2260 + 2261 + ret = device_set_wakeup_enable(cdev->dev, wol_enable); 2262 + if (ret) { 2263 + netdev_err(cdev->net, "Failed to set wakeup enable %pE\n", 2264 + ERR_PTR(ret)); 2265 + return ret; 2266 + } 2267 + 2268 + return 0; 2269 + } 2270 + 2241 2271 static const struct ethtool_ops m_can_ethtool_ops_coalescing = { 2242 2272 .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS_IRQ | 2243 2273 ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ | ··· 2277 2247 .get_ts_info = ethtool_op_get_ts_info, 2278 2248 .get_coalesce = m_can_get_coalesce, 2279 2249 .set_coalesce = m_can_set_coalesce, 2250 + .get_wol = m_can_get_wol, 2251 + .set_wol = m_can_set_wol, 2280 2252 }; 2281 2253 2282 2254 static const struct ethtool_ops m_can_ethtool_ops = { 2283 2255 .get_ts_info = ethtool_op_get_ts_info, 2256 + .get_wol = m_can_get_wol, 2257 + .set_wol = m_can_set_wol, 2284 2258 }; 2285 2259 2286 2260 static int register_m_can_dev(struct m_can_classdev *cdev) ··· 2410 2376 dev_err(dev, "Could not get Message RAM configuration."); 2411 2377 goto out; 2412 2378 } 2379 + 2380 + if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source")) 2381 + device_set_wakeup_capable(dev, true); 2413 2382 2414 2383 /* Get TX FIFO size 2415 2384 * Defines the total amount of echo buffers for loopback