diff options
author | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> | 2021-02-15 17:09:02 +0000 |
---|---|---|
committer | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> | 2021-03-11 09:22:25 +0000 |
commit | 87ae4906527444d67d3dc02c6109d25ac55cd88a (patch) | |
tree | 75e660c8206ababbb7b495c9489bb6b8adf16de9 | |
parent | 9b9f867fc3fefd23cfe6ab8c6c51635f8f7d5c8f (diff) |
soundwire: qcom: add clock stop via runtime pm support
Add Clock stop feature support using runtime PM.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
-rw-r--r-- | drivers/soundwire/qcom.c | 138 |
1 files changed, 129 insertions, 9 deletions
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index f52b934a0fc59..4a3491dc1c12a 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -10,6 +10,7 @@ #include <linux/of.h> #include <linux/of_irq.h> #include <linux/of_device.h> +#include <linux/pm_runtime.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/slimbus.h> @@ -19,6 +20,8 @@ #include <sound/soc.h> #include "bus.h" +#define SWRM_COMP_SW_RESET (0x008) +#define SWRM_COMP_STATUS (0x014) #define SWRM_COMP_HW_VERSION 0x00 #define SWRM_COMP_CFG_ADDR 0x04 #define SWRM_COMP_CFG_IRQ_LEVEL_OR_PULSE_MSK BIT(1) @@ -147,6 +150,7 @@ struct qcom_swrm_ctrl { int (*reg_read)(struct qcom_swrm_ctrl *ctrl, int reg, u32 *val); int (*reg_write)(struct qcom_swrm_ctrl *ctrl, int reg, int val); u32 slave_status; + bool clk_stop_bus_reset; }; struct qcom_swrm_data { @@ -172,18 +176,26 @@ static int qcom_swrm_ahb_reg_read(struct qcom_swrm_ctrl *ctrl, int reg, struct regmap *wcd_regmap = ctrl->regmap; int ret; + clk_prepare_enable(ctrl->hclk); + /* pg register + offset */ ret = regmap_bulk_write(wcd_regmap, SWRM_AHB_BRIDGE_RD_ADDR_0, (u8 *)®, 4); - if (ret < 0) - return SDW_CMD_FAIL; + if (ret < 0) { + ret = SDW_CMD_FAIL; + goto err; + } ret = regmap_bulk_read(wcd_regmap, SWRM_AHB_BRIDGE_RD_DATA_0, val, 4); if (ret < 0) - return SDW_CMD_FAIL; + ret = SDW_CMD_FAIL; + else + ret = SDW_CMD_OK; - return SDW_CMD_OK; +err: + clk_disable_unprepare(ctrl->hclk); + return ret; } static int qcom_swrm_ahb_reg_write(struct qcom_swrm_ctrl *ctrl, @@ -191,32 +203,46 @@ static int qcom_swrm_ahb_reg_write(struct qcom_swrm_ctrl *ctrl, { struct regmap *wcd_regmap = ctrl->regmap; int ret; + + clk_prepare_enable(ctrl->hclk); /* pg register + offset */ ret = regmap_bulk_write(wcd_regmap, SWRM_AHB_BRIDGE_WR_DATA_0, (u8 *)&val, 4); - if (ret) - return SDW_CMD_FAIL; + if (ret) { + ret = SDW_CMD_FAIL; + goto err; + } /* write address register */ ret = regmap_bulk_write(wcd_regmap, SWRM_AHB_BRIDGE_WR_ADDR_0, (u8 *)®, 4); if (ret) - return SDW_CMD_FAIL; + ret = SDW_CMD_FAIL; + else + ret = SDW_CMD_OK; - return SDW_CMD_OK; +err: + clk_disable_unprepare(ctrl->hclk); + return ret; } static int qcom_swrm_cpu_reg_read(struct qcom_swrm_ctrl *ctrl, int reg, u32 *val) { + clk_prepare_enable(ctrl->hclk); *val = readl(ctrl->mmio + reg); + clk_disable_unprepare(ctrl->hclk); + return SDW_CMD_OK; } static int qcom_swrm_cpu_reg_write(struct qcom_swrm_ctrl *ctrl, int reg, int val) { + clk_prepare_enable(ctrl->hclk); writel(val, ctrl->mmio + reg); + clk_disable_unprepare(ctrl->hclk); + return SDW_CMD_OK; } @@ -642,7 +668,6 @@ static int qcom_swrm_port_params(struct sdw_bus *bus, return ctrl->reg_write(ctrl, SWRM_DP_BLOCK_CTRL_1(p_params->num), p_params->bps - 1); - } static int qcom_swrm_transport_params(struct sdw_bus *bus, @@ -932,6 +957,15 @@ static int qcom_swrm_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *codec_dai; int ret, i; + ret = pm_runtime_get_sync(ctrl->dev); + if (ret < 0 && ret != -EACCES) { + dev_err_ratelimited(ctrl->dev, + "pm_runtime_get_sync failed in %s, ret %d\n", + __func__, ret); + pm_runtime_put_noidle(ctrl->dev); + return ret; + } + sruntime = sdw_alloc_stream(dai->name); if (!sruntime) return -ENOMEM; @@ -959,6 +993,9 @@ static void qcom_swrm_shutdown(struct snd_pcm_substream *substream, sdw_release_stream(ctrl->sruntime[dai->id]); ctrl->sruntime[dai->id] = NULL; + pm_runtime_mark_last_busy(ctrl->dev); + pm_runtime_put_autosuspend(ctrl->dev); + } static const struct snd_soc_dai_ops qcom_swrm_pdm_dai_ops = { @@ -1086,6 +1123,11 @@ static int qcom_swrm_get_port_config(struct qcom_swrm_ctrl *ctrl) memset(lane_control, SWR_INVALID_PARAM, QCOM_SDW_MAX_PORTS); of_property_read_u8_array(np, "qcom,ports-lane-control", lane_control, nports); + if (of_property_read_bool(np, "qcom,clock-stop-bus-reset-quirk")) + ctrl->clk_stop_bus_reset = true; + else + ctrl->clk_stop_bus_reset = false; + for (i = 0; i < nports; i++) { ctrl->pconfig[i].si = si[i]; ctrl->pconfig[i].off1 = off1[i]; @@ -1159,6 +1201,7 @@ static int qcom_swrm_probe(struct platform_device *pdev) ctrl->bus.ops = &qcom_swrm_ops; ctrl->bus.port_ops = &qcom_swrm_port_ops; ctrl->bus.compute_params = &qcom_swrm_compute_params; + ctrl->bus.clk_stop_timeout = 300; ret = qcom_swrm_get_port_config(ctrl); if (ret) @@ -1211,6 +1254,13 @@ static int qcom_swrm_probe(struct platform_device *pdev) (ctrl->version >> 24) & 0xff, (ctrl->version >> 16) & 0xff, ctrl->version & 0xffff); + pm_runtime_set_autosuspend_delay(dev, 30000); + pm_runtime_use_autosuspend(dev); + pm_runtime_mark_last_busy(dev); + + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + return 0; err_master_add: @@ -1231,6 +1281,75 @@ static int qcom_swrm_remove(struct platform_device *pdev) return 0; } +static int swrm_runtime_resume(struct device *dev) +{ + struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev); + int ret; + + clk_prepare_enable(ctrl->hclk); + + if (ctrl->clk_stop_bus_reset) { + reinit_completion(&ctrl->enumeration); + ctrl->reg_write(ctrl, SWRM_COMP_SW_RESET, 0x01); + qcom_swrm_get_device_status(ctrl); + sdw_handle_slave_status(&ctrl->bus, ctrl->status); + qcom_swrm_init(ctrl); + wait_for_completion_timeout(&ctrl->enumeration, + msecs_to_jiffies(TIMEOUT_MS)); + } else { + ctrl->reg_write(ctrl, SWRM_MCP_BUS_CTRL, SWRM_MCP_BUS_CLK_START); + ctrl->reg_write(ctrl, SWRM_INTERRUPT_CLEAR, + SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET); + + ctrl->intr_mask |= SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET; + ctrl->reg_write(ctrl, SWRM_INTERRUPT_MASK_ADDR, ctrl->intr_mask); + ctrl->reg_write(ctrl, SWRM_INTERRUPT_CPU_EN, ctrl->intr_mask); + } + usleep_range(100, 105); + ret = sdw_bus_exit_clk_stop(&ctrl->bus); + if (ret < 0) + dev_err(ctrl->dev, "bus failed to exit clock stop %d\n", ret); + pm_runtime_mark_last_busy(dev); + + return 0; +} + +static int __maybe_unused swrm_runtime_suspend(struct device *dev) +{ + struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev); + int ret; + + if (!ctrl->clk_stop_bus_reset) { + /* Mask bus clash interrupt */ + ctrl->intr_mask &= ~SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET; + ctrl->reg_write(ctrl, SWRM_INTERRUPT_MASK_ADDR, ctrl->intr_mask); + ctrl->reg_write(ctrl, SWRM_INTERRUPT_CPU_EN, ctrl->intr_mask); + } + + /* Prepare slaves for clock stop */ + ret = sdw_bus_prep_clk_stop(&ctrl->bus); + if (ret < 0) { + dev_err(dev, "prepare clock stop failed %d", ret); + return ret; + } + + ret = sdw_bus_clk_stop(&ctrl->bus); + if (ret < 0 && ret != -ENODATA) { + dev_err(dev, "bus clock stop failed %d", ret); + return ret; + } + + clk_disable_unprepare(ctrl->hclk); + + usleep_range(100, 105); + + return 0; +} + +static const struct dev_pm_ops swrm_dev_pm_ops = { + SET_RUNTIME_PM_OPS(swrm_runtime_suspend, swrm_runtime_resume, NULL) +}; + static const struct of_device_id qcom_swrm_of_match[] = { { .compatible = "qcom,soundwire-v1.3.0", .data = &swrm_v1_3_data }, { .compatible = "qcom,soundwire-v1.5.1", .data = &swrm_v1_5_data }, @@ -1245,6 +1364,7 @@ static struct platform_driver qcom_swrm_driver = { .driver = { .name = "qcom-soundwire", .of_match_table = qcom_swrm_of_match, + .pm = &swrm_dev_pm_ops, } }; module_platform_driver(qcom_swrm_driver); |