CEC hardware block is enable to resume the system if a command is received
on data lane.
Prior to implement suspend/resume functions a patch simplify clock management
int the driver by introducting pm_runtime{suspend/resume} functions.
Benjamin Gaignard (2):
cec: stm32: simplify clock management
cec: stm32: add suspend/resume functions
drivers/media/platform/stm32/stm32-cec.c | 112 ++++++++++++++++++++++---------
1 file changed, 82 insertions(+), 30 deletions(-)
--
2.15.0
From: Benjamin Gaignard <[email protected]>
Since CEC framework enable and disable the adapter when it is needed
just follow it orders to enable/disable the clocks.
Call stm32_cec_hw_init() when the adapter is enabled and do not let
regmap manage registers clock help to simplify clocking scheme.
While reworking cec clock start using pm_runtime.
Signed-off-by: Benjamin Gaignard <[email protected]>
---
drivers/media/platform/stm32/stm32-cec.c | 70 ++++++++++++++++++--------------
1 file changed, 40 insertions(+), 30 deletions(-)
diff --git a/drivers/media/platform/stm32/stm32-cec.c b/drivers/media/platform/stm32/stm32-cec.c
index 7c496bc1cf38..35cc2ffd6b96 100644
--- a/drivers/media/platform/stm32/stm32-cec.c
+++ b/drivers/media/platform/stm32/stm32-cec.c
@@ -12,6 +12,7 @@
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
#include <linux/regmap.h>
#include <media/cec.h>
@@ -70,7 +71,7 @@ struct stm32_cec {
int tx_cnt;
};
-static void cec_hw_init(struct stm32_cec *cec)
+static void stm32_cec_hw_init(struct stm32_cec *cec)
{
regmap_update_bits(cec->regmap, CEC_CR, TXEOM | TXSOM | CECEN, 0);
@@ -166,22 +167,17 @@ static irqreturn_t stm32_cec_irq_handler(int irq, void *arg)
static int stm32_cec_adap_enable(struct cec_adapter *adap, bool enable)
{
struct stm32_cec *cec = adap->priv;
- int ret = 0;
if (enable) {
- ret = clk_enable(cec->clk_cec);
- if (ret)
- dev_err(cec->dev, "fail to enable cec clock\n");
-
- clk_enable(cec->clk_hdmi_cec);
+ pm_runtime_get_sync(cec->dev);
+ stm32_cec_hw_init(cec);
regmap_update_bits(cec->regmap, CEC_CR, CECEN, CECEN);
} else {
- clk_disable(cec->clk_cec);
- clk_disable(cec->clk_hdmi_cec);
regmap_update_bits(cec->regmap, CEC_CR, CECEN, 0);
+ pm_runtime_disable(cec->dev);
}
- return ret;
+ return 0;
}
static int stm32_cec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr)
@@ -260,8 +256,8 @@ static int stm32_cec_probe(struct platform_device *pdev)
if (IS_ERR(mmio))
return PTR_ERR(mmio);
- cec->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "cec", mmio,
- &stm32_cec_regmap_cfg);
+ cec->regmap = devm_regmap_init_mmio(&pdev->dev, mmio,
+ &stm32_cec_regmap_cfg);
if (IS_ERR(cec->regmap))
return PTR_ERR(cec->regmap);
@@ -284,19 +280,10 @@ static int stm32_cec_probe(struct platform_device *pdev)
return PTR_ERR(cec->clk_cec);
}
- ret = clk_prepare(cec->clk_cec);
- if (ret) {
- dev_err(&pdev->dev, "Unable to prepare cec clock\n");
- return ret;
- }
-
cec->clk_hdmi_cec = devm_clk_get(&pdev->dev, "hdmi-cec");
- if (!IS_ERR(cec->clk_hdmi_cec)) {
- ret = clk_prepare(cec->clk_hdmi_cec);
- if (ret) {
- dev_err(&pdev->dev, "Unable to prepare hdmi-cec clock\n");
- return ret;
- }
+ if (IS_ERR(cec->clk_hdmi_cec)) {
+ dev_err(&pdev->dev, "Cannot get cec clock\n");
+ return PTR_ERR(cec->clk_hdmi_cec);
}
/*
@@ -315,24 +302,46 @@ static int stm32_cec_probe(struct platform_device *pdev)
return ret;
}
- cec_hw_init(cec);
-
platform_set_drvdata(pdev, cec);
+ pm_runtime_enable(&pdev->dev);
- return 0;
+ return ret;
}
static int stm32_cec_remove(struct platform_device *pdev)
{
struct stm32_cec *cec = platform_get_drvdata(pdev);
- clk_unprepare(cec->clk_cec);
- clk_unprepare(cec->clk_hdmi_cec);
-
cec_unregister_adapter(cec->adap);
+ pm_runtime_disable(&pdev->dev);
+
return 0;
}
+static int __maybe_unused stm32_cec_runtime_suspend(struct device *dev)
+{
+ struct stm32_cec *cec = dev_get_drvdata(dev);
+
+ clk_disable_unprepare(cec->clk_cec);
+ clk_disable_unprepare(cec->clk_hdmi_cec);
+
+ return 0;
+}
+
+static int __maybe_unused stm32_cec_runtime_resume(struct device *dev)
+{
+ struct stm32_cec *cec = dev_get_drvdata(dev);
+
+ clk_prepare_enable(cec->clk_cec);
+ clk_prepare_enable(cec->clk_hdmi_cec);
+
+ return 0;
+}
+
+static const struct dev_pm_ops stm32_cec_pm_ops = {
+ SET_RUNTIME_PM_OPS(stm32_cec_runtime_suspend, stm32_cec_runtime_resume,
+ NULL)
+};
static const struct of_device_id stm32_cec_of_match[] = {
{ .compatible = "st,stm32-cec" },
@@ -346,6 +355,7 @@ static struct platform_driver stm32_cec_driver = {
.driver = {
.name = CEC_NAME,
.of_match_table = stm32_cec_of_match,
+ .pm = &stm32_cec_pm_ops,
},
};
--
2.15.0
From: Benjamin Gaignard <[email protected]>
If wake up irq is defined in device-tree cec adapter
could be used has wake up source.
Signed-off-by: Benjamin Gaignard <[email protected]>
---
drivers/media/platform/stm32/stm32-cec.c | 44 +++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/stm32/stm32-cec.c b/drivers/media/platform/stm32/stm32-cec.c
index 35cc2ffd6b96..68e18ee6655b 100644
--- a/drivers/media/platform/stm32/stm32-cec.c
+++ b/drivers/media/platform/stm32/stm32-cec.c
@@ -11,8 +11,11 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
+#include <linux/of_irq.h>
#include <linux/platform_device.h>
+#include <linux/pinctrl/consumer.h>
#include <linux/pm_runtime.h>
+#include <linux/pm_wakeirq.h>
#include <linux/regmap.h>
#include <media/cec.h>
@@ -243,7 +246,7 @@ static int stm32_cec_probe(struct platform_device *pdev)
struct resource *res;
struct stm32_cec *cec;
void __iomem *mmio;
- int ret;
+ int ret, wakeirq;
cec = devm_kzalloc(&pdev->dev, sizeof(*cec), GFP_KERNEL);
if (!cec)
@@ -274,6 +277,12 @@ static int stm32_cec_probe(struct platform_device *pdev)
if (ret)
return ret;
+ wakeirq = of_irq_get_byname(pdev->dev.of_node, "wakeup");
+ if (wakeirq > 0) {
+ device_init_wakeup(&pdev->dev, true);
+ dev_pm_set_dedicated_wake_irq(&pdev->dev, wakeirq);
+ }
+
cec->clk_cec = devm_clk_get(&pdev->dev, "cec");
if (IS_ERR(cec->clk_cec)) {
dev_err(&pdev->dev, "Cannot get cec clock\n");
@@ -312,12 +321,44 @@ static int stm32_cec_remove(struct platform_device *pdev)
{
struct stm32_cec *cec = platform_get_drvdata(pdev);
+ dev_pm_clear_wake_irq(&pdev->dev);
+ device_init_wakeup(&pdev->dev, false);
+
cec_unregister_adapter(cec->adap);
pm_runtime_disable(&pdev->dev);
return 0;
}
+
+static int __maybe_unused stm32_cec_suspend(struct device *dev)
+{
+ struct stm32_cec *cec = dev_get_drvdata(dev);
+
+ pm_runtime_force_suspend(dev);
+
+ if (device_may_wakeup(dev))
+ enable_irq_wake(cec->irq);
+
+ pinctrl_pm_select_sleep_state(dev);
+
+ return 0;
+}
+
+static int __maybe_unused stm32_cec_resume(struct device *dev)
+{
+ struct stm32_cec *cec = dev_get_drvdata(dev);
+
+ pinctrl_pm_select_default_state(dev);
+
+ if (device_may_wakeup(dev))
+ disable_irq_wake(cec->irq);
+
+ pm_runtime_force_resume(dev);
+
+ return 0;
+}
+
static int __maybe_unused stm32_cec_runtime_suspend(struct device *dev)
{
struct stm32_cec *cec = dev_get_drvdata(dev);
@@ -341,6 +382,7 @@ static int __maybe_unused stm32_cec_runtime_resume(struct device *dev)
static const struct dev_pm_ops stm32_cec_pm_ops = {
SET_RUNTIME_PM_OPS(stm32_cec_runtime_suspend, stm32_cec_runtime_resume,
NULL)
+ SET_SYSTEM_SLEEP_PM_OPS(stm32_cec_suspend, stm32_cec_resume)
};
static const struct of_device_id stm32_cec_of_match[] = {
--
2.15.0