Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11444597ybi; Thu, 25 Jul 2019 16:43:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqySvr7nbuYGwIbSOkl87IwFay024wgGggIjxuTIRFnbHgyqJWYP4QAEPgels5oKBiTuRfub X-Received: by 2002:a63:221f:: with SMTP id i31mr90635735pgi.251.1564098209452; Thu, 25 Jul 2019 16:43:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564098209; cv=none; d=google.com; s=arc-20160816; b=EF9QGNxlgBz7neeIftwlbLr7zrhnYfc2AwNZzJjAmt+FgqwctQZYhH7G2oqjtyatV/ eo6/f1eCYPYzZxaNOxe/76SlkimV7Qbo2SmyMKRQ47cHwfp7lfBLzQ3J0v2dqEdh3xtS ugJfYri4hRadP37/QDv4V6Qd4RZHxI4elcREj8Rf/Wf2Vc564C87DHH/+X95SBr2UV8i C60wUOw31+g7QjKJ4uLvrX2LBjfTQ3s8ZNyyY2ZwJMaStTThA5/2F92XZTfVxsnJm7uX 9FJf33hWB1tI3lB6YQAUmeTm6RPsiXU8SSTHNYQJZ8/hP7Fxd9W1uhyhYMr3QMJw8CS5 KDYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vm13+aPgPS3qTS0bce2YahzRulrw6m2fkZY/zdpZ7BI=; b=GFLjyFGBuY9lXWGjXCyfuXzGxdJAo41SnzTul+Z+b6egwr/qE5RL1/QX9RMpGS6es1 vKo0r0fCj9W0Jv0QM8y6G4QTrK0nVyFnI9GwvH0ULo0qrj7M5aGL8mwWqPVaKBG0uGGY DkWSxt71Swhz4o+6a3GwnVmURN6+XCdzMB2qsgQUuisFS3o8G2wtHTM/SbcTxuAlxHyI mqbBwJJCWNWcVzGZtwZgN6k3QplPIVcBXGizatvvEK5VpEICzO/OgGdfn7y+psPMM156 Mgdl66+gYcqXiZKIo/6xHCFoGCjnqjIdYAaYO6JITa4PYFlr2EVlUYSUM+CnHaVmtyNh 6xtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d7si16909703plr.18.2019.07.25.16.43.14; Thu, 25 Jul 2019 16:43:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727723AbfGYXmI (ORCPT + 99 others); Thu, 25 Jul 2019 19:42:08 -0400 Received: from mga06.intel.com ([134.134.136.31]:51850 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727640AbfGYXmB (ORCPT ); Thu, 25 Jul 2019 19:42:01 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jul 2019 16:42:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,308,1559545200"; d="scan'208";a="369874872" Received: from amrutaku-mobl1.amr.corp.intel.com (HELO pbossart-mobl3.intel.com) ([10.255.230.75]) by fmsmga006.fm.intel.com with ESMTP; 25 Jul 2019 16:42:00 -0700 From: Pierre-Louis Bossart To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, tiwai@suse.de, broonie@kernel.org, vkoul@kernel.org, gregkh@linuxfoundation.org, jank@cadence.com, srinivas.kandagatla@linaro.org, slawomir.blauciak@intel.com, Pierre-Louis Bossart , Sanyog Kale Subject: [RFC PATCH 39/40] soundwire: intel: add pm_runtime support Date: Thu, 25 Jul 2019 18:40:31 -0500 Message-Id: <20190725234032.21152-40-pierre-louis.bossart@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725234032.21152-1-pierre-louis.bossart@linux.intel.com> References: <20190725234032.21152-1-pierre-louis.bossart@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add basic hooks in DAI .startup and .shutdown callbacks. The SoundWire IP should be powered between those two calls. By default the platform_device is in SUSPENDED mode, it is required to call pm_runtime_set_active() before _enable() FIXME: do we need to use mark_last_busy()? Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/intel.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index db7bf2912767..1394a2322553 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -707,6 +707,23 @@ static void intel_port_cleanup(struct sdw_cdns_dma_data *dma) } } +static int intel_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); + int ret; + + ret = pm_runtime_get_sync(cdns->dev); + if (ret < 0) { + dev_err_ratelimited(cdns->dev, + "pm_runtime_get_sync failed in %s, ret %d\n", + __func__, ret); + pm_runtime_put_noidle(cdns->dev); + } + + return ret; +} + static int intel_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) @@ -829,6 +846,8 @@ void intel_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct sdw_cdns_dma_data *dma; + struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); + int ret; dma = snd_soc_dai_get_dma_data(dai, substream); if (!dma) @@ -836,6 +855,13 @@ void intel_shutdown(struct snd_pcm_substream *substream, snd_soc_dai_set_dma_data(dai, substream, NULL); kfree(dma); + + pm_runtime_mark_last_busy(cdns->dev); + ret = pm_runtime_put_autosuspend(cdns->dev); + if (ret < 0) + dev_err_ratelimited(cdns->dev, + "pM_runtime_put_autosuspend failed in %s:, ret %d\n", + __func__, ret); } static int intel_pcm_set_sdw_stream(struct snd_soc_dai *dai, @@ -851,6 +877,7 @@ static int intel_pdm_set_sdw_stream(struct snd_soc_dai *dai, } static const struct snd_soc_dai_ops intel_pcm_dai_ops = { + .startup = intel_startup, .hw_params = intel_hw_params, .hw_free = intel_hw_free, .shutdown = intel_shutdown, @@ -1124,6 +1151,15 @@ static int intel_probe(struct platform_device *pdev) intel_debugfs_init(sdw); + /* Enable PM */ + pm_runtime_set_autosuspend_delay(&pdev->dev, 3000); + pm_runtime_use_autosuspend(&pdev->dev); + + pm_runtime_mark_last_busy(&pdev->dev); /* FIXME: needed? */ + + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); + return 0; err_dai: @@ -1141,6 +1177,7 @@ static int intel_remove(struct platform_device *pdev) sdw = platform_get_drvdata(pdev); if (!sdw->cdns.bus.prop.hw_disabled) { + pm_runtime_disable(&pdev->dev); intel_debugfs_exit(sdw); free_irq(sdw->res->irq, sdw); snd_soc_unregister_component(sdw->cdns.dev); @@ -1212,6 +1249,7 @@ static int intel_resume(struct device *dev) static const struct dev_pm_ops intel_pm = { SET_SYSTEM_SLEEP_PM_OPS(intel_suspend, intel_resume) + SET_RUNTIME_PM_OPS(intel_suspend, intel_resume, NULL) }; static struct platform_driver sdw_intel_drv = { -- 2.20.1