From patchwork Fri Mar 21 16:39:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 14025757 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 233F422D4DC; Fri, 21 Mar 2025 16:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=67.231.149.25 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742575201; cv=fail; b=GL76djdg37q8NeFsTC4zAZ8E2CPD4ixML443C47bu4ktI8HrEngkMdTZZEp7b1DxYZVaIF682/vFG3PexLeAd9oR0epTAf1yI4aIAV7UG6ZthWVTYRyPNDF2wgqsidO0uiVC+S9LCKsmP/F4jmP+5D6r+oFDKGzWfJEfUzcF0es= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742575201; c=relaxed/simple; bh=rJ7Zr+1aTfrpY77IoVlBdIDxsPzEFha9xZaOFWwpUx8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=pLnElqZj1llrmh7QN/DAc2NPO983oFR02/P+g6ZIn8RxBn1ltuNdEcze78nGpvc3TaX4TgM++WIB+/xAU5biJYMZsDyOwdT7hD+tND5ZfND9YDLNKGJvozqQg2UINylyUIYPhBHS085DlIxu9gdfc6hvg/ErjjbCiIaus7nAyok= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com; spf=pass smtp.mailfrom=cirrus.com; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b=jJPPRBm/; dkim=pass (1024-bit key) header.d=cirrus4.onmicrosoft.com header.i=@cirrus4.onmicrosoft.com header.b=qGpwkqPA; arc=fail smtp.client-ip=67.231.149.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cirrus.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="jJPPRBm/"; dkim=pass (1024-bit key) header.d=cirrus4.onmicrosoft.com header.i=@cirrus4.onmicrosoft.com header.b="qGpwkqPA" Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52L5KkjG026985; Fri, 21 Mar 2025 11:39:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= PODMain02222019; bh=bCQxKQMzWjQXS5Y/it3VH9/KsNGnaNyHPfw4WNeM/go=; b= jJPPRBm/UVJ4OXBo9XweURLGs3On9equXL0ALg92YVKdVma51wohX7HMppdr0zHv rTsYpkQcI0qhAo5Wi0IbEQos5oboaSjtRQkfpQkJgNwk80OS0RnxcPpMvzj0xiTy bwg41DpgUR2UpbFAXY22lpSjQjevcE3zM0Za3YauTflS8cPRPDKozE6BtUVteY/E llDYWyC0e9Wqu50qsbfAVSu80P7rmvUskUVChfPHuMIOklOFzqsZr6rUgJcMeYuZ JLojWMfjRJB4nKMA7ZsYqGaz6QxuywrmWB3cJjf4bZ6LO6O7JNKhBSBp2GY84vFu fOYt+PNoxhg2fpZuLfIhrg== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 45g9p6v7hh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Mar 2025 11:39:38 -0500 (CDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tq2mgzrQh7aEWmB/CGtsVrGIkuqmF8d7uKvM0KYXwt3FZWyPzrYpgp0rwKPVkZo0cNE2wfO8tL5Wnc7y6L6owbwjdJqJKJz+TzpvGrXzOCmqFRwQJ/lIGJ98hyca1erDwwO0Y/zAyJHbffyz1fcyPMkCSRydqrLIZXnX5bik7QJMW/J3IlsB8/m33e4xp6s4lPr4g9ZOzWHRJqwYbys5/fYceBJgr6jialshJWO80qTrfeS3g222zpHkjiD0k+cDaDbHY3kUJk+u1J0kQ7kWoAJO1Z7kpazhttUX9DHzY1AbS10NYyid8UKl/OykVMrXg/LlZRtu98AH5vhp4rbd9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=bCQxKQMzWjQXS5Y/it3VH9/KsNGnaNyHPfw4WNeM/go=; b=oLSisoyjG23eOXu8lXQfyn8j+G6LVfamOE7qjtOd8EpXrDR+XH+sbf11WNdyJsNniGaWc0bNTlhEQ2y/BJbR4FZrrzTD4j3ZXssCbYA8LSwCHxXtLTd9gkZgDRgpXq4EccK6La1MYZJ9mqrZMTuk3clSEKLQvtD+ZvwHok39Yt/OJQN1CMTOlf13RynXUo5Qg7ZvYKPTwKCY9ethOo5hzEyvtIi3nHE5DnSa7pdqeiklJHSadC6dCW+lVR6wszLS7lj8QvDa+/ia9KMsVuvH/TJo3SW/1Pn9C+c/tUEKVfFSuvs1fV/RCUDq1QKt8VT3OZT1J409pb9pQ3e5pc2V8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 84.19.233.75) smtp.rcpttodomain=cirrus.com smtp.mailfrom=cirrus.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject header.from=opensource.cirrus.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus4.onmicrosoft.com; s=selector2-cirrus4-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bCQxKQMzWjQXS5Y/it3VH9/KsNGnaNyHPfw4WNeM/go=; b=qGpwkqPAyQ3IMcTzq/5v3v95J0HvHrm74yuFt6yK+IgJU2ol1uT2lAeXBz3toGdE1zmhvudBKhy8iKO8XsyTqUPD7tGsXMD20qME1a/ABDjqarLa0NxaCH/QV+p2KqX8BPcWaodAlFV2tgL5+tM46mSevDERvifsqoKG4u/+6OU= Received: from MN2PR20CA0038.namprd20.prod.outlook.com (2603:10b6:208:235::7) by SA3PR19MB7748.namprd19.prod.outlook.com (2603:10b6:806:2fc::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.34; Fri, 21 Mar 2025 16:39:31 +0000 Received: from BN2PEPF000044A2.namprd02.prod.outlook.com (2603:10b6:208:235:cafe::f) by MN2PR20CA0038.outlook.office365.com (2603:10b6:208:235::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.37 via Frontend Transport; Fri, 21 Mar 2025 16:39:30 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 84.19.233.75) smtp.mailfrom=cirrus.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=opensource.cirrus.com; Received-SPF: Fail (protection.outlook.com: domain of cirrus.com does not designate 84.19.233.75 as permitted sender) receiver=protection.outlook.com; client-ip=84.19.233.75; helo=edirelay1.ad.cirrus.com; Received: from edirelay1.ad.cirrus.com (84.19.233.75) by BN2PEPF000044A2.mail.protection.outlook.com (10.167.243.153) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.20 via Frontend Transport; Fri, 21 Mar 2025 16:39:30 +0000 Received: from ediswmail9.ad.cirrus.com (ediswmail9.ad.cirrus.com [198.61.86.93]) by edirelay1.ad.cirrus.com (Postfix) with ESMTPS id E9EB6406547; Fri, 21 Mar 2025 16:39:28 +0000 (UTC) Received: from ediswws07.ad.cirrus.com (ediswws07.ad.cirrus.com [198.90.208.14]) by ediswmail9.ad.cirrus.com (Postfix) with ESMTP id BDD0482255C; Fri, 21 Mar 2025 16:39:28 +0000 (UTC) From: Charles Keepax To: broonie@kernel.org Cc: lgirdwood@gmail.com, pierre-louis.bossart@linux.dev, yung-chuan.liao@linux.intel.com, peter.ujfalusi@linux.intel.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com Subject: [PATCH 1/3] ASoC: SDCA: Create DAPM widgets and routes from DisCo Date: Fri, 21 Mar 2025 16:39:26 +0000 Message-Id: <20250321163928.793301-2-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250321163928.793301-1-ckeepax@opensource.cirrus.com> References: <20250321163928.793301-1-ckeepax@opensource.cirrus.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A2:EE_|SA3PR19MB7748:EE_ X-MS-Office365-Filtering-Correlation-Id: 03a37520-41dd-4f55-296b-08dd6896f41b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|61400799027|82310400026|376014|36860700013|13003099007; X-Microsoft-Antispam-Message-Info: fRrMASubirLfI1edbieDyHmdLJg8SsmCZudEX1UegYieM37y0LHBcg6nrgVtZzKhCTOFKhBYvgloxAujR8JvPQxMB4RwTwW6swYjxpF4mfC7Ku9srkx6KVdVVo+DJ2ipR1CRNB3sSFbyGq61R1Ks2jLrVll2umpH8m0zZ3dD1NAjtUt3oNafE0WdDuvly1m5EEbZsKZmjvwj+enFJlP3TZe1Od3Do4ATvrhw5/niInf+l/kHMdirKDEkRI+5rLgWLTTQdfsxC5pHjsq3P4TpcvDVwQlNWvPl0kl0++RQceuY5/NtaFqW0XiAuJxVMA0q83Cbtd+UCLHdrAnPAjA3iLDS1ULwgP71jwCOdKFxIuBYtc6Nr652hwExx8Bf55ZSZSIdF/zJxh6pAc11Ip5kfCBcMxXg3ixF5Fi05ZCb2HyZH1NO21g97bUR8TP24Z+95xDFhgb/bGAF/8i9IOvPNnMkCa2cQaInM4WRKXcwPpR2Y/ArmjYCyR3ac7hJzmbl8OE0MWrv4DkEci/aiQjG6kqpopATDvWFuIz8EPNRJlx8fyach6cZBwZkxJjtrtdyL5yNjvktGnwh/IsuSZgxqKRDMIRSmbiwt+h5eCIPlnyv2uWopwJOnk+Z/Cm4Z0zeLA4U8dYgbYBMert52E5HmQCN+A/u17hM6wzE1wbU+EL68sqfQiVF0I5yET5oGsup7D06ZjB89GOSukrOdnSbwN0jN4NYkwTFqasgSLxcYUFkxXbVl9hBZ6CKevJnZ8QA5vX1/BaNfUPd76dw/zFCnHNtQ2i/D2yKrcLjtFrJxF0Xt0GHqk7HJWFue+x3seehpUfUDlv2ku4O+P/8S++r69gQzM0b7rzcG2nslV1Dde6BadGI5OXzRwpP+fkXvr/A8zJIc+gVIlP+DhHtJeSMRP73gfhRnXawZd03fLX9EDa71me7JfKpxzxHn/bKTwAIXCvp7haKpFXCM+PKjk5+gaX/woh07DDaMetGFqJaf6Z4I6PMNQ/3vf4VQDxDmFc3KBorRLwdriZCkW9maSGiC5ed3yNgsRQW1riXJkUwKFd73GzsBbJ16g7XNrEKQ88+MjnMZYT1XEO+IlzbGTOA1KnyLbFHt/dVG58+9EUpb1/ZrVKR6Q5qoertw8J/r1beTSeLyrIEqa5l9GcMX5BN12GZ6cV9OPRphztnZA7TTiXoL6uVPtfY+lYehMWt9dSofsk2wXqikxVZPlEqJ6m5gVvHG7RS/ko3Nbt6TDUZKUliOPDngXVkeQAB/83107T6ydIYgvrZoriFEtGOBHFnTGs8IU2Z72th25/pNdhFvKr8n20W0uQKh7Ip0Bbf86tlg5Dbwm4SOI3fmGfjjj9TogIj/IAaVxyTynnbJvojIhnSqYOkWpGjAsbne45IBtBfl+70Nl+6ol37bRezJrl/tnKgNzJ8F3ZUBpnZF43loKg= X-Forefront-Antispam-Report: CIP:84.19.233.75;CTRY:GB;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:edirelay1.ad.cirrus.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(61400799027)(82310400026)(376014)(36860700013)(13003099007);DIR:OUT;SFP:1102; X-OriginatorOrg: opensource.cirrus.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2025 16:39:30.4094 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 03a37520-41dd-4f55-296b-08dd6896f41b X-MS-Exchange-CrossTenant-Id: bec09025-e5bc-40d1-a355-8e955c307de8 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=bec09025-e5bc-40d1-a355-8e955c307de8;Ip=[84.19.233.75];Helo=[edirelay1.ad.cirrus.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A2.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR19MB7748 X-Authority-Analysis: v=2.4 cv=Vcz3PEp9 c=1 sm=1 tr=0 ts=67dd964a cx=c_pps a=sGbpJkUcFVeWJOR+0qTsNQ==:117 a=h1hSm8JtM9GN1ddwPAif2w==:17 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=Vs1iUdzkB0EA:10 a=s63m1ICgrNkA:10 a=RWc_ulEos4gA:10 a=KJT-RnjOAAAA:8 a=w1d2syhTAAAA:8 a=04aGDqRuwiNVRNv7JHcA:9 a=HE_01F9_QflCRFonrIQr:22 a=BGLuxUZjE2igh1l4FkT-:22 X-Proofpoint-GUID: _j7s-kE4q1tegt5MzS5P4uKQoOyf6XnO X-Proofpoint-ORIG-GUID: _j7s-kE4q1tegt5MzS5P4uKQoOyf6XnO X-Proofpoint-Spam-Reason: safe Use the previously parsed DisCo information from ACPI to create DAPM widgets and routes representing a SDCA Function. For the most part SDCA maps well to the DAPM abstractions. The primary point of interest is the SDCA Power Domain Entities (PDEs), which actually control the power status of the device. Whilst these PDEs are the primary widgets the other parts of the SDCA graph are added to maintain a consistency with the hardware abstract, and allow routing to take effect. Other minor points of slightly complexity include, the Group Entities (GEs) these set the value of several other controls, typically Selector Units (SUs) for enabling a cetain jack configuration. These are easily modelled creating a single control and sharing it among the controlled muxes. SDCA also has a slight habit of having fully connected paths, relying more on activating the PDEs to enable functionality. This doesn't map quite so perfectly to DAPM which considers the path a reason to power the PDE. Whilst in the current specification Mixer Units are defined as fixed-function, in DAPM we create a virtual control for each input. This allows paths to be connected/disconnected, providing a more ASoC style approach to managing the power. A top level helper sdca_asoc_populate_component() is exported that counts and allocates everything, however, the intermediate counting and population functions are also exported. This will allow end drivers to do allocation and add custom handling, which is probably fairly likely for the early SDCA devices. Clock muxes are currently not fully supported, so some future work will also be required there. Signed-off-by: Charles Keepax --- include/sound/sdca_asoc.h | 30 ++ include/sound/sdca_function.h | 36 ++ sound/soc/sdca/Makefile | 2 +- sound/soc/sdca/sdca_asoc.c | 799 ++++++++++++++++++++++++++++++++++ 4 files changed, 866 insertions(+), 1 deletion(-) create mode 100644 include/sound/sdca_asoc.h create mode 100644 sound/soc/sdca/sdca_asoc.c diff --git a/include/sound/sdca_asoc.h b/include/sound/sdca_asoc.h new file mode 100644 index 0000000000000..414d461b6fc4a --- /dev/null +++ b/include/sound/sdca_asoc.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * The MIPI SDCA specification is available for public downloads at + * https://www.mipi.org/mipi-sdca-v1-0-download + * + * Copyright (C) 2025 Cirrus Logic, Inc. and + * Cirrus Logic International Semiconductor Ltd. + */ + +#ifndef __SDCA_ASOC_H__ +#define __SDCA_ASOC_H__ + +struct device; +struct sdca_function_data; +struct snd_soc_component_driver; +struct snd_soc_dapm_route; +struct snd_soc_dapm_widget; + +int sdca_asoc_count_component(struct device *dev, struct sdca_function_data *function, + int *num_widgets, int *num_routes); + +int sdca_asoc_populate_dapm(struct device *dev, struct sdca_function_data *function, + struct snd_soc_dapm_widget *widgets, + struct snd_soc_dapm_route *routes); + +int sdca_asoc_populate_component(struct device *dev, + struct sdca_function_data *function, + struct snd_soc_component_driver *component_drv); + +#endif // __SDCA_ASOC_H__ diff --git a/include/sound/sdca_function.h b/include/sound/sdca_function.h index 253654568a41e..447752f71286a 100644 --- a/include/sound/sdca_function.h +++ b/include/sound/sdca_function.h @@ -257,6 +257,14 @@ enum sdca_pde_controls { SDCA_CTL_PDE_ACTUAL_PS = 0x10, }; +/** + * enum sdca_requested_ps_range - Column definitions for Requested PS + */ +enum sdca_requested_ps_range { + SDCA_REQUESTED_PS_STATE = 0, + SDCA_REQUESTED_PS_NCOLS = 1, +}; + /** * enum sdca_ge_controls - SDCA Controls for Group Unit * @@ -268,6 +276,15 @@ enum sdca_ge_controls { SDCA_CTL_GE_DETECTED_MODE = 0x02, }; +/** + * enum sdca_selected_mode_range - Column definitions for Selected Mode + */ +enum sdca_selected_mode_range { + SDCA_SELECTED_MODE_INDEX = 0, + SDCA_SELECTED_MODE_TERM_TYPE = 1, + SDCA_SELECTED_MODE_NCOLS = 2, +}; + /** * enum sdca_spe_controls - SDCA Controls for Security & Privacy Unit * @@ -773,6 +790,25 @@ enum sdca_terminal_type { SDCA_TERM_TYPE_PRIVACY_INDICATORS = 0x747, }; +#define SDCA_TERM_TYPE_LINEIN_STEREO_NAME "LineIn Stereo" +#define SDCA_TERM_TYPE_LINEIN_FRONT_LR_NAME "LineIn Front-LR" +#define SDCA_TERM_TYPE_LINEIN_CENTER_LFE_NAME "LineIn Center-LFE" +#define SDCA_TERM_TYPE_LINEIN_SURROUND_LR_NAME "LineIn Surround-LR" +#define SDCA_TERM_TYPE_LINEIN_REAR_LR_NAME "LineIn Rear-LR" +#define SDCA_TERM_TYPE_LINEOUT_STEREO_NAME "LineOut Stereo" +#define SDCA_TERM_TYPE_LINEOUT_FRONT_LR_NAME "LineOut Front-LR" +#define SDCA_TERM_TYPE_LINEOUT_CENTER_LFE_NAME "LineOut Center-LFE" +#define SDCA_TERM_TYPE_LINEOUT_SURROUND_LR_NAME "LineOut Surround-LR" +#define SDCA_TERM_TYPE_LINEOUT_REAR_LR_NAME "LineOut Rear-LR" +#define SDCA_TERM_TYPE_MIC_JACK_NAME "Microphone " +#define SDCA_TERM_TYPE_STEREO_JACK_NAME "Speaker Stereo" +#define SDCA_TERM_TYPE_FRONT_LR_JACK_NAME "Speaker Front-LR" +#define SDCA_TERM_TYPE_CENTER_LFE_JACK_NAME "Speaker Center-LFE" +#define SDCA_TERM_TYPE_SURROUND_LR_JACK_NAME "Speaker Surround-LR" +#define SDCA_TERM_TYPE_REAR_LR_JACK_NAME "Speaker Rear-LR" +#define SDCA_TERM_TYPE_HEADPHONE_JACK_NAME "Headphone" +#define SDCA_TERM_TYPE_HEADSET_JACK_NAME "Headset" + /** * enum sdca_connector_type - SDCA Connector Types * diff --git a/sound/soc/sdca/Makefile b/sound/soc/sdca/Makefile index dddc3e6942569..53344f108ca67 100644 --- a/sound/soc/sdca/Makefile +++ b/sound/soc/sdca/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -snd-soc-sdca-y := sdca_functions.o sdca_device.o sdca_regmap.o +snd-soc-sdca-y := sdca_functions.o sdca_device.o sdca_regmap.o sdca_asoc.o obj-$(CONFIG_SND_SOC_SDCA) += snd-soc-sdca.o diff --git a/sound/soc/sdca/sdca_asoc.c b/sound/soc/sdca/sdca_asoc.c new file mode 100644 index 0000000000000..dab434a8daac2 --- /dev/null +++ b/sound/soc/sdca/sdca_asoc.c @@ -0,0 +1,799 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2025 Cirrus Logic, Inc. and +// Cirrus Logic International Semiconductor Ltd. + +/* + * The MIPI SDCA specification is available for public downloads at + * https://www.mipi.org/mipi-sdca-v1-0-download + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct sdca_control *selector_find_control(struct sdca_entity *entity, + const int sel) +{ + int i; + + for (i = 0; i < entity->num_controls; i++) { + struct sdca_control *control = &entity->controls[i]; + + if (control->sel == sel) + return control; + } + + return NULL; +} + +static struct sdca_control_range *control_find_range(struct device *dev, + struct sdca_entity *entity, + struct sdca_control *control, + int cols, int rows) +{ + struct sdca_control_range *range = &control->range; + + if ((cols && range->cols != cols) || (rows && range->rows != rows) || + !range->data) { + dev_err(dev, "%s: control %#x: ranges invalid (%d,%d)\n", + entity->label, control->sel, range->cols, range->rows); + return NULL; + } + + return range; +} + +static struct sdca_control_range *selector_find_range(struct device *dev, + struct sdca_entity *entity, + int sel, int cols, int rows) +{ + struct sdca_control *control; + + control = selector_find_control(entity, sel); + if (!control) { + dev_err(dev, "%s: control %#x: missing\n", entity->label, sel); + return NULL; + } + + return control_find_range(dev, entity, control, cols, rows); +} + +int sdca_asoc_count_component(struct device *dev, struct sdca_function_data *function, + int *num_widgets, int *num_routes) +{ + int i; + + *num_widgets = function->num_entities - 1; + *num_routes = 0; + + for (i = 0; i < function->num_entities - 1; i++) { + struct sdca_entity *entity = &function->entities[i]; + + switch (entity->type) { + case SDCA_ENTITY_TYPE_IT: + case SDCA_ENTITY_TYPE_OT: + *num_routes += !!entity->iot.clock; + *num_routes += !!entity->iot.is_dataport; + break; + case SDCA_ENTITY_TYPE_PDE: + *num_routes += entity->pde.num_managed; + break; + default: + break; + } + + *num_routes += entity->num_sources; + } + + return 0; +} +EXPORT_SYMBOL_NS(sdca_asoc_count_component, "SND_SOC_SDCA"); + +static const char *get_terminal_name(enum sdca_terminal_type type) +{ + switch (type) { + case SDCA_TERM_TYPE_LINEIN_STEREO: + return SDCA_TERM_TYPE_LINEIN_STEREO_NAME; + case SDCA_TERM_TYPE_LINEIN_FRONT_LR: + return SDCA_TERM_TYPE_LINEIN_FRONT_LR_NAME; + case SDCA_TERM_TYPE_LINEIN_CENTER_LFE: + return SDCA_TERM_TYPE_LINEIN_CENTER_LFE_NAME; + case SDCA_TERM_TYPE_LINEIN_SURROUND_LR: + return SDCA_TERM_TYPE_LINEIN_SURROUND_LR_NAME; + case SDCA_TERM_TYPE_LINEIN_REAR_LR: + return SDCA_TERM_TYPE_LINEIN_REAR_LR_NAME; + case SDCA_TERM_TYPE_LINEOUT_STEREO: + return SDCA_TERM_TYPE_LINEOUT_STEREO_NAME; + case SDCA_TERM_TYPE_LINEOUT_FRONT_LR: + return SDCA_TERM_TYPE_LINEOUT_FRONT_LR_NAME; + case SDCA_TERM_TYPE_LINEOUT_CENTER_LFE: + return SDCA_TERM_TYPE_LINEOUT_CENTER_LFE_NAME; + case SDCA_TERM_TYPE_LINEOUT_SURROUND_LR: + return SDCA_TERM_TYPE_LINEOUT_SURROUND_LR_NAME; + case SDCA_TERM_TYPE_LINEOUT_REAR_LR: + return SDCA_TERM_TYPE_LINEOUT_REAR_LR_NAME; + case SDCA_TERM_TYPE_MIC_JACK: + return SDCA_TERM_TYPE_MIC_JACK_NAME; + case SDCA_TERM_TYPE_STEREO_JACK: + return SDCA_TERM_TYPE_STEREO_JACK_NAME; + case SDCA_TERM_TYPE_FRONT_LR_JACK: + return SDCA_TERM_TYPE_FRONT_LR_JACK_NAME; + case SDCA_TERM_TYPE_CENTER_LFE_JACK: + return SDCA_TERM_TYPE_CENTER_LFE_JACK_NAME; + case SDCA_TERM_TYPE_SURROUND_LR_JACK: + return SDCA_TERM_TYPE_SURROUND_LR_JACK_NAME; + case SDCA_TERM_TYPE_REAR_LR_JACK: + return SDCA_TERM_TYPE_REAR_LR_JACK_NAME; + case SDCA_TERM_TYPE_HEADPHONE_JACK: + return SDCA_TERM_TYPE_HEADPHONE_JACK_NAME; + case SDCA_TERM_TYPE_HEADSET_JACK: + return SDCA_TERM_TYPE_HEADSET_JACK_NAME; + default: + return NULL; + } +} + +static int entity_early_parse_ge(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity) +{ + struct sdca_control_range *range; + struct sdca_control *control; + struct snd_kcontrol_new *kctl; + struct soc_enum *soc_enum; + const char *control_name; + unsigned int *values; + const char **texts; + int i; + + control = selector_find_control(entity, SDCA_CTL_GE_SELECTED_MODE); + if (!control) { + dev_err(dev, "%s: no selected mode control\n", entity->label); + return -EINVAL; + } + + if (control->layers != SDCA_ACCESS_LAYER_CLASS) + dev_warn(dev, "%s: unexpected access layer: %x\n", + entity->label, control->layers); + + range = control_find_range(dev, entity, control, SDCA_SELECTED_MODE_NCOLS, 0); + if (!range) + return -EINVAL; + + control_name = devm_kasprintf(dev, GFP_KERNEL, "%s %s", + entity->label, control->label); + if (!control_name) + return -ENOMEM; + + kctl = devm_kmalloc(dev, sizeof(*kctl), GFP_KERNEL); + if (!kctl) + return -ENOMEM; + + soc_enum = devm_kmalloc(dev, sizeof(*soc_enum), GFP_KERNEL); + if (!soc_enum) + return -ENOMEM; + + texts = devm_kcalloc(dev, range->rows + 3, sizeof(*texts), GFP_KERNEL); + if (!texts) + return -ENOMEM; + + values = devm_kcalloc(dev, range->rows + 3, sizeof(*values), GFP_KERNEL); + if (!values) + return -ENOMEM; + + texts[0] = "No Jack"; + texts[1] = "Jack Unknown"; + texts[2] = "Detection in Progress"; + values[0] = 0; + values[1] = 1; + values[2] = 2; + for (i = 0; i < range->rows; i++) { + enum sdca_terminal_type type; + + type = sdca_range(range, SDCA_SELECTED_MODE_TERM_TYPE, i); + + values[i + 3] = sdca_range(range, SDCA_SELECTED_MODE_INDEX, i); + texts[i + 3] = get_terminal_name(type); + if (!texts[i + 3]) { + dev_err(dev, "%s: Unrecognised terminal type: %#x\n", + entity->label, type); + return -EINVAL; + } + } + + soc_enum->reg = SDW_SDCA_CTL(function->desc->adr, entity->id, control->sel, 0); + soc_enum->items = range->rows + 3; + soc_enum->mask = roundup_pow_of_two(soc_enum->items) - 1; + soc_enum->texts = texts; + + kctl->iface = SNDRV_CTL_ELEM_IFACE_MIXER; + kctl->name = control_name; + kctl->info = snd_soc_info_enum_double; + kctl->get = snd_soc_dapm_get_enum_double; + kctl->put = snd_soc_dapm_put_enum_double; + kctl->private_value = (unsigned long)soc_enum; + + entity->ge.kctl = kctl; + + return 0; +} + +static void add_route(struct snd_soc_dapm_route **route, const char *sink, + const char *control, const char *source) +{ + (*route)->sink = sink; + (*route)->control = control; + (*route)->source = source; + (*route)++; +} + +static int entity_parse_simple(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct snd_soc_dapm_widget **widget, + struct snd_soc_dapm_route **route, + enum snd_soc_dapm_type id) +{ + int i; + + (*widget)->id = id; + (*widget)++; + + for (i = 0; i < entity->num_sources; i++) + add_route(route, entity->label, NULL, entity->sources[i]->label); + + return 0; +} + +static int entity_parse_it(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct snd_soc_dapm_widget **widget, + struct snd_soc_dapm_route **route) +{ + int i; + + if (entity->iot.is_dataport) { + const char *aif_name = devm_kasprintf(dev, GFP_KERNEL, "%s %s", + entity->label, "Playback"); + if (!aif_name) + return -ENOMEM; + + (*widget)->id = snd_soc_dapm_aif_in; + + add_route(route, entity->label, NULL, aif_name); + } else { + (*widget)->id = snd_soc_dapm_input; + } + + if (entity->iot.clock) + add_route(route, entity->label, NULL, entity->iot.clock->label); + + for (i = 0; i < entity->num_sources; i++) + add_route(route, entity->label, NULL, entity->sources[i]->label); + + (*widget)++; + + return 0; +} + +static int entity_parse_ot(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct snd_soc_dapm_widget **widget, + struct snd_soc_dapm_route **route) +{ + int i; + + if (entity->iot.is_dataport) { + const char *aif_name = devm_kasprintf(dev, GFP_KERNEL, "%s %s", + entity->label, "Capture"); + if (!aif_name) + return -ENOMEM; + + (*widget)->id = snd_soc_dapm_aif_out; + + add_route(route, aif_name, NULL, entity->label); + } else { + (*widget)->id = snd_soc_dapm_output; + } + + if (entity->iot.clock) + add_route(route, entity->label, NULL, entity->iot.clock->label); + + for (i = 0; i < entity->num_sources; i++) + add_route(route, entity->label, NULL, entity->sources[i]->label); + + (*widget)++; + + return 0; +} + +static int entity_pde_event(struct snd_soc_dapm_widget *widget, + struct snd_kcontrol *kctl, int event) +{ + struct snd_soc_component *component = widget->dapm->component; + struct sdca_entity *entity = widget->priv; + static const int poll_us = 10000; + int polls = 1; + unsigned int reg, val; + int from, to, i; + int ret; + + if (!component) + return -EIO; + + switch (event) { + case SND_SOC_DAPM_POST_PMD: + from = widget->on_val; + to = widget->off_val; + break; + case SND_SOC_DAPM_POST_PMU: + from = widget->off_val; + to = widget->on_val; + break; + } + + for (i = 0; i < entity->pde.num_max_delay; i++) { + struct sdca_pde_delay *delay = &entity->pde.max_delay[i]; + + if (delay->from_ps == from && delay->to_ps == to) { + polls = max(polls, delay->us / poll_us); + break; + } + } + + reg = SDW_SDCA_CTL(SDW_SDCA_CTL_FUNC(widget->reg), + SDW_SDCA_CTL_ENT(widget->reg), + SDCA_CTL_PDE_ACTUAL_PS, 0); + + for (i = 0; i < polls; i++) { + if (i) + fsleep(poll_us); + + ret = regmap_read(component->regmap, reg, &val); + if (ret) + return ret; + else if (val == to) + return 0; + } + + dev_err(component->dev, "%s: power transition failed: %x\n", + entity->label, val); + return -ETIMEDOUT; +} + +static int entity_parse_pde(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct snd_soc_dapm_widget **widget, + struct snd_soc_dapm_route **route) +{ + unsigned int target = (1 << SDCA_PDE_PS0) | (1 << SDCA_PDE_PS3); + struct sdca_control_range *range; + struct sdca_control *control; + unsigned int mask = 0; + int i; + + control = selector_find_control(entity, SDCA_CTL_PDE_REQUESTED_PS); + if (!control) { + dev_err(dev, "%s: no power control\n", entity->label); + return -EINVAL; + } + + /* Power should only be controlled by the driver */ + if (control->layers != SDCA_ACCESS_LAYER_CLASS) + dev_warn(dev, "%s: unexpected access layer: %x\n", + entity->label, control->layers); + + range = control_find_range(dev, entity, control, SDCA_REQUESTED_PS_NCOLS, 0); + if (!range) + return -EINVAL; + + for (i = 0; i < range->rows; i++) + mask |= 1 << sdca_range(range, SDCA_REQUESTED_PS_STATE, i); + + if ((mask & target) != target) { + dev_err(dev, "%s: power control missing states\n", entity->label); + return -EINVAL; + } + + (*widget)->id = snd_soc_dapm_supply; + (*widget)->reg = SDW_SDCA_CTL(function->desc->adr, entity->id, control->sel, 0); + (*widget)->mask = GENMASK(control->nbits - 1, 0); + (*widget)->on_val = SDCA_PDE_PS0; + (*widget)->off_val = SDCA_PDE_PS3; + (*widget)->event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD; + (*widget)->event = entity_pde_event; + (*widget)->priv = entity; + (*widget)++; + + for (i = 0; i < entity->pde.num_managed; i++) + add_route(route, entity->pde.managed[i]->label, NULL, entity->label); + + for (i = 0; i < entity->num_sources; i++) + add_route(route, entity->label, NULL, entity->sources[i]->label); + + return 0; +} + +/* Device selector units are controlled through a group entity */ +static int entity_parse_su_device(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct snd_soc_dapm_widget **widget, + struct snd_soc_dapm_route **route) +{ + struct sdca_control_range *range; + int num_routes = 0; + int i, j; + + if (!entity->group) { + dev_err(dev, "%s: device selector unit missing group\n", entity->label); + return -EINVAL; + } + + range = selector_find_range(dev, entity->group, SDCA_CTL_GE_SELECTED_MODE, + SDCA_SELECTED_MODE_NCOLS, 0); + if (!range) + return -EINVAL; + + (*widget)->id = snd_soc_dapm_mux; + (*widget)->kcontrol_news = entity->group->ge.kctl; + (*widget)->num_kcontrols = 1; + (*widget)++; + + for (i = 0; i < entity->group->ge.num_modes; i++) { + struct sdca_ge_mode *mode = &entity->group->ge.modes[i]; + + for (j = 0; j < mode->num_controls; j++) { + struct sdca_ge_control *affected = &mode->controls[j]; + int term; + + if (affected->id != entity->id || + affected->sel != SDCA_CTL_SU_SELECTOR || + !affected->val) + continue; + + if (affected->val - 1 >= entity->num_sources) { + dev_err(dev, "%s: Bad control value: %#x\n", + entity->label, affected->val); + return -EINVAL; + } + + if (++num_routes > entity->num_sources) { + dev_err(dev, "%s: Too many input routes\n", entity->label); + return -EINVAL; + } + + term = sdca_range_search(range, SDCA_SELECTED_MODE_INDEX, + mode->val, SDCA_SELECTED_MODE_TERM_TYPE); + if (!term) { + dev_err(dev, "%s: Mode not found: %#x\n", + entity->label, mode->val); + return -EINVAL; + } + + add_route(route, entity->label, get_terminal_name(term), + entity->sources[affected->val - 1]->label); + } + } + + return 0; +} + +/* Class selector units will be exported as an ALSA control */ +static int entity_parse_su_class(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct sdca_control *control, + struct snd_soc_dapm_widget **widget, + struct snd_soc_dapm_route **route) +{ + struct snd_kcontrol_new *kctl; + struct soc_enum *soc_enum; + const char **texts; + int i; + + kctl = devm_kmalloc(dev, sizeof(*kctl), GFP_KERNEL); + if (!kctl) + return -ENOMEM; + + soc_enum = devm_kmalloc(dev, sizeof(*soc_enum), GFP_KERNEL); + if (!soc_enum) + return -ENOMEM; + + texts = devm_kcalloc(dev, entity->num_sources + 1, sizeof(*texts), GFP_KERNEL); + if (!texts) + return -ENOMEM; + + texts[0] = "No Signal"; + for (i = 0; i < entity->num_sources; i++) + texts[i + 1] = entity->sources[i]->label; + + soc_enum->reg = SDW_SDCA_CTL(function->desc->adr, entity->id, control->sel, 0); + soc_enum->items = entity->num_sources + 1; + soc_enum->mask = roundup_pow_of_two(soc_enum->items) - 1; + soc_enum->texts = texts; + + kctl->iface = SNDRV_CTL_ELEM_IFACE_MIXER; + kctl->name = "Route"; + kctl->info = snd_soc_info_enum_double; + kctl->get = snd_soc_dapm_get_enum_double; + kctl->put = snd_soc_dapm_put_enum_double; + kctl->private_value = (unsigned long)soc_enum; + + (*widget)->id = snd_soc_dapm_mux; + (*widget)->kcontrol_news = kctl; + (*widget)->num_kcontrols = 1; + (*widget)++; + + for (i = 0; i < entity->num_sources; i++) + add_route(route, entity->label, texts[i + 1], entity->sources[i]->label); + + return 0; +} + +static int entity_parse_su(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct snd_soc_dapm_widget **widget, + struct snd_soc_dapm_route **route) +{ + struct sdca_control *control; + + if (!entity->num_sources) { + dev_err(dev, "%s: selector with no inputs\n", entity->label); + return -EINVAL; + } + + control = selector_find_control(entity, SDCA_CTL_SU_SELECTOR); + if (!control) { + dev_err(dev, "%s: no selector control\n", entity->label); + return -EINVAL; + } + + if (control->layers == SDCA_ACCESS_LAYER_DEVICE) + return entity_parse_su_device(dev, function, entity, widget, route); + + if (control->layers != SDCA_ACCESS_LAYER_CLASS) + dev_warn(dev, "%s: unexpected access layer: %x\n", + entity->label, control->layers); + + return entity_parse_su_class(dev, function, entity, control, widget, route); +} + +static int entity_parse_mu(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct snd_soc_dapm_widget **widget, + struct snd_soc_dapm_route **route) +{ + struct sdca_control *control; + struct snd_kcontrol_new *kctl; + int cn; + int i; + + if (!entity->num_sources) { + dev_err(dev, "%s: selector 1 or more inputs\n", entity->label); + return -EINVAL; + } + + control = selector_find_control(entity, SDCA_CTL_MU_MIXER); + if (!control) { + dev_err(dev, "%s: no mixer controls\n", entity->label); + return -EINVAL; + } + + /* MU control should be through DAPM */ + if (control->layers != SDCA_ACCESS_LAYER_CLASS) + dev_warn(dev, "%s: unexpected access layer: %x\n", + entity->label, control->layers); + + if (entity->num_sources != hweight64(control->cn_list)) { + dev_err(dev, "%s: mismatched control and sources\n", entity->label); + return -EINVAL; + } + + kctl = devm_kcalloc(dev, entity->num_sources, sizeof(*kctl), GFP_KERNEL); + if (!kctl) + return -ENOMEM; + + i = 0; + for_each_set_bit(cn, (unsigned long *)&control->cn_list, + BITS_PER_TYPE(control->cn_list)) { + const char *control_name; + struct soc_mixer_control *mc; + + control_name = devm_kasprintf(dev, GFP_KERNEL, "%s %d", + control->label, i + 1); + if (!control_name) + return -ENOMEM; + + mc = devm_kmalloc(dev, sizeof(*mc), GFP_KERNEL); + if (!mc) + return -ENOMEM; + + mc->reg = SND_SOC_NOPM; + mc->rreg = SND_SOC_NOPM; + mc->invert = 1; // Ensure default is connected + mc->min = 0; + mc->max = 1; + + kctl[i].name = control_name; + kctl[i].private_value = (unsigned long)mc; + kctl[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; + kctl[i].info = snd_soc_info_volsw; + kctl[i].get = snd_soc_dapm_get_volsw; + kctl[i].put = snd_soc_dapm_put_volsw; + i++; + } + + (*widget)->id = snd_soc_dapm_mixer; + (*widget)->kcontrol_news = kctl; + (*widget)->num_kcontrols = entity->num_sources; + (*widget)++; + + for (i = 0; i < entity->num_sources; i++) + add_route(route, entity->label, kctl[i].name, entity->sources[i]->label); + + return 0; +} + +static int entity_cs_event(struct snd_soc_dapm_widget *widget, + struct snd_kcontrol *kctl, int event) +{ + struct snd_soc_component *component = widget->dapm->component; + struct sdca_entity *entity = widget->priv; + + if (!component) + return -EIO; + + if (entity->cs.max_delay) + fsleep(entity->cs.max_delay); + + return 0; +} + +static int entity_parse_cs(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct snd_soc_dapm_widget **widget, + struct snd_soc_dapm_route **route) +{ + int i; + + (*widget)->id = snd_soc_dapm_supply; + (*widget)->subseq = 1; /* Ensure these run after PDEs */ + (*widget)->event_flags = SND_SOC_DAPM_POST_PMU; + (*widget)->event = entity_cs_event; + (*widget)->priv = entity; + (*widget)++; + + for (i = 0; i < entity->num_sources; i++) + add_route(route, entity->label, NULL, entity->sources[i]->label); + + return 0; +} + +int sdca_asoc_populate_dapm(struct device *dev, struct sdca_function_data *function, + struct snd_soc_dapm_widget *widget, + struct snd_soc_dapm_route *route) +{ + int ret; + int i; + + /* Some entities need to add controls referenced by other entities */ + for (i = 0; i < function->num_entities - 1; i++) { + struct sdca_entity *entity = &function->entities[i]; + + switch (entity->type) { + case SDCA_ENTITY_TYPE_GE: + ret = entity_early_parse_ge(dev, function, entity); + if (ret) + return ret; + break; + default: + break; + } + } + + for (i = 0; i < function->num_entities - 1; i++) { + struct sdca_entity *entity = &function->entities[i]; + + widget->name = entity->label; + widget->reg = SND_SOC_NOPM; + + switch (entity->type) { + case SDCA_ENTITY_TYPE_IT: + ret = entity_parse_it(dev, function, entity, &widget, &route); + break; + case SDCA_ENTITY_TYPE_OT: + ret = entity_parse_ot(dev, function, entity, &widget, &route); + break; + case SDCA_ENTITY_TYPE_PDE: + ret = entity_parse_pde(dev, function, entity, &widget, &route); + break; + case SDCA_ENTITY_TYPE_SU: + ret = entity_parse_su(dev, function, entity, &widget, &route); + break; + case SDCA_ENTITY_TYPE_MU: + ret = entity_parse_mu(dev, function, entity, &widget, &route); + break; + case SDCA_ENTITY_TYPE_CS: + ret = entity_parse_cs(dev, function, entity, &widget, &route); + break; + case SDCA_ENTITY_TYPE_CX: + /* + * FIXME: For now we will just treat these as a supply, + * meaning all options are enabled. + */ + dev_warn(dev, "%s: Clock Selectors not fully supported yet\n", + entity->label); + ret = entity_parse_simple(dev, function, entity, &widget, + &route, snd_soc_dapm_supply); + break; + case SDCA_ENTITY_TYPE_TG: + ret = entity_parse_simple(dev, function, entity, &widget, + &route, snd_soc_dapm_siggen); + break; + default: + ret = entity_parse_simple(dev, function, entity, &widget, + &route, snd_soc_dapm_pga); + break; + } + if (ret) + return ret; + } + + return 0; +} +EXPORT_SYMBOL_NS(sdca_asoc_populate_dapm, "SND_SOC_SDCA"); + +int sdca_asoc_populate_component(struct device *dev, + struct sdca_function_data *function, + struct snd_soc_component_driver *component_drv) +{ + struct snd_soc_dapm_widget *widgets; + struct snd_soc_dapm_route *routes; + int num_widgets, num_routes; + int ret; + + ret = sdca_asoc_count_component(dev, function, &num_widgets, &num_routes); + if (ret) + return ret; + + widgets = devm_kcalloc(dev, num_widgets, sizeof(*widgets), GFP_KERNEL); + if (!widgets) + return -ENOMEM; + + routes = devm_kcalloc(dev, num_routes, sizeof(*routes), GFP_KERNEL); + if (!routes) + return -ENOMEM; + + ret = sdca_asoc_populate_dapm(dev, function, widgets, routes); + if (ret) + return ret; + + component_drv->dapm_widgets = widgets; + component_drv->num_dapm_widgets = num_widgets; + component_drv->dapm_routes = routes; + component_drv->num_dapm_routes = num_routes; + + return 0; +} +EXPORT_SYMBOL_NS(sdca_asoc_populate_component, "SND_SOC_SDCA"); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("SDCA library"); From patchwork Fri Mar 21 16:39:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 14025756 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 542B222D4DE; Fri, 21 Mar 2025 16:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=67.231.152.168 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742575201; cv=fail; b=Zr0P8VSXczUpMJHFKLYn/d0HWBvI0oBsWkIvUcyyeb2yYX7RN0sS33AmSsmzrQ7hJdAnfEJIthacwwob89oPZte4Ws5FdPCMyr4ojbyyXDW98BeIXVDL/EVtOMAv9G6hA/lDgdl5w5dC60xMfcmdU6xNRFxY9cfhD8pjRMBK9WQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742575201; c=relaxed/simple; bh=tu7HYC7GXXkG7s/eCLPYEkjb38m2viDpjbKEz3OXp1w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Y0PSJixOdVSYtPf4n9L9OZ7ogiKGe9NqZMb+V0+AWAb9UPyB4MFc0gkEeT6Z+QzEPxCdAqIZcH7CGuU/BO1OEVVCfQif/Z9msD9H4sRb6RQvpsO/T422hMlN95uATt+igBLSLaAdfuQWgt+wM9vumrm+KfFhtzyaGcjpRYUNncw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com; spf=pass smtp.mailfrom=cirrus.com; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b=a7QbGzSA; dkim=pass (1024-bit key) header.d=cirrus4.onmicrosoft.com header.i=@cirrus4.onmicrosoft.com header.b=bha7aZxe; arc=fail smtp.client-ip=67.231.152.168 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cirrus.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="a7QbGzSA"; dkim=pass (1024-bit key) header.d=cirrus4.onmicrosoft.com header.i=@cirrus4.onmicrosoft.com header.b="bha7aZxe" Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52L7m8Xn023619; Fri, 21 Mar 2025 11:39:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= PODMain02222019; bh=THID0NyLaNu/WB4qD2MHyVJYRApa/bjYPcnPKoSGMPk=; b= a7QbGzSAehg7hzXA7Csvx758hvOThHlh/+E4YvxGPfmvrCN2a5lEs6mkbUGjRjpO fCxokVnTtyVOHJ60TTq2rlq6DwrwDvxOdsvetK3tU1hw+5brLgNRDzSX2U5iR6PI KXNwzZPf0xbHL0TNC+Jx+XXfMthnJPVOCqqFaJk99RLdnjR2AZmiklPkz5uJu/pd zO7GZSSHlC5074wo66pFaVpErqNWMoUjmkp+UyHBvGSr/K5Gc5giUCpSrcI3/CEX eCWgpqNCHZltQZqSlAeTboA276kRz0jDVfTDqYV7KKf2SoelxkHqyQpFrYYc2kLo xBgWR2KUngY3xsUMChdwYA== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2173.outbound.protection.outlook.com [104.47.55.173]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 45h40m11yn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Mar 2025 11:39:38 -0500 (CDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FOuMSGsGPbsWCNvZ5C49tv6XBx0iZ2o5Rf4OhFBRLSY8iBYtcpspt8W20WVmDvYzJyumypwqptPgZFAhH7rfAmL/lsctdqiaVUx1I9Ak7ljzf1lTHkyUJ1FVnTa/XFwbDP2OjAZml5b7pEUTFQvcjUfApxNSjmsnplBtv+cPs3GBr7Vf5M3DqSBI32UpkKlEGY88tjLl335r8NRRLys0Dvc2RoHXLSRYdbGV5T6Y1cpIwPR3sEBiRKtH/UQYjSkXYnwD/IZJI1Ka+Y+V2EBVye+YCUQOqqTZc0hw+TwUFa+j+yGSlRWCcn+cZWsSzrl+f0EhAG6Y8TJ1j4oVJRcX+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=THID0NyLaNu/WB4qD2MHyVJYRApa/bjYPcnPKoSGMPk=; b=n4GIWrldgFIpIgmvrpPisGAzDKgZ1EnRs1CAmn8bO9NxoQKoAUWIN8FHgjUR8wWRml0Lh8aISGTVXzhgHIadAAu3mwRnxic2a2F+PBI2S4ZLgD/PNUV5n2OnOc8J6APFZY71UcEt84Y1KvB1cJzrS8kbDz2w/KTmIsfrHRl6UEasYkxkSMJxzoP2ztk7JuTYqecin4D9N1FValoKT18V9hw86q1hhdrK+R7KnciDZcqfBcmEHkDpRgzeGr9Wpm7/RMuXhC6/8+qOUfx7pgHtKy3AtewQ/Yc32aDcS+9Rakzz9bez2oQzjL6raA+61izF69rerRwCuIPSULugwYkgKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 84.19.233.75) smtp.rcpttodomain=cirrus.com smtp.mailfrom=cirrus.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject header.from=opensource.cirrus.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus4.onmicrosoft.com; s=selector2-cirrus4-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=THID0NyLaNu/WB4qD2MHyVJYRApa/bjYPcnPKoSGMPk=; b=bha7aZxeO1qSUEIIdRhPKglLVpUPeECqHHqE0zFzfzgN+VapOLqlU+bREky6qbPw8h3hL7TfRABAT0MfMDpTVncf3e7zy4ydyBdXE43AjyFA3vhsWJtq//5fU5Zoizp5cI2W7NO9JmfEjKvwpKUh+hHg7wrrBqNjzn8iU7zGA2A= Received: from DS7P220CA0050.NAMP220.PROD.OUTLOOK.COM (2603:10b6:8:224::20) by IA1PR19MB7205.namprd19.prod.outlook.com (2603:10b6:208:42f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.37; Fri, 21 Mar 2025 16:39:32 +0000 Received: from DS1PEPF00017099.namprd05.prod.outlook.com (2603:10b6:8:224:cafe::1c) by DS7P220CA0050.outlook.office365.com (2603:10b6:8:224::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.33 via Frontend Transport; Fri, 21 Mar 2025 16:39:32 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 84.19.233.75) smtp.mailfrom=cirrus.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=opensource.cirrus.com; Received-SPF: Fail (protection.outlook.com: domain of cirrus.com does not designate 84.19.233.75 as permitted sender) receiver=protection.outlook.com; client-ip=84.19.233.75; helo=edirelay1.ad.cirrus.com; Received: from edirelay1.ad.cirrus.com (84.19.233.75) by DS1PEPF00017099.mail.protection.outlook.com (10.167.18.103) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.20 via Frontend Transport; Fri, 21 Mar 2025 16:39:30 +0000 Received: from ediswmail9.ad.cirrus.com (ediswmail9.ad.cirrus.com [198.61.86.93]) by edirelay1.ad.cirrus.com (Postfix) with ESMTPS id EBCAE40654A; Fri, 21 Mar 2025 16:39:28 +0000 (UTC) Received: from ediswws07.ad.cirrus.com (ediswws07.ad.cirrus.com [198.90.208.14]) by ediswmail9.ad.cirrus.com (Postfix) with ESMTP id C43A482255D; Fri, 21 Mar 2025 16:39:28 +0000 (UTC) From: Charles Keepax To: broonie@kernel.org Cc: lgirdwood@gmail.com, pierre-louis.bossart@linux.dev, yung-chuan.liao@linux.intel.com, peter.ujfalusi@linux.intel.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com Subject: [PATCH 2/3] ASoC: SDCA: Create ALSA controls from DisCo Date: Fri, 21 Mar 2025 16:39:27 +0000 Message-Id: <20250321163928.793301-3-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250321163928.793301-1-ckeepax@opensource.cirrus.com> References: <20250321163928.793301-1-ckeepax@opensource.cirrus.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017099:EE_|IA1PR19MB7205:EE_ X-MS-Office365-Filtering-Correlation-Id: 9a2c440a-68ff-432e-37dc-08dd6896f3f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|61400799027|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: Dt8lu9kT0cHofBkI2vVoNiZfa0psopZLmLwNYhiZnqyOreZ1EVJ25lQnvNOHPPSsAOmZG+S+x3pxIyut8N6+PewjE2ksT7B+9X/LzP+2wZtnY3HMoZ6wvrqLoZcWNU7TcZ0wyvdkTsITgCfhDyKf17Y/1Yi70IsghZ0Pskv3WlDGP3B1AaOk2+r5mZOFkXuD+B4ZE44O5fX+pNjjQn9NYOON4W/RIsMSxNUf/WV+9qdm46GFn3AEtcBXmJFhhz/2dHg6hRXQTz570bY3UTqtzdTFgEmJJiHMxMufWQK0t/bOfyXctINfGtOA+ynhWmHaxMFE1oSR7oIhYMNBMQYTQITxtT4rhl9eTXzpjjIuRGIfPqiZYYgckh9fxRGnfNZDzaBILKgQup2qXHbPcmW/TuinlNhqClwproyt9bb5Mnv4yKtLkXZdURQFID0Ff0GwpOXc79VQtjYmR+fNy8YreYHEyXQMZ5JpOtTLpFbGPeijrRSxCpHAJG/NB3ixcXGo9c46IjT6aZrgTXL6LKqZPKFY0mYu6hBp+oqf68gYeLzKxIvthzXscOmeqqo9tohzSCWS/r3UOZR3bq6rfkvo1j8JilaeRoe59fPMkpQdYMpOrgshyw/AD5FBLl4GLgNLUscbfMfVXieQvExerAyJHtawPvDkYQ4HGOFpf+srZfsyhZ3I1JYPUcvhUfE9ShQauk2BBIOqadV8Tn4q7yZ8cAU33dwF/xo2VcuNNM3ecruXtQa4Z7LHbi3Ib0j+G15AORKbxwswkobyIIuhcvePcu9MkpkIwSQ8wtOF9idSm9rXMIH41RMmGEoQUrFV1/XN3BXxIt7otwVDn/Alt29GTkK05nnK/iEEmOQ0EIIqdGFyjK3LXcAgOc7BTub2l4vKu4+RcSQzhUezukKoKFU4Nz0Aqcsi6BG9beUVKxEf2FJcjTVwUr1gsiaQBmz4UZYoONhNQxuG5xJ0oxyxEOR3gyc58Q3iROTHdcgu10zxM2d1jWnTpb0FkV4NANG6aPRrk1Ca3W7wpc96YPfz0ttm7lzpvpYeP8qv8yGZBYo+CiIU5OVTGuwMQqRTGjaelcjMiWuhkmgcv1pER6jnhTCAcNM0haB+IMDjagyKqhMxlWHBlWb9AE88yd7lSNhZW07PFP85WILkHCXjuIbGWEfIe4TGFTSGlQw3MBmgz337ujfBpZPWPwVVgXOMsJjHMaDYw/RKGmKtH1Blp5pHknYiWd84pmSgUJyTbAd+bvInLfpPmpLwB/drsAbVtFf2OAjWGr64X0j/6V4i3Xj04hUVHdw7XaiLqG/PE4wZQqhchf+Ht9k5UPM7MqRyNejne5SohWs7wFo7nKMD57KWCVeUtn6nu3xs3N5yFbTMK/ErCwCz7kuoWWTwa87hwmYP8NoHd4ubhHim3LgWeHQI9g8mQ/iYJAbm2DWBDtY9bnsAtDtbXHzj9gqEJvLGnWoIdRAC75TLsskmJjTj3pA5s1Q6YfbI1etv3ycgwgeShIAWWyg= X-Forefront-Antispam-Report: CIP:84.19.233.75;CTRY:GB;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:edirelay1.ad.cirrus.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(61400799027)(82310400026)(376014)(36860700013);DIR:OUT;SFP:1102; X-OriginatorOrg: opensource.cirrus.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2025 16:39:30.1492 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9a2c440a-68ff-432e-37dc-08dd6896f3f8 X-MS-Exchange-CrossTenant-Id: bec09025-e5bc-40d1-a355-8e955c307de8 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=bec09025-e5bc-40d1-a355-8e955c307de8;Ip=[84.19.233.75];Helo=[edirelay1.ad.cirrus.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017099.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR19MB7205 X-Proofpoint-GUID: JyB0bLWF__F0eOW49t6R3vDoN0SwxlgF X-Authority-Analysis: v=2.4 cv=DdkXqutW c=1 sm=1 tr=0 ts=67dd964a cx=c_pps a=ynuEE1Gfdg78pLiovR0MAg==:117 a=h1hSm8JtM9GN1ddwPAif2w==:17 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=Vs1iUdzkB0EA:10 a=s63m1ICgrNkA:10 a=RWc_ulEos4gA:10 a=w1d2syhTAAAA:8 a=x5gQ8A518QfWKtYHqdsA:9 a=BGLuxUZjE2igh1l4FkT-:22 X-Proofpoint-ORIG-GUID: JyB0bLWF__F0eOW49t6R3vDoN0SwxlgF X-Proofpoint-Spam-Reason: safe Use the previously parsed DisCo information from ACPI to create the ALSA controls required by an SDCA Function. This maps all User and Application level SDCA Controls to ALSA controls. Typically controls marked with those access levels are just volumes and mutes. SDCA defines volume controls as an integer in 1/256ths of a dB and then provides a mechanism to specify what values are valid (range templates). Currently only a simple case of a single linear volume range with a power of 2 step size is supported. This allows the code to expose the volume control using a simple shift. This will need expanded in the future, to support more complex ranges and probably also some additional control types but this should be sufficient to for a first pass. Signed-off-by: Charles Keepax --- include/sound/sdca_asoc.h | 6 +- include/sound/sdca_function.h | 10 ++ sound/soc/sdca/sdca_asoc.c | 191 +++++++++++++++++++++++++++++++++- 3 files changed, 202 insertions(+), 5 deletions(-) diff --git a/include/sound/sdca_asoc.h b/include/sound/sdca_asoc.h index 414d461b6fc4a..d19e7e969283a 100644 --- a/include/sound/sdca_asoc.h +++ b/include/sound/sdca_asoc.h @@ -12,16 +12,20 @@ struct device; struct sdca_function_data; +struct snd_kcontrol_new; struct snd_soc_component_driver; struct snd_soc_dapm_route; struct snd_soc_dapm_widget; int sdca_asoc_count_component(struct device *dev, struct sdca_function_data *function, - int *num_widgets, int *num_routes); + int *num_widgets, int *num_routes, int *num_controls); int sdca_asoc_populate_dapm(struct device *dev, struct sdca_function_data *function, struct snd_soc_dapm_widget *widgets, struct snd_soc_dapm_route *routes); +int sdca_asoc_populate_controls(struct device *dev, + struct sdca_function_data *function, + struct snd_kcontrol_new *kctl); int sdca_asoc_populate_component(struct device *dev, struct sdca_function_data *function, diff --git a/include/sound/sdca_function.h b/include/sound/sdca_function.h index 447752f71286a..358caacc28764 100644 --- a/include/sound/sdca_function.h +++ b/include/sound/sdca_function.h @@ -206,6 +206,16 @@ enum sdca_fu_controls { SDCA_CTL_FU_LATENCY = 0x10, }; +/** + * enum sdca_volume_range - Column definitions for Q7.8dB volumes/gains + */ +enum sdca_volume_range { + SDCA_VOLUME_LINEAR_MIN = 0, + SDCA_VOLUME_LINEAR_MAX = 1, + SDCA_VOLUME_LINEAR_STEP = 2, + SDCA_VOLUME_LINEAR_NCOLS = 3, +}; + /** * enum sdca_xu_controls - SDCA Controls for Extension Unit * diff --git a/sound/soc/sdca/sdca_asoc.c b/sound/soc/sdca/sdca_asoc.c index dab434a8daac2..aced9cc27a520 100644 --- a/sound/soc/sdca/sdca_asoc.c +++ b/sound/soc/sdca/sdca_asoc.c @@ -21,6 +21,7 @@ #include #include #include +#include static struct sdca_control *selector_find_control(struct sdca_entity *entity, const int sel) @@ -69,13 +70,24 @@ static struct sdca_control_range *selector_find_range(struct device *dev, return control_find_range(dev, entity, control, cols, rows); } +static bool exported_control(struct sdca_control *control) +{ + /* No need to export control for something that only has one value */ + if (control->has_fixed) + return false; + + return control->layers & (SDCA_ACCESS_LAYER_USER | + SDCA_ACCESS_LAYER_APPLICATION); +} + int sdca_asoc_count_component(struct device *dev, struct sdca_function_data *function, - int *num_widgets, int *num_routes) + int *num_widgets, int *num_routes, int *num_controls) { - int i; + int i, j; *num_widgets = function->num_entities - 1; *num_routes = 0; + *num_controls = 0; for (i = 0; i < function->num_entities - 1; i++) { struct sdca_entity *entity = &function->entities[i]; @@ -94,6 +106,11 @@ int sdca_asoc_count_component(struct device *dev, struct sdca_function_data *fun } *num_routes += entity->num_sources; + + for (j = 0; j < entity->num_controls; j++) { + if (exported_control(&entity->controls[j])) + (*num_controls)++; + } } return 0; @@ -761,16 +778,172 @@ int sdca_asoc_populate_dapm(struct device *dev, struct sdca_function_data *funct } EXPORT_SYMBOL_NS(sdca_asoc_populate_dapm, "SND_SOC_SDCA"); +static int control_limit_kctl(struct device *dev, + struct sdca_entity *entity, + struct sdca_control *control, + struct snd_kcontrol_new *kctl) +{ + struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value; + struct sdca_control_range *range; + int min, max, step; + unsigned int *tlv; + int shift; + + if (control->type != SDCA_CTL_DATATYPE_Q7P8DB) + return 0; + + /* + * FIXME: For now only handle the simple case of a single linear range + */ + range = control_find_range(dev, entity, control, SDCA_VOLUME_LINEAR_NCOLS, 1); + if (!range) + return -EINVAL; + + min = sdca_range(range, SDCA_VOLUME_LINEAR_MIN, 0); + max = sdca_range(range, SDCA_VOLUME_LINEAR_MAX, 0); + step = sdca_range(range, SDCA_VOLUME_LINEAR_STEP, 0); + + min = sign_extend32(min, control->nbits - 1); + max = sign_extend32(max, control->nbits - 1); + + /* + * FIXME: Only support power of 2 step sizes as this can be supported + * by a simple shift. + */ + if (hweight32(step) != 1) { + dev_err(dev, "%s: %s: currently unsupported step size\n", + entity->label, control->label); + return -EINVAL; + } + + /* + * The SDCA volumes are in steps of 1/256th of a dB, a step down of + * 64 (shift of 6) gives 1/4dB. 1/4dB is the smallest unit that is also + * representable in the ALSA TLVs which are in 1/100ths of a dB. + */ + shift = max(ffs(step) - 1, 6); + + tlv = devm_kcalloc(dev, 4, sizeof(*tlv), GFP_KERNEL); + if (!tlv) + return -ENOMEM; + + tlv[0] = SNDRV_CTL_TLVT_DB_SCALE; + tlv[1] = 2 * sizeof(*tlv); + tlv[2] = (min * 100) >> 8; + tlv[3] = ((1 << shift) * 100) >> 8; + + mc->min = min >> shift; + mc->max = max >> shift; + mc->shift = shift; + mc->rshift = shift; + mc->sign_bit = 15 - shift; + + kctl->access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE; + kctl->tlv.p = tlv; + + return 0; +} + +static int populate_control(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct sdca_control *control, + struct snd_kcontrol_new **kctl) +{ + const char *control_suffix = ""; + const char *control_name; + struct soc_mixer_control *mc; + int index = 0; + int ret; + int cn; + + if (!exported_control(control)) + return 0; + + if (control->type == SDCA_CTL_DATATYPE_ONEBIT) + control_suffix = " Switch"; + + control_name = devm_kasprintf(dev, GFP_KERNEL, "%s %s%s", entity->label, + control->label, control_suffix); + if (!control_name) + return -ENOMEM; + + mc = devm_kmalloc(dev, sizeof(*mc), GFP_KERNEL); + if (!mc) + return -ENOMEM; + + for_each_set_bit(cn, (unsigned long *)&control->cn_list, + BITS_PER_TYPE(control->cn_list)) { + switch (index++) { + case 0: + mc->reg = SDW_SDCA_CTL(function->desc->adr, entity->id, + control->sel, cn); + mc->rreg = mc->reg; + break; + case 1: + mc->rreg = SDW_SDCA_CTL(function->desc->adr, entity->id, + control->sel, cn); + break; + default: + dev_err(dev, "%s: %s: only mono/stereo controls supported\n", + entity->label, control->label); + return -EINVAL; + } + } + + mc->min = 0; + mc->max = (0x1ull << control->nbits) - 1; + + (*kctl)->name = control_name; + (*kctl)->private_value = (unsigned long)mc; + (*kctl)->iface = SNDRV_CTL_ELEM_IFACE_MIXER; + (*kctl)->info = snd_soc_info_volsw; + (*kctl)->get = snd_soc_get_volsw; + (*kctl)->put = snd_soc_put_volsw; + + ret = control_limit_kctl(dev, entity, control, *kctl); + if (ret) + return ret; + + (*kctl)++; + + return 0; +} + +int sdca_asoc_populate_controls(struct device *dev, + struct sdca_function_data *function, + struct snd_kcontrol_new *kctl) +{ + int i, j; + int ret; + + for (i = 0; i < function->num_entities; i++) { + struct sdca_entity *entity = &function->entities[i]; + + for (j = 0; j < entity->num_controls; j++) { + ret = populate_control(dev, function, entity, + &entity->controls[j], &kctl); + if (ret) + return ret; + } + } + + return 0; +} +EXPORT_SYMBOL_NS(sdca_asoc_populate_controls, "SND_SOC_SDCA"); + int sdca_asoc_populate_component(struct device *dev, struct sdca_function_data *function, struct snd_soc_component_driver *component_drv) { struct snd_soc_dapm_widget *widgets; struct snd_soc_dapm_route *routes; - int num_widgets, num_routes; + struct snd_kcontrol_new *controls; + int num_widgets, num_routes, num_controls; int ret; - ret = sdca_asoc_count_component(dev, function, &num_widgets, &num_routes); + ret = sdca_asoc_count_component(dev, function, &num_widgets, &num_routes, + &num_controls); if (ret) return ret; @@ -782,14 +955,24 @@ int sdca_asoc_populate_component(struct device *dev, if (!routes) return -ENOMEM; + controls = devm_kcalloc(dev, num_controls, sizeof(*controls), GFP_KERNEL); + if (!controls) + return -ENOMEM; + ret = sdca_asoc_populate_dapm(dev, function, widgets, routes); if (ret) return ret; + ret = sdca_asoc_populate_controls(dev, function, controls); + if (ret) + return ret; + component_drv->dapm_widgets = widgets; component_drv->num_dapm_widgets = num_widgets; component_drv->dapm_routes = routes; component_drv->num_dapm_routes = num_routes; + component_drv->controls = controls; + component_drv->num_controls = num_controls; return 0; } From patchwork Fri Mar 21 16:39:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 14025755 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23393155A25; Fri, 21 Mar 2025 16:39:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=67.231.149.25 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742575201; cv=fail; b=VFtzm5sos6pXRirBnaMkca3oUFqCPS/7jkeFQoU1fBfJysD9M+v2ov3T12s6GMNH81VLRqPHkZ6d1sNWUrdNcHdAStfChHDj9RdY3ckhoQAKCDwI1krNEhkcjuL4wjFZUeTbPz0XgCy3tWuHyKcGh2v9Xdc2oL3gfityGuxbODc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742575201; c=relaxed/simple; bh=kTtnj5vPyQf1EaKg4K4mBY6cmbN1QO3ntw9+fMLguBI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=b3E9dul4fsET+90mjwrRmqHodkyEscuJRw6JvfXPHcXCIhsDuF57qyNC2p9r5I0SZJ+nOZhTNYHCRTfiDR38aj/VEzlpc8P+sb32jOHrYIfn89pblPHeX66PT+Ndr2pJk/HrzEJibCi/ddSnJTj8M+9ZS57aPXfq8uAcdlHKyB4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com; spf=pass smtp.mailfrom=cirrus.com; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b=ak7lojVr; dkim=pass (1024-bit key) header.d=cirrus4.onmicrosoft.com header.i=@cirrus4.onmicrosoft.com header.b=DcnQKaNN; arc=fail smtp.client-ip=67.231.149.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cirrus.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="ak7lojVr"; dkim=pass (1024-bit key) header.d=cirrus4.onmicrosoft.com header.i=@cirrus4.onmicrosoft.com header.b="DcnQKaNN" Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52L5KkjH026985; Fri, 21 Mar 2025 11:39:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= PODMain02222019; bh=vjoclKEm5S24mIZoyUynMutELDAnmPjkKAogAfxqbF4=; b= ak7lojVrQN7WeTQcNMV5QxRm4Opg5CHvhTObWyYT24+7d/2Ap0wFcffSUjwaLj5k srbHusCUXIrz+zCsNGhDVhYTnqb2gpu3Ot0K0JM3y3UisvxXkBJj6XeufJHgRo37 UY0m6OXpoNvKtS/e74ZLY5iL7DBY/kJoUe/j2x4p2cYO2S7MVl+uoCDIiq1iEAB1 S2dvVSrYs7J3yxlvnUWixTehy6mtErHlGy8+IGe8djbSQeR5Acpyqj8mq/akF1gx CMveGxhDDPuEzkiH85Dt9GKlYJs4oG5BZBUsARkmSW8N0ygujEe8qdzAudRaiCjG 3SFXtWgBQiHB9yTQ0Eifrw== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 45g9p6v7hj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Mar 2025 11:39:38 -0500 (CDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NvJ21uxzQ0hhCFIQXrVEirc99hxb4laJOCT1wQM4Wif2A2iGqvKsj6vZlj4wy4sa4LwNrvCKBHlyTWXLmuEFrNiN3M6NCGIFR1IkYjMdLxUWAnTustlKHqXcGa79vsot8otMxR4Z53milLhC9WE16IljB9PrLhlfPrcvnZ4ubSqglGpPruCjy07DqcI+5ibel0EIzQVi87J1Lzuw959X0J5ZkVVxmjMwQfACqo9xR8vR7bFa307jcBg8Mt6Se4mgI44vCtjwlrUJxtbyinb//lRyhrFfkXWJ1s2GFUDoMnC2zJMJPrOOhMTlI5hWvGse3qW8UtWH3SK2fLpvgESnVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=vjoclKEm5S24mIZoyUynMutELDAnmPjkKAogAfxqbF4=; b=dPTZLQzIPxdswcUmFbrGQwv5PSSktgvGH6HoW/JnXHwiwSpqO3ISd0RABLQgXzM1QHPBveJDHH8eU5BNW/APtvYFI5QXyY46WpL49ax0ybQlAKngylYZBo4Mh2dmzL5o2EAAiYRrS+r9AjWv3rYNhKh4D0+8m5cNAkksLQYIkFxdIGZOrha9iL2tFfZdkIrW0UxLJY8irIEfCdtmfY/g4HfxHlRE16pFcZ9Si+sdjRCozTCTYLF3Z4pWnLYu8lAsduWfYWQg53JwGRhThO5R3G2QhTA7mSVM+R5KTeiQ5xvz2f322NmbMCFWCcfz3wWcPnM9iRiUzPZvlmIsIpI6mw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 84.19.233.75) smtp.rcpttodomain=cirrus.com smtp.mailfrom=cirrus.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject header.from=opensource.cirrus.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus4.onmicrosoft.com; s=selector2-cirrus4-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vjoclKEm5S24mIZoyUynMutELDAnmPjkKAogAfxqbF4=; b=DcnQKaNNbFjdj/i9twgX4vTSAUyzgtmVc2jw98f1vr718hezQexJYqHwNhXHj9/dY4Fh4QCADqUZpuCxH2N1+UFbLz974/4BbUfMU+fVNhJl66v11V9WcuRloPh8+xiBzvZF/n5BiPdXWBCfNatNIBBUBhe2DabjMWj8/Q4787I= Received: from BN0PR04CA0134.namprd04.prod.outlook.com (2603:10b6:408:ed::19) by SJ0PR19MB4810.namprd19.prod.outlook.com (2603:10b6:a03:2ed::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.37; Fri, 21 Mar 2025 16:39:31 +0000 Received: from BN2PEPF0000449F.namprd02.prod.outlook.com (2603:10b6:408:ed:cafe::b3) by BN0PR04CA0134.outlook.office365.com (2603:10b6:408:ed::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.36 via Frontend Transport; Fri, 21 Mar 2025 16:39:30 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 84.19.233.75) smtp.mailfrom=cirrus.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=opensource.cirrus.com; Received-SPF: Fail (protection.outlook.com: domain of cirrus.com does not designate 84.19.233.75 as permitted sender) receiver=protection.outlook.com; client-ip=84.19.233.75; helo=edirelay1.ad.cirrus.com; Received: from edirelay1.ad.cirrus.com (84.19.233.75) by BN2PEPF0000449F.mail.protection.outlook.com (10.167.243.150) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.20 via Frontend Transport; Fri, 21 Mar 2025 16:39:30 +0000 Received: from ediswmail9.ad.cirrus.com (ediswmail9.ad.cirrus.com [198.61.86.93]) by edirelay1.ad.cirrus.com (Postfix) with ESMTPS id EE26440654D; Fri, 21 Mar 2025 16:39:28 +0000 (UTC) Received: from ediswws07.ad.cirrus.com (ediswws07.ad.cirrus.com [198.90.208.14]) by ediswmail9.ad.cirrus.com (Postfix) with ESMTP id C883382255E; Fri, 21 Mar 2025 16:39:28 +0000 (UTC) From: Charles Keepax To: broonie@kernel.org Cc: lgirdwood@gmail.com, pierre-louis.bossart@linux.dev, yung-chuan.liao@linux.intel.com, peter.ujfalusi@linux.intel.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com Subject: [PATCH 3/3] ASoC: SDCA: Create DAI drivers from DisCo Date: Fri, 21 Mar 2025 16:39:28 +0000 Message-Id: <20250321163928.793301-4-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250321163928.793301-1-ckeepax@opensource.cirrus.com> References: <20250321163928.793301-1-ckeepax@opensource.cirrus.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF0000449F:EE_|SJ0PR19MB4810:EE_ X-MS-Office365-Filtering-Correlation-Id: 43acb2ac-d2b2-422f-b50d-08dd6896f40d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|61400799027|82310400026; X-Microsoft-Antispam-Message-Info: EO/JOcPV9gS6iPeyL5Og8SHxv1U9DsFrS6/zV2aYKFKAYV/lZ5ivRkAx/KJvQB+R7xIN3EPNRyWGHp5HQ06HZ4DeGsQAdT6RsELfaofMikZXPM7W/D2l72B1M5ynM3508zYuavp9RNN3zcWILiL7tarwgqNM0efcQqlh4Uxb4zCtfIrO8PFjnrSbG9fE/ATIgmWmjgvM3Epe+xkhYzix8PfaWX0dyFByHocHpeW7Pa/nw7mAFDgnpxzZjS8pSTopKI5f3AkhTQRpwE9tkbyz0Py39W5EAsxMYqbYumsKDXSt9xO53XcenbmJWGud3/tjiF2iDFI9AK9ZszhhuAp/QaYgTEaES/avpic+gzcGQ25cWPRnIBmI/LhiLmTn0ZzbL0KLWLrw8DDmygD0GeEQ1m6ZMS9zOQ4gjK4WkWVvF+6PT2HqECeTmW380rtoOEeqHU0xbZntU0o8udZd4cztkPZ3wHtxjPeXMYodNjF9nrjHk2Ta34r91LE0bfKa+999P2qT9i7Kst8ebm3eGuUjsZ5HtEA2oRE38rxY8sBSD7lhnGCn0LziQ1pVVZgAZg+cFfkZ2SL8rmgpBR12U1qT6ep+JYz8AFEJT9/YrDYjCXP0UHt+p/wY9mYqREwWGseuWFnhInVt4DREjPjDifjzVRSvuHAE+TTz+B57tJkIFf5lI7bafIIjJFhNBnWmiDbnp9c0BqUdVDWyB0LN30l7a0k0iBV+HGwrJggi62QreRtFDplGw30dRf9KF+0JGukS6BUD0J03VKHzXdSp/XsLd6LREj4gf2HU8xbqL6XkGkQPwr2FIt5CLuWU1EKNijS8ep5J/ReY6HsAuUbIoxKYPkclv0UBwq++MHRnCC4ekzs2khF0w94J9qQieMmV7GG8buMzWhE+OabsIZ56yFSoViysfIo54JEphob7BBgKEfFMxcRAwU7xUC5QbQbP8XoL0jPs1Fq2i6pw/tncEycd8QGe4/wmRONnFq0UwS8oeSGqzPRsFnIZ3iUFaGJ8LP2ZuE2WjBgUy7C93b9tNgpo7SjiM3oJsSNYYNPyU5jGt8aW3CPFLpRt8zt0cYMyb+b2fGOzQ5KzgeS5rkv9LGJNxfuh23fjM4HzT9N6PHJmv+fR6IMTAiW0R41YJXvXLo7fihANgckXjDreRE+CPS5IUcEIS9u8UB5HC0kUCRwSS+SxDzlB76ZOplHxWr1xuhHNdLKUwOsDyWMpUoXCNHPhekG0gK7lfw7/wMYMAb/9ke+C19kyVFsM1C7+3oU1szAmDQcFMhlZYfF//pkIAOqjf4XPw27jDLajrOT4dtbhy6Di9WvF8NYj7KKJJOi33pnw8uWGRRbR/MZ0Xho54QAm78pHN0o7j0gzYVxF5gS26y7Rarepdq/r8C+Fa/af15vgnll4oQ+NQyzvg7eC7T+OQJ22Iyk3s6j5C6aiO0NadcYelobXlef7/ohScr9VGkUCd2gCpU6Aae0KDMTUaCQs9d8HJEVPA4okGry8E6fABP8= X-Forefront-Antispam-Report: CIP:84.19.233.75;CTRY:GB;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:edirelay1.ad.cirrus.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(61400799027)(82310400026);DIR:OUT;SFP:1102; X-OriginatorOrg: opensource.cirrus.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2025 16:39:30.3369 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 43acb2ac-d2b2-422f-b50d-08dd6896f40d X-MS-Exchange-CrossTenant-Id: bec09025-e5bc-40d1-a355-8e955c307de8 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=bec09025-e5bc-40d1-a355-8e955c307de8;Ip=[84.19.233.75];Helo=[edirelay1.ad.cirrus.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF0000449F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR19MB4810 X-Authority-Analysis: v=2.4 cv=Vcz3PEp9 c=1 sm=1 tr=0 ts=67dd964a cx=c_pps a=LxkDbUgDkQmSfly3BTNqMw==:117 a=h1hSm8JtM9GN1ddwPAif2w==:17 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=Vs1iUdzkB0EA:10 a=s63m1ICgrNkA:10 a=RWc_ulEos4gA:10 a=w1d2syhTAAAA:8 a=mtmGHodxziJHnfEkOdcA:9 a=BGLuxUZjE2igh1l4FkT-:22 X-Proofpoint-GUID: vuosxof-ybqcyKHF1lcJtYFpsH9LLaMR X-Proofpoint-ORIG-GUID: vuosxof-ybqcyKHF1lcJtYFpsH9LLaMR X-Proofpoint-Spam-Reason: safe Use the previously parsed DisCo information from ACPI to create the DAI drivers required to connect an SDCA Function into an ASoC soundcard. Create DAI driver structures and populate the supported sample rates and sample widths into them based on the Input/Output Terminal and any attach Clock Source entities. More complex relationships with channels etc. will be added later as constraints as part of the DAI startup. Signed-off-by: Charles Keepax --- include/sound/sdca_asoc.h | 12 +- include/sound/sdca_function.h | 23 ++++ sound/soc/sdca/sdca_asoc.c | 209 +++++++++++++++++++++++++++++++++- 3 files changed, 238 insertions(+), 6 deletions(-) diff --git a/include/sound/sdca_asoc.h b/include/sound/sdca_asoc.h index d19e7e969283a..9121531f08260 100644 --- a/include/sound/sdca_asoc.h +++ b/include/sound/sdca_asoc.h @@ -14,11 +14,14 @@ struct device; struct sdca_function_data; struct snd_kcontrol_new; struct snd_soc_component_driver; +struct snd_soc_dai_driver; +struct snd_soc_dai_ops; struct snd_soc_dapm_route; struct snd_soc_dapm_widget; int sdca_asoc_count_component(struct device *dev, struct sdca_function_data *function, - int *num_widgets, int *num_routes, int *num_controls); + int *num_widgets, int *num_routes, int *num_controls, + int *num_dais); int sdca_asoc_populate_dapm(struct device *dev, struct sdca_function_data *function, struct snd_soc_dapm_widget *widgets, @@ -26,9 +29,14 @@ int sdca_asoc_populate_dapm(struct device *dev, struct sdca_function_data *funct int sdca_asoc_populate_controls(struct device *dev, struct sdca_function_data *function, struct snd_kcontrol_new *kctl); +int sdca_asoc_populate_dais(struct device *dev, struct sdca_function_data *function, + struct snd_soc_dai_driver *dais, + const struct snd_soc_dai_ops *ops); int sdca_asoc_populate_component(struct device *dev, struct sdca_function_data *function, - struct snd_soc_component_driver *component_drv); + struct snd_soc_component_driver *component_drv, + struct snd_soc_dai_driver **dai_drv, int *num_dai_drv, + const struct snd_soc_dai_ops *ops); #endif // __SDCA_ASOC_H__ diff --git a/include/sound/sdca_function.h b/include/sound/sdca_function.h index 358caacc28764..c995cf51a9f21 100644 --- a/include/sound/sdca_function.h +++ b/include/sound/sdca_function.h @@ -168,6 +168,20 @@ enum sdca_ot_controls { SDCA_CTL_OT_NDAI_PACKETTYPE = 0x17, }; +/** + * enum sdca_usage_range - Column definitions for Usage + */ +enum sdca_usage_range { + SDCA_USAGE_NUMBER = 0, + SDCA_USAGE_CBN = 1, + SDCA_USAGE_SAMPLE_RATE = 2, + SDCA_USAGE_SAMPLE_WIDTH = 3, + SDCA_USAGE_FULL_SCALE = 4, + SDCA_USAGE_NOISE_FLOOR = 5, + SDCA_USAGE_TAG = 6, + SDCA_USAGE_NCOLS = 7, +}; + /** * enum sdca_mu_controls - SDCA Controls for Mixer Unit * @@ -246,6 +260,15 @@ enum sdca_cs_controls { SDCA_CTL_CS_SAMPLERATEINDEX = 0x10, }; +/** + * enum sdca_samplerateindex_range - Column definitions for SampleRateIndex + */ +enum sdca_samplerateindex_range { + SDCA_SAMPLERATEINDEX_INDEX = 0, + SDCA_SAMPLERATEINDEX_RATE = 1, + SDCA_SAMPLERATEINDEX_NCOLS = 2, +}; + /** * enum sdca_cx_controls - SDCA Controls for Clock Selector * diff --git a/sound/soc/sdca/sdca_asoc.c b/sound/soc/sdca/sdca_asoc.c index aced9cc27a520..67a182a7616ef 100644 --- a/sound/soc/sdca/sdca_asoc.c +++ b/sound/soc/sdca/sdca_asoc.c @@ -81,13 +81,15 @@ static bool exported_control(struct sdca_control *control) } int sdca_asoc_count_component(struct device *dev, struct sdca_function_data *function, - int *num_widgets, int *num_routes, int *num_controls) + int *num_widgets, int *num_routes, int *num_controls, + int *num_dais) { int i, j; *num_widgets = function->num_entities - 1; *num_routes = 0; *num_controls = 0; + *num_dais = 0; for (i = 0; i < function->num_entities - 1; i++) { struct sdca_entity *entity = &function->entities[i]; @@ -97,6 +99,7 @@ int sdca_asoc_count_component(struct device *dev, struct sdca_function_data *fun case SDCA_ENTITY_TYPE_OT: *num_routes += !!entity->iot.clock; *num_routes += !!entity->iot.is_dataport; + *num_dais += !!entity->iot.is_dataport; break; case SDCA_ENTITY_TYPE_PDE: *num_routes += entity->pde.num_managed; @@ -932,18 +935,205 @@ int sdca_asoc_populate_controls(struct device *dev, } EXPORT_SYMBOL_NS(sdca_asoc_populate_controls, "SND_SOC_SDCA"); +static unsigned int rate_find_mask(unsigned int rate) +{ + switch (rate) { + case 0: + return SNDRV_PCM_RATE_8000_768000; + case 5512: + return SNDRV_PCM_RATE_5512; + case 8000: + return SNDRV_PCM_RATE_8000; + case 11025: + return SNDRV_PCM_RATE_11025; + case 16000: + return SNDRV_PCM_RATE_16000; + case 22050: + return SNDRV_PCM_RATE_22050; + case 32000: + return SNDRV_PCM_RATE_32000; + case 44100: + return SNDRV_PCM_RATE_44100; + case 48000: + return SNDRV_PCM_RATE_48000; + case 64000: + return SNDRV_PCM_RATE_64000; + case 88200: + return SNDRV_PCM_RATE_88200; + case 96000: + return SNDRV_PCM_RATE_96000; + case 176400: + return SNDRV_PCM_RATE_176400; + case 192000: + return SNDRV_PCM_RATE_192000; + case 352800: + return SNDRV_PCM_RATE_352800; + case 384000: + return SNDRV_PCM_RATE_384000; + case 705600: + return SNDRV_PCM_RATE_705600; + case 768000: + return SNDRV_PCM_RATE_768000; + case 12000: + return SNDRV_PCM_RATE_12000; + case 24000: + return SNDRV_PCM_RATE_24000; + case 128000: + return SNDRV_PCM_RATE_128000; + default: + return 0; + } +} + +static u64 width_find_mask(unsigned int bits) +{ + switch (bits) { + case 0: + return SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S20_LE | SNDRV_PCM_FMTBIT_S24_LE | + SNDRV_PCM_FMTBIT_S32_LE; + case 8: + return SNDRV_PCM_FMTBIT_S8; + case 16: + return SNDRV_PCM_FMTBIT_S16_LE; + case 20: + return SNDRV_PCM_FMTBIT_S20_LE; + case 24: + return SNDRV_PCM_FMTBIT_S24_LE; + case 32: + return SNDRV_PCM_FMTBIT_S32_LE; + default: + return 0; + } +} + +static int populate_rate_format(struct device *dev, + struct sdca_function_data *function, + struct sdca_entity *entity, + struct snd_soc_pcm_stream *stream) +{ + struct sdca_control_range *range; + unsigned int sample_rate, sample_width; + unsigned int clock_rates = 0; + unsigned int rates = 0; + u64 formats = 0; + int sel, i; + + switch (entity->type) { + case SDCA_ENTITY_TYPE_IT: + sel = SDCA_CTL_IT_USAGE; + break; + case SDCA_ENTITY_TYPE_OT: + sel = SDCA_CTL_OT_USAGE; + break; + default: + dev_err(dev, "%s: entity type has no usage control\n", + entity->label); + return -EINVAL; + } + + if (entity->iot.clock) { + range = selector_find_range(dev, entity->iot.clock, + SDCA_CTL_CS_SAMPLERATEINDEX, + SDCA_SAMPLERATEINDEX_NCOLS, 0); + if (!range) + return -EINVAL; + + for (i = 0; i < range->rows; i++) { + sample_rate = sdca_range(range, SDCA_SAMPLERATEINDEX_RATE, i); + clock_rates |= rate_find_mask(sample_rate); + } + } else { + clock_rates = UINT_MAX; + } + + range = selector_find_range(dev, entity, sel, SDCA_USAGE_NCOLS, 0); + if (!range) + return -EINVAL; + + for (i = 0; i < range->rows; i++) { + sample_rate = sdca_range(range, SDCA_USAGE_SAMPLE_RATE, i); + sample_rate = rate_find_mask(sample_rate); + + if (sample_rate & clock_rates) { + rates |= sample_rate; + + sample_width = sdca_range(range, SDCA_USAGE_SAMPLE_WIDTH, i); + formats |= width_find_mask(sample_width); + } + } + + stream->formats = formats; + stream->rates = rates; + + return 0; +} + +int sdca_asoc_populate_dais(struct device *dev, struct sdca_function_data *function, + struct snd_soc_dai_driver *dais, + const struct snd_soc_dai_ops *ops) +{ + int i, j; + int ret; + + for (i = 0, j = 0; i < function->num_entities - 1; i++) { + struct sdca_entity *entity = &function->entities[i]; + struct snd_soc_pcm_stream *stream; + const char *stream_suffix; + + switch (entity->type) { + case SDCA_ENTITY_TYPE_IT: + stream = &dais[j].playback; + stream_suffix = "Playback"; + break; + case SDCA_ENTITY_TYPE_OT: + stream = &dais[j].capture; + stream_suffix = "Capture"; + break; + default: + continue; + } + + if (!entity->iot.is_dataport) + continue; + + stream->stream_name = devm_kasprintf(dev, GFP_KERNEL, "%s %s", + entity->label, stream_suffix); + if (!stream->stream_name) + return -ENOMEM; + /* Channels will be further limited by constraints */ + stream->channels_min = 1; + stream->channels_max = SDCA_MAX_CHANNEL_COUNT; + + ret = populate_rate_format(dev, function, entity, stream); + if (ret) + return ret; + + dais[j].id = i; + dais[j].name = entity->label; + dais[j].ops = ops; + j++; + } + + return 0; +} +EXPORT_SYMBOL_NS(sdca_asoc_populate_dais, "SND_SOC_SDCA"); + int sdca_asoc_populate_component(struct device *dev, struct sdca_function_data *function, - struct snd_soc_component_driver *component_drv) + struct snd_soc_component_driver *component_drv, + struct snd_soc_dai_driver **dai_drv, int *num_dai_drv, + const struct snd_soc_dai_ops *ops) { struct snd_soc_dapm_widget *widgets; struct snd_soc_dapm_route *routes; struct snd_kcontrol_new *controls; - int num_widgets, num_routes, num_controls; + struct snd_soc_dai_driver *dais; + int num_widgets, num_routes, num_controls, num_dais; int ret; ret = sdca_asoc_count_component(dev, function, &num_widgets, &num_routes, - &num_controls); + &num_controls, &num_dais); if (ret) return ret; @@ -959,6 +1149,10 @@ int sdca_asoc_populate_component(struct device *dev, if (!controls) return -ENOMEM; + dais = devm_kcalloc(dev, num_dais, sizeof(*dais), GFP_KERNEL); + if (!dais) + return -ENOMEM; + ret = sdca_asoc_populate_dapm(dev, function, widgets, routes); if (ret) return ret; @@ -967,6 +1161,10 @@ int sdca_asoc_populate_component(struct device *dev, if (ret) return ret; + ret = sdca_asoc_populate_dais(dev, function, dais, ops); + if (ret) + return ret; + component_drv->dapm_widgets = widgets; component_drv->num_dapm_widgets = num_widgets; component_drv->dapm_routes = routes; @@ -974,6 +1172,9 @@ int sdca_asoc_populate_component(struct device *dev, component_drv->controls = controls; component_drv->num_controls = num_controls; + *dai_drv = dais; + *num_dai_drv = num_dais; + return 0; } EXPORT_SYMBOL_NS(sdca_asoc_populate_component, "SND_SOC_SDCA");