From patchwork Thu Feb 8 23:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp517666dyd; Thu, 8 Feb 2024 15:34:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6QsG4meIVj+w8+f4ksbxMPhkHwKPOrwaV+Cb8pDqJwTMTXfDl1zWJJQcrnQa1YBtUFugK X-Received: by 2002:a1f:df82:0:b0:4c0:1ab8:ac8 with SMTP id w124-20020a1fdf82000000b004c01ab80ac8mr97792vkg.3.1707435241014; Thu, 08 Feb 2024 15:34:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435240; cv=pass; d=google.com; s=arc-20160816; b=t/SVs1UiUqutZe5M7o9pSAAey+NvnwiLj/4Os5M8SFluua2DDVH81ii9fcguM6K8+0 3BFtGJBXSoLTonzjAs/OkbXga2PpIhFnp127Qv4Xcze2tySka8PqF3rAJj8x0dZOOhq4 AcT2V8JpcTgnPh7hzV7pEPIR6mUxyRVvJUIabUIs9GlqvDno2gUDx8ZqQu6GFf7fRqW3 PDavkcl1jzOv0RwWL2usgaZI+HPYPUEW7nfRzZ/nqGvU9PQ3/3gq5Z4JNgFFfVRyLVRJ lgxW+/nyJRP4AFCQPh1n3GVOt12znnKCYxBXwwyUepO++dAX1uNWHAR9+/QwLrGeCmZh HrkQ== 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=TP9fyOwkywtfaOI9LqRokjI/c6lBCTPIOkl0CcpX2Ew=; fh=QJ/hZmsw1vzyBP/94ev68V/7RHa4ICZrgHskl2HlgLs=; b=ASnhFsd2eqvWmnbT0PFlFrvXBxm5tfIw2bjJ5zIGsYtxpX7MqPdmVSGc5cvaw1RrUQ QSvk40kft7+4ylkTf20t8ZNXvc/3QIyXC0akvGvZOToU6HpuLkdgbRnjO+RKhxek7H36 ivZ/OGXa1aXlN5oWmgJxAOj+IVHItriPsVRI7jaj3oZUPGv86jKWBevegs+WF6nW0T4l JKXYeVoxna2Pxctrpq33/YXprNGHyZjlBNxBJ/JfCB3xNpeZZ9EOft0Xv/CokhCch+AK HUUe74a1uj2RDG9kEXnSO4JAhVpvItDQDYOeW2J/fOZDAJVW/VxeCxcMxFTZ9EPpA723 OqrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=c2cWnabg; 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-58845-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58845-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWOCo+kdijdk2McKX+91MFV7Y0Hk6YmeNb4vsUVQM+F7XEIVqhYwFFT30VVd+QPi0YTqRHTpVuhAq67EpNou6LxFFczpw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kj7-20020a056214528700b0068c65ca8e3esi673880qvb.143.2024.02.08.15.34.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:34:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58845-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=c2cWnabg; 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-58845-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58845-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 B5A5D1C215C6 for ; Thu, 8 Feb 2024 23:34:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 987EE657C7; Thu, 8 Feb 2024 23:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="c2cWnabg" 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 13DC952F94; Thu, 8 Feb 2024 23:14:46 +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=1707434091; cv=none; b=sIAmH2MmlW4EpNj7ZmHXaJUCUdJxy5p9bgeFwT6H+DzJd4nkVdAEWFcvKUIDblNnPvhYJdOGoE2eo9d2y1K8kr7ujsCM3bWA3GrqPOmRlvrcNvXUUnk7mxS6JHHEaO69DyH0uMY7cazBX5rTE9VoHeLN383opuOGqb4MD0wD1Y4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; c=relaxed/simple; bh=RtmQaj8NkOIBrQYRKvHrCqtxnDMndM5jafzZvCboeCs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CU7mLUhyetQgquytpdGaNTmOHL80reibq7k7a+Ur28qDgzhclpljHGEElB8f6r/p5p4ivbHW4Yon09C3lw5LvwEdi9q5MbNsnsZSJdVzKZWkDCh+miLh2IRbX2WvxEat74qovKAeYr4u/oIHhunIcdJZVBzelDqoLXRk28e9kRE= 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=c2cWnabg; 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 (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 418MFqIM022116; Thu, 8 Feb 2024 23:14:29 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=TP9fyOwkywtfaOI9LqRo kjI/c6lBCTPIOkl0CcpX2Ew=; b=c2cWnabgoyrRqmiIMVLN/dRloJgomExyfbdP Z8lZkaEIGVQXFU5/6CCCmS3l7esNYTGIv7sjrvi+NQo5bFNQpX4FBn00bUmV57OQ hb05hUsfnyLZHXpJdSMSovoZ/fzylR+kqkwck6ipd2NjQL+WYbtBmuBCVAEgV7Ky c8IdQNMysVThnDpTxnasc+oEwlSLM6ZUjNKhoIpf7RMvPhzUtZFBCZ6f6OJNlhhs eWXcdXuYbcxdA23TQqD3Q0h1dIaZTBavtQ31Lypnv6IN1N1IYKExxc0dw5I5ObLF OGbFW0DG3A4hMkSbTH4u0tVqo7nCGZr1FgTLbu6PEaf+v57+Cw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sudj9yq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:28 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 418NESnF013190 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:28 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; Thu, 8 Feb 2024 15:14:27 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 44/53] ASoC: qcom: qdsp6: Add PCM ops to track current state Date: Thu, 8 Feb 2024 15:13:57 -0800 Message-ID: <20240208231406.27397-45-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: Zi5kGkVCl-qkeoGQEZG27HTsVVobxTji X-Proofpoint-ORIG-GUID: Zi5kGkVCl-qkeoGQEZG27HTsVVobxTji 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-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375615411964999 X-GMAIL-MSGID: 1790375615411964999 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 61d30303a7bb..84543b34f2b7 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; }