From patchwork Thu Mar 2 06:21:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mukunda,Vijendar" X-Patchwork-Id: 13156755 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 6EA58C678D4 for ; Thu, 2 Mar 2023 06:21:31 +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 8F81E209; Thu, 2 Mar 2023 07:20:38 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8F81E209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1677738088; bh=OufZdlweVltB8oPPhaIhJ7ZJjF1yUIJYJmCIIaTzN8k=; 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=F4YXeKEoZBLQzG9bHHQFeccGTxGfqKqRY5giPAH+I8RbIpeaR6FoaahdLVOUqsunQ ACy2AFozhMhswXNl9JMUV37+gymF61xlmsghlvJ0yfj9Zn5l3OUzw0lsbpnTRWhHJK mYkn7oF/nRNJuXpHeUuWsZd6UahK1T5GgkF9xA/w= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 63CF2F80548; Thu, 2 Mar 2023 07:20:02 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id EA50FF80533; Thu, 2 Mar 2023 07:19:55 +0100 (CET) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2061a.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::61a]) (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 3AA8EF8052D for ; Thu, 2 Mar 2023 07:19:49 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3AA8EF8052D 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=5W10JQOJ ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bhnKNFhMEyxjtAIM9d+8xkZ0bQhbQgibUDFwA4+pZaUavjwWCVPN1sDxKTe7NUbsLcUSDQYsKUdEhC6UVq/2gEnDjhXeKoibJzWY9pX1+1U0rZz7hsgKIrGA5A2d+tH8bMGOwGF5HSbs+0l76WfvmOsvkgiAuuvAt/m3qX0YDUjoplEzUuQsmaAa91XLMBftly7nzT80XXaSwpdisXJ+1I3xY36d+7EuUR1Hlkjk9xCD1GktbXrt63AE5uVE6NS8g/P20haURRDtTEKcVopLqctXMLYV6hl8P1xFrHOT99eV3FDNW8UxPiCsfZMbocw58w+2GROiZHuiMIcPCOV71Q== 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=pBhSefZ9CFdJnp7doS7vXDfQd9A3+KRh+03dcoZ/QjM=; b=Gnxp50oeO2B6XUZMpSQ1UOqgi7oEhwjqginchcDyQwqqJA6INSe6vpadAASHAmko6LrDhuNA2eyfSIIOb39QqQTCiHlSk7G8Doc83F++9ZfqFV6sjptE0pgqaQqK8Ys9HXy/6wXk3gQCziEKxSV2ZGBFMTdgUQ4f0sG1HrAWBwJm9SpOy/6pHhr+gd89I5V5BcUitEjC3dzK8NU/N1hjexDS1ahc5ABPEDgI1k2UmLDOiSxv+WrSDcTJkXow6rnV9hTKwzZtyEa8ga6WpMH42L0IxNN386ogiM5RNha454XNdaim64xhxXlSVpqZs0k4l1lQFs1tSG6f/sRYO59NWg== 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=pBhSefZ9CFdJnp7doS7vXDfQd9A3+KRh+03dcoZ/QjM=; b=5W10JQOJvN+oJTQWKNOcdXtHb3yo7JzE9AVWwBszUdO2Y5odAjGpRdxPQso5Stvomu22EAeqg1U3JbNpK9dG/4Ngs4JX/+zroemzQ+tIiZXzluQTXh0AvqCucOBhFcdCfXMsPH7N/YypXvixlGzw8xn/Aq82J55EVgmAOAT+lXc= Received: from DM6PR06CA0055.namprd06.prod.outlook.com (2603:10b6:5:54::32) by DM4PR12MB6277.namprd12.prod.outlook.com (2603:10b6:8:a5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Thu, 2 Mar 2023 06:19:44 +0000 Received: from DS1PEPF0000E651.namprd02.prod.outlook.com (2603:10b6:5:54:cafe::8c) by DM6PR06CA0055.outlook.office365.com (2603:10b6:5:54::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.19 via Frontend Transport; Thu, 2 Mar 2023 06:19:44 +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=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by DS1PEPF0000E651.mail.protection.outlook.com (10.167.18.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6156.12 via Frontend Transport; Thu, 2 Mar 2023 06:19:44 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 2 Mar 2023 00:19:43 -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; Thu, 2 Mar 2023 00:19:39 -0600 From: Vijendar Mukunda To: Subject: [PATCH V5 8/8] soundwire: amd: add pm_prepare callback and pm ops support Date: Thu, 2 Mar 2023 11:51:07 +0530 Message-ID: <20230302062107.207845-9-Vijendar.Mukunda@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230302062107.207845-1-Vijendar.Mukunda@amd.com> References: <20230302062107.207845-1-Vijendar.Mukunda@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E651:EE_|DM4PR12MB6277:EE_ X-MS-Office365-Filtering-Correlation-Id: f3fa4981-d870-47b0-573d-08db1ae61d6f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7r8v4sEsr12E+mU0EEXgVSS0yrQVr0m5HyLcuay5QhafXXRkyo/75FDPzApJL5v++t4j5pWW3sc7BiTbdDOUwqT9NUOWEmFFyUBjC0WBH0p2gmNDACNIWGIJfnn4ZUTCy0HhJCDZmTmWWmp1y6kzV6HvZljhNamWCq7sjCU8g18KV1MuZtYV6wZLa8rBTPC603cRVt1owcVJ+OFJxOvoPwOrPMwVx7R+sIRPKRRE2NjHp7Gmbzz512IUYb+xRT89FjGe/CN/mdrxlngiU0CVHhyUwNKCNETjh9yGSe0SNrBXYbonvx46jabUvvOpppOmHeM9VzjVb/yDvEW7kOvCwosfskiCvrQ5RyP9DPoXdE/W3emNJ0QRcIFUfNQ9nmVWvXLrhZ6A74XQA06pxwVJ+pvrv9rTZPLp8rfWcZa053CtLr/aJgY9N9Z/Ug2koLMFJVj7SGYxUhrTsEbFZKUs87dSXN9l/ybUgK8vzJT4841B9CSWKTyGWSr5Z7kqoXX4dF3EQSMHZoPeCf0d2NyEH6k3PpqLYkHYtcDzBnpgQ3k9q7pZ5Qul5QgnIjTEtw+fFCqPxGWKW/mGtlWi0i4C6t75ekjO+orIiEASTtYoHktIw/Jbrfql92uJ7j/H3B/VHaslP0S4nqyZu23kg1TVeX0rwj/5UKrqudpfwCX6DQbXkiwl9tjr6SIj6OjtbXfyGiFn/gkWGI4ZsfhcCWrrMB/wcWXtar/gdxZoTwr/ssQ= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(136003)(39860400002)(376002)(396003)(346002)(451199018)(46966006)(36840700001)(40470700004)(7696005)(36756003)(356005)(86362001)(41300700001)(8936002)(40480700001)(8676002)(6916009)(5660300002)(4326008)(70206006)(82740400003)(36860700001)(81166007)(6666004)(316002)(54906003)(478600001)(70586007)(47076005)(82310400005)(2906002)(83380400001)(426003)(186003)(336012)(1076003)(26005)(2616005)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2023 06:19:44.0912 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3fa4981-d870-47b0-573d-08db1ae61d6f 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0000E651.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6277 Message-ID-Hash: K7G63NCPQOB54ZP4L2RNCU7H5GC3BOFO X-Message-ID-Hash: K7G63NCPQOB54ZP4L2RNCU7H5GC3BOFO 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: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, Basavaraj.Hiregoudar@amd.com, Sunil-kumar.Dommati@amd.com, Mario.Limonciello@amd.com, amadeuszx.slawinski@linux.intel.com, Mastan.Katragadda@amd.com, Arungopal.kondaveeti@amd.com, Vijendar Mukunda , Bard Liao , Sanyog Kale , 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 | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c index 1caad2ccdd20..f7e68702ee7a 100644 --- a/drivers/soundwire/amd_manager.c +++ b/drivers/soundwire/amd_manager.c @@ -1148,6 +1148,89 @@ 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) +{ + struct sdw_slave *slave = dev_to_sdw_dev(dev); + int ret; + + 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, "pm_request_resume failed: %d\n", 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 (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, "amd_resume_child_device failed: %d\n", 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) { + return amd_sdw_clock_stop(amd_manager); + } 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; + return amd_deinit_sdw_manager(amd_manager); + } + return 0; +} + static int __maybe_unused amd_suspend_runtime(struct device *dev) { struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev); @@ -1220,6 +1303,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) };