From patchwork Mon Feb 21 10:41:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 545301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24539C433EF for ; Mon, 21 Feb 2022 10:43:13 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id D6C571699; Mon, 21 Feb 2022 11:42:21 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D6C571699 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1645440191; bh=BpRDITN5byLhz8jVygp1nNvxAU9oVFtliH7PkbKoyro=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=To8os50zP/o7qV4BPoF2yIOoQwnkKGFLamdEQgzjCPNJfq6DLM4F8gagmgQrrEsnU V2vSHcuvwZtUMB+46Sa9FZ1qNvrB0GkdtZNp/08kmA3F+9tQieMu6PE83bayVo7ink HhTuxGpBtbGoqJhu9SbgjeUrU+p94aE2ZQSEem/g= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B53F2F80508; Mon, 21 Feb 2022 11:41:48 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3FE33F80516; Mon, 21 Feb 2022 11:41:47 +0100 (CET) Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 4B1CAF80139 for ; Mon, 21 Feb 2022 11:41:40 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4B1CAF80139 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OfsXYcjL" Received: by mail-wr1-x435.google.com with SMTP id d3so10600707wrf.1 for ; Mon, 21 Feb 2022 02:41:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R5u3/tjplSbqBvtv+CBLeJGiOWDAXG28Kg+gjvP6yzs=; b=OfsXYcjLe0Pa80cVcxnRTOtZ7+c5BlxackmLVJIdwvnrCgJ3M53PK2/ooaVS6oWl5v 7a4z9FKfbxXklj0IakAJvzFjiO4b24fad1VOg2n3JdLJrYPF2gGTxi8xaH2rTl50pKrP 89l/SF+XvRTSn7YT7q2ywopGtjP7All7CB0QaOJXRsToVKy/DQEY+6/5YVPRI+jMtpMQ kyHMUnbcU8PTZVNMmFlgmDtxCrcmEkUdkCEKU9zMf/5PA147i694oCzOdQkDPi+/22Xr sRx/KhelK+Wy9NKCjXOU4sy0ziaxujbE7CHHDGqC1q/m/03HSFKnAuUtAr7td+DH2j/y phUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R5u3/tjplSbqBvtv+CBLeJGiOWDAXG28Kg+gjvP6yzs=; b=gC3B4q1vUyOQ+rh+rwJXefTDMNK5nhv3R9bLfzw+Jbshnk4g4d48U9JdAhNRr2QaZr E+Yo840v4Cbhdt8ajMUuGxNl0OwCqBPbdd7S27Mg/e16vCAX/WlPXHHITNVJRZaZb9f7 x9zoNXXf1yRZEK9wOFMgxkbexmAi9oCPDzAa0CVT9whcu4EM9yeLTKA+X5riJ26Efadq agEeGbAcsSlzMCIdys15bPbGv75kq5CUhOeENfvqGmQUudse990hs9W7NYG75QPb5BD3 Dj4bnX2HVVpILi6PXQjrSKFyTWM6WWuAwRPbCKfVvuJVowkaxNlYOGpzUl+F/ol68KLs G/DQ== X-Gm-Message-State: AOAM532VHqxaCMOpD6gDQWl/FdKFnES0R9cMGXPXR6yUN/VbUHaszaF8 U24BmoJM5TFnE1uHgCj/Cx+teA== X-Google-Smtp-Source: ABdhPJzY+draSc+xcUZXs87PrrqgPD4blTi4+DXCDX9LaPaldj4TGaB+vs9fcyL7Ah7398OqmA+f9w== X-Received: by 2002:adf:f644:0:b0:1e3:bfed:6eb5 with SMTP id x4-20020adff644000000b001e3bfed6eb5mr15181547wrp.654.1645440100186; Mon, 21 Feb 2022 02:41:40 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id n19-20020a05600c4f9300b0037c06fe68casm7584817wmq.44.2022.02.21.02.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 02:41:39 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, vkoul@kernel.org, yung-chuan.liao@linux.intel.com Subject: [PATCH 1/3] soundwire: qcom: add runtime pm support Date: Mon, 21 Feb 2022 10:41:25 +0000 Message-Id: <20220221104127.15670-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220221104127.15670-1-srinivas.kandagatla@linaro.org> References: <20220221104127.15670-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, linux-kernel@vger.kernel.org, Srinivas Kandagatla , quic_srivasam@quicinc.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Add support to runtime PM using SoundWire clock stop on supported instances and bus reset on instances that require full reset. Signed-off-by: Srinivas Kandagatla --- drivers/soundwire/qcom.c | 150 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 149 insertions(+), 1 deletion(-) diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index 54813417ef8e..3b2eb95a7e96 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,9 @@ #include #include "bus.h" +#define SWRM_COMP_SW_RESET 0x008 +#define SWRM_COMP_STATUS 0x014 +#define SWRM_FRM_GEN_ENABLED BIT(0) #define SWRM_COMP_HW_VERSION 0x00 #define SWRM_COMP_CFG_ADDR 0x04 #define SWRM_COMP_CFG_IRQ_LEVEL_OR_PULSE_MSK BIT(1) @@ -29,6 +33,7 @@ #define SWRM_COMP_PARAMS_RD_FIFO_DEPTH GENMASK(19, 15) #define SWRM_COMP_PARAMS_DOUT_PORTS_MASK GENMASK(4, 0) #define SWRM_COMP_PARAMS_DIN_PORTS_MASK GENMASK(9, 5) +#define SWRM_COMP_MASTER_ID 0x104 #define SWRM_INTERRUPT_STATUS 0x200 #define SWRM_INTERRUPT_STATUS_RMSK GENMASK(16, 0) #define SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ BIT(0) @@ -111,6 +116,13 @@ #define SWR_MAX_CMD_ID 14 #define MAX_FIFO_RD_RETRY 3 #define SWR_OVERFLOW_RETRY_COUNT 30 +#define SWRM_LINK_STATUS_RETRY_CNT 100 + +enum { + MASTER_ID_WSA = 1, + MASTER_ID_RX, + MASTER_ID_TX +}; struct qcom_swrm_port_config { u8 si; @@ -159,6 +171,7 @@ struct qcom_swrm_ctrl { u32 slave_status; u32 wr_fifo_depth; u32 rd_fifo_depth; + bool clk_stop_bus_reset; }; struct qcom_swrm_data { @@ -497,6 +510,7 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) u32 i; int devnum; int ret = IRQ_HANDLED; + clk_prepare_enable(swrm->hclk); swrm->reg_read(swrm, SWRM_INTERRUPT_STATUS, &intr_sts); intr_sts_masked = intr_sts & swrm->intr_mask; @@ -604,6 +618,7 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) intr_sts_masked = intr_sts & swrm->intr_mask; } while (intr_sts_masked); + clk_disable_unprepare(swrm->hclk); return ret; } @@ -1017,6 +1032,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; @@ -1044,6 +1068,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 = { @@ -1197,12 +1224,23 @@ static int qcom_swrm_get_port_config(struct qcom_swrm_ctrl *ctrl) static int swrm_reg_show(struct seq_file *s_file, void *data) { struct qcom_swrm_ctrl *swrm = s_file->private; - int reg, reg_val; + int reg, reg_val, ret; + + ret = pm_runtime_get_sync(swrm->dev); + if (ret < 0 && ret != -EACCES) { + dev_err_ratelimited(swrm->dev, + "pm_runtime_get_sync failed in %s, ret %d\n", + __func__, ret); + pm_runtime_put_noidle(swrm->dev); + } for (reg = 0; reg <= SWR_MSTR_MAX_REG_ADDR; reg += 4) { swrm->reg_read(swrm, reg, ®_val); seq_printf(s_file, "0x%.3x: 0x%.2x\n", reg, reg_val); } + pm_runtime_mark_last_busy(swrm->dev); + pm_runtime_put_autosuspend(swrm->dev); + return 0; } @@ -1267,6 +1305,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) @@ -1319,6 +1358,21 @@ 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, 3000); + pm_runtime_use_autosuspend(dev); + pm_runtime_mark_last_busy(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + + /* Clk stop is not supported on WSA Soundwire masters */ + if (ctrl->version <= 0x01030000) { + ctrl->clk_stop_bus_reset = true; + } else { + ctrl->reg_read(ctrl, SWRM_COMP_MASTER_ID, &val); + if (val == MASTER_ID_WSA) + ctrl->clk_stop_bus_reset = true; + } + #ifdef CONFIG_DEBUG_FS ctrl->debugfs = debugfs_create_dir("qualcomm-sdw", ctrl->bus.debugfs); debugfs_create_file("qualcomm-registers", 0400, ctrl->debugfs, ctrl, @@ -1345,6 +1399,99 @@ static int qcom_swrm_remove(struct platform_device *pdev) return 0; } +static bool swrm_wait_for_frame_gen_enabled(struct qcom_swrm_ctrl *swrm) +{ + int retry = SWRM_LINK_STATUS_RETRY_CNT; + int comp_sts; + + do { + swrm->reg_read(swrm, SWRM_COMP_STATUS, &comp_sts); + + if (comp_sts & SWRM_FRM_GEN_ENABLED) + return true; + + usleep_range(500, 510); + } while (retry--); + + dev_err(swrm->dev, "%s: link status not %s\n", __func__, + comp_sts && SWRM_FRM_GEN_ENABLED ? "connected" : "disconnected"); + + return false; +} + +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); + } + + if (!swrm_wait_for_frame_gen_enabled(ctrl)) + dev_err(ctrl->dev, "link failed to connect\n"); + + usleep_range(300, 305); + ret = sdw_bus_exit_clk_stop(&ctrl->bus); + if (ret < 0) + dev_err(ctrl->dev, "bus failed to exit clock stop %d\n", ret); + + 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(300, 305); + + 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 }, @@ -1359,6 +1506,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); From patchwork Mon Feb 21 10:41:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 544452 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BDE3FC433F5 for ; Mon, 21 Feb 2022 10:43:23 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id A09911691; Mon, 21 Feb 2022 11:42:31 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A09911691 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1645440201; bh=/HrfPYImxjh1yk+WzVw8yE0VmOENxTV4OENlPgorNtc=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=CqPQTQjM4BH7hD+aTugZvHysg01DUPPCpe1TFzl6xYPypNBZQELulacB+xnzX4swn efDxjQK0Pp1v+hO1l9Sym3vjgMxHcH2zupP72yvZ/nsetHW0mlzPTST2BlyxJUXCo3 w1uIZ7E8f+aCHXNouA2NZf6e2Mrytsa4WQZKQCXU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 307A2F80518; Mon, 21 Feb 2022 11:41:49 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 84023F80515; Mon, 21 Feb 2022 11:41:48 +0100 (CET) Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 60F2CF800FA for ; Mon, 21 Feb 2022 11:41:42 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 60F2CF800FA Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nPaWk5Lf" Received: by mail-wr1-x434.google.com with SMTP id f17so1368188wrh.7 for ; Mon, 21 Feb 2022 02:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o+5vqkQXPirAu/1Sjt7YkAPFccDLqMMWnr+8F22imTk=; b=nPaWk5LfwzEn0LL7hDjXHx+adKazsGK3boQBxuXVtBNxfdkOK746wnkgp6LMGfbhNb 3KhQCNaITzFt30AfGjK/tMU6Ty0Y1aPMFmaXUWXdSX3geNrC4MbtJgK9NPA6Yi8KYO1o EX2g32al3a6ytLBMQhRI0spcxQ9/mBc+6ltz1kvW7dHU3NqyrHAKC2vhfes1UCWGIy4p jrYsuSRudJi9MWk7Fmvr9vgyfKZXrma/Y5v6yIlFaDHOZ6O5MQtRWS3HlhGu4Kh9aN/1 6TvoM04B93mNPWb7ajM4h1WPBNwewoS/SuCfZ7+1gsLqUkKzAQwyQ+veib4QgYSn/z5Z wx8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o+5vqkQXPirAu/1Sjt7YkAPFccDLqMMWnr+8F22imTk=; b=vZp4jpmK6Rsb5NQzSlzKszTdXVnj2GsAbMBVSHNdAIcziPtjDNUuK9DoMrzaR8EQm/ g6sGCqWsQd5rJECIwy1VS+CMagxGf2QNjoH2UAl3Fd7BG0Y1oiyjBsiHoU7wTaZYDtHR +xzc4+bArryw/rQVYtdN03qup4WXId4D3c9w2s1uAvISU4aNqqRJRL4P+jUxwHe7fFqn xk0W9MHrZrSxiWgR8FOei6nk1YkmJoOI+VqXuR05wQni8J541e7b873JFxQLWXSBw7Lq lXRMljMcJQteznmOsVPBqrTVCgCeHe3//zvh8BLL7HwbGFGTSp9/82SFi5+Q95sGdEX+ o6Ow== X-Gm-Message-State: AOAM530ldZDoZmPiERYCZnL0akIXR9dEJzsXxr+B9Ojaq0VeYy8U1EGr EYn8SD4Vy6v4MNCWSO77a1bULQ== X-Google-Smtp-Source: ABdhPJzpstyVfklHCpbOqUjZGxa3zUfwEkkM2h9RLHKyNYm3+7V5P1Ua7b4QPNqF21HRAwBj9jw2Ng== X-Received: by 2002:adf:efcc:0:b0:1e7:cf03:b419 with SMTP id i12-20020adfefcc000000b001e7cf03b419mr15153603wrp.122.1645440101330; Mon, 21 Feb 2022 02:41:41 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id n19-20020a05600c4f9300b0037c06fe68casm7584817wmq.44.2022.02.21.02.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 02:41:40 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, vkoul@kernel.org, yung-chuan.liao@linux.intel.com Subject: [PATCH 2/3] dt-bindings: soundwire: qcom: document optional wake irq Date: Mon, 21 Feb 2022 10:41:26 +0000 Message-Id: <20220221104127.15670-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220221104127.15670-1-srinivas.kandagatla@linaro.org> References: <20220221104127.15670-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, linux-kernel@vger.kernel.org, Srinivas Kandagatla , quic_srivasam@quicinc.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Wake IRQ is optional interrupt that can be wired up on SoundWire controller instances like RX path along with MBHC(Multi Button Headset connection). Document this in bindings. Signed-off-by: Srinivas Kandagatla --- Documentation/devicetree/bindings/soundwire/qcom,sdw.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/soundwire/qcom,sdw.txt b/Documentation/devicetree/bindings/soundwire/qcom,sdw.txt index b93a2b3e029d..bade68f429b0 100644 --- a/Documentation/devicetree/bindings/soundwire/qcom,sdw.txt +++ b/Documentation/devicetree/bindings/soundwire/qcom,sdw.txt @@ -22,7 +22,7 @@ board specific bus parameters. - interrupts: Usage: required Value type: - Definition: should specify the SoundWire Controller IRQ + Definition: should specify the SoundWire Controller and optional wake IRQ - clock-names: Usage: required From patchwork Mon Feb 21 10:41:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 545300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4A072C433F5 for ; Mon, 21 Feb 2022 10:43:29 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1B0FD16B3; Mon, 21 Feb 2022 11:42:37 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1B0FD16B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1645440207; bh=ZIhgnwpiwk7h7w5Yw9JLt4K4maT0eOv5++sTxlEmwRk=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=rYfnPzwF2Jo3ezhnKTMl8Kz6lWmXl4J9CsAUQZpVUZ2strJdFQ15wGBHSMnvK4kWI A5Af5J+hUUAAH6luoY/Kapx0eY9sUbeXslH71ltZNrgi2FwOFKo09SAQAzjSMW/jg2 PYVAeXNUQ7xtGe2Tovg2E60DSUzX/hsJ54y5tweY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id A857BF8051B; Mon, 21 Feb 2022 11:41:53 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1CF5BF8051C; Mon, 21 Feb 2022 11:41:52 +0100 (CET) Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8C795F80118 for ; Mon, 21 Feb 2022 11:41:43 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8C795F80118 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="aMCfeRwM" Received: by mail-wm1-x32c.google.com with SMTP id n8so9234813wms.3 for ; Mon, 21 Feb 2022 02:41:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fMcxbuw6I6KTX07OCnquH99Hzxoc4oIUIzEIajyR3Yc=; b=aMCfeRwMKXBIimw4TBzFj85xCm0lDCzNtDN3dZXJfWrWc8IMyECCsBq1jslJuMWLHy HPqXKulqgipa6mBmEnn3JkU1Fzyysnl3d0uPk8ZcCK1uB2h8QWIoIFz0Oi7aOSn6UyJT jz7UkphKfHQ3vkotJZQMqe7nz7jpjJwpJfEAC+zJnixrP10IOWuqj98gYkPjuJ+gC/vH jojjMJ7onKKHgKWFrmqLjvfC3Ey2hNdM8ls6yx7buwvz4XLb+g8y70tgum0Y585u3hTP DEHw8byPVcc2LGlL7ssk8DcnqRAAFhU3VhBKjF50BmesxaMG4BKmUTE8wbIEHCVz+nm1 Mjcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fMcxbuw6I6KTX07OCnquH99Hzxoc4oIUIzEIajyR3Yc=; b=BgACF+uf9WqAt2JhZccSq8p339sSoow/bzdWmRzwfts2mIriK27KnzAKiUBY1EyeQL Nux1EHy9wRIz5qz2/IIuXGq7mxWEz088h0yDX1aJ/+t9+5plqjidXnzQYcJYZISNUcat M4d1Hj5A2/G5HYmZNdbxTgC/jl0tj7kQ7hXhFBoz9U24c24bCT33dt7ljewIDJaz5MFt Mc5OQAQ+5sRx47PDsPQS52UuNuNKfoW8FI1idDtkrCD3+g2ok26DUGwU9n4sQndwj2wP TuSXeP/xCqcfgsu3qeteviKo44+FbO8Lb3y5pGzz1iNHy4/4BJk+XZbD6bUaWiXjv9eU 6NNg== X-Gm-Message-State: AOAM532OclQgBKSykVQ9G2YD+uHVc4njiK+yIk+wdNCUib0OH28OIx7/ SDi3kQjVh+UsGkfdLA40nH1fQQ== X-Google-Smtp-Source: ABdhPJxXek3z/IqIcPNmes42fE7hmTRzBr2LPQ2Ztup4nG4rhEXOxSj7rikJ7T2bKIhQwvS4iJMWGw== X-Received: by 2002:a05:600c:1583:b0:346:3f83:6b8 with SMTP id r3-20020a05600c158300b003463f8306b8mr16940773wmf.75.1645440102448; Mon, 21 Feb 2022 02:41:42 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id n19-20020a05600c4f9300b0037c06fe68casm7584817wmq.44.2022.02.21.02.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 02:41:42 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, vkoul@kernel.org, yung-chuan.liao@linux.intel.com Subject: [PATCH 3/3] soundwire: qcom: add wake up interrupt support Date: Mon, 21 Feb 2022 10:41:27 +0000 Message-Id: <20220221104127.15670-4-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220221104127.15670-1-srinivas.kandagatla@linaro.org> References: <20220221104127.15670-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, linux-kernel@vger.kernel.org, Srinivas Kandagatla , quic_srivasam@quicinc.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Some of the Qualcomm SoundWire Controller instances like the ones that are connected to RX path along with Headset connections support Waking up Controller from Low power clock stop state. Add support to this wake up interrupt. Signed-off-by: Srinivas Kandagatla --- drivers/soundwire/qcom.c | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index 3b2eb95a7e96..b9b76031307b 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -154,6 +155,7 @@ struct qcom_swrm_ctrl { u8 rd_cmd_id; int irq; unsigned int version; + int wake_irq; int num_din_ports; int num_dout_ports; int cols_index; @@ -503,6 +505,46 @@ static int qcom_swrm_enumerate(struct sdw_bus *bus) return 0; } +static irqreturn_t qcom_swrm_wake_irq_handler(int irq, void *dev_id) +{ + struct qcom_swrm_ctrl *swrm = dev_id; + int ret = IRQ_HANDLED; + struct sdw_slave *slave; + + clk_prepare_enable(swrm->hclk); + + if (swrm->wake_irq > 0) { + if (!irqd_irq_disabled(irq_get_irq_data(swrm->wake_irq))) + disable_irq_nosync(swrm->wake_irq); + } + + /* + * resume all the slaves which must have potentially generated this + * interrupt, this should also wake the controller at the same time. + * this is much safer than waking controller directly that will deadlock! + */ + list_for_each_entry(slave, &swrm->bus.slaves, node) { + ret = pm_runtime_get_sync(&slave->dev); + if (ret < 0 && ret != -EACCES) { + dev_err_ratelimited(swrm->dev, + "pm_runtime_get_sync failed in %s, ret %d\n", + __func__, ret); + pm_runtime_put_noidle(&slave->dev); + ret = IRQ_NONE; + goto err; + } + } + + list_for_each_entry(slave, &swrm->bus.slaves, node) { + pm_runtime_mark_last_busy(&slave->dev); + pm_runtime_put_autosuspend(&slave->dev); + } +err: + clk_disable_unprepare(swrm->hclk); + return IRQ_HANDLED; +} + + static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) { struct qcom_swrm_ctrl *swrm = dev_id; @@ -1340,6 +1382,19 @@ static int qcom_swrm_probe(struct platform_device *pdev) goto err_clk; } + ctrl->wake_irq = of_irq_get(dev->of_node, 1); + if (ctrl->wake_irq > 0) { + ret = devm_request_threaded_irq(dev, ctrl->wake_irq, NULL, + qcom_swrm_wake_irq_handler, + IRQF_TRIGGER_HIGH | IRQF_ONESHOT, + "swr_wake_irq", ctrl); + if (ret) { + dev_err(dev, "Failed to request soundwire wake irq\n"); + goto err_init; + } + } + + ret = sdw_bus_master_add(&ctrl->bus, dev, dev->fwnode); if (ret) { dev_err(dev, "Failed to register Soundwire controller (%d)\n", @@ -1424,6 +1479,11 @@ static int swrm_runtime_resume(struct device *dev) struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev); int ret; + if (ctrl->wake_irq > 0) { + if (!irqd_irq_disabled(irq_get_irq_data(ctrl->wake_irq))) + disable_irq_nosync(ctrl->wake_irq); + } + clk_prepare_enable(ctrl->hclk); if (ctrl->clk_stop_bus_reset) { @@ -1485,6 +1545,11 @@ static int __maybe_unused swrm_runtime_suspend(struct device *dev) usleep_range(300, 305); + if (ctrl->wake_irq > 0) { + if (irqd_irq_disabled(irq_get_irq_data(ctrl->wake_irq))) + enable_irq(ctrl->wake_irq); + } + return 0; }