From patchwork Fri Nov 19 09:43:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel Baluta (OSS)" X-Patchwork-Id: 12628587 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46B92C433F5 for ; Fri, 19 Nov 2021 09:45:33 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7385B615E6 for ; Fri, 19 Nov 2021 09:45:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7385B615E6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oss.nxp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org 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 D4E7D17D4; Fri, 19 Nov 2021 10:44:40 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D4E7D17D4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1637315130; bh=qmzWD08Kfa8VlD+nxKsplmD7jlP0ovWLFkY4Le3ntNk=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=frFiVYREb0MrWynV5MliElKbnyN7+UTz07ml1m05KIkWdIeIIyFCfOAR51bBFlL/9 t7/PQSRCGjA5Uh1sUsVKYdkM2L4dcePs7GPhwXJlb0YqR3iZK/FvElfLII0c5HptrY 0WfONT7ZnPcAzOV8RT1Zsj0EGhyBy5pZwME2I4BA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 16F2BF804FE; Fri, 19 Nov 2021 10:43:50 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E0D7DF804D2; Fri, 19 Nov 2021 10:43:44 +0100 (CET) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2049.outbound.protection.outlook.com [40.107.20.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8E0B4F8027D for ; Fri, 19 Nov 2021 10:43:36 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8E0B4F8027D Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="fS305YoI" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PliBtMN8OrfXGNdMaNoghrOquiZ8c5j1N027Xrsop/moFJtddfn3jtKO07CdsSI33j7kBbzmn6VMrp7Z339c3SA2YsGC3p0Qm9FBQqON4kljn2LXfNsEfnzqd91Wq/IPXI6j7++dvQWZZ+6djij2k0mb2U3wskas4OsjzHTsaWFAP5J02drf5VFDlE+GZQoNAtCtZKTJ5nYf+IKYf8PSyIVDIczf0le7zJN3nxcSUz1GPrvJDKJ1XEevSXlmJcI2B4IAhaoDLYL7bFwmSG3TqwXNPcPykPVXSZ1PgI1El/3GlDR3cgwIHZmWI32XU42vtBn0Q3j+6wD/YffOzswahg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Hxh10uJCvH4bSN1kqJK3p+nh3xdYf0fnlgTDIY2+/gk=; b=bn5HJ/L10GryVr3lUQEbaHbQOmghr9geEiKr/jx7rn4zprRL+nT9nm7kYjvAS9cXehDomljSKY8AsiVjsddueJx8f91TptlffgopqynNd86r7ojS8I6yAcQxsgZ/2kFRVu6yrQ9g/AOOEwpVFJxrrVirDNDWMuTLxLdYY2WdTdWmxoc5u9dx4Fu1OetHudYoj5vdVQGT1AfNZCwPsf4Eun7yVofQne8FRUU08Q41o7Ic1O7nFO+Fkfrc3WpV/CcQ1wr3PQnFWAhZ0XCq/0zcqwG2MiD7TfyTFrT3+9zLRvVjWccubMVrg6i26Nhvpq7Vqw4r7H5oWgpLaNKNTqCktg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Hxh10uJCvH4bSN1kqJK3p+nh3xdYf0fnlgTDIY2+/gk=; b=fS305YoIRgiVhoQ/Txw978NBy886z+QLV3gbZIR/Rm9xNYzjiYCOoWdV3kd5GskuxNbMvrXaUhHdiT6oPcPzeSRpJz6VqWv6WWpnt3rLvibDodYmtCzSOJsFgZXYS5zZrv6T4ZTGGP6aIbhyjjFtx7NWJmYoF7jAqfqZJLRKq8s= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from VI1PR04MB5151.eurprd04.prod.outlook.com (2603:10a6:803:61::28) by VE1PR04MB7358.eurprd04.prod.outlook.com (2603:10a6:800:1a5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15; Fri, 19 Nov 2021 09:43:33 +0000 Received: from VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::85af:f8be:aa99:ba5f]) by VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::85af:f8be:aa99:ba5f%3]) with mapi id 15.20.4690.029; Fri, 19 Nov 2021 09:43:33 +0000 From: Daniel Baluta To: broonie@kernel.org, alsa-devel@alsa-project.org Subject: [PATCH v2 2/5] ASoC: SOF: imx8: Add runtime PM / System PM support Date: Fri, 19 Nov 2021 11:43:16 +0200 Message-Id: <20211119094319.81674-3-daniel.baluta@oss.nxp.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211119094319.81674-1-daniel.baluta@oss.nxp.com> References: <20211119094319.81674-1-daniel.baluta@oss.nxp.com> X-ClientProxiedBy: AM0PR02CA0099.eurprd02.prod.outlook.com (2603:10a6:208:154::40) To VI1PR04MB5151.eurprd04.prod.outlook.com (2603:10a6:803:61::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (2a02:2f08:5706:b700:187d:3f5e:91e7:280d) by AM0PR02CA0099.eurprd02.prod.outlook.com (2603:10a6:208:154::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 09:43:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: af825f02-2e29-46cb-dfbc-08d9ab410d62 X-MS-TrafficTypeDiagnostic: VE1PR04MB7358: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2+llvFKhw4kIzC983IPRTFY7McTJVsSHpTy65+LxMbaoGsXsZt3gJicQDrqumxfj+EUaW9X7GO3BfSpn8cM7pHnjZ+OjEd0uYFvcDlyJXEnZ1MFRgcgBZK1we7M027kApP+4ftqhc81h0rUDJOcSVVdPj/CFkUveD4gl4djlgIECkvagVYjEQTNI/neqkp0OIFlmn592mS5TqDYBobOtChOGFqVoGglYoggZQWQlUR+y/x8nmrxv37c9cwCWg1w86OMUlXBodHpbSG+lWyvm4me/W6Yj/Vc45nekTu3yIbLYU907csuAx0c6KHGbD0ZmD7xCMqtW0FNo9PUhsyb3zsznzaP/A8OZDoU9DKxHvdh/Xe2KHEhqOYtEXETnwaJMQjuduvLLhzrEtT/7G2FW/e5m474H9sO9POL28cWlYTCFRFD+wB2co9vdNMnc7hUL3Djy88DV5epnQh4+f6ZAwwYr0o/jTEp+cu/1ZOTcRXMcSFoj6UgRk9Yvy4chf0OCbYVrFHsFk7xBf1BAZ7AJJaOjTQl7DlUaWnPQpuEYdDH1kkySqX7kiStdM231yHxyP8MN5zbwLl0hfkd/p+2MPxRGF2O6b2KngBgGXqjRxniOwWFCrBRP6C4F2a2766Cy6MielNaaPQS7E7SnIMPN6w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5151.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(2906002)(66556008)(52116002)(186003)(6506007)(6512007)(44832011)(2616005)(8936002)(508600001)(66476007)(66946007)(1076003)(5660300002)(83380400001)(38100700002)(6666004)(4326008)(6486002)(316002)(8676002)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: J8M3CkOxyZ1zSOqvzoWD1+J1fBhOiKWqY+gs1lKMOiMQ6Xoym5IoIhsaEcT8B1m1zo1MIGmKRHMaONAR7E1jtyemE7JhcMenAzeoGrXVDW8SKzTab4KMaDWvkMUpxC90OJICAYKKPmPzmz+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gnCpNzzYGNeY4O+03ie+C2SY7Yc2NxMzRXsShpMCgD+iBurrjawjLUQY4jPxUKKQz5T6ak87Pt+UZC8Xl5ER8w2S0OAi7WvjZGgr+zm6+0om/R3Ayf/NwuV+WV9h6txvK4F/T2fratEPTN0MwOwK65amLrrZCH8cBi8yUMkbQeUnpH/86tVwBJi76waoTOG1C9ZVu/Q5yx+PUKq8kOxP0SLL31rdUatNgrWhNVts4KL1cPjRoXxzJzS/Wt8eHF0GDsKDo8dssPwd85n4QVxGO9sgLR0xAUDM/6FKfdF/0sPtInMZJtyonIoexKpCXR3NsDvZCXyOBMwU0T/nr6cvH9/CHa5ije4im0RVRnB7K4/OqrDzAuUFpdROyrP9cSAIGjeMYBJo4GJdNX3VSNdB3sFgQtiq0OAiFXcXDGE+7WTb+elU4ms3Qg5/IKfJJe87+pTg/2syVYalgPg1M6i9LJpBrdBO80udNLAjAGHZXAdmKJZgVSVm0l+jvsl X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: af825f02-2e29-46cb-dfbc-08d9ab410d62 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5151.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 09:43:33.6902 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KT/DaHZyphvMUEJ+/JNji7O+/pSd0zkywnAjnVgGsl4ZPM/2v4tEnuxc7AXDQyFxQSnduKK1ho6o2fb5PFRt0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7358 Cc: daniel.baluta@gmail.com, lgirdwood@gmail.com, Ranjani Sridharan , linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, linux-imx@nxp.com, daniel.baluta@nxp.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" From: Daniel Baluta Handle clocks and mailbox channels at runtime suspend/resume in order to save power. DSP runtime PM uses a timeout of 2s. If device is idle for 2s system will enter runtime suspend. Because SOF state machine assumes that even if the DSP wasn't previously active at a System resume, will re-load the firmware we need to make sure that all needed resources are active. Kernel core will take care of enabling the PD, we need to make sure that we request the MU channels. Signed-off-by: Daniel Baluta Reviewed-by: Ranjani Sridharan Reviewed-by: Pierre-Louis Bossart --- sound/soc/sof/imx/imx8.c | 116 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/sound/soc/sof/imx/imx8.c b/sound/soc/sof/imx/imx8.c index 32f852cbba30..c4755c88d492 100644 --- a/sound/soc/sof/imx/imx8.c +++ b/sound/soc/sof/imx/imx8.c @@ -320,7 +320,9 @@ static int imx8_probe(struct snd_sof_dev *sdev) if (ret < 0) goto exit_pdev_unregister; - imx8_enable_clocks(sdev, priv->clks); + ret = imx8_enable_clocks(sdev, priv->clks); + if (ret < 0) + goto exit_pdev_unregister; return 0; @@ -364,6 +366,92 @@ static int imx8_get_bar_index(struct snd_sof_dev *sdev, u32 type) } } +static void imx8_suspend(struct snd_sof_dev *sdev) +{ + int i; + struct imx8_priv *priv = (struct imx8_priv *)sdev->pdata->hw_pdata; + + for (i = 0; i < DSP_MU_CHAN_NUM; i++) + imx_dsp_free_channel(priv->dsp_ipc, i); + + imx8_disable_clocks(sdev, priv->clks); +} + +static int imx8_resume(struct snd_sof_dev *sdev) +{ + struct imx8_priv *priv = (struct imx8_priv *)sdev->pdata->hw_pdata; + int ret; + int i; + + ret = imx8_enable_clocks(sdev, priv->clks); + if (ret < 0) + return ret; + + for (i = 0; i < DSP_MU_CHAN_NUM; i++) + imx_dsp_request_channel(priv->dsp_ipc, i); + + return 0; +} + +static int imx8_dsp_runtime_resume(struct snd_sof_dev *sdev) +{ + int ret; + const struct sof_dsp_power_state target_dsp_state = { + .state = SOF_DSP_PM_D0, + }; + + ret = imx8_resume(sdev); + if (ret < 0) + return ret; + + return snd_sof_dsp_set_power_state(sdev, &target_dsp_state); +} + +static int imx8_dsp_runtime_suspend(struct snd_sof_dev *sdev) +{ + const struct sof_dsp_power_state target_dsp_state = { + .state = SOF_DSP_PM_D3, + }; + + imx8_suspend(sdev); + + return snd_sof_dsp_set_power_state(sdev, &target_dsp_state); +} + +static int imx8_dsp_suspend(struct snd_sof_dev *sdev, unsigned int target_state) +{ + const struct sof_dsp_power_state target_dsp_state = { + .state = target_state, + }; + + if (!pm_runtime_suspended(sdev->dev)) + imx8_suspend(sdev); + + return snd_sof_dsp_set_power_state(sdev, &target_dsp_state); +} + +static int imx8_dsp_resume(struct snd_sof_dev *sdev) +{ + int ret; + const struct sof_dsp_power_state target_dsp_state = { + .state = SOF_DSP_PM_D0, + }; + + ret = imx8_resume(sdev); + if (ret < 0) + return ret; + + if (pm_runtime_suspended(sdev->dev)) { + pm_runtime_disable(sdev->dev); + pm_runtime_set_active(sdev->dev); + pm_runtime_mark_last_busy(sdev->dev); + pm_runtime_enable(sdev->dev); + pm_runtime_idle(sdev->dev); + } + + return snd_sof_dsp_set_power_state(sdev, &target_dsp_state); +} + static struct snd_soc_dai_driver imx8_dai[] = { { .name = "esai0", @@ -389,6 +477,14 @@ static struct snd_soc_dai_driver imx8_dai[] = { }, }; +static int imx8_dsp_set_power_state(struct snd_sof_dev *sdev, + const struct sof_dsp_power_state *target_state) +{ + sdev->dsp_power_state = *target_state; + + return 0; +} + /* i.MX8 ops */ struct snd_sof_dsp_ops sof_imx8_ops = { /* probe and remove */ @@ -441,6 +537,15 @@ struct snd_sof_dsp_ops sof_imx8_ops = { SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_NO_PERIOD_WAKEUP, + + /* PM */ + .runtime_suspend = imx8_dsp_runtime_suspend, + .runtime_resume = imx8_dsp_runtime_resume, + + .suspend = imx8_dsp_suspend, + .resume = imx8_dsp_resume, + + .set_power_state = imx8_dsp_set_power_state, }; EXPORT_SYMBOL(sof_imx8_ops); @@ -490,6 +595,15 @@ struct snd_sof_dsp_ops sof_imx8x_ops = { .drv = imx8_dai, .num_drv = ARRAY_SIZE(imx8_dai), + /* PM */ + .runtime_suspend = imx8_dsp_runtime_suspend, + .runtime_resume = imx8_dsp_runtime_resume, + + .suspend = imx8_dsp_suspend, + .resume = imx8_dsp_resume, + + .set_power_state = imx8_dsp_set_power_state, + /* ALSA HW info flags */ .hw_info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |