Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1431512rdb; Fri, 16 Feb 2024 16:22:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXiv1jGVs0lBlen7zad/4eN79asqRp+WBAcQgE7pfTfYI2FOYPzq00BmBg4TpUQct3cL0V+BVVBbxE3AzTYbEeyvS+LpwSvI1EMidXQlA== X-Google-Smtp-Source: AGHT+IEKqeDcUmlHpO0JxcXpVUEXphRK6QNL9AfBFj3a6dEuvOCVSdfyocI8AxEjeKMi/MgHdvkB X-Received: by 2002:a37:f50d:0:b0:787:1890:7f2e with SMTP id l13-20020a37f50d000000b0078718907f2emr6457268qkk.63.1708129379722; Fri, 16 Feb 2024 16:22:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708129379; cv=pass; d=google.com; s=arc-20160816; b=Jw7p4l3SVLb7TvLEc+Z1nw743EuUQ45y1feqyfIL17NQNcoAcz4wOUuE8Qcp9tIr7T tpJ8sS8Pp0MkfkWyDIsKVHPtlDWzur4HFwrFhH9WD7H5wim3nvoHmezm1iXGiNOuEHHk 7i4ZLXrbU3072LwKXgMePgLL/cR/MxIPaSTqPVAMmh34Ref37YE2Y6wCotx6yfOSlWBa fT8TtMNJr7POVBbmF9EQBrcwggL7KTRrU7X7C3uEOwuGM63FX533bPTCFh7h1MO37C19 yeHo40M1O8J1LF5S+5JsmvmN8wXlx5jlCxyBm2HrApByAH8zr95Ts99Q4mqScASDjZ9p LCew== 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=AdaNG5c6GcKhfBnkAPS8fazsoPLbcmGY8JTtFcHJtuSbnsc6X9EH1cxXvzRLqrYi62 UI08KyZPzslrpKjdQoqp1Rw2TIX2X8q2C3WdKZKyiFKXlzZjdEk6t1ReDt/fJc3wYLo9 0XcBekS6nrpOJ5rjeVRMhLt0G4pyDe776lfA9SI2nkT4hdHbhxMkanIX/UOwF02TIcCk COUBMyx/KkaWYzWjIsOVm4WCp8YEI+uOOEBXFKju2CYtBWpDh9NqxGGlshNjAslL4LOS jDGpD8U6/1U/qGSmMlwLHokQiV7WGzZFFHq0plJWBC6mc3FXD6jqtiP9nPay0ZoyaKYa 2rwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=NcKjeFZW; 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-69562-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69562-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c11-20020a05620a268b00b00787214c3309si1327771qkp.476.2024.02.16.16.22.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:22:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69562-linux.lists.archive=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=NcKjeFZW; 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-69562-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69562-linux.lists.archive=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 8AEA21C2319F for ; Sat, 17 Feb 2024 00:22:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2ABA77B3FB; Sat, 17 Feb 2024 00:11:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="NcKjeFZW" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 7773C56755; Sat, 17 Feb 2024 00:11:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708128665; cv=none; b=SyEmd5QQoGCTUkNGExzKxXsag3gmWGUW9q2tn4SPSxbiesjJ31rYrg/aAmWhaWns+ZyE4DL1U0IHg3hYFtjupTcwIXsYCXSdm+g0b9RT5/FA2x59c5oXxfCj2iQRtDSUbnxDoLUDL1uCLg4BOQ44AG5MnYJIkX49f+X7dKAXQ/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708128665; 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=ULK46tOa9Jpo72shFM1cPZNtP1P8EtFCba5Ar5FMDArhDfPC2S0YJfPQvHRsp1GhtGGVuMpReHNCuhXO/o3rZzkeiDyrpRIk1XyiZ36G2AQpYxaAkz85arYKzYojsF3AFeo68gWsrtuT7azig6w88pplI698wieb+tpye8jpd+c= 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=NcKjeFZW; arc=none smtp.client-ip=205.220.180.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 (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41H0AgM8031492; Sat, 17 Feb 2024 00:10:42 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=NcKjeFZWbJhLZVcnC4+sqT28nywe4r/lJ8oC DRTdwt+9P4cIKGKtr9DNc0AQvSvmNnRF68+uqJ/l8FjxAt/iuj3Ji7VHj957IpdA P5D972memUsUIEPFtzLexzdjWEjHn6mGSikcCUM5NMjFDfAiV5oaKxlcJiVDFe7k 4c/N0IWQgJG9Mg+wxhOPfsrxYrJhCgEf6ORkXrqeu9Dp1iHYkI/GH2Dft16m57X7 I5wQdnICrOeIwuonFi3HS0DfqcqFHK3jsWszvD+BrjKi0EroQAaahm6dhbuD8sBA bqspbIUh9jaagUhjsyn3Ra6CbppstFQZnufM6R4Xxtk48PrXtA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wa6nk9e62-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 17 Feb 2024 00:10:42 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41H0AfaD025798 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 17 Feb 2024 00:10:41 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; Fri, 16 Feb 2024 16:10:41 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v17 42/51] ASoC: qcom: qdsp6: Add PCM ops to track current state Date: Fri, 16 Feb 2024 16:10:08 -0800 Message-ID: <20240217001017.29969-43-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240217001017.29969-1-quic_wcheng@quicinc.com> References: <20240217001017.29969-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 Content-Type: text/plain 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: To32oNIncvgr2wbxLjGZWEkPwQ5UMMSl X-Proofpoint-ORIG-GUID: To32oNIncvgr2wbxLjGZWEkPwQ5UMMSl 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-16_23,2024-02-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 spamscore=0 bulkscore=0 mlxscore=0 adultscore=0 clxscore=1015 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402160189 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; }