From patchwork Wed Dec 20 22:45:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 181837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp58566dyi; Wed, 20 Dec 2023 15:00:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyTTmhFMMlVLgdYjcWZ7jC/GlBiH5mhJwES7ZSanN12pvDAHasYNpVIYCh7QmUnqKJv8KI X-Received: by 2002:a17:906:24c:b0:a23:3254:83e8 with SMTP id 12-20020a170906024c00b00a23325483e8mr2205397ejl.282.1703113206469; Wed, 20 Dec 2023 15:00:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703113206; cv=none; d=google.com; s=arc-20160816; b=xIp+vXMBkPPHSkmyt1D1g+y4jixyOcH8bqYFuquDBV3yqrGNKPU7D8BS4NODCjQXop 9iUWIOA4/2GQvjhJzFik96nwr1eavDm1/vwucI7IV/ZEamUnZDjun8ey3PO/coj6hjDj AJ/blgXx384AFYxqpoDEZZFUrpLiaJHhXgpsrNwa8s8HvrZBznFDcsjkbLoRZ3fGkMoC DZHFkOQL/YAVmX9QuMIFpkYsdV+VxR0PH2MgKUeGdArPgHUtJqfm5M34zWH1a/CJYla7 P5vvMmafFmkaEb4he2iOVnOMQjScj6TIBgX5zMsvoFBWg80JbHd4V/gRhNmVTvQ4tqjt te6A== ARC-Message-Signature: i=1; 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=L2qotf6xpYYmqLwnEkW9ngHyZkfprz9VyYE0khXKWZA=; fh=0KzismZj+xI0Z//ZGdqKIH/FO9LtSZM7Yj4P0VtrCz0=; b=UbduXK5buJ604a3mdG+iu2+awvmxJVJU/28gRdeCxQWT0bvDSyVw1gEWbdqPw99GKq Y/9od4gPbmQwHdQASwCv/9H8F5AFdOnAPfi3vgkcVbSbTMOtxXRNKscoXDli/JfmB1mR P5wmvsreI/ASiVexZECW+khiDMIV33QdEMicDjKb3lZN/ZM6GxFppoeDTelB1+qlM+Qh xLEMePBv/cCvjtC8vJIUuxNgl+DNQbG9DFZ24DYeDbf8bMtZNF9pEPC9cxz2cDhA7Fu3 o+JMh73VHVG5wsrDwb5+v4/GefpbeXYu0x7bX0QLtqikAjPYQ7tO7mYuiXj2ULKw912M GfQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=P8qBrQVi; spf=pass (google.com: domain of linux-kernel+bounces-7562-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7562-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q5-20020a170906144500b00a23645fc93asi243090ejc.886.2023.12.20.15.00.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 15:00:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7562-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=P8qBrQVi; spf=pass (google.com: domain of linux-kernel+bounces-7562-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7562-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 am.mirrors.kernel.org (Postfix) with ESMTPS id E5C411F2462C for ; Wed, 20 Dec 2023 23:00:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 365AE68EA0; Wed, 20 Dec 2023 22:46:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="P8qBrQVi" X-Original-To: linux-kernel@vger.kernel.org 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 5D78A4F211; Wed, 20 Dec 2023 22:46:18 +0000 (UTC) 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 (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BKM9amG029693; Wed, 20 Dec 2023 22:46:04 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=L2qotf6xpYYmqLwnEkW9 ngHyZkfprz9VyYE0khXKWZA=; b=P8qBrQViITH8EHrC3aOh8uCVs//GZWxXzueP 6tHdH1Sn/xCPPreImXbK0muh5cro03KEkC9ERR0nxbwdMoW0BpjTBrzPQsYyCVja FKB3wQIcDRl9TSclUEo+VSWEjImKddErW6bgsI6CWgZj2WDZpMQmQOcjK5J8NhRQ aadpA6VS5olatgVgtkZG3moQe/SgYTYPmQC4JMZY2yYFdcTtcTUcPOzxvmzzu/Ct rLJyr4HP8trrC6uIL8P3JgwRkZCIpCcWlN1ouXSD86fqQku5w6vQUhqiiBH/sscE Zt2On4ygS0xvQBDTCplMyG8AYkPbyYEWSIiaobNdZBmlR2bPtw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3v3tmm2d5j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Dec 2023 22:46:04 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BKMk3nh017756 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Dec 2023 22:46:03 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; Wed, 20 Dec 2023 14:46:03 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v11 32/41] ASoC: qcom: qdsp6: Add PCM ops to track current state Date: Wed, 20 Dec 2023 14:45:35 -0800 Message-ID: <20231220224544.18031-33-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231220224544.18031-1-quic_wcheng@quicinc.com> References: <20231220224544.18031-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: nalasex01a.na.qualcomm.com (10.47.209.196) 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: Cv2__ddZnuM8VH6gbnDKw2Yfr42FnBRF X-Proofpoint-ORIG-GUID: Cv2__ddZnuM8VH6gbnDKw2Yfr42FnBRF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 impostorscore=0 mlxscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 adultscore=0 malwarescore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312200163 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785843633433197335 X-GMAIL-MSGID: 1785843633433197335 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 e41b83a58874..fd4da457d834 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,10 +186,15 @@ static int q6usb_put_offload_dev(struct snd_kcontrol *kcontrol, int pcmidx; int cardidx; + 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; + cardidx = ucontrol->value.integer.value[0]; pcmidx = ucontrol->value.integer.value[1]; - mutex_lock(&data->mutex); if ((cardidx >= 0 && test_bit(cardidx, &data->available_card_slot))) { data->sel_card_idx = cardidx; changed = 1; @@ -203,8 +245,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; }