Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2877635ybc; Mon, 18 Nov 2019 06:10:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwmeL5RW+JnHsD7XnKCwiRsuFAngJRliCTQWoEsMGsTRPcfZb5YT7AGp7wAHilSOUwrYp3N X-Received: by 2002:adf:9185:: with SMTP id 5mr21488949wri.389.1574086233651; Mon, 18 Nov 2019 06:10:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1574086233; cv=pass; d=google.com; s=arc-20160816; b=vfdhD7LhLkpfRTxXdbhIIaaKnaFKIpzAIhdtX5wZI8+qDMcECmFJheQDtAkF1AWkAn DGXmEccxy/7p8JBF4Z5ibjRfJp5XriHpcabBQG4Hc7YXczoKfFZPIT/hJEj5rfIR80WA 3DAzztGb/bZYu7YKUy15deu78sn0Nvzzb8CX1gibfuo5x+zn/aMZcka81ZHP44AVHuxi Wbw7Ynu4327iNqYP7RZXOdi0cRGzxccK5vrt/cUqvVsYLIc5Vfp+NDotKim7gjS8l69y WvMxjOs1Zqgx67erNDsHl9rfxUlcHUTHBvIdzh5V3sbe4u1s/WvlIwvHt8mrl7Tj74/F Cbiw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:mime-version:references:in-reply-to :message-id:date:subject:cc:from:dkim-signature; bh=cr7NOqUjSnDeEzYB1Bc/pu3vclxK+rSRirMqtarc/08=; b=JWiC2FF44iO7p6o9mwH75++tLoqksD7pK+AZUhlg33QsBEDVmIrubduuwU6K9dV8IH pyldQv+WRrYr3qLFFHA1LRVGNoWeBoxo5mnfSB9C5MmVsbz1iNWkLgVp3f/OKcudkzpx 3lY+J6FjsVYy+3mosiVg3Y1dhdXcPOdYDNd7xkba0AYQ6EWbuLq1ZeyVYlfS5fDtdotl 9h5B6dIKRehEClOJYoXc69SqneDpB/zm3kvyOBz3kqbA1ITZ6kve5I/VBO8nm3YBfq+K +wwW6RyRiRqg/Eqgjjii2i+91mBinsQaxY4d3VTXZACbSzJ/0I3i+u+WP3QCEXJxSTjh ytBQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=ZesD1BfT; arc=pass (i=1); 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20si12130089edq.317.2019.11.18.06.10.08; Mon, 18 Nov 2019 06:10:33 -0800 (PST) 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; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=ZesD1BfT; arc=pass (i=1); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727241AbfKROGe (ORCPT + 99 others); Mon, 18 Nov 2019 09:06:34 -0500 Received: from mail-eopbgr730068.outbound.protection.outlook.com ([40.107.73.68]:18689 "EHLO NAM05-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727202AbfKROGd (ORCPT ); Mon, 18 Nov 2019 09:06:33 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yxp5+0oZtoJfZaGd4wo3toBBxIcxQmn5GDGZyLgK0AKnO56eohmvr8kLMihF9WUJtUMP6i5RY3ih2izfuOVPKbFZHrcd8PTUYOCNPwQCsnoGe1JdtIVZuBd9hOHwZJOA2muAiljUcbT9Y1tP7poOT1KsEOsbYUqO3efIaXkADnZKluhKZsZAK8m0iaAHoHl4RMm+oU13F/drLkfFB/VDopQadmY6Gu2NujFzBYSqujeultS3g2au42Of2UktaYk4iS2o4GWhGvYOEIRRKYeilq9F3ppUa3/yWzpTdn5hHxCsrLmmm8bnI3ebZy/N1Oq6jvCaY0VmWwbdkSbU//uvFg== 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-SenderADCheck; bh=cr7NOqUjSnDeEzYB1Bc/pu3vclxK+rSRirMqtarc/08=; b=ATUuHa8bf4zofyUwHoEm4CEuaEM/s4zjnl1fFIVSuhFzn/mQTrS5sbCvwU+XKoeePJbAoP++qOUMvm1N+qSj/Ah1APdD0RtlaGjSyp45MNGwQe8KoGIG9aGSO9g4ijLIIpMMHwCg7jCgHwGI8889gQ/XjkHW0f1hqvFkB9QjkoFvu/z9/Jd5P7sSbYcZW7wK9JxKoG+5cttCpYjgxQT3Ttij943xjj8kkWxW+7GRdI4fc4BsWBfIXqT3rpfLYi7kx0E+yFDQMWs5oNH5VOuF7T5VdrWc0p5MC5bAN6NJvLKyik4FbEvdMvU4H6dP43M6PnSy3JfN1JKD2/OOd7xscA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com smtp.mailfrom=amd.com; dmarc=permerror action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cr7NOqUjSnDeEzYB1Bc/pu3vclxK+rSRirMqtarc/08=; b=ZesD1BfTpV/G24yJm63EAu1QiLKmkUG00VzHzA4J/rayQD4z7VsZdhZLANc20j56138XeZQmcO3lTdF3KBYU3OdKTejWGl2Hqs/ArZJhny6NdRuDDc0fxbntJDlF+ntnSHvxSJnyhEndr5PBrVAv37gfUXXtQMsTmgUY371CZag= Received: from BN8PR12CA0027.namprd12.prod.outlook.com (2603:10b6:408:60::40) by MN2PR12MB3167.namprd12.prod.outlook.com (2603:10b6:208:a9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.26; Mon, 18 Nov 2019 14:06:25 +0000 Received: from CO1NAM11FT051.eop-nam11.prod.protection.outlook.com (2a01:111:f400:7eab::207) by BN8PR12CA0027.outlook.office365.com (2603:10b6:408:60::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.23 via Frontend Transport; Mon, 18 Nov 2019 14:06:24 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; google.com; dkim=none (message not signed) header.d=none;google.com; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXMB02.amd.com (165.204.84.17) by CO1NAM11FT051.mail.protection.outlook.com (10.13.174.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.2451.23 via Frontend Transport; Mon, 18 Nov 2019 14:06:24 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB02.amd.com (10.181.40.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 18 Nov 2019 08:06:23 -0600 Received: from SATLEXMB02.amd.com (10.181.40.143) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 18 Nov 2019 08:06:22 -0600 Received: from vishnu-All-Series.amd.com (10.180.168.240) by SATLEXMB02.amd.com (10.181.40.143) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Mon, 18 Nov 2019 08:06:18 -0600 From: Ravulapati Vishnu vardhan rao CC: , , , Ravulapati Vishnu vardhan rao , Liam Girdwood , Mark Brown , Jaroslav Kysela , "Takashi Iwai" , Vijendar Mukunda , "Gustavo A. R. Silva" , Kuninori Morimoto , Colin Ian King , Dan Carpenter , "moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM..." , open list Subject: [PATCH v7 6/6] ASoC: amd: Added ACP3x system resume and runtime pm Date: Mon, 18 Nov 2019 19:34:21 +0530 Message-ID: <1574085861-22818-7-git-send-email-Vishnuvardhanrao.Ravulapati@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1574085861-22818-1-git-send-email-Vishnuvardhanrao.Ravulapati@amd.com> References: <1574085861-22818-1-git-send-email-Vishnuvardhanrao.Ravulapati@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(39860400002)(346002)(376002)(136003)(396003)(428003)(199004)(189003)(23433003)(186003)(5660300002)(1671002)(2906002)(53416004)(446003)(486006)(6666004)(126002)(476003)(11346002)(336012)(426003)(316002)(478600001)(16586007)(7416002)(305945005)(36756003)(47776003)(54906003)(70586007)(86362001)(7696005)(51416003)(4326008)(70206006)(8676002)(81156014)(81166006)(26005)(50466002)(76176011)(2616005)(356004)(30864003)(109986005)(48376002)(50226002)(14444005)(8936002)(266003)(32563001);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR12MB3167;H:SATLEXMB02.amd.com;FPR:;SPF:None;LANG:en;PTR:InfoDomainNonexistent;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bb76ae3c-834a-49f5-8cbc-08d76c307f4f X-MS-TrafficTypeDiagnostic: MN2PR12MB3167: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:28; X-Forefront-PRVS: 0225B0D5BC X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JLXR6ftPR7zwvKTJNC6ZuikAEatkYNdJieANmNhpGHDyxmi/QU2PPWrfd6Uh+OpzDCxW78NsJXVgSkYyU0nVc2zGQ/oBpDkKmcslQrCKZBQMM6FamjFYFM6qRyxs5GsMglsRMXzLTtIj/SsY7rvmxNQb/R25rhW2biuSPWOSDS55ZIJDoUAJvj7kxB1/+B+NIJYtgCYDhk4uwffct6DU8xRclvThrnMh+ejtVWJ7mxrp20uuT0zNvV8qNv7CgiCmRBfwVEhW2wf6DkUYQWNA8krIAGk/L2tpa4TCyPBInu7I6heYtpR/p2Y1zvU9grwIbDZbzk4hHQoqisY4WluWyylq8M+WRq2VPLGf8QoJkXvB7g8CBx/K9DY8R2IOJln0A2rsObgIO/u/UL5P0GbyzfGNUfoN522pArNeOHdczm1YwD49Ch2jgq/+aDjyZfcC X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2019 14:06:24.4572 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb76ae3c-834a-49f5-8cbc-08d76c307f4f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3167 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When system wide suspend happens, ACP will be powered off and when system resumes,for audio usecase to continue,all the runtime configuration data needs to be programmed again. Added resume pm call back to ACP pm ops and also added runtime PM operations for ACP3x PCM platform device. Device will enter into D3 state when there is no activity on audio I2S lines. Signed-off-by: Ravulapati Vishnu vardhan rao --- sound/soc/amd/raven/acp3x-pcm-dma.c | 143 +-------------------------- sound/soc/amd/raven/acp3x.h | 7 ++ sound/soc/amd/raven/pci-acp3x.c | 189 +++++++++++++++++++++++++++++++++++- 3 files changed, 196 insertions(+), 143 deletions(-) diff --git a/sound/soc/amd/raven/acp3x-pcm-dma.c b/sound/soc/amd/raven/acp3x-pcm-dma.c index 3de2e25..4d577fc 100644 --- a/sound/soc/amd/raven/acp3x-pcm-dma.c +++ b/sound/soc/amd/raven/acp3x-pcm-dma.c @@ -58,106 +58,6 @@ static const struct snd_pcm_hardware acp3x_pcm_hardware_capture = { .periods_max = CAPTURE_MAX_NUM_PERIODS, }; -static int acp3x_power_on(void __iomem *acp3x_base, bool on) -{ - u16 val, mask; - u32 timeout; - - if (on == true) { - val = 1; - mask = ACP3x_POWER_ON; - } else { - val = 0; - mask = ACP3x_POWER_OFF; - } - - rv_writel(val, acp3x_base + mmACP_PGFSM_CONTROL); - timeout = 0; - while (true) { - val = rv_readl(acp3x_base + mmACP_PGFSM_STATUS); - if ((val & ACP3x_POWER_OFF_IN_PROGRESS) == mask) - break; - if (timeout > 100) { - pr_err("ACP3x power state change failure\n"); - return -ENODEV; - } - timeout++; - cpu_relax(); - } - return 0; -} - -static int acp3x_reset(void __iomem *acp3x_base) -{ - u32 val, timeout; - - rv_writel(1, acp3x_base + mmACP_SOFT_RESET); - timeout = 0; - while (true) { - val = rv_readl(acp3x_base + mmACP_SOFT_RESET); - if ((val & ACP3x_SOFT_RESET__SoftResetAudDone_MASK) || - timeout > 100) { - if (val & ACP3x_SOFT_RESET__SoftResetAudDone_MASK) - break; - return -ENODEV; - } - timeout++; - cpu_relax(); - } - - rv_writel(0, acp3x_base + mmACP_SOFT_RESET); - timeout = 0; - while (true) { - val = rv_readl(acp3x_base + mmACP_SOFT_RESET); - if (!val || timeout > 100) { - if (!val) - break; - return -ENODEV; - } - timeout++; - cpu_relax(); - } - return 0; -} - -static int acp3x_init(void __iomem *acp3x_base) -{ - int ret; - - /* power on */ - ret = acp3x_power_on(acp3x_base, true); - if (ret) { - pr_err("ACP3x power on failed\n"); - return ret; - } - /* Reset */ - ret = acp3x_reset(acp3x_base); - if (ret) { - pr_err("ACP3x reset failed\n"); - return ret; - } - return 0; -} - -static int acp3x_deinit(void __iomem *acp3x_base) -{ - int ret; - - /* Reset */ - ret = acp3x_reset(acp3x_base); - if (ret) { - pr_err("ACP3x reset failed\n"); - return ret; - } - /* power off */ - ret = acp3x_power_on(acp3x_base, false); - if (ret) { - pr_err("ACP3x power off failed\n"); - return ret; - } - return 0; -} - static irqreturn_t i2s_irq_handler(int irq, void *dev_id) { struct i2s_dev_data *rv_i2s_data; @@ -536,26 +436,20 @@ static int acp3x_audio_probe(struct platform_device *pdev) adata->i2s_irq = res->start; dev_set_drvdata(&pdev->dev, adata); - /* Initialize ACP */ - status = acp3x_init(adata->acp3x_base); - if (status) { - ret = -ENODEV; - goto base_err; - } status = devm_snd_soc_register_component(&pdev->dev, &acp3x_i2s_component, NULL, 0); if (status) { dev_err(&pdev->dev, "Fail to register acp i2s component\n"); ret = -ENODEV; - goto dev_err; + goto base_err; } status = devm_request_irq(&pdev->dev, adata->i2s_irq, i2s_irq_handler, irqflags, "ACP3x_I2S_IRQ", adata); if (status) { dev_err(&pdev->dev, "ACP3x I2S IRQ request failed\n"); ret = -ENODEV; - goto dev_err; + goto base_err; } pm_runtime_set_autosuspend_delay(&pdev->dev, 5000); @@ -563,14 +457,6 @@ static int acp3x_audio_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); return 0; -dev_err: - devm_kfree(&pdev->dev, adata); - status = acp3x_deinit(adata->acp3x_base); - if (status) - dev_err(&pdev->dev, "ACP de-init failed\n"); - else - dev_dbg(&pdev->dev, "ACP de-initialized\n"); - return ret; base_err: devm_kfree(&pdev->dev, adata); return ret; @@ -578,16 +464,6 @@ static int acp3x_audio_probe(struct platform_device *pdev) static int acp3x_audio_remove(struct platform_device *pdev) { - struct i2s_dev_data *adata; - int ret; - - adata = dev_get_drvdata(&pdev->dev); - ret = acp3x_deinit(adata->acp3x_base); - if (ret) - dev_err(&pdev->dev, "ACP de-init failed\n"); - else - dev_dbg(&pdev->dev, "ACP de-initialized\n"); - pm_runtime_disable(&pdev->dev); return 0; } @@ -595,13 +471,9 @@ static int acp3x_audio_remove(struct platform_device *pdev) static int acp3x_resume(struct device *dev) { struct i2s_dev_data *adata; - int status; u32 val; adata = dev_get_drvdata(dev); - status = acp3x_init(adata->acp3x_base); - if (status) - return -ENODEV; if (adata->play_stream && adata->play_stream->runtime) { struct i2s_stream_instance *rtd = @@ -648,14 +520,8 @@ static int acp3x_resume(struct device *dev) static int acp3x_pcm_runtime_suspend(struct device *dev) { struct i2s_dev_data *adata; - int status; adata = dev_get_drvdata(dev); - status = acp3x_deinit(adata->acp3x_base); - if (status) - dev_err(dev, "ACP de-init failed\n"); - else - dev_dbg(dev, "ACP de-initialized\n"); rv_writel(0, adata->acp3x_base + mmACP_EXTERNAL_INTR_ENB); @@ -665,12 +531,9 @@ static int acp3x_pcm_runtime_suspend(struct device *dev) static int acp3x_pcm_runtime_resume(struct device *dev) { struct i2s_dev_data *adata; - int status; adata = dev_get_drvdata(dev); - status = acp3x_init(adata->acp3x_base); - if (status) - return -ENODEV; + rv_writel(1, adata->acp3x_base + mmACP_EXTERNAL_INTR_ENB); return 0; } diff --git a/sound/soc/amd/raven/acp3x.h b/sound/soc/amd/raven/acp3x.h index 01b283a..cf16ceb 100644 --- a/sound/soc/amd/raven/acp3x.h +++ b/sound/soc/amd/raven/acp3x.h @@ -65,6 +65,13 @@ #define SLOT_WIDTH_16 0x10 #define SLOT_WIDTH_24 0x18 #define SLOT_WIDTH_32 0x20 +#define ACP_PGFSM_CNTL_POWER_ON_MASK 0x01 +#define ACP_PGFSM_CNTL_POWER_OFF_MASK 0x00 +#define ACP_PGFSM_STATUS_MASK 0x03 +#define ACP_POWERED_ON 0x00 +#define ACP_POWER_ON_IN_PROGRESS 0x01 +#define ACP_POWERED_OFF 0x02 +#define ACP_POWER_OFF_IN_PROGRESS 0x03 struct acp3x_platform_info { u16 play_i2s_instance; diff --git a/sound/soc/amd/raven/pci-acp3x.c b/sound/soc/amd/raven/pci-acp3x.c index 174adbc..6d79e8d 100644 --- a/sound/soc/amd/raven/pci-acp3x.c +++ b/sound/soc/amd/raven/pci-acp3x.c @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include #include "acp3x.h" @@ -19,6 +22,120 @@ struct acp3x_dev_data { struct platform_device *pdev[ACP3x_DEVS]; }; +static int acp3x_power_on(void __iomem *acp3x_base) +{ + u32 val; + u32 timeout; + + timeout = 0; + val = rv_readl(acp3x_base + mmACP_PGFSM_STATUS); + + if (val == 0) + return val; + + if (!((val & ACP_PGFSM_STATUS_MASK) == + ACP_POWER_ON_IN_PROGRESS)) + rv_writel(ACP_PGFSM_CNTL_POWER_ON_MASK, + acp3x_base + mmACP_PGFSM_CONTROL); + while (++timeout) { + val = rv_readl(acp3x_base + mmACP_PGFSM_STATUS); + if (!val) + break; + udelay(1); + if (timeout > 500) { + pr_err("ACP is Not Powered ON\n"); + return -ETIMEDOUT; + } + } + return 0; +} +static int acp3x_power_off(void __iomem *acp3x_base) +{ + u32 val; + u32 timeout, ret; + + timeout = 0; + rv_writel(ACP_PGFSM_CNTL_POWER_OFF_MASK, + acp3x_base + mmACP_PGFSM_CONTROL); + while (++timeout) { + val = rv_readl(acp3x_base + mmACP_PGFSM_STATUS); + if ((val & ACP_PGFSM_STATUS_MASK) == ACP_POWERED_OFF) { + ret = 0; + break; + } + udelay(1); + if (timeout > 500) { + pr_err("ACP is Not Powered OFF\n"); + ret = -ETIMEDOUT; + break; + } + } + return ret; +} +static int acp3x_reset(void __iomem *acp3x_base) +{ + u32 val, timeout; + + rv_writel(1, acp3x_base + mmACP_SOFT_RESET); + timeout = 0; + while (++timeout) { + val = rv_readl(acp3x_base + mmACP_SOFT_RESET); + if ((val & ACP3x_SOFT_RESET__SoftResetAudDone_MASK) || + timeout > 100) { + if (val & ACP3x_SOFT_RESET__SoftResetAudDone_MASK) + break; + return -ENODEV; + } + cpu_relax(); + } + rv_writel(0, acp3x_base + mmACP_SOFT_RESET); + timeout = 0; + while (++timeout) { + val = rv_readl(acp3x_base + mmACP_SOFT_RESET); + if (!val) + break; + if (timeout > 100) + return -ENODEV; + cpu_relax(); + } + return 0; +} +static int acp3x_init(void __iomem *acp3x_base) +{ + int ret; + + /* power on */ + ret = acp3x_power_on(acp3x_base); + if (ret) { + pr_err("ACP3x power on failed\n"); + return ret; + } + /* Reset */ + ret = acp3x_reset(acp3x_base); + if (ret) { + pr_err("ACP3x reset failed\n"); + return ret; + } + return 0; +} +static int acp3x_deinit(void __iomem *acp3x_base) +{ + int ret; + + /* Reset */ + ret = acp3x_reset(acp3x_base); + if (ret) { + pr_err("ACP3x reset failed\n"); + return ret; + } + /* power off */ + ret = acp3x_power_off(acp3x_base); + if (ret) { + pr_err("ACP3x power off failed\n"); + return ret; + } + return 0; +} static int snd_acp3x_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { @@ -64,6 +181,9 @@ static int snd_acp3x_probe(struct pci_dev *pci, } pci_set_master(pci); pci_set_drvdata(pci, adata); + ret = acp3x_init(adata->acp3x_base); + if (ret) + goto release_regions; val = rv_readl(adata->acp3x_base + mmACP_I2S_PIN_CONFIG); switch (val) { @@ -73,7 +193,7 @@ static int snd_acp3x_probe(struct pci_dev *pci, GFP_KERNEL); if (!adata->res) { ret = -ENOMEM; - goto release_regions; + goto release_resource; } adata->res[0].name = "acp3x_i2s_iomem"; @@ -134,9 +254,19 @@ static int snd_acp3x_probe(struct pci_dev *pci, ret = -ENODEV; goto unmap_mmio; } + pm_runtime_set_autosuspend_delay(&pci->dev, 5000); + pm_runtime_use_autosuspend(&pci->dev); + pm_runtime_set_active(&pci->dev); + pm_runtime_put_noidle(&pci->dev); + pm_runtime_enable(&pci->dev); return 0; unmap_mmio: + ret = acp3x_deinit(adata->acp3x_base); + if (ret) + dev_err(&pci->dev, "ACP de-init failed\n"); + else + dev_dbg(&pci->dev, "ACP de-initialized\n"); if (val == I2S_MODE) for (i = 0 ; i < ACP3x_DEVS ; i++) platform_device_unregister(adata->pdev[i]); @@ -145,6 +275,17 @@ static int snd_acp3x_probe(struct pci_dev *pci, pci_disable_msi(pci); pci_release_regions(pci); pci_disable_device(pci); +release_resource: + ret = acp3x_deinit(adata->acp3x_base); + if (ret) + dev_err(&pci->dev, "ACP de-init failed\n"); + else + dev_dbg(&pci->dev, "ACP de-initialized\n"); + devm_kfree(&pci->dev, adata->res); + devm_kfree(&pci->dev, adata); + pci_disable_msi(pci); + pci_release_regions(pci); + pci_disable_device(pci); release_regions: devm_kfree(&pci->dev, adata); pci_disable_msi(pci); @@ -158,16 +299,55 @@ static int snd_acp3x_probe(struct pci_dev *pci, return ret; } +static int snd_acp3x_suspend(struct device *dev) +{ + int status; + struct acp3x_dev_data *adata; + adata = dev_get_drvdata(dev); + status = acp3x_deinit(adata->acp3x_base); + if (status) + dev_err(dev, "ACP de-init failed\n"); + else + dev_dbg(dev, "ACP de-initialized\n"); + + return 0; +} +static int snd_acp3x_resume(struct device *dev) +{ + int status; + struct acp3x_dev_data *adata; + + adata = dev_get_drvdata(dev); + status = acp3x_init(adata->acp3x_base); + if (status) { + dev_err(dev, "ACP init failed\n"); + return status; + } + return 0; +} +static const struct dev_pm_ops acp3x_pm = { + .runtime_suspend = snd_acp3x_suspend, + .runtime_resume = snd_acp3x_resume, + .resume = snd_acp3x_resume, +}; static void snd_acp3x_remove(struct pci_dev *pci) { - struct acp3x_dev_data *adata = pci_get_drvdata(pci); - int i; + struct acp3x_dev_data *adata; + int i, ret; + adata = pci_get_drvdata(pci); if (adata->acp3x_audio_mode == ACP3x_I2S_MODE) { for (i = 0 ; i < ACP3x_DEVS ; i++) platform_device_unregister(adata->pdev[i]); } + ret = acp3x_deinit(adata->acp3x_base); + if (ret) + dev_err(&pci->dev, "ACP de-init failed\n"); + else + dev_dbg(&pci->dev, "ACP de-initialized\n"); + pm_runtime_disable(&pci->dev); + pm_runtime_get_noresume(&pci->dev); pci_disable_msi(pci); pci_release_regions(pci); pci_disable_device(pci); @@ -186,6 +366,9 @@ static struct pci_driver acp3x_driver = { .id_table = snd_acp3x_ids, .probe = snd_acp3x_probe, .remove = snd_acp3x_remove, + .driver = { + .pm = &acp3x_pm, + } }; module_pci_driver(acp3x_driver); -- 2.7.4