From patchwork Fri Feb 16 03:59:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 201894 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp287230dyb; Thu, 15 Feb 2024 20:12:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWsOOUnpb6iBgJytw3j+1IDrmN6Vx0WXkIrRXoenXcmERwlDU+E4hBJ1qPNCjjGFD8j0UYJThP+sg/CKGkUGd5s3/7qGg== X-Google-Smtp-Source: AGHT+IGTcjvIgPXChA49iuCeHLb3wG3meodT9rT0TGcK5AKsNLSWeMSn2Ew2B/dTJJBXnnSeimhO X-Received: by 2002:ae9:e70a:0:b0:785:db7f:3539 with SMTP id m10-20020ae9e70a000000b00785db7f3539mr4200441qka.63.1708056776862; Thu, 15 Feb 2024 20:12:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708056776; cv=pass; d=google.com; s=arc-20160816; b=T2pktV1PK76Zq1WvzwtY1UPCNUMUrCzXZbrTrCYO3sg7v+JrGC6dYGr2KiYoPRj8kJ wdygcCwaLcaLhXvTMby60bLPGwgMO40QhIpm6b+DUkpXTsJ3BjQlVTTkvSVrNJIDE32P /P9SzMViW+anpws71wc5KWWBUhbWQeldIFWbIzfMDDIsN+QkGcDjnsacZUMd9bQU0D8D ug2HWmmWCUyEadA9mrJYY9zk3qctMEXH/URDwxQSNcp3sSZqk3qjdfENU44gPTb+hom4 e6aaYixhce0ZdEQCd1rz6+3nUXAyNwf8HMFi6v687ROmh+SCKXUCd7qCd0OgIR8hpQ2U XwXw== 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=COET+VKr61UcAXrCyqbkxNC55S4/rdmcsgc0ujRZX44=; fh=VKrp0Y7I/+wT36BfKZ6oI/4N9BIwFCn9zerObkOrgGw=; b=fL8zLE3lzkXYguWSBtLGFr+XoFccy7zu54NCo9diWSiah7CH/yZW1sp+TvYChJLDwd vKWKUMU4MuAIOo7CEpHLkXKBXvzJitD8F5EGBa/1O6nuroWtWPWnT0Iw/yNcMPhpX9+W Zd3/1t0BCV5tTDXjFgV+/gWfYz67v/hEg4pRA8FHq8FbWJAAvzAc2iPmmR1Wulml18GL 9nHzwvhwl0TtxbqoBl4KtL3qyWCnXwLjXcFqaUehGfUsVP5b33SM5yoELpKsYnr17/e8 pylrSABljgX7mY44P2PQ9/ljci5Kre7G+zna8BYBkwMta7z/rExD14Ya3eLuAWrprdwj +gvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=fzVDaMRB; 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-68016-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68016-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 u19-20020a05620a121300b00785be8e5f85si3075916qkj.247.2024.02.15.20.12.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:12:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68016-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=fzVDaMRB; 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-68016-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68016-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 801E51C21CEC for ; Fri, 16 Feb 2024 04:12:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A70104F5FF; Fri, 16 Feb 2024 04:00:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="fzVDaMRB" 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 A524217BB5; Fri, 16 Feb 2024 04:00:00 +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=1708056003; cv=none; b=T+sPafRhizvOisOK17s7yBDdRkhr6sZTu4YjsTuJHfOiwg4ba/DFc5lDepA9rVsIzBH8TpY6t77U0CoDrpowX7NoaZ2tfA91by/YZb0ccDYRIiZmhRUCo5RSEGwhkHgmsfZCIcpGEbVswQUh/rYxKx183kymxNguwOxGnlzynKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708056003; c=relaxed/simple; bh=8u+xqzU+x+/1yIzYCl2J7sXjGhIN1AahbPmAerwT6XM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MeMst1G4J8bBUCbB9cyiH57vSFVi1K8vKXegx//GArXwnQbpai5YQ1e0OdLs7E3do1W+4TADw6ogtmzeBFSl7YunYBUq4FtZUxPnZrI04tcgMZNFsoJ0dFWr3NyMeVRdUWjLosgFzMDBJGPT358syjJTFtV3cZQXrG4xcabgs8o= 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=fzVDaMRB; 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 (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41G3vMrU028333; Fri, 16 Feb 2024 03:59:46 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=COET+VKr61UcAXrCyqbk xNC55S4/rdmcsgc0ujRZX44=; b=fzVDaMRBp2DGD2mUyxbVth9KSuaSGkbHX3pr vZnzZT6aNq51BO8IBGg3yuxoCDwsIfvv/7BVaetH2Ju5Jyq5TRd52gUlX6Msa3uQ WnBDeZCqy2KibS4SzD8lssjyquJXc9HJy2R8Elf1iCl7Ac+JtnEfkrGjOKFqCFpZ r0VntT8J7Hl91v/AXmQQz1f1Q4E+QMCotTUnc0cCVshMD94IU2Ua37IGfVpIT0vl Qu6OPUHaWfxizVA6NXbW6DQ13jl+p9qANtgAVeTxGatJmRQyexRj/vMTCcvjYZkY qNJYRsCmTwbwIzIsXPn2wFPvsohBmok+sRUB/nxcJpS46i+iVg== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w9wxf06yy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 03:59:45 +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 41G3xi2e020591 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 03:59: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; Thu, 15 Feb 2024 19:59:44 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v16 42/50] ASoC: qcom: qdsp6: Add PCM ops to track current state Date: Thu, 15 Feb 2024 19:59:15 -0800 Message-ID: <20240216035923.23392-43-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240216035923.23392-1-quic_wcheng@quicinc.com> References: <20240216035923.23392-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: bZQJIXY1djh0IsPc9Uk08L1_QH7LMR7Z X-Proofpoint-ORIG-GUID: bZQJIXY1djh0IsPc9Uk08L1_QH7LMR7Z 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_02,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 mlxscore=0 clxscore=1015 impostorscore=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402160029 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791027342933899361 X-GMAIL-MSGID: 1791027342933899361 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. Change-Id: Idc4142da495b040ced4f301c56dea2e1345f0358 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; }