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

Configure Feed

Select the types of activity you want to include in your feed.

Merge patch series "Add R-Car CAN-FD suspend/resume support"

Biju <biju.das.au@gmail.com> says:

From: Biju Das <biju.das.jz@bp.renesas.com>

This patch series adds proper suspend/resume support to the Renesas
R-Car CAN-FD controller driver, after the customary cleanups and fixes.
It aims to fix CAN-FD operation after resume from s2ram on systems where
PSCI powers down the SoC.

This patch series has been tested on RZ/G3E SMARC EVK and RZ/G2L SMARC
EVK.

This patch series depend upon [1]
[1] https://lore.kernel.org/all/20251123112326.128448-1-biju.das.jz@bp.renesas.com/

v2->v3:
* Updated commit header and description for patch#3
* Collected tags.
v1->v2:
* Added logs from RZ/G3E
* Collected tags.
* Moved enabling of RAM clk from probe().
* Added RAM clk handling in rcar_canfd_global_{,de}init().
* Fixed the typo in error path of rcar_canfd_resume().

Logs from RZ/G3E:
root@smarc-rzg3e:~# /canfd_t_003_all.sh
[INFO] Testing can0<->can1 with bitrate 1000000 and dbitrate 4000000
[INFO] Bringing down can0 can1
[INFO] Bringing up can0 can1
[INFO] Testing can1 as producer and can0 as consumer
[ 541.705921] can: controller area network core
[ 541.710369] NET: Registered PF_CAN protocol family
[ 541.753974] can: raw protocol
[INFO] Testing can0 as producer and can1 as consumer
[INFO] Testing can0<->can1 with bitrate 500000 and dbitrate 2000000
[INFO] Bringing down can0 can1
[INFO] Bringing up can0 can1
[INFO] Testing can1 as producer and can0 as consumer
[INFO] Testing can0 as producer and can1 as consumer
[INFO] Testing can0<->can1 with bitrate 250000 and dbitrate 1000000
[INFO] Bringing down can0 can1
[INFO] Bringing up can0 can1
[INFO] Testing can1 as producer and can0 as consumer
[INFO] Testing can0 as producer and can1 as consumer

EXIT|PASS|canfd_t_003.sh|[00:00:25] ||

bind/unbind
----------
[ 566.821475] rcar_canfd 12440000.can: can_clk rate is 80000000
[ 566.828076] rcar_canfd 12440000.can: device registered (channel 1)
[ 566.834361] rcar_canfd 12440000.can: can_clk rate is 80000000
[ 566.841842] rcar_canfd 12440000.can: device registered (channel 4)
[ 566.848093] rcar_canfd 12440000.can: global operational state (canfd clk, fd mode)
[INFO] Testing can0<->can1 with bitrate 1000000 and dbitrate 4000000
[INFO] Bringing down can0 can1
[INFO] Bringing up can0 can1
[INFO] Testing can1 as producer and can0 as consumer
[INFO] Testing can0 as producer and can1 as consumer
[INFO] Testing can0<->can1 with bitrate 500000 and dbitrate 2000000
[INFO] Bringing down can0 can1
[INFO] Bringing up can0 can1
[INFO] Testing can1 as producer and can0 as consumer
[INFO] Testing can0 as producer and can1 as consumer
[INFO] Testing can0<->can1 with bitrate 250000 and dbitrate 1000000
[INFO] Bringing down can0 can1
[INFO] Bringing up can0 can1
[INFO] Testing can1 as producer and can0 as consumer
[INFO] Testing can0 as producer and can1 as consumer

EXIT|PASS|canfd_t_003.sh|[00:00:25] ||

s2idle
-----
[ 592.182479] PM: suspend entry (s2idle)
[ 592.187031] Filesystems sync: 0.000 seconds
[ 592.193221] Freezing user space processes
[ 592.199425] Freezing user space processes completed (elapsed 0.002 seconds)
[ 592.206450] OOM killer disabled.
[ 592.209843] Freezing remaining freezable tasks
[ 592.215775] Freezing remaining freezable tasks completed (elapsed 0.001 seconds)
[ 592.223247] printk: Suspending console(s) (use no_console_suspend to debug)
[ 592.260524] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[ 592.322759] renesas-gbeth 15c30000.ethernet end0: Link is Down
[ 596.070955] dwmac4: Master AXI performs any burst length
[ 596.072307] renesas-gbeth 15c30000.ethernet end0: No Safety Features support found
[ 596.072376] renesas-gbeth 15c30000.ethernet end0: IEEE 1588-2008 Advanced Timestamp supported
[ 596.077470] renesas-gbeth 15c30000.ethernet end0: configuring for phy/rgmii-id link mode
[ 596.087503] dwmac4: Master AXI performs any burst length
[ 596.088817] renesas-gbeth 15c40000.ethernet end1: No Safety Features support found
[ 596.088881] renesas-gbeth 15c40000.ethernet end1: IEEE 1588-2008 Advanced Timestamp supported
[ 596.093997] renesas-gbeth 15c40000.ethernet end1: configuring for phy/rgmii-id link mode
[ 596.141986] usb usb1: root hub lost power or was reset
[ 596.142031] usb usb2: root hub lost power or was reset
[ 598.304525] usb 2-1: reset SuperSpeed Plus Gen 2x1 USB device number 2 using xhci-renesas-hcd
[ 598.414846] OOM killer enabled.
[ 598.418002] Restarting tasks: Starting
[ 598.422518] Restarting tasks: Done
[ 598.425999] random: crng reseeded on system resumption
[ 598.431248] PM: suspend exit
[ 598.661875] renesas-gbeth 15c30000.ethernet end0: Link is Up - 1Gbps/Full - flow control rx/tx
[INFO] Testing can0<->can1 with bitrate 1000000 and dbitrate 4000000
[INFO] Bringing down can0 can1
[INFO] Bringing up can0 can1
[INFO] Testing can1 as producer and can0 as consumer
[INFO] Testing can0 as producer and can1 as consumer
[INFO] Testing can0<->can1 with bitrate 500000 and dbitrate 2000000
[INFO] Bringing down can0 can1
[INFO] Bringing up can0 can1
[INFO] Testing can1 as producer and can0 as consumer
[INFO] Testing can0 as producer and can1 as consumer
[INFO] Testing can0<->can1 with bitrate 250000 and dbitrate 1000000
[INFO] Bringing down can0 can1
[INFO] Bringing up can0 can1
[INFO] Testing can1 as producer and can0 as consumer
[INFO] Testing can0 as producer and can1 as consumer

EXIT|PASS|canfd_t_003.sh|[00:00:25] ||

Link: https://patch.msgid.link/20251124102837.106973-1-biju.das.jz@bp.renesas.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

+168 -78
+168 -78
drivers/net/can/rcar/rcar_canfd.c
··· 468 468 struct platform_device *pdev; /* Respective platform device */ 469 469 struct clk *clkp; /* Peripheral clock */ 470 470 struct clk *can_clk; /* fCAN clock */ 471 + struct clk *clk_ram; /* Clock RAM */ 471 472 unsigned long channels_mask; /* Enabled channels mask */ 472 473 bool extclk; /* CANFD or Ext clock */ 473 474 bool fdmode; /* CAN FD or Classical CAN only mode */ ··· 1570 1569 netif_stop_queue(ndev); 1571 1570 rcar_canfd_stop(ndev); 1572 1571 napi_disable(&priv->napi); 1573 - clk_disable_unprepare(gpriv->can_clk); 1574 1572 close_candev(ndev); 1573 + clk_disable_unprepare(gpriv->can_clk); 1575 1574 phy_power_off(priv->transceiver); 1576 1575 return 0; 1577 1576 } ··· 1961 1960 } 1962 1961 } 1963 1962 1963 + static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv) 1964 + { 1965 + struct device *dev = &gpriv->pdev->dev; 1966 + u32 rule_entry = 0; 1967 + u32 ch, sts; 1968 + int err; 1969 + 1970 + err = reset_control_reset(gpriv->rstc1); 1971 + if (err) 1972 + return err; 1973 + 1974 + err = reset_control_reset(gpriv->rstc2); 1975 + if (err) 1976 + goto fail_reset1; 1977 + 1978 + /* Enable peripheral clock for register access */ 1979 + err = clk_prepare_enable(gpriv->clkp); 1980 + if (err) { 1981 + dev_err(dev, "failed to enable peripheral clock: %pe\n", 1982 + ERR_PTR(err)); 1983 + goto fail_reset2; 1984 + } 1985 + 1986 + /* Enable RAM clock */ 1987 + err = clk_prepare_enable(gpriv->clk_ram); 1988 + if (err) { 1989 + dev_err(dev, 1990 + "failed to enable RAM clock, error %d\n", err); 1991 + goto fail_clk; 1992 + } 1993 + 1994 + err = rcar_canfd_reset_controller(gpriv); 1995 + if (err) { 1996 + dev_err(dev, "reset controller failed: %pe\n", ERR_PTR(err)); 1997 + goto fail_ram_clk; 1998 + } 1999 + 2000 + /* Controller in Global reset & Channel reset mode */ 2001 + rcar_canfd_configure_controller(gpriv); 2002 + 2003 + /* Configure per channel attributes */ 2004 + for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) { 2005 + /* Configure Channel's Rx fifo */ 2006 + rcar_canfd_configure_rx(gpriv, ch); 2007 + 2008 + /* Configure Channel's Tx (Common) fifo */ 2009 + rcar_canfd_configure_tx(gpriv, ch); 2010 + 2011 + /* Configure receive rules */ 2012 + rcar_canfd_configure_afl_rules(gpriv, ch, rule_entry); 2013 + rule_entry += RCANFD_CHANNEL_NUMRULES; 2014 + } 2015 + 2016 + /* Configure common interrupts */ 2017 + rcar_canfd_enable_global_interrupts(gpriv); 2018 + 2019 + /* Start Global operation mode */ 2020 + rcar_canfd_update_bit(gpriv->base, RCANFD_GCTR, RCANFD_GCTR_GMDC_MASK, 2021 + RCANFD_GCTR_GMDC_GOPM); 2022 + 2023 + /* Verify mode change */ 2024 + err = readl_poll_timeout((gpriv->base + RCANFD_GSTS), sts, 2025 + !(sts & RCANFD_GSTS_GNOPM), 2, 500000); 2026 + if (err) { 2027 + dev_err(dev, "global operational mode failed\n"); 2028 + goto fail_mode; 2029 + } 2030 + 2031 + return 0; 2032 + 2033 + fail_mode: 2034 + rcar_canfd_disable_global_interrupts(gpriv); 2035 + fail_ram_clk: 2036 + clk_disable_unprepare(gpriv->clk_ram); 2037 + fail_clk: 2038 + clk_disable_unprepare(gpriv->clkp); 2039 + fail_reset2: 2040 + reset_control_assert(gpriv->rstc2); 2041 + fail_reset1: 2042 + reset_control_assert(gpriv->rstc1); 2043 + return err; 2044 + } 2045 + 2046 + static void rcar_canfd_global_deinit(struct rcar_canfd_global *gpriv, bool full) 2047 + { 2048 + rcar_canfd_disable_global_interrupts(gpriv); 2049 + 2050 + if (full) { 2051 + rcar_canfd_reset_controller(gpriv); 2052 + 2053 + /* Enter global sleep mode */ 2054 + rcar_canfd_set_bit(gpriv->base, RCANFD_GCTR, RCANFD_GCTR_GSLPR); 2055 + } 2056 + 2057 + clk_disable_unprepare(gpriv->clk_ram); 2058 + clk_disable_unprepare(gpriv->clkp); 2059 + reset_control_assert(gpriv->rstc2); 2060 + reset_control_assert(gpriv->rstc1); 2061 + } 2062 + 1964 2063 static int rcar_canfd_probe(struct platform_device *pdev) 1965 2064 { 1966 2065 struct phy *transceivers[RCANFD_NUM_CHANNELS] = { NULL, }; 1967 2066 const struct rcar_canfd_hw_info *info; 1968 2067 struct device *dev = &pdev->dev; 1969 2068 void __iomem *addr; 1970 - u32 sts, ch, fcan_freq; 1971 2069 struct rcar_canfd_global *gpriv; 1972 2070 struct device_node *of_child; 1973 2071 unsigned long channels_mask = 0; 1974 2072 int err, ch_irq, g_irq; 1975 2073 int g_err_irq, g_recc_irq; 1976 - u32 rule_entry = 0; 1977 2074 bool fdmode = true; /* CAN FD only mode - default */ 1978 2075 char name[9] = "channelX"; 1979 - struct clk *clk_ram; 2076 + u32 ch, fcan_freq; 1980 2077 int i; 1981 2078 1982 2079 info = of_device_get_match_data(dev); ··· 2164 2065 gpriv->extclk = gpriv->info->external_clk; 2165 2066 } 2166 2067 2167 - clk_ram = devm_clk_get_optional_enabled(dev, "ram_clk"); 2168 - if (IS_ERR(clk_ram)) 2169 - return dev_err_probe(dev, PTR_ERR(clk_ram), 2170 - "cannot get enabled ram clock\n"); 2068 + gpriv->clk_ram = devm_clk_get_optional(dev, "ram_clk"); 2069 + if (IS_ERR(gpriv->clk_ram)) 2070 + return dev_err_probe(dev, PTR_ERR(gpriv->clk_ram), 2071 + "cannot get ram clock\n"); 2171 2072 2172 2073 addr = devm_platform_ioremap_resource(pdev, 0); 2173 2074 if (IS_ERR(addr)) { ··· 2216 2117 } 2217 2118 } 2218 2119 2219 - err = reset_control_reset(gpriv->rstc1); 2120 + err = rcar_canfd_global_init(gpriv); 2220 2121 if (err) 2221 - goto fail_dev; 2222 - err = reset_control_reset(gpriv->rstc2); 2223 - if (err) { 2224 - reset_control_assert(gpriv->rstc1); 2225 - goto fail_dev; 2226 - } 2227 - 2228 - /* Enable peripheral clock for register access */ 2229 - err = clk_prepare_enable(gpriv->clkp); 2230 - if (err) { 2231 - dev_err(dev, "failed to enable peripheral clock: %pe\n", 2232 - ERR_PTR(err)); 2233 - goto fail_reset; 2234 - } 2235 - 2236 - err = rcar_canfd_reset_controller(gpriv); 2237 - if (err) { 2238 - dev_err(dev, "reset controller failed: %pe\n", ERR_PTR(err)); 2239 - goto fail_clk; 2240 - } 2241 - 2242 - /* Controller in Global reset & Channel reset mode */ 2243 - rcar_canfd_configure_controller(gpriv); 2244 - 2245 - /* Configure per channel attributes */ 2246 - for_each_set_bit(ch, &gpriv->channels_mask, info->max_channels) { 2247 - /* Configure Channel's Rx fifo */ 2248 - rcar_canfd_configure_rx(gpriv, ch); 2249 - 2250 - /* Configure Channel's Tx (Common) fifo */ 2251 - rcar_canfd_configure_tx(gpriv, ch); 2252 - 2253 - /* Configure receive rules */ 2254 - rcar_canfd_configure_afl_rules(gpriv, ch, rule_entry); 2255 - rule_entry += RCANFD_CHANNEL_NUMRULES; 2256 - } 2257 - 2258 - /* Configure common interrupts */ 2259 - rcar_canfd_enable_global_interrupts(gpriv); 2260 - 2261 - /* Start Global operation mode */ 2262 - rcar_canfd_update_bit(gpriv->base, RCANFD_GCTR, RCANFD_GCTR_GMDC_MASK, 2263 - RCANFD_GCTR_GMDC_GOPM); 2264 - 2265 - /* Verify mode change */ 2266 - err = readl_poll_timeout((gpriv->base + RCANFD_GSTS), sts, 2267 - !(sts & RCANFD_GSTS_GNOPM), 2, 500000); 2268 - if (err) { 2269 - dev_err(dev, "global operational mode failed\n"); 2270 2122 goto fail_mode; 2271 - } 2272 2123 2273 2124 for_each_set_bit(ch, &gpriv->channels_mask, info->max_channels) { 2274 2125 err = rcar_canfd_channel_probe(gpriv, ch, fcan_freq, ··· 2237 2188 for_each_set_bit(ch, &gpriv->channels_mask, info->max_channels) 2238 2189 rcar_canfd_channel_remove(gpriv, ch); 2239 2190 fail_mode: 2240 - rcar_canfd_disable_global_interrupts(gpriv); 2241 - fail_clk: 2242 - clk_disable_unprepare(gpriv->clkp); 2243 - fail_reset: 2244 - reset_control_assert(gpriv->rstc1); 2245 - reset_control_assert(gpriv->rstc2); 2191 + rcar_canfd_global_deinit(gpriv, false); 2246 2192 fail_dev: 2247 2193 return err; 2248 2194 } ··· 2247 2203 struct rcar_canfd_global *gpriv = platform_get_drvdata(pdev); 2248 2204 u32 ch; 2249 2205 2250 - rcar_canfd_reset_controller(gpriv); 2251 - rcar_canfd_disable_global_interrupts(gpriv); 2252 - 2253 2206 for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) { 2254 2207 rcar_canfd_disable_channel_interrupts(gpriv->ch[ch]); 2255 2208 rcar_canfd_channel_remove(gpriv, ch); 2256 2209 } 2257 2210 2258 - /* Enter global sleep mode */ 2259 - rcar_canfd_set_bit(gpriv->base, RCANFD_GCTR, RCANFD_GCTR_GSLPR); 2260 - clk_disable_unprepare(gpriv->clkp); 2261 - reset_control_assert(gpriv->rstc1); 2262 - reset_control_assert(gpriv->rstc2); 2211 + rcar_canfd_global_deinit(gpriv, true); 2263 2212 } 2264 2213 2265 - static int __maybe_unused rcar_canfd_suspend(struct device *dev) 2214 + static int rcar_canfd_suspend(struct device *dev) 2266 2215 { 2216 + struct rcar_canfd_global *gpriv = dev_get_drvdata(dev); 2217 + int err; 2218 + u32 ch; 2219 + 2220 + for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) { 2221 + struct rcar_canfd_channel *priv = gpriv->ch[ch]; 2222 + struct net_device *ndev = priv->ndev; 2223 + 2224 + if (!netif_running(ndev)) 2225 + continue; 2226 + 2227 + netif_device_detach(ndev); 2228 + 2229 + err = rcar_canfd_close(ndev); 2230 + if (err) { 2231 + netdev_err(ndev, "rcar_canfd_close() failed %pe\n", 2232 + ERR_PTR(err)); 2233 + return err; 2234 + } 2235 + 2236 + priv->can.state = CAN_STATE_SLEEPING; 2237 + } 2238 + 2239 + /* TODO Skip if wake-up (which is not yet supported) is enabled */ 2240 + rcar_canfd_global_deinit(gpriv, false); 2241 + 2267 2242 return 0; 2268 2243 } 2269 2244 2270 - static int __maybe_unused rcar_canfd_resume(struct device *dev) 2245 + static int rcar_canfd_resume(struct device *dev) 2271 2246 { 2247 + struct rcar_canfd_global *gpriv = dev_get_drvdata(dev); 2248 + int err; 2249 + u32 ch; 2250 + 2251 + err = rcar_canfd_global_init(gpriv); 2252 + if (err) { 2253 + dev_err(dev, "rcar_canfd_global_init() failed %pe\n", ERR_PTR(err)); 2254 + return err; 2255 + } 2256 + 2257 + for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) { 2258 + struct rcar_canfd_channel *priv = gpriv->ch[ch]; 2259 + struct net_device *ndev = priv->ndev; 2260 + 2261 + if (!netif_running(ndev)) 2262 + continue; 2263 + 2264 + err = rcar_canfd_open(ndev); 2265 + if (err) { 2266 + netdev_err(ndev, "rcar_canfd_open() failed %pe\n", 2267 + ERR_PTR(err)); 2268 + return err; 2269 + } 2270 + 2271 + netif_device_attach(ndev); 2272 + } 2273 + 2272 2274 return 0; 2273 2275 } 2274 2276 2275 - static SIMPLE_DEV_PM_OPS(rcar_canfd_pm_ops, rcar_canfd_suspend, 2276 - rcar_canfd_resume); 2277 + static DEFINE_SIMPLE_DEV_PM_OPS(rcar_canfd_pm_ops, rcar_canfd_suspend, 2278 + rcar_canfd_resume); 2277 2279 2278 2280 static const __maybe_unused struct of_device_id rcar_canfd_of_table[] = { 2279 2281 { .compatible = "renesas,r8a779a0-canfd", .data = &rcar_gen4_hw_info }, ··· 2336 2246 .driver = { 2337 2247 .name = RCANFD_DRV_NAME, 2338 2248 .of_match_table = of_match_ptr(rcar_canfd_of_table), 2339 - .pm = &rcar_canfd_pm_ops, 2249 + .pm = pm_sleep_ptr(&rcar_canfd_pm_ops), 2340 2250 }, 2341 2251 .probe = rcar_canfd_probe, 2342 2252 .remove = rcar_canfd_remove,