Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5282015rdb; Wed, 13 Dec 2023 04:36:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgksi6VpCCiv+ucGG0qDHaOcLGUyMFHw81kiY/x99WHyQLDlj/2dkJkuFchxiQ0EptjqWN X-Received: by 2002:aa7:88cf:0:b0:6ce:7a8f:af7c with SMTP id k15-20020aa788cf000000b006ce7a8faf7cmr9078104pff.12.1702470986795; Wed, 13 Dec 2023 04:36:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702470986; cv=none; d=google.com; s=arc-20160816; b=jzcjwoyWM1Wb9mTxLnYt9287vvLtiE8W78jkB4kRAHj3zMdqBk5L+V5aGu2YKiIJFi 5blG2ymz7LZ5ul9pTLGKPIYdlkuT9WJX/9RlY1aShzcWetOJosp13x7idIs3vw63YWRL 8L8ywBUpJmCI0/Tho/6QE6sIVmxvg0vPlEtnZZXHR5fUwx5uxpTpTCWYTF1EqXWukQAF /AZVYeEGGKCpVsh9qCOk1UjmqH8M6K4RvJ71Ld9az790CmH1aAQlc8eHTmzWb72Ux4DL 79TkU6iMXtWBGQUcwWS44PuQMVtKUESxwMdHdn41GY/rfVe1aVkzMX5X7NsuvzjRdWTq km/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=rYGQmeoSqfkicHbElfiPvY8CF43myiqrL//zoYaASs8=; fh=AjXMO6p+MtnAhJgZ2dXRvhWyXDMGQ+GS3ooIwv5cGEg=; b=xPDCaryXNCW8brxc9iO2/udqDBz2TFb1/GaMrCJGXLcYJJZ6sCI0P7xldiN00wV4fK bDSkSDVX5r0zDQ5B5X40tgzt9VrpfWJ9TcCylt+p1y3Ro+MCOUpjdWUfg/TteRe+FWlX LsSEI3unfRUe/fggrjmKhYMpQ//tHWnOViUg6ioD+PBL8/kNdYsyh6A6+fWn8Koss28z AYipsbMSQfRovGuEiupLPJmLm4Q3w8c6yM+MFYyn9aS3OiYIn3S6W9JrRdUO/qRjv5fs 5+6naIk8D2gYsFT0oSzwNBZaNOI7wn6qbH1h1HRkFbtImUJm7CsEiYOymec06Vp0Whwk 0RjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="RBn/ou01"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id s16-20020a056a00195000b006cdfca5f4dbsi9736695pfk.106.2023.12.13.04.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 04:36:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="RBn/ou01"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 155E3803D449; Wed, 13 Dec 2023 04:36:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233414AbjLMMgF (ORCPT + 99 others); Wed, 13 Dec 2023 07:36:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233303AbjLMMgE (ORCPT ); Wed, 13 Dec 2023 07:36:04 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD130A4; Wed, 13 Dec 2023 04:36:10 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6cea5548eb2so6084863b3a.0; Wed, 13 Dec 2023 04:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702470970; x=1703075770; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=rYGQmeoSqfkicHbElfiPvY8CF43myiqrL//zoYaASs8=; b=RBn/ou01ctheAZXDuwbzJmyOT9uxtab/kI9ipYWCqUJv0G9K6MS1CXSYK2SYAZCAD/ /rQFuxskJ9WDepLLmiCd+EgJBnpgs2TgIg6Edz2THkS6mJWQDJc0rynzdvJRyIZWMgFD XjYTfda0kMc2/mdnS1/e9Csyjq1IkPuqGFzSn9IHejOVEBDNPzSILBevyj6WcZFaJXgV SNf1W2Xq8FVRaP8Ey3TmnjRs/vAYaXjliXDZ+32DwE1iLsngA4JpSHI77JAwcfyyx0Dw p3iUrYqAbwNZCeXhTzapJy/wTyPAfPa+YnoI2USpX4K2uxXvIrDI4wwTeLh5jDWab6vK D+YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702470970; x=1703075770; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rYGQmeoSqfkicHbElfiPvY8CF43myiqrL//zoYaASs8=; b=VoyFt6gp+IURhoFOOLZrnMNEXI2bm04cefBvoJYaK4jCbF5LZdOApOm5ACozuYc6Pj cIlIfbsccseJM5c4w0QnOpf6oeMAS2hazAq7gyzkK8VKzFTPB/+RQqy3+99tjM6cA0Lf dQ83HG5tndGFJ0v7LxDAsvNURP/3tZvXi9+LHK8ibQ4vuj+HVp17+5fcjoQpOQY8EkG5 0V5gd9iqBQLNZLOTDd95zaODROKMwpdO5B3t7TRE9ru9Oq8Nvcd5hAmk8EAD1zUMgRu4 0tQyubXjsY1SFFg8ja7qntBiN5zWPEub9jBlOyysyt2yO4m9gJBiUN37VDTuAJsf8k2/ gIaQ== X-Gm-Message-State: AOJu0Yx8a4ltvw7mCDmLKbxP8Lttf5t8m1lBoeqc7fc47zbHTUWfQ1fY hrcP1w0uvBTG8lkwhYfW4oM= X-Received: by 2002:a05:6a00:2354:b0:6cd:e2c2:13d7 with SMTP id j20-20020a056a00235400b006cde2c213d7mr9982036pfj.23.1702470970088; Wed, 13 Dec 2023 04:36:10 -0800 (PST) Received: from localhost.localdomain ([117.189.237.103]) by smtp.gmail.com with ESMTPSA id x3-20020a056a00188300b0068fe5a5a566sm10193584pfh.142.2023.12.13.04.36.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 04:36:09 -0800 (PST) From: Jianhua Lu To: Srinivas Kandagatla , Banajit Goswami , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Jianhua Lu Subject: [PATCH v3 1/4] ASoC: qcom: common: Add qcom_snd_tdm_hw_params function Date: Wed, 13 Dec 2023 20:35:53 +0800 Message-ID: <20231213123556.20469-1-lujianhua000@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 13 Dec 2023 04:36:24 -0800 (PST) Add qcom TDM setup function to support TDM ports for qcom platform. Signed-off-by: Jianhua Lu --- Changes in v3: 1. new patch 2. split qcom_snd_tdm_hw_params function from [Patch v2 1/2] to here sound/soc/qcom/common.c | 69 +++++++++++++++++++++++++++++++++++++++++ sound/soc/qcom/common.h | 2 ++ 2 files changed, 71 insertions(+) diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c index 483bbf53a541..c0ab201416ef 100644 --- a/sound/soc/qcom/common.c +++ b/sound/soc/qcom/common.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "common.h" @@ -13,6 +14,8 @@ static const struct snd_soc_dapm_widget qcom_jack_snd_widgets[] = { SND_SOC_DAPM_MIC("Mic Jack", NULL), }; +static unsigned int tdm_slot_offset[8] = { 0, 4, 8, 12, 16, 20, 24, 28 }; + int qcom_snd_parse_of(struct snd_soc_card *card) { struct device_node *np; @@ -239,4 +242,70 @@ int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd, return 0; } EXPORT_SYMBOL_GPL(qcom_snd_wcd_jack_setup); + +int qcom_snd_tdm_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + int slots = ARRAY_SIZE(tdm_slot_offset); + int channels, slot_width, tx_mask, rx_mask; + int ret; + + switch (params_format(params)) { + case SNDRV_PCM_FORMAT_S16_LE: + slot_width = 16; + break; + case SNDRV_PCM_FORMAT_S24_LE: + slot_width = 24; + break; + case SNDRV_PCM_FORMAT_S32_LE: + slot_width = 32; + break; + default: + dev_err(rtd->dev, "%s: invalid param format 0x%x\n", __func__, + params_format(params)); + return -EINVAL; + } + + channels = params_channels(params); + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + tx_mask = 0; + rx_mask = BIT(channels) - 1; + ret = snd_soc_dai_set_tdm_slot(cpu_dai, tx_mask, rx_mask, slots, slot_width); + if (ret < 0) { + dev_err(rtd->dev, "%s: failed to set tdm slot, err:%d\n", + __func__, ret); + return ret; + } + + ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL, channels, + tdm_slot_offset); + if (ret < 0) { + dev_err(rtd->dev, "%s: failed to set channel map, err:%d\n", + __func__, ret); + return ret; + } + } else { + tx_mask = 0xf; + rx_mask = 0; + ret = snd_soc_dai_set_tdm_slot(cpu_dai, tx_mask, rx_mask, slots, slot_width); + if (ret < 0) { + dev_err(rtd->dev, "%s: failed to set tdm slot, err:%d\n", + __func__, ret); + return ret; + } + + ret = snd_soc_dai_set_channel_map(cpu_dai, channels, + tdm_slot_offset, 0, NULL); + if (ret < 0) { + dev_err(rtd->dev, "%s: failed to set channel map, err:%d\n", + __func__, ret); + return ret; + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(qcom_snd_tdm_hw_params); MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/qcom/common.h b/sound/soc/qcom/common.h index d7f80ee5ae26..b583110f556e 100644 --- a/sound/soc/qcom/common.h +++ b/sound/soc/qcom/common.h @@ -9,5 +9,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card); int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd, struct snd_soc_jack *jack, bool *jack_setup); +int qcom_snd_tdm_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params); #endif -- 2.41.0