aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/slimbus/qcom-ctrl.c
diff options
context:
space:
mode:
authorSagar Dharia <sdharia@codeaurora.org>2017-12-11 18:43:06 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-12-19 05:01:03 -0500
commitc088c335b49228ca1759dca5676f1534b0ac13a5 (patch)
tree44988185641a4bc6b97f8c76091a05c7e46f986b /drivers/slimbus/qcom-ctrl.c
parentad7fcbc308b050e3c27c545021663d2cd73f8b23 (diff)
slimbus: qcom: Add runtime-pm support using clock-pause
Slimbus HW mandates that clock-pause sequence has to be executed before disabling relevant interface and core clocks. Runtime-PM's autosuspend feature is used here to enter/exit low power mode for Qualcomm's Slimbus controller. Autosuspend feature enables driver to avoid changing power-modes too frequently since entering clock-pause is an expensive sequence Signed-off-by: Sagar Dharia <sdharia@codeaurora.org> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Reviwed-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/slimbus/qcom-ctrl.c')
-rw-r--r--drivers/slimbus/qcom-ctrl.c101
1 files changed, 98 insertions, 3 deletions
diff --git a/drivers/slimbus/qcom-ctrl.c b/drivers/slimbus/qcom-ctrl.c
index ace85ce3de90..35ad70dbfe3a 100644
--- a/drivers/slimbus/qcom-ctrl.c
+++ b/drivers/slimbus/qcom-ctrl.c
@@ -14,6 +14,7 @@
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/of.h> 15#include <linux/of.h>
16#include <linux/dma-mapping.h> 16#include <linux/dma-mapping.h>
17#include <linux/pm_runtime.h>
17#include "slimbus.h" 18#include "slimbus.h"
18 19
19/* Manager registers */ 20/* Manager registers */
@@ -65,6 +66,7 @@
65 ((l) | ((mt) << 5) | ((mc) << 8) | ((dt) << 15) | ((ad) << 16)) 66 ((l) | ((mt) << 5) | ((mc) << 8) | ((dt) << 15) | ((ad) << 16))
66 67
67#define SLIM_ROOT_FREQ 24576000 68#define SLIM_ROOT_FREQ 24576000
69#define QCOM_SLIM_AUTOSUSPEND 1000
68 70
69/* MAX message size over control channel */ 71/* MAX message size over control channel */
70#define SLIM_MSGQ_BUF_LEN 40 72#define SLIM_MSGQ_BUF_LEN 40
@@ -275,6 +277,30 @@ static irqreturn_t qcom_slim_interrupt(int irq, void *d)
275 return ret; 277 return ret;
276} 278}
277 279
280static int qcom_clk_pause_wakeup(struct slim_controller *sctrl)
281{
282 struct qcom_slim_ctrl *ctrl = dev_get_drvdata(sctrl->dev);
283
284 clk_prepare_enable(ctrl->hclk);
285 clk_prepare_enable(ctrl->rclk);
286 enable_irq(ctrl->irq);
287
288 writel_relaxed(1, ctrl->base + FRM_WAKEUP);
289 /* Make sure framer wakeup write goes through before ISR fires */
290 mb();
291 /*
292 * HW Workaround: Currently, slave is reporting lost-sync messages
293 * after SLIMbus comes out of clock pause.
294 * Transaction with slave fail before slave reports that message
295 * Give some time for that report to come
296 * SLIMbus wakes up in clock gear 10 at 24.576MHz. With each superframe
297 * being 250 usecs, we wait for 5-10 superframes here to ensure
298 * we get the message
299 */
300 usleep_range(1250, 2500);
301 return 0;
302}
303
278void *slim_alloc_txbuf(struct qcom_slim_ctrl *ctrl, struct slim_msg_txn *txn, 304void *slim_alloc_txbuf(struct qcom_slim_ctrl *ctrl, struct slim_msg_txn *txn,
279 struct completion *done) 305 struct completion *done)
280{ 306{
@@ -511,6 +537,7 @@ static int qcom_slim_probe(struct platform_device *pdev)
511 537
512 sctrl->set_laddr = qcom_set_laddr; 538 sctrl->set_laddr = qcom_set_laddr;
513 sctrl->xfer_msg = qcom_xfer_msg; 539 sctrl->xfer_msg = qcom_xfer_msg;
540 sctrl->wakeup = qcom_clk_pause_wakeup;
514 ctrl->tx.n = QCOM_TX_MSGS; 541 ctrl->tx.n = QCOM_TX_MSGS;
515 ctrl->tx.sl_sz = SLIM_MSGQ_BUF_LEN; 542 ctrl->tx.sl_sz = SLIM_MSGQ_BUF_LEN;
516 ctrl->rx.n = QCOM_RX_MSGS; 543 ctrl->rx.n = QCOM_RX_MSGS;
@@ -618,14 +645,81 @@ static int qcom_slim_remove(struct platform_device *pdev)
618{ 645{
619 struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev); 646 struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev);
620 647
621 disable_irq(ctrl->irq); 648 pm_runtime_disable(&pdev->dev);
622 clk_disable_unprepare(ctrl->hclk);
623 clk_disable_unprepare(ctrl->rclk);
624 slim_unregister_controller(&ctrl->ctrl); 649 slim_unregister_controller(&ctrl->ctrl);
625 destroy_workqueue(ctrl->rxwq); 650 destroy_workqueue(ctrl->rxwq);
626 return 0; 651 return 0;
627} 652}
628 653
654/*
655 * If PM_RUNTIME is not defined, these 2 functions become helper
656 * functions to be called from system suspend/resume.
657 */
658#ifdef CONFIG_PM
659static int qcom_slim_runtime_suspend(struct device *device)
660{
661 struct platform_device *pdev = to_platform_device(device);
662 struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev);
663 int ret;
664
665 dev_dbg(device, "pm_runtime: suspending...\n");
666 ret = slim_ctrl_clk_pause(&ctrl->ctrl, false, SLIM_CLK_UNSPECIFIED);
667 if (ret) {
668 dev_err(device, "clk pause not entered:%d", ret);
669 } else {
670 disable_irq(ctrl->irq);
671 clk_disable_unprepare(ctrl->hclk);
672 clk_disable_unprepare(ctrl->rclk);
673 }
674 return ret;
675}
676
677static int qcom_slim_runtime_resume(struct device *device)
678{
679 struct platform_device *pdev = to_platform_device(device);
680 struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev);
681 int ret = 0;
682
683 dev_dbg(device, "pm_runtime: resuming...\n");
684 ret = slim_ctrl_clk_pause(&ctrl->ctrl, true, 0);
685 if (ret)
686 dev_err(device, "clk pause not exited:%d", ret);
687 return ret;
688}
689#endif
690
691#ifdef CONFIG_PM_SLEEP
692static int qcom_slim_suspend(struct device *dev)
693{
694 int ret = 0;
695
696 if (!pm_runtime_enabled(dev) ||
697 (!pm_runtime_suspended(dev))) {
698 dev_dbg(dev, "system suspend");
699 ret = qcom_slim_runtime_suspend(dev);
700 }
701
702 return ret;
703}
704
705static int qcom_slim_resume(struct device *dev)
706{
707 if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) {
708 int ret;
709
710 dev_dbg(dev, "system resume");
711 ret = qcom_slim_runtime_resume(dev);
712 if (!ret) {
713 pm_runtime_mark_last_busy(dev);
714 pm_request_autosuspend(dev);
715 }
716 return ret;
717
718 }
719 return 0;
720}
721#endif /* CONFIG_PM_SLEEP */
722
629static const struct dev_pm_ops qcom_slim_dev_pm_ops = { 723static const struct dev_pm_ops qcom_slim_dev_pm_ops = {
630 SET_SYSTEM_SLEEP_PM_OPS(qcom_slim_suspend, qcom_slim_resume) 724 SET_SYSTEM_SLEEP_PM_OPS(qcom_slim_suspend, qcom_slim_resume)
631 SET_RUNTIME_PM_OPS( 725 SET_RUNTIME_PM_OPS(
@@ -647,6 +741,7 @@ static struct platform_driver qcom_slim_driver = {
647 .driver = { 741 .driver = {
648 .name = "qcom_slim_ctrl", 742 .name = "qcom_slim_ctrl",
649 .of_match_table = qcom_slim_dt_match, 743 .of_match_table = qcom_slim_dt_match,
744 .pm = &qcom_slim_dev_pm_ops,
650 }, 745 },
651}; 746};
652module_platform_driver(qcom_slim_driver); 747module_platform_driver(qcom_slim_driver);