From patchwork Tue Nov 23 16:31:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Tanure X-Patchwork-Id: 12636225 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 0D38FC4167B for ; Wed, 24 Nov 2021 07:10:41 +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 3F1A11716; Wed, 24 Nov 2021 08:09:49 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3F1A11716 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1637737839; bh=kTayGuvFuy0HJdX7S0+gh7wj25KjM0NjFA7hVWhtRjA=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LvuYf3GdtpvlOCMNkvK4eOTZ1V5C4QN1e9ZjsuxIV5MjAAoV4q7z3by2tlSo3jpd4 MNMZUAWiW3WpGGRN9dTYdL6L8durEgehYseS0w0Hc4j8Wdotuz/iAje9jctIJ3PKZ6 0miIzmS5WdGb8d015aOfKfOCNR85GJn17a7gx8gs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4D7BDF80528; Wed, 24 Nov 2021 08:06:03 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3CD71F804E6; Tue, 23 Nov 2021 17:32:14 +0100 (CET) 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 alsa1.perex.cz (Postfix) with ESMTPS id 0E21BF804FB for ; Tue, 23 Nov 2021 17:32:02 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0E21BF804FB Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="mBzqTLJD" Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1AN7k0BC013868; Tue, 23 Nov 2021 10:32:00 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=ATn3v5FpDaLdr5ZeC+/nTRw9PYiV4Lv2gQEjGJ7czWI=; b=mBzqTLJDKTVBPjfb9a4WI/MiWBGfbrQz+OjQcQFgeGUQBveDMXpmBfxRZpcFOdTbTThD Vpo7tLnw4IJQnsmmycRgDAZNQCYJqsIbE+2iZroN/Pg50oRwtp85OOhfqRBy4wDS3qhL tORbtmBsTguEGDHv/WxfvRwtOdn9HeJ9AmRyM5vnVRU9UCpEFewbIRaejuEI850xZmPw iPOlyQc3c5hRI1ayRboOCKXFU40AkVR9XAkJqfore6FEBLr2MdCnyJm8H5PcTSt4QXs3 qesJlNygBxBovmx0duzdWUDfBkUogxamm0wdAmm7pFsZ3rGDxKubdJL5WQVpVzOCEkf0 mA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3cg3v7a220-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 23 Nov 2021 10:31:59 -0600 Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Tue, 23 Nov 2021 16:31:57 +0000 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Tue, 23 Nov 2021 16:31:57 +0000 Received: from aryzen.ad.cirrus.com (unknown [198.61.65.11]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 722922A1; Tue, 23 Nov 2021 16:31:56 +0000 (UTC) From: Lucas Tanure To: "Rafael J . Wysocki" , Len Brown , Hans de Goede , Mark Gross , "Liam Girdwood" , Jaroslav Kysela , Mark Brown , Takashi Iwai , Kailang Yang , Shuming Fan , "Pierre-Louis Bossart" , David Rhodes , Vitaly Rodionov Subject: [PATCH 08/11] ASoC: cs35l41: Create shared function for setting channels Date: Tue, 23 Nov 2021 16:31:46 +0000 Message-ID: <20211123163149.1530535-9-tanureal@opensource.cirrus.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211123163149.1530535-1-tanureal@opensource.cirrus.com> References: <20211123163149.1530535-1-tanureal@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: YvymC5K6L6g4PSNiPa0k72Ok9bN1h3kx X-Proofpoint-ORIG-GUID: YvymC5K6L6g4PSNiPa0k72Ok9bN1h3kx X-Proofpoint-Spam-Reason: safe X-Mailman-Approved-At: Wed, 24 Nov 2021 08:05:53 +0100 Cc: Chris Chiu , Alexandre Belloni , Jack Yu , Lucas Tanure , Arnd Bergmann , Jeremy Szu , patches@opensource.cirrus.com, Elia Devito , alsa-devel@alsa-project.org, Werner Sembach , platform-driver-x86@vger.kernel.org, Hui Wang , linux-acpi@vger.kernel.org, Lars-Peter Clausen , Sami Loone , Cameron Berkenpas , linux-kernel@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" ASoC and HDA will use the same register to set channels for the device Signed-off-by: Lucas Tanure --- include/sound/cs35l41.h | 3 +++ sound/soc/codecs/cs35l41-lib.c | 32 ++++++++++++++++++++++++++++++++ sound/soc/codecs/cs35l41.c | 30 +++--------------------------- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/include/sound/cs35l41.h b/include/sound/cs35l41.h index e33bc0ed502d..219f23f643a6 100644 --- a/include/sound/cs35l41.h +++ b/include/sound/cs35l41.h @@ -766,5 +766,8 @@ extern struct regmap_config cs35l41_regmap_spi; int cs35l41_init_supplies(struct device *dev, struct regulator_bulk_data *supplies); int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap); int cs35l41_register_errata_patch(struct device *dev, struct regmap *reg, unsigned int reg_revid); +int cs35l41_set_channels(struct device *dev, struct regmap *reg, + unsigned int tx_num, unsigned int *tx_slot, + unsigned int rx_num, unsigned int *rx_slot); #endif /* __CS35L41_H */ diff --git a/sound/soc/codecs/cs35l41-lib.c b/sound/soc/codecs/cs35l41-lib.c index b7a6dbf7fb8b..5bb733bb02a0 100644 --- a/sound/soc/codecs/cs35l41-lib.c +++ b/sound/soc/codecs/cs35l41-lib.c @@ -951,3 +951,35 @@ int cs35l41_register_errata_patch(struct device *dev, struct regmap *reg, unsign return ret; } + +int cs35l41_set_channels(struct device *dev, struct regmap *reg, + unsigned int tx_num, unsigned int *tx_slot, + unsigned int rx_num, unsigned int *rx_slot) +{ + unsigned int val, mask; + int i; + + if (tx_num > 4 || rx_num > 2) + return -EINVAL; + + val = 0; + mask = 0; + for (i = 0; i < rx_num; i++) { + dev_dbg(dev, "rx slot %d position = %d\n", i, rx_slot[i]); + val |= rx_slot[i] << (i * 8); + mask |= 0x3F << (i * 8); + } + regmap_update_bits(reg, CS35L41_SP_FRAME_RX_SLOT, mask, val); + + val = 0; + mask = 0; + for (i = 0; i < tx_num; i++) { + dev_dbg(dev, "tx slot %d position = %d\n", i, tx_slot[i]); + val |= tx_slot[i] << (i * 8); + mask |= 0x3F << (i * 8); + } + regmap_update_bits(reg, CS35L41_SP_FRAME_TX_SLOT, mask, val); + + return 0; +} + diff --git a/sound/soc/codecs/cs35l41.c b/sound/soc/codecs/cs35l41.c index b1202ac9f264..e61736daef62 100644 --- a/sound/soc/codecs/cs35l41.c +++ b/sound/soc/codecs/cs35l41.c @@ -746,36 +746,12 @@ static const struct cs_dsp_region cs35l41_dsp1_regions[] = { {. type = WMFW_ADSP2_YM, .base = CS35L41_DSP1_YMEM_UNPACK24_0}, }; -static int cs35l41_set_channel_map(struct snd_soc_dai *dai, unsigned int tx_num, - unsigned int *tx_slot, unsigned int rx_num, - unsigned int *rx_slot) +static int cs35l41_set_channel_map(struct snd_soc_dai *dai, unsigned int tx_n, + unsigned int *tx_slot, unsigned int rx_n, unsigned int *rx_slot) { struct cs35l41_private *cs35l41 = snd_soc_component_get_drvdata(dai->component); - unsigned int val, mask; - int i; - - if (tx_num > 4 || rx_num > 2) - return -EINVAL; - val = 0; - mask = 0; - for (i = 0; i < rx_num; i++) { - dev_dbg(cs35l41->dev, "rx slot %d position = %d\n", i, rx_slot[i]); - val |= rx_slot[i] << (i * 8); - mask |= 0x3F << (i * 8); - } - regmap_update_bits(cs35l41->regmap, CS35L41_SP_FRAME_RX_SLOT, mask, val); - - val = 0; - mask = 0; - for (i = 0; i < tx_num; i++) { - dev_dbg(cs35l41->dev, "tx slot %d position = %d\n", i, tx_slot[i]); - val |= tx_slot[i] << (i * 8); - mask |= 0x3F << (i * 8); - } - regmap_update_bits(cs35l41->regmap, CS35L41_SP_FRAME_TX_SLOT, mask, val); - - return 0; + return cs35l41_set_channels(cs35l41->dev, cs35l41->regmap, tx_n, tx_slot, rx_n, rx_slot); } static int cs35l41_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)