From patchwork Wed Feb 28 01:36:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 207607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3080140dyb; Tue, 27 Feb 2024 17:50:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX3UdJigybhOk/PRxMMQCQ1wdJJsZmL+T1aL5atnK9XPwFffpPpEatnTC8lShp87puCWxRYMBY77vOoG+b61/Gifs1Hzg== X-Google-Smtp-Source: AGHT+IFRV903Jrztdt06MwZ2+WyKkvX36J9IjFDl8muq0ZadZs9b3e9U+51WjKjycg79Xc2EKVnh X-Received: by 2002:ac8:580a:0:b0:42e:768e:6682 with SMTP id g10-20020ac8580a000000b0042e768e6682mr2106669qtg.9.1709085001153; Tue, 27 Feb 2024 17:50:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709085001; cv=pass; d=google.com; s=arc-20160816; b=B5Sctmfk2U9gNj/o40IwDcRYSgqxd6+PlYarnbVMtze6jbDiuzrPcAJRWxC6XrZre/ BxyQnce/1sURGbtyYAX0CmCyKTTz2orVrx9ObApiHyx0CX9yKAqgxzH1Ebyp8e+lMtLN 6ZW9/6Z0ltwKWOOWSkgQV5BebrZb9DCYUbUeMz5xtopl/ENnx+Znmt0P+FDMjxqaCnfl RiejIx2NSF8VvV1TYA1c01FYqT/OQpzjCTdy7UOclkrfiHKe2xWMKn53z4joBXG3Z582 +X5fsLIsyvqEP8cmNwB2XAJmcIJGEYj6GUnd0/V5dDNeE/CHm/JrQUWcmYW9pyXcBXBE QfPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Hs3fpdD+l1O4EfSuPsgbK4Q6nEGroTvEVrnQjm293OU=; fh=VKrp0Y7I/+wT36BfKZ6oI/4N9BIwFCn9zerObkOrgGw=; b=jxGXX771EB9QQG+QcdtgvKw4rw4d1D+6y04GO/DQZtSCOJizLdgMSVfC5HSAFooMHn eWPo9945lb8HzEhWzAlIdBRnDAOKesB0XBhXdyJddWi2vpzENfH+X6RV3A2wCf+f9R2O P39+5fyFu58/gwz8h9nBGuux3gQgcZRyQ1PcYip1r15pMfYOweUYpBVP4SIV3AsZAAMl D/IQAWHhT5TH/cTe/SRMLw0KZR1s7CYdL6qyQEtMWXqWJOVyXgJnSZ2qdgPKiaGY3AGc jUE9DBXqhvaIAuCHNH/U794vsSX2Rzj4C1lB5xcsSzGkzwEKhLq2vLab4dHZGGj9pXew A9YA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="Z/rQbEIc"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-84373-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84373-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i17-20020ac84f51000000b0042e5cff28dfsi8651719qtw.759.2024.02.27.17.50.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 17:50:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84373-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="Z/rQbEIc"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-84373-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84373-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DF27C1C23BFE for ; Wed, 28 Feb 2024 01:50:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7B0658AC2; Wed, 28 Feb 2024 01:37:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Z/rQbEIc" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 5B3C5364CD; Wed, 28 Feb 2024 01:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709084223; cv=none; b=DTbpKrZ/MHsK6I4d6riN3Whjfq2SVvG5FPA0354KHcXLzyi+/ArGAjuvyJfbX4YTce6iog+eEU+X0GRZKn5uODynHDMgvULzmYurU/x2bRq/p5ve/4HfEylB+piCA0h5FRFSNKRp7XlttCnes5viRBnWUHTC4isNOdkmXbl/LEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709084223; c=relaxed/simple; bh=dtH+XypTk/Dtwesx70WStgcYULhuLJpaBE5SqAaS+wg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fHeEfVRTN4IxNRKvXGhmXxTvRqQPAPcTz5ETgGzd4oLEkHjs+WfVVWHKIb+ALpxxBQbhaojffZz+fxHEQ1PKqNIxNR+EQD91tNqhxZU09ieTtzG6mZ8q91VFF56v5qakVnFT8GypQRPYWh1OSR6c5PU2gzH0X5Rx4Q0W4fpDahg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=Z/rQbEIc; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41RMdMTd015253; Wed, 28 Feb 2024 01:36:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=Hs3fpdD+l1O4EfSuPsgb K4Q6nEGroTvEVrnQjm293OU=; b=Z/rQbEIc0L54VOolO1oERCYNovfJIs1AkkcN YGf83ElHBwnqYwpDE6s2yjMPV1RB1xJZr1dhNDhH1Gf7x7+5K3QnHympp55IFWOD fSeyUhi+M6lQErzPhwJ4nC+iymeiu6lHb+yEygd/zzCyYmIAfUuIDWfcWxs+uPHb e+z6qk68L2HioKmpSostx8/bxDTBzcbX8NHJReK9ygM8VP77WBOcC9WKcn/Mqgqx X41hkv20sajPU7UjN+mRsxUI7ugXmwLksLGC4kMSyomNkFBPg1AKaUX1RvZykSlf 8GGxYwFkhf9dFe7eWVOlAOEbNFPxpfpOjsmajg4IAB+rkItRoA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3whrqag95d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 01:36:39 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41S1acij005372 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 01:36:38 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 27 Feb 2024 17:36:37 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v18 32/41] ASoC: qcom: qdsp6: Add PCM ops to track current state Date: Tue, 27 Feb 2024 17:36:10 -0800 Message-ID: <20240228013619.29758-33-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240228013619.29758-1-quic_wcheng@quicinc.com> References: <20240228013619.29758-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: zpJNfn8iTwTstnGUU4z4QsYNQ9lR4CMB X-Proofpoint-ORIG-GUID: zpJNfn8iTwTstnGUU4z4QsYNQ9lR4CMB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-27_11,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 bulkscore=0 phishscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 priorityscore=1501 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402280011 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792105514225615082 X-GMAIL-MSGID: 1792105514225615082 Register PCM callbacks so that the Q6USB DPCM backend dai link can track and update the status of the PCM device. Utilize the SOC USB state APIs to ensure that the SND kcontrol for the offload status is updated properly. Signed-off-by: Wesley Cheng --- sound/soc/qcom/qdsp6/q6usb.c | 52 +++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index 72ec7d45f916..32971395ab13 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -30,6 +30,9 @@ struct q6usb_status { struct snd_soc_usb_device *sdev; unsigned int pcm_index; + bool prepared; + bool running; + int session_id; }; struct q6usb_port_data { @@ -81,14 +84,48 @@ static int q6usb_hw_params(struct snd_pcm_substream *substream, goto out; data->status[data->sel_card_idx].pcm_index = data->sel_pcm_idx; + data->status[data->sel_card_idx].prepared = true; + data->status[data->sel_card_idx].session_id = + snd_soc_usb_prepare_session(data->usb, data->sel_card_idx, + data->sel_pcm_idx); out: mutex_unlock(&data->mutex); return ret; } +static int q6usb_prepare(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6usb_port_data *data = dev_get_drvdata(dai->dev); + + mutex_lock(&data->mutex); + data->status[data->sel_card_idx].running = true; + snd_soc_usb_set_session_state(data->usb, + data->status[data->sel_card_idx].session_id, + SND_SOC_USB_RUNNING); + mutex_unlock(&data->mutex); + + return 0; +} + +static void q6usb_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6usb_port_data *data = dev_get_drvdata(dai->dev); + + mutex_lock(&data->mutex); + data->status[data->sel_card_idx].running = false; + data->status[data->sel_card_idx].prepared = false; + snd_soc_usb_shutdown_session(data->usb, + data->status[data->sel_card_idx].session_id); + mutex_unlock(&data->mutex); +} + static const struct snd_soc_dai_ops q6usb_ops = { .hw_params = q6usb_hw_params, + .prepare = q6usb_prepare, + .shutdown = q6usb_shutdown, }; static struct snd_soc_dai_driver q6usb_be_dais[] = { @@ -149,9 +186,14 @@ static int q6usb_put_offload_dev(struct snd_kcontrol *kcontrol, int changed = 0; int idx; + mutex_lock(&data->mutex); + + /* Don't allow changes to the offloading devices if session is busy */ + if (data->sel_card_idx >= 0 && data->status[data->sel_card_idx].prepared) + goto out; + idx = ucontrol->value.integer.value[0]; - mutex_lock(&data->mutex); switch (type) { case SND_SOC_USB_KCTL_CARD_ROUTE: if (idx >= 0 && test_bit(idx, &data->available_card_slot)) { @@ -210,8 +252,12 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, mutex_lock(&data->mutex); if (connected) { - /* We only track the latest USB headset plugged in */ - if (!data->idx_valid) { + /* + * Update the latest USB headset plugged in, if session is + * idle. + */ + if (!data->idx_valid && + !data->status[data->sel_card_idx].prepared) { data->sel_card_idx = sdev->card_idx; data->sel_pcm_idx = 0; }