Skip to content

Commit 0184165

Browse files
Niklas Söderlunddavem330
Niklas Söderlund
authored andcommitted
ravb: add sleep PM suspend/resume support
The interface would not function after the system had been woken up after have been suspended (echo mem > /sys/power/state) cycle. The reason for this is that all device registers have been reset to its default values. This patch adds sleep suspend and resume functions that detached the interface at suspend and restore the registers and reattach the interface at resume. Only the registers that are only configured at probe time needs to be explicitly restored by the resume handler. All other registers are reconfigured by either reopening the device in the resume handler (if the device was running when the system was suspended) or when the interface is opened by a user at a later time. Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0dff88d commit 0184165

File tree

1 file changed

+64
-8
lines changed

1 file changed

+64
-8
lines changed

drivers/net/ethernet/renesas/ravb_main.c

+64-8
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,20 @@ static int ravb_set_gti(struct net_device *ndev)
18761876
return 0;
18771877
}
18781878

1879+
static void ravb_set_config_mode(struct net_device *ndev)
1880+
{
1881+
struct ravb_private *priv = netdev_priv(ndev);
1882+
1883+
if (priv->chip_id == RCAR_GEN2) {
1884+
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
1885+
/* Set CSEL value */
1886+
ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB);
1887+
} else {
1888+
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG |
1889+
CCC_GAC | CCC_CSEL_HPB);
1890+
}
1891+
}
1892+
18791893
static int ravb_probe(struct platform_device *pdev)
18801894
{
18811895
struct device_node *np = pdev->dev.of_node;
@@ -1978,14 +1992,7 @@ static int ravb_probe(struct platform_device *pdev)
19781992
ndev->ethtool_ops = &ravb_ethtool_ops;
19791993

19801994
/* Set AVB config mode */
1981-
if (chip_id == RCAR_GEN2) {
1982-
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG);
1983-
/* Set CSEL value */
1984-
ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB);
1985-
} else {
1986-
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_CONFIG |
1987-
CCC_GAC | CCC_CSEL_HPB);
1988-
}
1995+
ravb_set_config_mode(ndev);
19891996

19901997
/* Set GTI value */
19911998
error = ravb_set_gti(ndev);
@@ -2097,6 +2104,54 @@ static int ravb_remove(struct platform_device *pdev)
20972104
}
20982105

20992106
#ifdef CONFIG_PM
2107+
static int ravb_runtime_suspend(struct device *dev)
2108+
{
2109+
struct net_device *ndev = dev_get_drvdata(dev);
2110+
int ret = 0;
2111+
2112+
if (netif_running(ndev)) {
2113+
netif_device_detach(ndev);
2114+
ret = ravb_close(ndev);
2115+
}
2116+
2117+
return ret;
2118+
}
2119+
2120+
static int ravb_runtime_resume(struct device *dev)
2121+
{
2122+
struct net_device *ndev = dev_get_drvdata(dev);
2123+
struct ravb_private *priv = netdev_priv(ndev);
2124+
int ret = 0;
2125+
2126+
/* All register have been reset to default values.
2127+
* Restore all registers which where setup at probe time and
2128+
* reopen device if it was running before system suspended.
2129+
*/
2130+
2131+
/* Set AVB config mode */
2132+
ravb_set_config_mode(ndev);
2133+
2134+
/* Set GTI value */
2135+
ret = ravb_set_gti(ndev);
2136+
if (ret)
2137+
return ret;
2138+
2139+
/* Request GTI loading */
2140+
ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
2141+
2142+
/* Restore descriptor base address table */
2143+
ravb_write(ndev, priv->desc_bat_dma, DBAT);
2144+
2145+
if (netif_running(ndev)) {
2146+
ret = ravb_open(ndev);
2147+
if (ret < 0)
2148+
return ret;
2149+
netif_device_attach(ndev);
2150+
}
2151+
2152+
return ret;
2153+
}
2154+
21002155
static int ravb_runtime_nop(struct device *dev)
21012156
{
21022157
/* Runtime PM callback shared between ->runtime_suspend()
@@ -2110,6 +2165,7 @@ static int ravb_runtime_nop(struct device *dev)
21102165
}
21112166

21122167
static const struct dev_pm_ops ravb_dev_pm_ops = {
2168+
SET_SYSTEM_SLEEP_PM_OPS(ravb_runtime_suspend, ravb_runtime_resume)
21132169
SET_RUNTIME_PM_OPS(ravb_runtime_nop, ravb_runtime_nop, NULL)
21142170
};
21152171

0 commit comments

Comments
 (0)