mirror of
https://github.com/torvalds/linux.git
synced 2026-05-28 09:04:39 +02:00
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>
This commit is contained in:
commit
4718d39e72
|
|
@ -468,6 +468,7 @@ struct rcar_canfd_global {
|
|||
struct platform_device *pdev; /* Respective platform device */
|
||||
struct clk *clkp; /* Peripheral clock */
|
||||
struct clk *can_clk; /* fCAN clock */
|
||||
struct clk *clk_ram; /* Clock RAM */
|
||||
unsigned long channels_mask; /* Enabled channels mask */
|
||||
bool extclk; /* CANFD or Ext clock */
|
||||
bool fdmode; /* CAN FD or Classical CAN only mode */
|
||||
|
|
@ -1569,8 +1570,8 @@ static int rcar_canfd_close(struct net_device *ndev)
|
|||
netif_stop_queue(ndev);
|
||||
rcar_canfd_stop(ndev);
|
||||
napi_disable(&priv->napi);
|
||||
clk_disable_unprepare(gpriv->can_clk);
|
||||
close_candev(ndev);
|
||||
clk_disable_unprepare(gpriv->can_clk);
|
||||
phy_power_off(priv->transceiver);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1960,22 +1961,120 @@ static void rcar_canfd_channel_remove(struct rcar_canfd_global *gpriv, u32 ch)
|
|||
}
|
||||
}
|
||||
|
||||
static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv)
|
||||
{
|
||||
struct device *dev = &gpriv->pdev->dev;
|
||||
u32 rule_entry = 0;
|
||||
u32 ch, sts;
|
||||
int err;
|
||||
|
||||
err = reset_control_reset(gpriv->rstc1);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = reset_control_reset(gpriv->rstc2);
|
||||
if (err)
|
||||
goto fail_reset1;
|
||||
|
||||
/* Enable peripheral clock for register access */
|
||||
err = clk_prepare_enable(gpriv->clkp);
|
||||
if (err) {
|
||||
dev_err(dev, "failed to enable peripheral clock: %pe\n",
|
||||
ERR_PTR(err));
|
||||
goto fail_reset2;
|
||||
}
|
||||
|
||||
/* Enable RAM clock */
|
||||
err = clk_prepare_enable(gpriv->clk_ram);
|
||||
if (err) {
|
||||
dev_err(dev,
|
||||
"failed to enable RAM clock, error %d\n", err);
|
||||
goto fail_clk;
|
||||
}
|
||||
|
||||
err = rcar_canfd_reset_controller(gpriv);
|
||||
if (err) {
|
||||
dev_err(dev, "reset controller failed: %pe\n", ERR_PTR(err));
|
||||
goto fail_ram_clk;
|
||||
}
|
||||
|
||||
/* Controller in Global reset & Channel reset mode */
|
||||
rcar_canfd_configure_controller(gpriv);
|
||||
|
||||
/* Configure per channel attributes */
|
||||
for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) {
|
||||
/* Configure Channel's Rx fifo */
|
||||
rcar_canfd_configure_rx(gpriv, ch);
|
||||
|
||||
/* Configure Channel's Tx (Common) fifo */
|
||||
rcar_canfd_configure_tx(gpriv, ch);
|
||||
|
||||
/* Configure receive rules */
|
||||
rcar_canfd_configure_afl_rules(gpriv, ch, rule_entry);
|
||||
rule_entry += RCANFD_CHANNEL_NUMRULES;
|
||||
}
|
||||
|
||||
/* Configure common interrupts */
|
||||
rcar_canfd_enable_global_interrupts(gpriv);
|
||||
|
||||
/* Start Global operation mode */
|
||||
rcar_canfd_update_bit(gpriv->base, RCANFD_GCTR, RCANFD_GCTR_GMDC_MASK,
|
||||
RCANFD_GCTR_GMDC_GOPM);
|
||||
|
||||
/* Verify mode change */
|
||||
err = readl_poll_timeout((gpriv->base + RCANFD_GSTS), sts,
|
||||
!(sts & RCANFD_GSTS_GNOPM), 2, 500000);
|
||||
if (err) {
|
||||
dev_err(dev, "global operational mode failed\n");
|
||||
goto fail_mode;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
fail_mode:
|
||||
rcar_canfd_disable_global_interrupts(gpriv);
|
||||
fail_ram_clk:
|
||||
clk_disable_unprepare(gpriv->clk_ram);
|
||||
fail_clk:
|
||||
clk_disable_unprepare(gpriv->clkp);
|
||||
fail_reset2:
|
||||
reset_control_assert(gpriv->rstc2);
|
||||
fail_reset1:
|
||||
reset_control_assert(gpriv->rstc1);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void rcar_canfd_global_deinit(struct rcar_canfd_global *gpriv, bool full)
|
||||
{
|
||||
rcar_canfd_disable_global_interrupts(gpriv);
|
||||
|
||||
if (full) {
|
||||
rcar_canfd_reset_controller(gpriv);
|
||||
|
||||
/* Enter global sleep mode */
|
||||
rcar_canfd_set_bit(gpriv->base, RCANFD_GCTR, RCANFD_GCTR_GSLPR);
|
||||
}
|
||||
|
||||
clk_disable_unprepare(gpriv->clk_ram);
|
||||
clk_disable_unprepare(gpriv->clkp);
|
||||
reset_control_assert(gpriv->rstc2);
|
||||
reset_control_assert(gpriv->rstc1);
|
||||
}
|
||||
|
||||
static int rcar_canfd_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct phy *transceivers[RCANFD_NUM_CHANNELS] = { NULL, };
|
||||
const struct rcar_canfd_hw_info *info;
|
||||
struct device *dev = &pdev->dev;
|
||||
void __iomem *addr;
|
||||
u32 sts, ch, fcan_freq;
|
||||
struct rcar_canfd_global *gpriv;
|
||||
struct device_node *of_child;
|
||||
unsigned long channels_mask = 0;
|
||||
int err, ch_irq, g_irq;
|
||||
int g_err_irq, g_recc_irq;
|
||||
u32 rule_entry = 0;
|
||||
bool fdmode = true; /* CAN FD only mode - default */
|
||||
char name[9] = "channelX";
|
||||
struct clk *clk_ram;
|
||||
u32 ch, fcan_freq;
|
||||
int i;
|
||||
|
||||
info = of_device_get_match_data(dev);
|
||||
|
|
@ -2065,10 +2164,10 @@ static int rcar_canfd_probe(struct platform_device *pdev)
|
|||
gpriv->extclk = gpriv->info->external_clk;
|
||||
}
|
||||
|
||||
clk_ram = devm_clk_get_optional_enabled(dev, "ram_clk");
|
||||
if (IS_ERR(clk_ram))
|
||||
return dev_err_probe(dev, PTR_ERR(clk_ram),
|
||||
"cannot get enabled ram clock\n");
|
||||
gpriv->clk_ram = devm_clk_get_optional(dev, "ram_clk");
|
||||
if (IS_ERR(gpriv->clk_ram))
|
||||
return dev_err_probe(dev, PTR_ERR(gpriv->clk_ram),
|
||||
"cannot get ram clock\n");
|
||||
|
||||
addr = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(addr)) {
|
||||
|
|
@ -2117,59 +2216,9 @@ static int rcar_canfd_probe(struct platform_device *pdev)
|
|||
}
|
||||
}
|
||||
|
||||
err = reset_control_reset(gpriv->rstc1);
|
||||
err = rcar_canfd_global_init(gpriv);
|
||||
if (err)
|
||||
goto fail_dev;
|
||||
err = reset_control_reset(gpriv->rstc2);
|
||||
if (err) {
|
||||
reset_control_assert(gpriv->rstc1);
|
||||
goto fail_dev;
|
||||
}
|
||||
|
||||
/* Enable peripheral clock for register access */
|
||||
err = clk_prepare_enable(gpriv->clkp);
|
||||
if (err) {
|
||||
dev_err(dev, "failed to enable peripheral clock: %pe\n",
|
||||
ERR_PTR(err));
|
||||
goto fail_reset;
|
||||
}
|
||||
|
||||
err = rcar_canfd_reset_controller(gpriv);
|
||||
if (err) {
|
||||
dev_err(dev, "reset controller failed: %pe\n", ERR_PTR(err));
|
||||
goto fail_clk;
|
||||
}
|
||||
|
||||
/* Controller in Global reset & Channel reset mode */
|
||||
rcar_canfd_configure_controller(gpriv);
|
||||
|
||||
/* Configure per channel attributes */
|
||||
for_each_set_bit(ch, &gpriv->channels_mask, info->max_channels) {
|
||||
/* Configure Channel's Rx fifo */
|
||||
rcar_canfd_configure_rx(gpriv, ch);
|
||||
|
||||
/* Configure Channel's Tx (Common) fifo */
|
||||
rcar_canfd_configure_tx(gpriv, ch);
|
||||
|
||||
/* Configure receive rules */
|
||||
rcar_canfd_configure_afl_rules(gpriv, ch, rule_entry);
|
||||
rule_entry += RCANFD_CHANNEL_NUMRULES;
|
||||
}
|
||||
|
||||
/* Configure common interrupts */
|
||||
rcar_canfd_enable_global_interrupts(gpriv);
|
||||
|
||||
/* Start Global operation mode */
|
||||
rcar_canfd_update_bit(gpriv->base, RCANFD_GCTR, RCANFD_GCTR_GMDC_MASK,
|
||||
RCANFD_GCTR_GMDC_GOPM);
|
||||
|
||||
/* Verify mode change */
|
||||
err = readl_poll_timeout((gpriv->base + RCANFD_GSTS), sts,
|
||||
!(sts & RCANFD_GSTS_GNOPM), 2, 500000);
|
||||
if (err) {
|
||||
dev_err(dev, "global operational mode failed\n");
|
||||
goto fail_mode;
|
||||
}
|
||||
|
||||
for_each_set_bit(ch, &gpriv->channels_mask, info->max_channels) {
|
||||
err = rcar_canfd_channel_probe(gpriv, ch, fcan_freq,
|
||||
|
|
@ -2188,12 +2237,7 @@ static int rcar_canfd_probe(struct platform_device *pdev)
|
|||
for_each_set_bit(ch, &gpriv->channels_mask, info->max_channels)
|
||||
rcar_canfd_channel_remove(gpriv, ch);
|
||||
fail_mode:
|
||||
rcar_canfd_disable_global_interrupts(gpriv);
|
||||
fail_clk:
|
||||
clk_disable_unprepare(gpriv->clkp);
|
||||
fail_reset:
|
||||
reset_control_assert(gpriv->rstc1);
|
||||
reset_control_assert(gpriv->rstc2);
|
||||
rcar_canfd_global_deinit(gpriv, false);
|
||||
fail_dev:
|
||||
return err;
|
||||
}
|
||||
|
|
@ -2203,33 +2247,79 @@ static void rcar_canfd_remove(struct platform_device *pdev)
|
|||
struct rcar_canfd_global *gpriv = platform_get_drvdata(pdev);
|
||||
u32 ch;
|
||||
|
||||
rcar_canfd_reset_controller(gpriv);
|
||||
rcar_canfd_disable_global_interrupts(gpriv);
|
||||
|
||||
for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) {
|
||||
rcar_canfd_disable_channel_interrupts(gpriv->ch[ch]);
|
||||
rcar_canfd_channel_remove(gpriv, ch);
|
||||
}
|
||||
|
||||
/* Enter global sleep mode */
|
||||
rcar_canfd_set_bit(gpriv->base, RCANFD_GCTR, RCANFD_GCTR_GSLPR);
|
||||
clk_disable_unprepare(gpriv->clkp);
|
||||
reset_control_assert(gpriv->rstc1);
|
||||
reset_control_assert(gpriv->rstc2);
|
||||
rcar_canfd_global_deinit(gpriv, true);
|
||||
}
|
||||
|
||||
static int __maybe_unused rcar_canfd_suspend(struct device *dev)
|
||||
static int rcar_canfd_suspend(struct device *dev)
|
||||
{
|
||||
struct rcar_canfd_global *gpriv = dev_get_drvdata(dev);
|
||||
int err;
|
||||
u32 ch;
|
||||
|
||||
for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) {
|
||||
struct rcar_canfd_channel *priv = gpriv->ch[ch];
|
||||
struct net_device *ndev = priv->ndev;
|
||||
|
||||
if (!netif_running(ndev))
|
||||
continue;
|
||||
|
||||
netif_device_detach(ndev);
|
||||
|
||||
err = rcar_canfd_close(ndev);
|
||||
if (err) {
|
||||
netdev_err(ndev, "rcar_canfd_close() failed %pe\n",
|
||||
ERR_PTR(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
priv->can.state = CAN_STATE_SLEEPING;
|
||||
}
|
||||
|
||||
/* TODO Skip if wake-up (which is not yet supported) is enabled */
|
||||
rcar_canfd_global_deinit(gpriv, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __maybe_unused rcar_canfd_resume(struct device *dev)
|
||||
static int rcar_canfd_resume(struct device *dev)
|
||||
{
|
||||
struct rcar_canfd_global *gpriv = dev_get_drvdata(dev);
|
||||
int err;
|
||||
u32 ch;
|
||||
|
||||
err = rcar_canfd_global_init(gpriv);
|
||||
if (err) {
|
||||
dev_err(dev, "rcar_canfd_global_init() failed %pe\n", ERR_PTR(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) {
|
||||
struct rcar_canfd_channel *priv = gpriv->ch[ch];
|
||||
struct net_device *ndev = priv->ndev;
|
||||
|
||||
if (!netif_running(ndev))
|
||||
continue;
|
||||
|
||||
err = rcar_canfd_open(ndev);
|
||||
if (err) {
|
||||
netdev_err(ndev, "rcar_canfd_open() failed %pe\n",
|
||||
ERR_PTR(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
netif_device_attach(ndev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SIMPLE_DEV_PM_OPS(rcar_canfd_pm_ops, rcar_canfd_suspend,
|
||||
rcar_canfd_resume);
|
||||
static DEFINE_SIMPLE_DEV_PM_OPS(rcar_canfd_pm_ops, rcar_canfd_suspend,
|
||||
rcar_canfd_resume);
|
||||
|
||||
static const __maybe_unused struct of_device_id rcar_canfd_of_table[] = {
|
||||
{ .compatible = "renesas,r8a779a0-canfd", .data = &rcar_gen4_hw_info },
|
||||
|
|
@ -2246,7 +2336,7 @@ static struct platform_driver rcar_canfd_driver = {
|
|||
.driver = {
|
||||
.name = RCANFD_DRV_NAME,
|
||||
.of_match_table = of_match_ptr(rcar_canfd_of_table),
|
||||
.pm = &rcar_canfd_pm_ops,
|
||||
.pm = pm_sleep_ptr(&rcar_canfd_pm_ops),
|
||||
},
|
||||
.probe = rcar_canfd_probe,
|
||||
.remove = rcar_canfd_remove,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user