From patchwork Mon Feb 13 09:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vijendar Mukunda X-Patchwork-Id: 13138054 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 59D86C636D4 for ; Mon, 13 Feb 2023 09:41:52 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 649A0857; Mon, 13 Feb 2023 10:41:00 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 649A0857 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1676281310; bh=Sfp3mmAnM09NP/gQVfRKnuJjf7s/xrr8zXjSFZ3Ogm4=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=deUreFPtPwfAZLcXqXyMUCOuqbjHTlF6qSNHR42rQHzsRpwP3BUZiZP+uANxCXJV/ pZkiKpF5RkoIDa8e18JrXBm76uIBbRYwjeBxLgvxGQxCvvIqhYTkmrXCjO7pwsqSVw XF9c2PN8hW0odByso9jE2jVKt363GXo6Y2sPiaP8= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id C7828F804DA; Mon, 13 Feb 2023 10:39:55 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D33F9F80571; Mon, 13 Feb 2023 10:38:15 +0100 (CET) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2060b.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eb2::60b]) (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 9C0B1F804D6 for ; Mon, 13 Feb 2023 10:38:07 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9C0B1F804D6 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=uNfsqc3j ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dHCnHsizlnKCu0tnnFMPBsiykSgbiXaTzRFoTgwZ+VvLG2q+gMe7YO3IbqchLbIaS7DLNctoqJ5HdOBBRXw9mQyp75RgWTPk9LMjuyU8LsTs6b8gbXnD5M3zuBFo0HRRo1w29ixkJOT298I7wddWdFQ5wL5NQFm/L3k9fZe0ZjpF8KX/Cu3OZMsFCP6MxutM+BPvRsA7hGmWPOVAIGEH+brClE8T9GQgMy6vL7pHzD6Ix+wn44UaiJTI6NvZfyqg06zzHsGr3u56kB9bYDtrIg18E4A9+eXLIbTdWXR8ONfCIEpB8s9sngX/lus+zTEPzIOmGf8Sb7thW7PviwwaMw== 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=UwZp4Yp6i2AyVuqNXN9CzKcCl9D8YMwGQAppUrzkEFc=; b=WFEshbJQUYTkWVrDicYRf+hCP4/axkCG1HmJOkflIq6zEtPe+SSlIMgeZL3Ftn5qTW0RHqg2HxJrpeKW+EmQE45avM2IZsYPBhAMMGcnoL6I6nY2V5DvKETmkn4ML2znNFd3e7fEqdx06Tpd3mgYm9jVKdsGsjVvTZAvmAh+SlBip4oKZCX4Qd2atibHnXHYaU+QZQb+3mj2u8CZQwWYX1y0i4BQGoa9p8tp2cx6OXC+tIk2zAT2DyMIJS693pn4Jat5wskOLN4dwGhDdinMpdbA+jc2XCLYfZf0SvZERjoU4gFnuWUWGs0ZnRuG9mn6851y7ONQ+BpW0nqDS8/4yw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UwZp4Yp6i2AyVuqNXN9CzKcCl9D8YMwGQAppUrzkEFc=; b=uNfsqc3j0eozqF/5qtUfnyMdvtKDVhbOrNwRAwgASk9WJq0B47poMoYytfgIEKR9aOJycHcl0ej+iL6ji4ZsI9Qri/Yc0JpYu/89Axzld5+5R3wRH7v08zKr702ko/ptnqXBC72qgjTq4z7u5n7LoGa0T0ocqF82Xg9ceeG5Ypw= Received: from BN9PR03CA0976.namprd03.prod.outlook.com (2603:10b6:408:109::21) by CH2PR12MB4152.namprd12.prod.outlook.com (2603:10b6:610:a7::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.24; Mon, 13 Feb 2023 09:38:04 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:109:cafe::1a) by BN9PR03CA0976.outlook.office365.com (2603:10b6:408:109::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.23 via Frontend Transport; Mon, 13 Feb 2023 09:38:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6086.24 via Frontend Transport; Mon, 13 Feb 2023 09:38:03 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 13 Feb 2023 03:38:01 -0600 Received: from vijendar-X570-GAMING-X.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Mon, 13 Feb 2023 03:37:57 -0600 From: Vijendar Mukunda To: Subject: [PATCH V2 8/8] soundwire: amd: add pm_prepare callback and pm ops support Date: Mon, 13 Feb 2023 15:10:31 +0530 Message-ID: <20230213094031.2231058-9-Vijendar.Mukunda@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213094031.2231058-1-Vijendar.Mukunda@amd.com> References: <20230213094031.2231058-1-Vijendar.Mukunda@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT015:EE_|CH2PR12MB4152:EE_ X-MS-Office365-Filtering-Correlation-Id: 47951d6d-384c-40c5-df67-08db0da6013b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cf2dtrX6/f2hAlVrNVJeUBkw4jyFwVakOUu1stNTgf1pUTEjQWoR/2T9vOATAd6J4Zz6UuNXV9JINKCRHM6hcSfl52a6Yl4EjqSmdThz3bfoNJkIyVjMH9xnwF5dqmYCUz1zWwQRlv2oMmAhEkdhQtHqax8Qjp62Pepu7yXivOg4Cc800UyPdwJrrvFb+E9EuchnV6NYHipwsF7UZovkaihrvqFttVijaFKkbFQDbRt5gBvkW5VxA1edJQGkVi+gRl8pXLZYOgvh5V2h86Q8n+lwj+0qw8Cq37+MAIkyQi9NUX9W/s8xHrYxsVlG94I1Q2QepKowdt70LEiqUAEkm5sIPYb8+ju1pKS2b7yFbK4NEjVYKPtcg5yOWEJtmua8nluIM5iVJRrOeZrJkFRsS9qDOJCIT0YDTN3ckoEsTBV2T75q5hX559MrZ5CMXPgoa9vNAb1ke8vAGBXuFozDkJr+Eh8ey4w4zUq9f0x9+LOfdwDN/4Up5wQkFKNMlNU58tH9LDR81nSRgcH23OEfDp8zRLvh9TITNfHmfnZR6qwqcq4dBZj4RpnawYAStvbkH0GQHGV94j2tDUz0aloXnkRCmqfa+vrN241NzMnFcE6c32JOpgx2JJR/wka3jMJQOEisMLVFo2qOjxNw8of01DS3++vYjgeme7rYuczA8IjK5x90M1GIw1jOQ3mwzCv9r30n3ZSiNoMnoKyWg7LRtp7iazsrkUuqCEBG65jvTM4= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(136003)(376002)(346002)(396003)(451199018)(46966006)(40470700004)(36840700001)(5660300002)(47076005)(83380400001)(426003)(26005)(186003)(36756003)(2906002)(1076003)(82310400005)(86362001)(41300700001)(478600001)(40460700003)(6666004)(7696005)(8936002)(82740400003)(81166007)(336012)(40480700001)(36860700001)(356005)(2616005)(54906003)(316002)(70206006)(6916009)(8676002)(4326008)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2023 09:38:03.9021 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47951d6d-384c-40c5-df67-08db0da6013b 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4152 Message-ID-Hash: HGU5SX7G26GJNKDVNZELIBHW6UO4XPPX X-Message-ID-Hash: HGU5SX7G26GJNKDVNZELIBHW6UO4XPPX X-MailFrom: Vijendar.Mukunda@amd.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: amadeuszx.slawinski@linux.intel.com, Mario.Limonciello@amd.com, Sunil-kumar.Dommati@amd.com, Basavaraj.Hiregoudar@amd.com, Mastan.Katragadda@amd.com, Arungopal.kondaveeti@amd.com, Vijendar Mukunda , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , "moderated list:SOUNDWIRE SUBSYSTEM" , open list X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add pm_prepare callback and System level pm ops support for AMD soundwire manager driver. Signed-off-by: Vijendar Mukunda Signed-off-by: Mastan Katragadda --- drivers/soundwire/amd_manager.c | 90 +++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c index e53dc67f8529..350d411e695d 100644 --- a/drivers/soundwire/amd_manager.c +++ b/drivers/soundwire/amd_manager.c @@ -1157,6 +1157,94 @@ static int amd_sdw_clock_stop_exit(struct amd_sdw_manager *amd_manager) return 0; } +static int amd_resume_child_device(struct device *dev, void *data) +{ + int ret; + struct sdw_slave *slave = dev_to_sdw_dev(dev); + + if (!slave->probed) { + dev_dbg(dev, "skipping device, no probed driver\n"); + return 0; + } + if (!slave->dev_num_sticky) { + dev_dbg(dev, "skipping device, never detected on bus\n"); + return 0; + } + + if (!pm_runtime_suspended(dev)) + return 0; + ret = pm_request_resume(dev); + if (ret < 0) + dev_err(dev, "%s: pm_request_resume failed: %d\n", __func__, ret); + + return ret; +} + +static int __maybe_unused amd_pm_prepare(struct device *dev) +{ + struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev); + struct sdw_bus *bus = &amd_manager->bus; + int ret; + + if (bus->prop.hw_disabled) { + dev_dbg(bus->dev, "Soundwire manager %d is disabled, ignoring\n", + bus->link_id); + return 0; + } + /* + * When multiple peripheral devices connected over the same link, if soundwire manager + * device is not in runtime suspend state, observed that device alerts are missing + * without pm_prepare on AMD platforms in clockstop mode0. + */ + if (pm_runtime_suspended(dev) && amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) { + ret = pm_request_resume(dev); + if (ret < 0) { + dev_err(bus->dev, "pm_request_resume failed: %d\n", ret); + return 0; + } + } + /* To force peripheral devices to system level suspend state, resume the devices + * from runtime suspend state first. Without that unable to dispatch the alert + * status to peripheral driver during system level resume as they are in runtime + * suspend state. + */ + ret = device_for_each_child(bus->dev, NULL, amd_resume_child_device); + if (ret < 0) + dev_err(dev, "%s: amd_resume_child_device failed: %d\n", __func__, ret); + return 0; +} + +static int __maybe_unused amd_suspend(struct device *dev) +{ + struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev); + struct sdw_bus *bus = &amd_manager->bus; + int ret; + + if (bus->prop.hw_disabled) { + dev_dbg(bus->dev, "Soundwire manager %d is disabled, ignoring\n", + bus->link_id); + return 0; + } + + if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) { + ret = amd_sdw_clock_stop(amd_manager); + if (ret) + return ret; + } else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) { + /* + * As per hardware programming sequence on AMD platforms, + * clock stop should be invoked first before powering-off + */ + ret = amd_sdw_clock_stop(amd_manager); + if (ret) + return ret; + ret = amd_deinit_sdw_manager(amd_manager); + if (ret) + return ret; + } + return 0; +} + static int __maybe_unused amd_suspend_runtime(struct device *dev) { struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev); @@ -1229,6 +1317,8 @@ static int __maybe_unused amd_resume_runtime(struct device *dev) } static const struct dev_pm_ops amd_pm = { + .prepare = amd_pm_prepare, + SET_SYSTEM_SLEEP_PM_OPS(amd_suspend, amd_resume_runtime) SET_RUNTIME_PM_OPS(amd_suspend_runtime, amd_resume_runtime, NULL) };