From patchwork Tue Mar 21 05:09:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mukunda,Vijendar" X-Patchwork-Id: 72686 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1593732wrt; Mon, 20 Mar 2023 22:14:33 -0700 (PDT) X-Google-Smtp-Source: AK7set8Wtb3aIs/TG5EHB9v2ILQyo8EFFiML0u5Q8U83RsC8nOAih4eQegDkjEkyBTB0wFc/b+iY X-Received: by 2002:a17:903:6c3:b0:1a1:c2cb:f44e with SMTP id kj3-20020a17090306c300b001a1c2cbf44emr826302plb.53.1679375673634; Mon, 20 Mar 2023 22:14:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679375673; cv=pass; d=google.com; s=arc-20160816; b=jalx9J8hhq5H3zQgrhkYhr+CU1po4QYsaTO2cj8I2E3gymmUxFOo6bMArbYvZ10aU4 dtepSDI9xIOJDsg29sQFmrWhw2txBEO0sO9qqtGJlnqS+98iJCaF6ek1LaClpRI/zXZm yfyU0kF6FM3VlCyU55iZn4RMH7dIJYzmXL1pFlJwYw7JRqocdP1bDL2szY8gBTdgn+PH Vr+KPzyUTWzRAICgLw+TxRvYYj4pjZBlLMK6kiW6wrO1Qyskn138RTUz5qbFzqQBPo7H QUbPBTZwHA4nvnk1pL26plQtjKqMOcfmdkaY3TjSWeYTZH3ZsdLb9NXQkgScZaLaMfb1 U8VA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/vtmCyG1DR9qTV7kxTkz6C+OXVQcLCxmWyWvVNCTc2Y=; b=igyE3AJzMijRzB9BOOb4UZYYBdNn1yCBVRKFhezqH7SkkLLBV0T9SVitiffOmmEe1o lEJN10x5kijSECMCmdcXfaXvb0ZbDCiMzmSm5U4kY29uHtpiBMLJKM6xH/valCVJQrhu C11DBHjmjG2lfI1K1U9c7Qle5wzkb1xldDNacz91KpfLEGr4f5k+UR34BCzVsJRMnaPi VCFSxRZ4O1ybi5sFRlxMfB6VMpIAUR84XgU7RdaRmXAyh2bW4RkAHYJy4BeGrLRKjy+9 Ljt1itLIgKq/uvh2DKwQIiMp4YcOjfryOYR+cMfw63aobUUhobdkZevNUFHGGgBAzrkT JvVQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=tmrr+BWE; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020a170902700900b001a1809e22d6si11381111plk.130.2023.03.20.22.14.17; Mon, 20 Mar 2023 22:14:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=tmrr+BWE; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229924AbjCUFHP (ORCPT + 99 others); Tue, 21 Mar 2023 01:07:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230025AbjCUFGr (ORCPT ); Tue, 21 Mar 2023 01:06:47 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2040.outbound.protection.outlook.com [40.107.101.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9BBB26869 for ; Mon, 20 Mar 2023 22:06:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h8ykGX9ynoQd7K06A2IUWqJ43bycX/Xfo3OxktTdXXpe8DACAXUQfGzPMjcBOKZF33TH9aH1RI2HTOg1VE4H2ER6Txec/L1562Pks81DFWCc82dUjZrFpurYaKKZ5V//G2Y3wjoFGDFT3rUhPYqKF9VlMUuHi1jLwberp8uoqj17xy8yguGYM2Mlzb8TXy1leWRZQFRG2Uo+OBLYjpHvECmjJVEGMv7bHBcXoFo4VaL8rdbKEezfK4mV7po2o6dKn/XzdD/TNwBNmTo6o9gjhhFSHXo+/gJ9V7WHREm+L4r7STKKEvPm9cpjxBn3dDxTS56j8nduuwGZgMGXzBYWKw== 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=/vtmCyG1DR9qTV7kxTkz6C+OXVQcLCxmWyWvVNCTc2Y=; b=hK0F08xupu58hNgYSlrg5Yoo22f/zm3ahcVvBbuEsKOxBl+ciBv5hIdtiyAzTJVqjYudFY9kh01oZPf/3IRwFAeBJvl+i3+HGwolsYm0CQi1yU3lqz+8tSo1EOGMJvmx/RiSMmey59NqNUAovzKS2x8we5KqKLixSNN7f1lO0OZCsWP8V2yochFVcRf63KC00AS9C+OQHtqFH/2aYzX1u8CQN5VjTCXRqSG43UOLFHtwG2pz31nAOotrEVHR+pTiXpgsG9qMVGxaxQtFIHh3yCCHAekj7jxwLOG4RD/DnPlCMZT9x1/nQMPMgChLaCNHa83vbC8bhQAADHn8TWtsLQ== 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=/vtmCyG1DR9qTV7kxTkz6C+OXVQcLCxmWyWvVNCTc2Y=; b=tmrr+BWENcADrewCIbn3cPM7LgcSdLMbbB3+yGYroYAQDvv6JdLOwr+zc4kxoJNcPKI2a3B0UBkdi9ahGxXUjxZpcwLWWbOp9cmd+adpcUXTHU5LShtqzcGxISfP1kFoIGD20HqZJe+2ZolKFo8yq6UUSY+xEzVjgETHGfl6G9U= Received: from BN8PR12CA0005.namprd12.prod.outlook.com (2603:10b6:408:60::18) by DM4PR12MB5328.namprd12.prod.outlook.com (2603:10b6:5:39f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 21 Mar 2023 05:06:01 +0000 Received: from BL02EPF00010209.namprd05.prod.outlook.com (2603:10b6:408:60:cafe::2c) by BN8PR12CA0005.outlook.office365.com (2603:10b6:408:60::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Tue, 21 Mar 2023 05:06:01 +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 BL02EPF00010209.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.30 via Frontend Transport; Tue, 21 Mar 2023 05:06:01 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) 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; Tue, 21 Mar 2023 00:06:00 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 20 Mar 2023 22:06:00 -0700 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; Tue, 21 Mar 2023 00:05:56 -0500 From: Vijendar Mukunda To: CC: , , , , , , , , , , "Vijendar Mukunda" , Bard Liao , Sanyog Kale , open list Subject: [PATCH V8 8/8] soundwire: amd: add pm_prepare callback and pm ops support Date: Tue, 21 Mar 2023 10:39:01 +0530 Message-ID: <20230321050901.115439-9-Vijendar.Mukunda@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230321050901.115439-1-Vijendar.Mukunda@amd.com> References: <20230321050901.115439-1-Vijendar.Mukunda@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00010209:EE_|DM4PR12MB5328:EE_ X-MS-Office365-Filtering-Correlation-Id: ad8021f5-3788-4845-3e31-08db29c9f710 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Mup2Dpc+q4OypZHk1u1GUKooM/r/u+jceQIg+CIiIBk1bS3bnqg2noZd74mn1hb0AxEiz7v9TrJ3nQN0N8GjJVbZVYyeBn/zs+YvKD3iSlaGISfX63oxwrIQGsRseI4Z+UOjW2XI4K8k6eM9nzId5MCpVYSRBliFSmCSeIXxS0cTBdOncw5kiWDjQjacvlaL9E557YtP72BzWW61H75cb0h0oZnSlHSCFJP5MxWNyLqFWoWq/zoKb/X7biYY/KnaybGt5ZPkc/sHB6lrX06Zp4RyT7n8mufDmOnBgqXl7H53U/Vr7+2ZtGjE2KsXpztydqlComUpblcHfgAL/1Y+DQdEm5Tsb1gJ3cRiMcG6kVcW+w8ISzroIRR8fWevoqzuiW9eul3ZEcz1xGmhlNmfeVkTTj4yt1BPx/EYSzIR+L0wb5gkopLvrczhC2IO0bnWit1axc3e2Qha7yOPUxbXPtlL2p99pde3uielUdAyTeuaVFuj/tyRSSiJdNEncMkb/om5olFv08V9SneankMdT/JbouxrOK3hTI14ujUBHg+sWfoPdZcRR8gWMWzZb+S8pYUQ9LilwQbQvcvTOAWcB/QR57CtzixO7bnznImnvv1qDAzkLvg1SHNpObtJrxQAY4FaSewVmbYEZguimypAZGgkaHfPqb/qxkx0uoPKOtW3qahlGwK7rjqVSXb1Tbswy/kxugxb1ZHyUePgHtei4nDyeoCyQ6o8Ld7QR3uZi+E= 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)(376002)(136003)(396003)(39860400002)(346002)(451199018)(40470700004)(46966006)(36840700001)(336012)(2616005)(47076005)(83380400001)(82310400005)(426003)(7696005)(316002)(478600001)(966005)(54906003)(6666004)(26005)(186003)(1076003)(81166007)(36860700001)(82740400003)(6916009)(356005)(40460700003)(86362001)(2906002)(5660300002)(70206006)(8936002)(70586007)(40480700001)(4326008)(36756003)(41300700001)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2023 05:06:01.2790 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ad8021f5-3788-4845-3e31-08db29c9f710 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: BL02EPF00010209.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5328 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760953026137879948?= X-GMAIL-MSGID: =?utf-8?q?1760953026137879948?= 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 Reviewed-by: Pierre-Louis Bossart Link: https://lore.kernel.org/lkml/20230310162554.699766-9-Vijendar.Mukunda@amd.com --- drivers/soundwire/amd_manager.c | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c index d55706e87d83..9fb7f91ca182 100644 --- a/drivers/soundwire/amd_manager.c +++ b/drivers/soundwire/amd_manager.c @@ -1043,6 +1043,88 @@ 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; + } + ret = pm_request_resume(dev); + if (ret < 0) { + dev_err(dev, "pm_request_resume failed: %d\n", ret); + return ret; + } + return 0; +} + +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); @@ -1105,6 +1187,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) };