From patchwork Tue Jan 2 21:45:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 184477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4699467dyb; Tue, 2 Jan 2024 13:48:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IETMBNclFTpoyBqC5yNHirhVWGEg5sMKjaN9uyM83nOoYk0CFxXi1PgRpjVllark9aJNMel X-Received: by 2002:a05:6e02:1888:b0:35e:6b97:b8a4 with SMTP id o8-20020a056e02188800b0035e6b97b8a4mr27149965ilu.4.1704232115715; Tue, 02 Jan 2024 13:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704232115; cv=none; d=google.com; s=arc-20160816; b=bWD2aKapSmgZ3O9YBKy/Xn50QHDtEEmd4+4t9xPh5XSeznVYEHW6G1/Oe9/5swJwwZ U+bkTW11zTY7e/9F1R3H62s60KrzwjDGEErG/DUJCrQ1s14vFnitPLEDQUTgZDeWuUb9 4nZhu255DBG4roZ+/QT/sW2m2dbzq2IKolsRjmQj/upcE4xMJ7Q680mEKWLkHkyrc7Su oi6uCm8OSKkpJUy8etIZHNqawLBtbItq1mmF6zczRyg0T3SoXORCe49lffLrgzaPACFR DrpQiY8TZQT3Y5Zmnxvgd7IO5RTJlRvdFXhiLw720qFthoQBFmtiUoKOCvZgg+5cRU5g oGjA== 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=TP9fyOwkywtfaOI9LqRokjI/c6lBCTPIOkl0CcpX2Ew=; fh=0KzismZj+xI0Z//ZGdqKIH/FO9LtSZM7Yj4P0VtrCz0=; b=j4UMEvCAFzR+rrLWCrYyeJnzcCu2/gKHSG5Bttd9cD/1d5CHsLFvXVXAAOwIeEp1mZ D3ZGdwQMVknF4zALUukcCEkQ/GGd73qLSs+NTIWqUTG5hmnUsNO487sTSyDL3WH5hc3j JSFO0bmnafXkjJRMJVEr1WkoW2lW3eAAZh7+nL6TLXH/Ph+D5eC4rzWknZ41uKJNPms/ TNg1ji2XgQYJOreqnFxkUgB0S2xNcqYjv1+5dDOgmSXn/wefrFfhR9VGh/oIUgbpRCIg 9z8bt1K3GkiTz07++8GNDx24JT+77XeTnnB/+lVijxS6otiMpVkjz9mmTD0vsvnSQ7Qm meKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="lOofI/ks"; spf=pass (google.com: domain of linux-kernel+bounces-14861-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14861-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 200-20020a6302d1000000b005b96d038729si20731803pgc.728.2024.01.02.13.48.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 13:48:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14861-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="lOofI/ks"; spf=pass (google.com: domain of linux-kernel+bounces-14861-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14861-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5D72BB229C6 for ; Tue, 2 Jan 2024 21:48:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BA0018027; Tue, 2 Jan 2024 21:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="lOofI/ks" 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 55C90168BC; Tue, 2 Jan 2024 21:46:40 +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 (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 402LboY4007716; Tue, 2 Jan 2024 21:46:28 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=lOofI/ks0a87JPGBnYnN+JheFSVBWMD2E5oj 59PY2pItYow1Q9omYsgJhhCHmB9TRmjvucecc7JpbvNH+R774rvp4LTCChQYWSF+ 62xwvmy/HG3v/PTowHk8/kJH17Hz9Eaoi5iZ+zbMywWk7M+t+YHru35bjUPzjw41 2TO+jLZ6IhdtLuFC9obth54bweaXmurgleAXz5XyiIMWMP/yUDjXY4aHHXelr58x qN0xVBesik4e45EjDqQPfU/0vu6tyXGty3LuolbROtVu254y7DwG6t+QfoIjVZEn PhCqHrCVkOF0mpgiXb8cusT7VYw9KcvEx3J6nHS6T+8wA+7ouw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vcgub98m5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 21:46:28 +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 402LkRjF003278 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 2 Jan 2024 21:46:27 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; Tue, 2 Jan 2024 13:46:27 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v12 32/41] ASoC: qcom: qdsp6: Add PCM ops to track current state Date: Tue, 2 Jan 2024 13:45:40 -0800 Message-ID: <20240102214549.22498-33-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240102214549.22498-1-quic_wcheng@quicinc.com> References: <20240102214549.22498-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-ORIG-GUID: Nim_oPG2o0WMKjmPbFvESuyeysK_ot38 X-Proofpoint-GUID: Nim_oPG2o0WMKjmPbFvESuyeysK_ot38 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 malwarescore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=999 impostorscore=0 adultscore=0 spamscore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401020161 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787016894675515758 X-GMAIL-MSGID: 1787016894675515758 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; }