Commit 822c8d45 authored by Masahiro Yamada's avatar Masahiro Yamada Committed by Wolfram Sang

i2c: uniphier-f: add suspend / resume support

When resuming, set up registers that have been lost in the sleep state.
Also, add clock handling in the resume / suspend hooks.
Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 9f9d6a40
...@@ -97,6 +97,7 @@ struct uniphier_fi2c_priv { ...@@ -97,6 +97,7 @@ struct uniphier_fi2c_priv {
int error; int error;
unsigned int flags; unsigned int flags;
unsigned int busy_cnt; unsigned int busy_cnt;
unsigned int clk_cycle;
}; };
static void uniphier_fi2c_fill_txfifo(struct uniphier_fi2c_priv *priv, static void uniphier_fi2c_fill_txfifo(struct uniphier_fi2c_priv *priv,
...@@ -461,9 +462,9 @@ static struct i2c_bus_recovery_info uniphier_fi2c_bus_recovery_info = { ...@@ -461,9 +462,9 @@ static struct i2c_bus_recovery_info uniphier_fi2c_bus_recovery_info = {
.unprepare_recovery = uniphier_fi2c_unprepare_recovery, .unprepare_recovery = uniphier_fi2c_unprepare_recovery,
}; };
static void uniphier_fi2c_hw_init(struct uniphier_fi2c_priv *priv, static void uniphier_fi2c_hw_init(struct uniphier_fi2c_priv *priv)
u32 bus_speed, unsigned long clk_rate)
{ {
unsigned int cyc = priv->clk_cycle;
u32 tmp; u32 tmp;
tmp = readl(priv->membase + UNIPHIER_FI2C_CR); tmp = readl(priv->membase + UNIPHIER_FI2C_CR);
...@@ -472,12 +473,10 @@ static void uniphier_fi2c_hw_init(struct uniphier_fi2c_priv *priv, ...@@ -472,12 +473,10 @@ static void uniphier_fi2c_hw_init(struct uniphier_fi2c_priv *priv,
uniphier_fi2c_reset(priv); uniphier_fi2c_reset(priv);
tmp = clk_rate / bus_speed; writel(cyc, priv->membase + UNIPHIER_FI2C_CYC);
writel(cyc / 2, priv->membase + UNIPHIER_FI2C_LCTL);
writel(tmp, priv->membase + UNIPHIER_FI2C_CYC); writel(cyc / 2, priv->membase + UNIPHIER_FI2C_SSUT);
writel(tmp / 2, priv->membase + UNIPHIER_FI2C_LCTL); writel(cyc / 16, priv->membase + UNIPHIER_FI2C_DSUT);
writel(tmp / 2, priv->membase + UNIPHIER_FI2C_SSUT);
writel(tmp / 16, priv->membase + UNIPHIER_FI2C_DSUT);
uniphier_fi2c_prepare_operation(priv); uniphier_fi2c_prepare_operation(priv);
} }
...@@ -531,6 +530,7 @@ static int uniphier_fi2c_probe(struct platform_device *pdev) ...@@ -531,6 +530,7 @@ static int uniphier_fi2c_probe(struct platform_device *pdev)
goto disable_clk; goto disable_clk;
} }
priv->clk_cycle = clk_rate / bus_speed;
init_completion(&priv->comp); init_completion(&priv->comp);
priv->adap.owner = THIS_MODULE; priv->adap.owner = THIS_MODULE;
priv->adap.algo = &uniphier_fi2c_algo; priv->adap.algo = &uniphier_fi2c_algo;
...@@ -541,7 +541,7 @@ static int uniphier_fi2c_probe(struct platform_device *pdev) ...@@ -541,7 +541,7 @@ static int uniphier_fi2c_probe(struct platform_device *pdev)
i2c_set_adapdata(&priv->adap, priv); i2c_set_adapdata(&priv->adap, priv);
platform_set_drvdata(pdev, priv); platform_set_drvdata(pdev, priv);
uniphier_fi2c_hw_init(priv, bus_speed, clk_rate); uniphier_fi2c_hw_init(priv);
ret = devm_request_irq(dev, irq, uniphier_fi2c_interrupt, 0, ret = devm_request_irq(dev, irq, uniphier_fi2c_interrupt, 0,
pdev->name, priv); pdev->name, priv);
...@@ -568,6 +568,33 @@ static int uniphier_fi2c_remove(struct platform_device *pdev) ...@@ -568,6 +568,33 @@ static int uniphier_fi2c_remove(struct platform_device *pdev)
return 0; return 0;
} }
static int __maybe_unused uniphier_fi2c_suspend(struct device *dev)
{
struct uniphier_fi2c_priv *priv = dev_get_drvdata(dev);
clk_disable_unprepare(priv->clk);
return 0;
}
static int __maybe_unused uniphier_fi2c_resume(struct device *dev)
{
struct uniphier_fi2c_priv *priv = dev_get_drvdata(dev);
int ret;
ret = clk_prepare_enable(priv->clk);
if (ret)
return ret;
uniphier_fi2c_hw_init(priv);
return 0;
}
static const struct dev_pm_ops uniphier_fi2c_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(uniphier_fi2c_suspend, uniphier_fi2c_resume)
};
static const struct of_device_id uniphier_fi2c_match[] = { static const struct of_device_id uniphier_fi2c_match[] = {
{ .compatible = "socionext,uniphier-fi2c" }, { .compatible = "socionext,uniphier-fi2c" },
{ /* sentinel */ } { /* sentinel */ }
...@@ -580,6 +607,7 @@ static struct platform_driver uniphier_fi2c_drv = { ...@@ -580,6 +607,7 @@ static struct platform_driver uniphier_fi2c_drv = {
.driver = { .driver = {
.name = "uniphier-fi2c", .name = "uniphier-fi2c",
.of_match_table = uniphier_fi2c_match, .of_match_table = uniphier_fi2c_match,
.pm = &uniphier_fi2c_pm_ops,
}, },
}; };
module_platform_driver(uniphier_fi2c_drv); module_platform_driver(uniphier_fi2c_drv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment