From patchwork Tue Feb 13 00:54:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 200156 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp272685dyb; Mon, 12 Feb 2024 17:40:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUEy9KYuvdZGDSRSksji+/ByrYxpgNVAS2gcXw/WgOTL2f1o2Alg9vUJxQ+a4A+0T3uVdF9GLXRIQ0DpSKOTU4AF4CoxA== X-Google-Smtp-Source: AGHT+IFs90tR+ll26WHsCJIuJNU/EKg5myQ94qX2IrGig0ycCw5NPo9ybe2ARZzAPHdxQ+fzXeoR X-Received: by 2002:a05:6870:15d6:b0:219:51de:344 with SMTP id k22-20020a05687015d600b0021951de0344mr9327990oad.3.1707788442277; Mon, 12 Feb 2024 17:40:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707788442; cv=pass; d=google.com; s=arc-20160816; b=zd5QZyOEv9FRWyNvCP3DpPPsYLSSjM8eUuSu3oyskBkCtnXGi8mCoIlflHH2rS///m KjPKccmD24W85LJcBBMhxGQT8aW7p0OVMrbvsydG4QdPMTuQrOH1gdr8I6DywXYETNpl Zvb2Co5/9fybkVdZxW+CyCfpVfk9WvmzfZy4J8Fb5SaY7FRGv4cvrUG2ZynE6yU2VRO5 yEk6WLfw6imhmCHa5wrYjOm6MenEAop0s4mfPwxzw3va7OXmDB/zIUJn3VxoabbyDi72 5K/DFOX5CRjnAz9cyo/T00v52zwhlYuTtwKwN1YTx+ApKY/XdAHFmE9NstRLyiE5E3Rr +GkQ== 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=oiZj2Mh6UZlttWm5z+Bx81n87ZP+d57u7+N7hZwEZ3U=; b=kFFwo0v7Uv8TCR/lQX7GqAua2wwxwZ9Ykkit9mA5+kmNjxY54tCG85yOOY7ncCVR8B w9Nzyc21pRKCaw4oRExvv592qGtKJmF5c3yPFRyTzm/ec9RbrZkrsoJFDkKZI5Vz8Ehd ErRzIsZW13HOHfpVLT5/fAm6rSPF+jd8333/RBGBYl0I24YwcmY+PT62TvAXv3+LWzOu uMlcnnHhRibxsI3zqcViTeMSDyuDQFB2Ubg+kZjauqdhkzAz4XxhIgnmjLALiz+Jjre9 h2m22swkVVnpinzlHn0thgog+4KOGgrbFtigF/sQCGLNZ4fXWVIOdYN1CYdrWy58/rPA ikAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eEbzHleP; 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-62826-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62826-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXvxBR60Qj2fyH/W6fPjnQCutlQtqfH3KuJjcNq6+GCVmF/L381EN6Mtc817z8S03gQ4qkQJ94b3dAy1o2vXfwqUZU3cw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d124-20020a633682000000b005dc4b41e2d0si1098381pga.591.2024.02.12.17.40.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:40:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62826-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eEbzHleP; 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-62826-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62826-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 01D4E288538 for ; Tue, 13 Feb 2024 01:36:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA351634E4; Tue, 13 Feb 2024 00:55:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="eEbzHleP" 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 BBD0759140; Tue, 13 Feb 2024 00:55:07 +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=1707785714; cv=none; b=S4nfHOtXzaAahwJCnK+STvO5koEwAp3UsX32e5LCVTNSL3RQfDd8aG45nMpkCnLadvDqz8pswp0dwK1BANR/0XEaAh+UFtINcAu9QFvrAfOlFF9L1zpUxzpc2GACRZudSxw2CKhAz4ARRgUtbgS5+4ODt83IURqUoPSUkjtHWsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785714; c=relaxed/simple; bh=RtmQaj8NkOIBrQYRKvHrCqtxnDMndM5jafzZvCboeCs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kYJBTuZSRWRrP4VqPCoXr9sJdMS8qEYgJ41s4B2c+xBH281K1KOh+A55pLd4+C5zXbsS4f33W4Y9gfxPiUnjY7GtlzohTeY1HDnncX8RcMXo9WWA4ylm5+EAMP4kCkqML3fZMnGvQK1fpMFPTJSU22L9moFWK8nWI9FUB9Wkvmg= 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=eEbzHleP; 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 (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D0kqEa002770; Tue, 13 Feb 2024 00:54:45 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=eEbzHleP4IvVKYMAeJNazIeF6Hf8a88A0Bv1 +oREfTyjuQnRr3G8NuUuuwHqZi8KGeR+odJq+deUEV1uiYqC3BAa5w7Gfuw1EYjJ r1YUQiDyz53Fx0RSLe2ocvCaIFKdmywKUZWcb7rbAYtxrg3rnjtjqcuKH+96ATKn 94GsxDYV+QNDCfvrRpBiMPBAvLEv9jSvIv+lPFZJQtrtzVM3ET9O1Gw+f7DZaGcn Ps6RDrLdMCWSbytC2o47yhEAwuZ8RUgfQEsXhaKKGQYJ48xSU3NvRdgpTL0CDmsh 6XAAB1spUG8/KtTRzPwU6GLxICMgTBBmU/+gNecWpjUtZhQIxA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gse1tuj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:45 +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 41D0siOH030072 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 00:54:44 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; Mon, 12 Feb 2024 16:54:44 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v15 42/50] ASoC: qcom: qdsp6: Add PCM ops to track current state Date: Mon, 12 Feb 2024 16:54:14 -0800 Message-ID: <20240213005422.3121-43-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240213005422.3121-1-quic_wcheng@quicinc.com> References: <20240213005422.3121-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: p9iPdqQ6jTGAzA9IzhGTzHGUP9wlC9mb X-Proofpoint-ORIG-GUID: p9iPdqQ6jTGAzA9IzhGTzHGUP9wlC9mb 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-12_20,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 adultscore=0 spamscore=0 clxscore=1015 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130005 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790745973505304584 X-GMAIL-MSGID: 1790745973505304584 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; }