From patchwork Thu Mar 10 11:41:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sameer Pujar X-Patchwork-Id: 550526 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 7720CC433F5 for ; Thu, 10 Mar 2022 11:44:00 +0000 (UTC) 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 842DC18F5; Thu, 10 Mar 2022 12:43:08 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 842DC18F5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1646912638; bh=EKvI70GL7OjZ6Z7lqjhaQpRaHmBGTI++yaskeBpFqTs=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=asg50g86EFRyDJ1Cx12Y+ZdhJNNq8d2C1dUpyGgwBgaLb2yE32MtKK/X9Ln+Y7IdW zjy3GWW240WC/Ch8H2B9Fc+yJ2wHCop+AoB2e2x9Tbki6FCUsPZE4ecH518NXecfb6 i728tp/lLaAuPvFhxgGiwRq4P7+YCZBV11CwYn4c= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id BC520F8016C; Thu, 10 Mar 2022 12:42:43 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id AFBB3F8027B; Thu, 10 Mar 2022 12:42:42 +0100 (CET) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2061b.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8a::61b]) (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 762F3F8012C for ; Thu, 10 Mar 2022 12:42:36 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 762F3F8012C Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="dfhsU6lA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nPqZmlPEv5F/KId/w9cZcOM43WTXpONad+/FVmus+9QkYgTVuiyCvBw/xcQ9+rwOYYeWYZU/7BLy/k7p7jglUKhEIRPBcBgMQlqyI/42nnruEYnT4W5kztFj9eWhCvlmWwpG1LqgR0J/t8Nh2CIp3l/NK8OH8OakREYDA1KH5lPsLPlRukwbgFJF4wUx+d9szIInkKLHLiUFFGwJeq4ftpurf72UwTpLjK2XJ8PYwZyNy1zB1jiegR+HfUFLaXLm4hF17u+MS2iFXb/amVrOfWL/2JEyHx07XbSdJCeJ3QCH6bJgHGkwfxUjA/bN+E+GTvraDC/znHzKB7aWlkCC6g== 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=9zik1vcpPSiC0eIrz6I1m4gA+hH+Pf27ZiFHQdb820M=; b=l9p1kyeF++vJ132Am1aTAGK771qWmjZnJMl0wmdah8ROF3BW9K3eGCydU8LYxo/PvZrB2M3gFJ3uzREu1mJBWOW5b5oJnT3k+WHwdwKV7PMj++2JflbWQKKqZjvpJVNfw+fegCzUYdg9bwbyXs7as/F3kuI28CXxxKta/DkywzMr6ZUPvYEYR19owlC+wN30G2B3mY2ffFTB/m/tcm8mmOPXy9qIVIdq2cGP+ycy98FgTDMZz+CjNxfzpr2k0k6UdYogvI8ITH8BRxCC7jtnriIsMAQg1KzkoVYEXxlPrFN1FkQ24nDyvJUNxBiazGMKwwiNIT8EKNK8NqKVjmVX3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=gmail.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9zik1vcpPSiC0eIrz6I1m4gA+hH+Pf27ZiFHQdb820M=; b=dfhsU6lAK8kaoi92rrdcVX2muVWZwJZInbfW27BTI+oPVu2PzauG67A/j7LcA1p+ZQWKojHjq+owjJV8Q6YLZZsyRZk9JBltAQkLIu+zz+zN/tMF+XiKldB5DCCUbeMwbDJzMhX4VRaDPgzQa4w5TlHZI9wi9ze1faSSb5OQkRSMxu/N1HwhDitc0tVc4JJs4+/ias0/fPKMiGlZeogYTNpwLvRK3buEP2tF8r2J3eoVzb1tT0O8CM3eLKo/PKOkHbwTTaZdgOEFixnxyrxBFqoyzLU3fSIFtmIvI38+eNYuTF36qdMazp1N8SaFiU9Uu4QXqTYPGhWPWBMJssM6IQ== Received: from DM6PR14CA0066.namprd14.prod.outlook.com (2603:10b6:5:18f::43) by BYAPR12MB2805.namprd12.prod.outlook.com (2603:10b6:a03:72::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.16; Thu, 10 Mar 2022 11:42:30 +0000 Received: from DM6NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:5:18f:cafe::cc) by DM6PR14CA0066.outlook.office365.com (2603:10b6:5:18f::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 11:42:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.234) by DM6NAM11FT015.mail.protection.outlook.com (10.13.172.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5038.14 via Frontend Transport; Thu, 10 Mar 2022 11:42:30 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 10 Mar 2022 11:42:29 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 10 Mar 2022 03:42:28 -0800 Received: from audio.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Thu, 10 Mar 2022 03:42:25 -0800 From: Sameer Pujar To: , , , , , Subject: [RFC PATCH 1/3] ASoC: soc-pcm: tweak DPCM BE hw_param() call order Date: Thu, 10 Mar 2022 17:11:15 +0530 Message-ID: <1646912477-3160-2-git-send-email-spujar@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1646912477-3160-1-git-send-email-spujar@nvidia.com> References: <1646912477-3160-1-git-send-email-spujar@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fc13ccfa-1301-431d-0668-08da028b0f3c X-MS-TrafficTypeDiagnostic: BYAPR12MB2805:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: URjE8JbSPKK0Thxufv35D04/oWRF3/uQpFtYMyJMClFSCp66BPNWR1PS65uRl9xd199NY9nwB8u/AbqI32GSoCMe23ExzecObITll1953oCYhOWSHH9++QqB3qwq0Krn17/mmZG0XzsvkqUazLhSCLED3kJvazG+NIciHBO9NWEgCduBEVwT9YrWYS5nMivq1GB4MP6CbWBNca6BNVzRjtbD1m9Gco3oadotxkbBll+IARGZfh49CaaTRYQYc/k/W2tPTrYY2GVD+V3yGNl3omro1cSDX9EEgkmOpYz83hLIKuyWQci0seoloav8thZ/MvwdC7rt2srDhE0rFaFlrMCWeKP+ShJ3KIIRhqvpmSNk3+nMCHpYjkFqr6F0j7UBKjQP1GlLktiwk2eznzUXxrBhdINXqNQDN64DhTTz0xkf7JGkYGLSUAn4EK+Mj2Ge9zTRxPYAPng2Z73X8rfItH/qRqXlbGlLsGEAtLGIIWwgx/GM9SkvBkEnoaI96PbgtKWjfyiNHoXKp+72NsMgKSsjoUDs6zTff3N1IetOIJno4Zw5XJy5wKp/m3Qrjluyy+oW+sdogFpg2Wc8d5CA1txi9LrU6pRhAPCMlrlxfc6M2ujlyCkbwoNb6w6i9RH6wDFWEHa5IrWpwG0jygKzFtozRE/R7DR4jcN//ZZWE6qHwOtAZmI33uJvmKCiDBlWPV3xVLZeMm5lcGONr7WwrA== X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(47076005)(336012)(316002)(2616005)(40460700003)(186003)(70586007)(70206006)(83380400001)(54906003)(110136005)(36756003)(4326008)(36860700001)(86362001)(8676002)(107886003)(81166007)(356005)(426003)(5660300002)(82310400004)(26005)(7416002)(508600001)(8936002)(7696005)(6666004)(2906002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 11:42:30.4085 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc13ccfa-1301-431d-0668-08da028b0f3c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2805 Cc: alsa-devel@alsa-project.org, Sameer Pujar , linux-kernel@vger.kernel.org, jonathanh@nvidia.com, thierry.reding@gmail.com, linux-tegra@vger.kernel.org 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" For DPCM links, the order of hw_param() call depends on the sequence of BE connection to FE. It is possible that one BE link can provide clock to another BE link. In such cases consumer BE DAI, to get the rate set by provider BE DAI, can use the standard clock functions only if provider has already set the appropriate rate during its hw_param() stage. Presently the order is fixed and does not depend on the provider and consumer relationships. So the clock rates need to be known ahead of hw_param() stage. This patch tweaks the hw_param() order by connecting the provider BEs late to a FE. With this hw_param() calls for provider BEs happen first and then followed by consumer BEs. The consumers can use the standard clk_get_rate() function to get the rate of the clock they depend on. Signed-off-by: Sameer Pujar --- TODO: * The FE link is not considered in this. For Tegra it is fine to call hw_params() for FE at the end. But systems, which want to apply this tweak for FE as well, have to extend this tweak to FE. * Also only DPCM is considered here. If normal links require such tweak, it needs to be extended. sound/soc/soc-pcm.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 941410c..cfaff25 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1442,6 +1442,29 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream, return prune; } +static bool defer_dpcm_be_connect(struct snd_soc_pcm_runtime *rtd) +{ + struct snd_soc_dai *dai; + int i; + + if (!(rtd->dai_link->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK)) + return false; + + if ((rtd->dai_link->dai_fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) == + SND_SOC_DAIFMT_CBC_CFC) { + + for_each_rtd_cpu_dais(rtd, i, dai) { + + if (!snd_soc_dai_is_dummy(dai)) + return true; + } + } + + return false; +} + +#define MAX_CLK_PROVIDER_BE 10 + static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream, struct snd_soc_dapm_widget_list **list_) { @@ -1449,7 +1472,8 @@ static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream, struct snd_soc_dapm_widget_list *list = *list_; struct snd_soc_pcm_runtime *be; struct snd_soc_dapm_widget *widget; - int i, new = 0, err; + struct snd_soc_pcm_runtime *prov[MAX_CLK_PROVIDER_BE]; + int i, new = 0, err, count = 0; /* Create any new FE <--> BE connections */ for_each_dapm_widgets(list, i, widget) { @@ -1489,6 +1513,40 @@ static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream, (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE)) continue; + /* Connect clock provider BEs at the end */ + if (defer_dpcm_be_connect(be)) { + if (count >= MAX_CLK_PROVIDER_BE) { + dev_err(fe->dev, "ASoC: too many clock provider BEs\n"); + return -EINVAL; + } + + prov[count++] = be; + continue; + } + + /* newly connected FE and BE */ + err = dpcm_be_connect(fe, be, stream); + if (err < 0) { + dev_err(fe->dev, "ASoC: can't connect %s\n", + widget->name); + break; + } else if (err == 0) /* already connected */ + continue; + + /* new */ + dpcm_set_be_update_state(be, stream, SND_SOC_DPCM_UPDATE_BE); + new++; + } + + /* + * Now connect clock provider BEs. A late connection means, + * these BE links appear first in the list maintained by FE + * and hw_param() call for these happen first. + */ + for (i = 0; i < count; i++) { + + be = prov[i]; + /* newly connected FE and BE */ err = dpcm_be_connect(fe, be, stream); if (err < 0) { From patchwork Thu Mar 10 11:41:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sameer Pujar X-Patchwork-Id: 550147 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 033ADC433F5 for ; Thu, 10 Mar 2022 11:44:18 +0000 (UTC) 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 4C33B1901; Thu, 10 Mar 2022 12:43:26 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4C33B1901 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1646912656; bh=TaYDb3e7CSKXCqZeOTCSwUqAg8PxPcCTSHjXD0/4UFY=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=UAJd1K+/xxCr0RKFLWgT0J7cl2PfmhXDQBqIAdcxH7xH9mEjxektaNROEJaRu7jDK p8SKkUjqVGXxQ3enrtJXhW4Y8osqevsTPemIgoJbNJEl2oHcLcwdF4EezvK1W7VmlA jKwAO75ZOA26Tdlw/ummuuAAebJyY/qU04UeyjHs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 49080F80515; Thu, 10 Mar 2022 12:42:47 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 6F938F80516; Thu, 10 Mar 2022 12:42:46 +0100 (CET) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20623.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe5a::623]) (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 56851F8013C for ; Thu, 10 Mar 2022 12:42:39 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 56851F8013C Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="dfSGgJVU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WQdcyVYTlxdfJ4sA6pMPGjvmfb9TDuYl63wSd3xxVrNnnmUiXVVBjtPC12HVCaRFJIIcPs2pkjYUFk1ZQOGh5fXHrkwgLrF3D4+55vBFDmclgPF3NUgaNLRMFU5AP4BLqQPNVwKXqdOpCUoiGvtMMN1sA/9nhcMdalwQNq1icpoZBmdFWX/ph1c0LcS4EY8cdmnP5AFRfK1LG1lmnDs3v94Op7ogr0TaOO6qX9bN0Rau0mOeYBJJZ9bd0DOvQnB1E930wUswWZ4mZfaZVzbFFftb0i0Vadd8vDHptEZh+qCR53iMDUPAX0vPS5JJEsbJPFvHoh+c/nwZbQcDU/d5qQ== 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=7EfmLz9yqAXn3QVIeDHD+bBctdGz/PxJ/ZC0ONwsD4c=; b=HD6n+oEANBZCS5cJoS0akjvrf0Q6cfWP8/FcAcdFP8BjV1xIETc39X7KGL/SKSlhQnem+fFLIWY7N9aMWHKm7t/cHGB+Qc+bW9WYN9J3+BZpPHuo5yOSxMX2jOlbUVs6OOwRob68N1Bs+7RlABDgmc7V11dTJnNClTyyUFwRQR3pHAFcnXuSXIzIXO+zZKTJV3yDbAe8w/YLPtroCufKxilA0CEcXrBB2Ugn8oAzPtIPARGNQhiWWdrs4uu9n9dXF9zeaOTZAFW7xJK4QkzMxm5lekL1P1oe6KFfxZtn+SURZ5mLFEtBk4F33maBk35KBc15Yn0uhqcgbPuPN379Hw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=gmail.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7EfmLz9yqAXn3QVIeDHD+bBctdGz/PxJ/ZC0ONwsD4c=; b=dfSGgJVUMRIS6gF7NwDokuGCUm4UtBU4CDNSZBa46o94Q7BgXzNHP5j/b3Tu1peSTbtz2MhA0/T+FHEescKIa4bv1ROAEgEhwxFCwL6lhUw4ziL09tuWnm/6PGyaueEqs9Uh7HaGd8v60GMaFv4gcSMukf5c5Zg1Cgn/wPDioJXmI/oN5ym9PF0/xVIMf8WkYuM1xmLJPGvJjFv5urZ1mrXHDf4+bxDyaBrsQ4our6v2H66zCuoeVIwHh+dT5XUtLoGTbV/OCtFG2mYxFyNNKfcMZ0ItOwWDNNoOS2aILSe/CZ3iA8OpP1m2ihebMr2hnlN/1ZgfCrxtRPFo/eSqlQ== Received: from DM6PR13CA0042.namprd13.prod.outlook.com (2603:10b6:5:134::19) by BYAPR12MB3607.namprd12.prod.outlook.com (2603:10b6:a03:dd::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Thu, 10 Mar 2022 11:42:34 +0000 Received: from DM6NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:5:134:cafe::8b) by DM6PR13CA0042.outlook.office365.com (2603:10b6:5:134::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.7 via Frontend Transport; Thu, 10 Mar 2022 11:42:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT046.mail.protection.outlook.com (10.13.172.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 11:42:34 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 10 Mar 2022 11:42:33 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 10 Mar 2022 03:42:31 -0800 Received: from audio.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Thu, 10 Mar 2022 03:42:28 -0800 From: Sameer Pujar To: , , , , , Subject: [RFC PATCH 2/3] ASoC: rt5659: Expose internal clock relationships Date: Thu, 10 Mar 2022 17:11:16 +0530 Message-ID: <1646912477-3160-3-git-send-email-spujar@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1646912477-3160-1-git-send-email-spujar@nvidia.com> References: <1646912477-3160-1-git-send-email-spujar@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 978d91fd-98cd-41f7-d357-08da028b1195 X-MS-TrafficTypeDiagnostic: BYAPR12MB3607:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cr8Zw/Ad7lxLk1b59Fpxo+uB2YyaXn85wzLtMZg0qJ6ZZQyCG7g4OwW4nQlKC+57+e0KMSCkrOvxhD1bZMSnrNaguw299Tw5GJljm11X7Ts6sSH6mhVrUgj8OvpQBn/JYNRxyKtCXNwpzhZaCEoofwGCRS9qA6mRVxmNDDblwJSB3F6aWkialHBv47HT8RGDeeGpLVqYZIzCMdOHo2v7JK5wLC10u+Y/Wp1Tr/kGr3Oh8mkj+3CMh2vBN9Ta3QvEujx2SvVC3VyyaV7rXmV0f/QYZ0vTZdwrv++q/LtJg3WfuAfHPFIyrQTZNajUw0eBt7ETmgRkjaCoaHo6Omp8fQQCFVvl1SBOm0f5Pa2eBwR/76tJddzsmR/GFMWkBGqDKaRokARp+KWiHUOt1obdae4dbsvaCvB/FJs3c2Mi/hivs5F+71R3ocJE3aNMEmRPozLsSeXrz813Tp9sM8nDHGASSW2R35fOxMqlekQ0BDmY9w+uRXkkIYS4z8dn5NprkJZTPu++ehJ8nbMtiLMuXKqkrHa6WLa3mP704KbnB+DkI3ehMBNcxoaGQmzGO/gO6xnPsPS5w9ji1c8FmslbZN/uXbrxZXQM8jCinqapqDEJ/SLmwDspj4SXNYp/QfqnfJ3H94D00IEYkjglc8uLduzfOsodFxpMyT4DRnT9aVTEpvI5dMZooc4H1mCjByRx/CAgsRa7t6EM+a77M+aJ+gIXjRg8cBmQT/W/Q07l8bMYkcepDYl+aZuQZ6Opkh5gVjrhkm9Ip2v/LZX6L6nwEWwMkR9uvzLV32nCuGWaYhc= X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(7416002)(336012)(356005)(966005)(83380400001)(7696005)(26005)(40460700003)(2616005)(316002)(82310400004)(6666004)(5660300002)(8676002)(2906002)(81166007)(426003)(8936002)(508600001)(30864003)(70586007)(70206006)(186003)(36860700001)(47076005)(107886003)(54906003)(36756003)(4326008)(110136005)(86362001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 11:42:34.3369 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 978d91fd-98cd-41f7-d357-08da028b1195 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3607 Cc: alsa-devel@alsa-project.org, Sameer Pujar , linux-kernel@vger.kernel.org, jonathanh@nvidia.com, thierry.reding@gmail.com, linux-tegra@vger.kernel.org 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" The RT5658 or RT5659 codecs have multiple options to derive Sysclk: * Sysclk sourced from MCLK clock supplied by SoC * Sysclk sourced from codec internal PLL. The PLL again can take reference from I2S BCLKs and MCLK. * Sysclk sourced from RCCLK. The clock relationship for codec is as following: |\ | \ |\ BCLK1 ---->| \ RCCLK | \ | \ |----------->| \ BCLK2 ---->| M \ ____________ | \ | U | | | PLL output | M \ BCLK3 ---->| X |----->| Codec PLL |---------------->| U | | | |____________| | X |----> Sysclk BCLK4 ---->| / |----->| | | / | | / MCLK ---->| / | | / | |/ | | / | MCLK | |/ |_______________________________________| Presently 'snd_soc_component_driver' and 'snd_soc_dai_driver' expose callbacks, set_sysclk() for Sysclk and set_pll() for PLL configurations, which are implemented on codec driver side. The generic machine drivers (simple-card or audio-graph-card) depend on default values for Sysclk source or PLL reference. Specific clock relationships are not supported. The simpler solution would be to expose new DT binding properties to convey the PLL and Sysclk source. This attempt was made before with [0], but was not encouraged because it tries to do the same thing what standard clock bindings already provide This patch uses standard clock bindings to establish the codec clock relationships. Specific configurations can be applied by DT bindings from codec device node. The codec driver registers PLL and MUX clocks to provide this flexibility. [0] https://patchwork.kernel.org/project/alsa-devel/list/?series=438531&archive=both&state=* Signed-off-by: Sameer Pujar Cc: Oder Chiou --- Note: If such model is OK, other codec drivers will require similar handling. Objective is to drive clock relationships from DT using standard clock bindings. With this machine driver need not know the details for configuring codec PLL or other clocks and thus can be more generic. sound/soc/codecs/rt5659.c | 257 ++++++++++++++++++++++++++++++++++++++++++++-- sound/soc/codecs/rt5659.h | 9 ++ 2 files changed, 257 insertions(+), 9 deletions(-) diff --git a/sound/soc/codecs/rt5659.c b/sound/soc/codecs/rt5659.c index 29e0055..d1b01ff 100644 --- a/sound/soc/codecs/rt5659.c +++ b/sound/soc/codecs/rt5659.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -18,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -3273,18 +3276,25 @@ static const struct snd_soc_dapm_route rt5659_dapm_routes[] = { { "SPDIF", NULL, "SPDIF Mux" }, }; +static int rt5659_setup_clk(struct snd_soc_dai *dai, + struct snd_pcm_hw_params *params); + static int rt5659_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { struct snd_soc_component *component = dai->component; struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); unsigned int val_len = 0, val_clk, mask_clk; - int pre_div, frame_size; + int pre_div, frame_size, ret; pr_err("deBUG: %s and %d, rate = %d, channels = %d\n", __func__, __LINE__, params_rate(params), params_channels(params)); + ret = rt5659_setup_clk(dai, params); + if (ret < 0) + return ret; + rt5659->lrck[dai->id] = params_rate(params); pre_div = rl6231_get_clk_info(rt5659->sysclk, rt5659->lrck[dai->id]); if (pre_div < 0) { @@ -3533,6 +3543,9 @@ static int rt5659_set_component_pll(struct snd_soc_component *component, int pll rt5659->pll_out = freq_out; rt5659->pll_src = source; + dev_dbg(component->dev, "pll_in = %u Hz, pll_out = %u Hz, pll_src = %d\n", + freq_in, freq_out, source); + return 0; } @@ -3849,6 +3862,237 @@ static int rt5659_parse_dt(struct rt5659_priv *rt5659, struct device *dev) return 0; } +static unsigned long rt5659_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) +{ + struct rt5659_priv *rt5659 = + container_of(hw, struct rt5659_priv, clk_pll_out); + + return rt5659->pll_out; +} + +static long rt5659_pll_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *parent_rate) +{ + return rate; +} + +static int rt5659_pll_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct rt5659_priv *rt5659 = + container_of(hw, struct rt5659_priv, clk_pll_out); + + rt5659->pll_out = rate; + + return 0; +} + +static const struct clk_ops rt5659_pll_out_ops = { + .recalc_rate = &rt5659_pll_recalc_rate, + .round_rate = &rt5659_pll_round_rate, + .set_rate = &rt5659_pll_set_rate, +}; + +static int rt5659_setup_clk(struct snd_soc_dai *dai, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_component *component = dai->component; + struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component); + int ret, sysclk_src; + + /* + * Update the clock rate if Codec is driving it. The consumers + * can use clk_get_rate() function to get the rate. + */ + if (rt5659->master[dai->id] && rt5659->clk_bclk[dai->id]) { + unsigned int bclk_rate = params_rate(params) * + params_width(params) * + params_channels(params); + + clk_set_rate(rt5659->clk_bclk[dai->id], bclk_rate); + } + + if (rt5659->clk_sysclk_src) { + sysclk_src = clk_hw_get_parent_index(rt5659->clk_sysclk_src); + + ret = rt5659_set_component_sysclk(component, sysclk_src, 0, + rt5659->sysclk, 0); + if (ret) + return ret; + } + + if (rt5659->clk_pll_src && (sysclk_src == RT5659_SCLK_S_PLL1)) { + unsigned int pll_src = + clk_hw_get_parent_index(rt5659->clk_pll_src); + unsigned int freq_in = clk_get_rate(rt5659->clk_pll_src->clk); + + ret = rt5659_set_component_pll(component, 0, pll_src, + freq_in, rt5659->sysclk); + if (ret) + return ret; + } + + return 0; +} + +static int rt5659_register_clks(struct device *dev, struct rt5659_priv *rt5659) +{ + const struct clk_hw *sysclk_clk_hw[RT5659_NUM_SCLK_SRC_CLKS] = { NULL }; + const char *pnames_sysclk[RT5659_NUM_SCLK_SRC_CLKS] = { NULL }; + const char *pnames_pll[RT5659_NUM_PLL1_SRC_CLKS] = { NULL }; + struct clk_init_data init = { }; + static void __iomem *clk_base; + const char *clk_name; + int ret, i, count_pll_src = 0, count_sysclk_src = 0; + + /* Check if MCLK provided */ + rt5659->mclk = devm_clk_get(dev, "mclk"); + if (IS_ERR(rt5659->mclk)) { + if (PTR_ERR(rt5659->mclk) != -ENOENT) + return PTR_ERR(rt5659->mclk); + /* Otherwise mark the mclk pointer to NULL */ + rt5659->mclk = NULL; + } + + if (!of_find_property(dev->of_node, "#clock-cells", NULL)) + return 0; + + /* Get PLL source */ + rt5659->pll_ref = devm_clk_get(dev, "pll_ref"); + if (IS_ERR(rt5659->pll_ref)) { + if (PTR_ERR(rt5659->pll_ref) != -ENOENT) + return PTR_ERR(rt5659->pll_ref); + + rt5659->pll_ref = NULL; + } + + /* Possible parents for PLL */ + if (rt5659->mclk) { + pnames_pll[count_pll_src] = __clk_get_name(rt5659->mclk); + count_pll_src++; + } + + for (i = 0; i < RT5659_AIFS; i++) { + char name[50]; + + memset(name, '\0', sizeof(name)); + snprintf(name, sizeof(name), "%s%d", "bclk", i + 1); + + rt5659->clk_bclk[i] = devm_clk_get(dev, name); + if (IS_ERR(rt5659->clk_bclk[i])) { + if (PTR_ERR(rt5659->clk_bclk[i]) != -ENOENT) + return PTR_ERR(rt5659->clk_bclk[i]); + + rt5659->clk_bclk[i] = NULL; + continue; + } + + pnames_pll[count_pll_src] = __clk_get_name(rt5659->clk_bclk[i]); + count_pll_src++; + } + + clk_base = devm_kzalloc(dev, sizeof(char) * 4, GFP_KERNEL); + + /* Register MUX for PLL source */ + rt5659->clk_pll_src = clk_hw_register_mux(dev, "rt5659_pll_ref", + pnames_pll, count_pll_src, + CLK_SET_RATE_PARENT, + clk_base, 0, 1, 0, NULL); + + ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, + rt5659->clk_pll_src); + if (ret) { + dev_err(dev, "failed to register clk hw\n"); + return ret; + } + + if (rt5659->pll_ref) { + ret = clk_set_parent(rt5659->clk_pll_src->clk, rt5659->pll_ref); + if (ret) { + dev_err(dev, "failaed to set parent for clk %s\n", + __clk_get_name(rt5659->clk_pll_src->clk)); + return ret; + } + } + + /* Register PLL out clock */ + if (of_property_read_string(dev->of_node, "clock-output-names", + (const char **) &clk_name)) + clk_name = "rt5659_pll_out"; + + init.name = clk_name; + init.ops = &rt5659_pll_out_ops; + init.flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_GATE; + init.parent_hws = (const struct clk_hw **) &rt5659->clk_pll_src; + init.num_parents = 1; + + rt5659->clk_pll_out.init = &init; + + ret = devm_clk_hw_register(dev, &rt5659->clk_pll_out); + if (ret) { + dev_err(dev, "failed to register PLL clock HW\n"); + return ret; + } + + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, + &rt5659->clk_pll_out); + if (ret) { + dev_err(dev, "failed to add PLL clock provider\n"); + return ret; + } + + /* Get sysclk source */ + rt5659->sysclk_ref = devm_clk_get(dev, "sysclk"); + if (IS_ERR(rt5659->sysclk_ref)) { + if (PTR_ERR(rt5659->sysclk_ref) != -ENOENT) + return PTR_ERR(rt5659->sysclk_ref); + + rt5659->sysclk_ref = NULL; + } + + /* Possible parents for Sysclk */ + if (rt5659->mclk) { + /* For sysclk */ + pnames_sysclk[count_sysclk_src] = __clk_get_name(rt5659->mclk); + sysclk_clk_hw[count_sysclk_src] = __clk_get_hw(rt5659->mclk); + count_sysclk_src++; + } + + if (rt5659->clk_pll_out.clk) { + pnames_sysclk[count_sysclk_src] = __clk_get_name(rt5659->clk_pll_out.clk); + sysclk_clk_hw[count_sysclk_src] = __clk_get_hw(rt5659->clk_pll_out.clk); + count_sysclk_src++; + } + + /* Register MUX for sysclk source */ + rt5659->clk_sysclk_src = __clk_hw_register_mux(dev, dev->of_node, + "rt5659_sysclk", + count_sysclk_src, + pnames_sysclk, + sysclk_clk_hw, NULL, + CLK_SET_RATE_PARENT, + clk_base, 0, 1, 0, + NULL, NULL); + + ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, + rt5659->clk_sysclk_src); + if (ret) { + dev_err(dev, "failed to register clk hw\n"); + return ret; + } + + if (rt5659->sysclk_ref) { + ret = clk_set_parent(rt5659->clk_sysclk_src->clk, rt5659->sysclk_ref); + if (ret) { + dev_err(dev, "failed to set parent for clk %s\n", + __clk_get_name(rt5659->clk_sysclk_src->clk)); + return ret; + } + } + + return 0; +} + static void rt5659_calibrate(struct rt5659_priv *rt5659) { int value, count; @@ -4148,14 +4392,9 @@ static int rt5659_i2c_probe(struct i2c_client *i2c, regmap_write(rt5659->regmap, RT5659_RESET, 0); - /* Check if MCLK provided */ - rt5659->mclk = devm_clk_get(&i2c->dev, "mclk"); - if (IS_ERR(rt5659->mclk)) { - if (PTR_ERR(rt5659->mclk) != -ENOENT) - return PTR_ERR(rt5659->mclk); - /* Otherwise mark the mclk pointer to NULL */ - rt5659->mclk = NULL; - } + ret = rt5659_register_clks(&i2c->dev, rt5659); + if (ret) + return ret; rt5659_calibrate(rt5659); diff --git a/sound/soc/codecs/rt5659.h b/sound/soc/codecs/rt5659.h index b49fd8b..d46d39f 100644 --- a/sound/soc/codecs/rt5659.h +++ b/sound/soc/codecs/rt5659.h @@ -1763,6 +1763,7 @@ enum { RT5659_SCLK_S_MCLK, RT5659_SCLK_S_PLL1, RT5659_SCLK_S_RCCLK, + RT5659_NUM_SCLK_SRC_CLKS, }; /* PLL1 Source */ @@ -1772,6 +1773,7 @@ enum { RT5659_PLL1_S_BCLK2, RT5659_PLL1_S_BCLK3, RT5659_PLL1_S_BCLK4, + RT5659_NUM_PLL1_SRC_CLKS, }; enum { @@ -1797,6 +1799,13 @@ struct rt5659_priv { struct gpio_desc *gpiod_reset; struct snd_soc_jack *hs_jack; struct delayed_work jack_detect_work; + + struct clk_hw *clk_sysclk_src; + struct clk_hw *clk_pll_src; + struct clk_hw clk_pll_out; + struct clk *clk_bclk[RT5659_AIFS]; + struct clk *sysclk_ref; + struct clk *pll_ref; struct clk *mclk; int sysclk; From patchwork Thu Mar 10 11:41:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sameer Pujar X-Patchwork-Id: 550525 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 C179AC433EF for ; Thu, 10 Mar 2022 11:44:37 +0000 (UTC) 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 186FB1908; Thu, 10 Mar 2022 12:43:46 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 186FB1908 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1646912676; bh=N1zDPVUZQcyTk/+aW4LuqQ0j9MVldmOlF/5V/QJPyac=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Ck4CP1bDm3JPdBNF5cztLuPHNnqtrx/URvgEF7o1jv+hlsDiXdtBuDxKXaTB6WiXS sNfjZrWZTrX4lJUgvCZUNKIJMjpMc4bfCkBUGufclyGn8npPANBTVyUiFMoaYmGM7I yWdcSyPdMKGfd/O3Jpqo+uS6OgbEHUcWH/+JNwvA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3BEDBF8051E; Thu, 10 Mar 2022 12:42:50 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 25085F8015B; Thu, 10 Mar 2022 12:42:49 +0100 (CET) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20619.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eaa::619]) (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 8293AF8015B for ; Thu, 10 Mar 2022 12:42:42 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8293AF8015B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="XKclA3Nr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k4eAAxhVrCoaLp3vGApvwX6WdoOr1+Jft1fy3qvPsDbhElB2ePnPjwyfuPzbpBahvD4PgseCI7p9H05n4lKnCEIkdEbZwkv1+sIW5JCRIZPJof8SposBuUwFQwi9eQJvxdHUKCG2g5IUslaJ3QhaIer9T/27TYik3mk6+AOvWAeGCgXsXqHVKdkBtM/PVUvO7ndDM1XXqJz5Jgyk4nsnUAECLnaP7WbQKXX7jWWkQ7BLmfBzL/CX8Hg2RCM5+0iKjxTlmgBhogGDSgfB0L7ZP9M9ee4YOzveJBx7AMtd+8o/2bnqTju15MHXElzthZ0+Hkxwp9K+1Lt4GtFf98N3uQ== 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=1puj/fXFRo0cMKqEDoys9zxAmynyKn93oWJh76oYvNc=; b=eCsve2QEJsGKv0XpbAjw4uXVVN7FZpT9Yg75TblIWkEOxViIIxaNZ+fWQKUzu4BfTjkeQt3sBajMmuLHkBqQjgKg6bQF7pGUhu4XB0lh9tEyRFYk/EqsyXYuYyew3u2Hp1syGztnFZP3nnM1NaA6laMIGJW9dOMIZ5IjtKZlau8iNiAW1hQY30rQw4SfNMKiampGZcjr+4Z2kfrxS5B9C471KQNaT1hDVjadXn9DcMbfF/qCA7jXJo6IK/T7fSQF6pXaG75rT2fhWFRGJKy4+ieQ0GmITs5aNP87XJfmNkpt/AhrbUoy8G0C6HeG8l9iPOCrYuMQ7mqEpgmcFVldTg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=gmail.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1puj/fXFRo0cMKqEDoys9zxAmynyKn93oWJh76oYvNc=; b=XKclA3Nrs8FfdlVF0JSnNxcoMl2r3e5xPgVE8gqmABThW6vtRhMCGUpvCR4s6kqt8w3RYND3E5sX8Or6Bsr4R0g9JJkehmn+pxBfUyAhqGbzHsMVH8ghtTsB4r2J8CPfkHdzxxJGBwANC3riC6Jw9zszFUozUQvp4GSQ6aZAgHGEwuBEnQng2VgWql4f51EBWVN60oS4UdQwccD/byERom7P1u18hg6VSwV22V0dlPnFPQRKr6i3RI7AuY1DA6EsN+tK8DBLsR+I3qBYS93K4eK8awEuQDR5XnE+jtJDiyiJbVojgPC8Kc2HWXilwGmshy/qKTKto5fXrWt0n0q2LA== Received: from BN6PR19CA0109.namprd19.prod.outlook.com (2603:10b6:404:a0::23) by BN6PR1201MB2513.namprd12.prod.outlook.com (2603:10b6:404:ae::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.26; Thu, 10 Mar 2022 11:42:38 +0000 Received: from BN8NAM11FT033.eop-nam11.prod.protection.outlook.com (2603:10b6:404:a0:cafe::81) by BN6PR19CA0109.outlook.office365.com (2603:10b6:404:a0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.23 via Frontend Transport; Thu, 10 Mar 2022 11:42:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by BN8NAM11FT033.mail.protection.outlook.com (10.13.177.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 11:42:37 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 10 Mar 2022 11:42:37 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 10 Mar 2022 03:42:35 -0800 Received: from audio.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Thu, 10 Mar 2022 03:42:32 -0800 From: Sameer Pujar To: , , , , , Subject: [RFC PATCH 3/3] ASoC: tegra: Get clock rate in consumer mode Date: Thu, 10 Mar 2022 17:11:17 +0530 Message-ID: <1646912477-3160-4-git-send-email-spujar@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1646912477-3160-1-git-send-email-spujar@nvidia.com> References: <1646912477-3160-1-git-send-email-spujar@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3893c7ce-3bb9-4c69-8140-08da028b13c1 X-MS-TrafficTypeDiagnostic: BN6PR1201MB2513:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IgQXAFOd2THqnzgRvxY1elb4hwVPDuEX5IlNtXQQFk5YLdjqT+5gQO20PHd40wG1/st2k6BpAcjzJJ8QiMmVySaIBEI+qOzg1sFdjkB1ACpS52Ht0OaUYOc/jYs+kAMJHQ6TWIb0uMZdTqH3Y8zOILRdpvF5YRuTP9xUWQHM1pxaYjowWBGe7a2OCsnvn0EbGeWOEN6gPvsgJY9OCtUytTF8sA8bd7+ai3Ap86Rys8HfLG1cJTnn9tPXK/EXLlgNQh1a34dSopwTSCq5sshASAditQ8m/7J49ls3dWuDdBoHUInEJECZ77FdnZ6w3w+9RnDqk0LVHNly7E1Otyl8Cbl3pjKNTKM7DKuG50EFHSL0hq475RoNsLbIi+rbU2LNWe5gbxTKIidEvVJIhuf1KJAvRTap/Uqq9qAdfxjcueMc8PDyogwY8Hlq78Ov2WBPcIG1OX3ibDIfuiVHGFSzvy8I9VVNza5st8OIkd2K5yQsiAjjpzlhM7fhhz7+XHU/G6e8P9uHMOeZi/+64HTZ3KWqSKQLzPdv7xnStXeJ8HKI+YcDp70LaI7rYxuQK6FcxQ4qol/3DrESDPpF/QKJt+oGtyUHN9pCe3K8/Ke0OzArXAF+n/C6tbzioUxplunKLwbIWwtXN/f1pv2O/pVF+T+DP3MU7e/kLm3BJh0jZ3/ZdQ9JjM/0ntYhktiMhBMO5g7nLL8HRcm3X1qvFdpUGA== X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(7416002)(8936002)(40460700003)(36756003)(508600001)(81166007)(83380400001)(107886003)(8676002)(36860700001)(336012)(356005)(5660300002)(426003)(2616005)(186003)(26005)(6666004)(70206006)(86362001)(2906002)(70586007)(54906003)(110136005)(7696005)(316002)(82310400004)(4326008)(47076005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 11:42:37.9786 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3893c7ce-3bb9-4c69-8140-08da028b13c1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT033.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB2513 Cc: alsa-devel@alsa-project.org, Sameer Pujar , linux-kernel@vger.kernel.org, jonathanh@nvidia.com, thierry.reding@gmail.com, linux-tegra@vger.kernel.org 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" When Tegra I2S is consumer the clock is driven by the external codec. In such cases, ideally the bit clock (BCLK) rate needs to be updated by provider. Consumer can use standard clock function to get the rate. On Tegra HW it is possible to use I2S BCLK clock as reference to the I/O (other I2S or DMIC or DSPK) interfaces. This input clock is called as SYNC input clock and it can act as a parent clock to any of the remaining I/O interfaces. Thus it is important to set the clock rate in Tegra I2S consumer mode as well. With this patch SYNC input clock rate is updated and any I/O interface relying on this can derive required rate. Signed-off-by: Sameer Pujar --- Following are the DT binding cases I tried on Jetson AGX Xavier platform. 1. Sysclk derived from MCLK : This is currently being used. No DT binding change would be necessary. Clock tree dump snippet in this case with proposed series: ... pll_a | |-- plla_out0 | |-- ahub | |-- aud_mclk | | | |-- rt5659_sysclk | |-- i2s1 ... 2. Sysclk is derived from codec internal PLL and this PLL uses I2S bit clock (BCLK) as reference. rt5658: audio-codec@1a { ... clocks = <&bpmp TEGRA194_CLK_AUD_MCLK>, <&bpmp TEGRA194_CLK_I2S1>, <&bpmp TEGRA194_CLK_I2S1>, <&rt5658 0>; clock-names = "mclk", "bclk1", "pll_ref", "sysclk"; #clock-cells = <1>; clock-output-names = "rt5659_pll_out"; ... }; Clock tree dump snippet in this case with proposed series: ... pll_a | |-- plla_out0 | |-- ahub | |-- aud_mclk | |-- i2s1 | |-- rt5659_pll_ref | |-- rt5659_pll_out | |-- rt5659_sysclk ... sound/soc/tegra/tegra210_i2s.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sound/soc/tegra/tegra210_i2s.c b/sound/soc/tegra/tegra210_i2s.c index 43fa106..91819db 100644 --- a/sound/soc/tegra/tegra210_i2s.c +++ b/sound/soc/tegra/tegra210_i2s.c @@ -53,17 +53,24 @@ static int tegra210_i2s_set_clock_rate(struct device *dev, regmap_read(i2s->regmap, TEGRA210_I2S_CTRL, &val); - /* No need to set rates if I2S is being operated in slave */ - if (!(val & I2S_CTRL_MASTER_EN)) - return 0; - - err = clk_set_rate(i2s->clk_i2s, clock_rate); - if (err) { - dev_err(dev, "can't set I2S bit clock rate %u, err: %d\n", - clock_rate, err); - return err; + /* + * If I2S is consumer, then the clock rate is expected to be + * set by the respective provider and thus just read the rate + * in such case. If I2S is provider, then set the clock rate. + */ + if (!(val & I2S_CTRL_MASTER_EN)) { + clock_rate = clk_get_rate(i2s->clk_i2s); + } else { + err = clk_set_rate(i2s->clk_i2s, clock_rate); + if (err) { + dev_err(dev, "can't set I2S bit clock rate %u, err: %d\n", + clock_rate, err); + return err; + } } + dev_dbg(dev, "bit clock (BCLK) rate is %u\n", clock_rate); + if (!IS_ERR(i2s->clk_sync_input)) { /* * Other I/O modules in AHUB can use i2s bclk as reference