Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1412573lqd; Thu, 25 Apr 2024 15:06:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVu0ru1Yp8eAAmp/w0LwByQfL3ZPCbxLybetOXc4yKlpxaD2/bLKRmvPwv630/YlN3eq4aYzADezBEpaCEaltnAFXUTqRm17bHHX+NvJg== X-Google-Smtp-Source: AGHT+IH2Il5liGFkxprI1Lu4ZP5V2/F3S55DIsyR9LnsX0q+a9tvi+BOAg3xYV6hwVSEXALSk4WI X-Received: by 2002:ad4:5aa6:0:b0:6a0:7b74:62ee with SMTP id u6-20020ad45aa6000000b006a07b7462eemr1259727qvg.47.1714082802253; Thu, 25 Apr 2024 15:06:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714082802; cv=pass; d=google.com; s=arc-20160816; b=Tat3+LzymKS7GliJfuV2oVPaLe3jg+4i+lgn9h5Xu6sm1JqykpoJSFU6jLa5j0241O lGnwAcf8opHgAM8UmJANDJ4PuwarycezWvKg7nrnrmcn5IJTpURbBqDi2WHgcPzOK+go pkcl7H+40PmmhjPbz8bX4MPxMIECJb43dKKQO5x2Y6uYC7ato2SYPu6YR0C51+j7c0RN jdj13MYfwcPaARyjy5DrDT8RUvNPo/B8w4IjcbFPtAkIknuu0bVLRRJKbUr6DS8YuLXk /wFO5jW62dfDsOMAF76OLYTIeZx1/5keyx9IROaEN0zWIm3w8sAi1k/fp5V5CPkvYlx8 jzyQ== 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=usWEz1eJjYCle08WABmDyuqCrJGq9m48/LVlmybnzRs=; b=ADtynpehHR/pYtHEZiDr9m8nKX4QS810tycjVdRFymszShfe20f6oYmvfDyU1fS8tU j9tdjbEZ1Rld3LD1xXTjHSKvqawY6TwsK/4QxPc+HWKHu/grBP7w/09cmkueUEdfOEgI VWhaamq6gBKv3WNqTfDhjnaAYmx9IMJKPYTKq6Txgjnx7BX3dvwUOzn/LMKSbfO9QgWp 9yeaL8fx/OB73re+EyLzHk+hhW8L/93J+aZqkvjfs8hUOJD2g5cCAGDm4AZCx170a9HD GRX17GF0aYJoGgAbetr7xfo41VBjsyVWPqHAq+oJfO5mv1uXuQaD46GWyuoHGDjR6fTf 4ftg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=la2oZcn8; 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-159277-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159277-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. [147.75.199.223]) by mx.google.com with ESMTPS id q2-20020ad45ca2000000b00699216d6e56si18705483qvh.354.2024.04.25.15.06.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 15:06:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159277-linux.lists.archive=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=la2oZcn8; 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-159277-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159277-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 693C11C242DF for ; Thu, 25 Apr 2024 22:05:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FFC81C6891; Thu, 25 Apr 2024 21:52:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="la2oZcn8" 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 9E58D181318; Thu, 25 Apr 2024 21:52:20 +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=1714081943; cv=none; b=EX1XRRZmGa3wGsTP6A5jqukuQrp+63kzsAeQvo8TQ8bdg4qcpgr6urlz5FrbDf1Y9+lTuhBz+NeGfQbkvciCNTGqZ5xasJWfrIrHjs9nj+9tCaTvSbinjsibmk6x9DWy4PtaEqtSrnfpO32dls1Ct7IpZ2EsUT+DkTZ1nsjtUUw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714081943; 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=qAtwYJYIuGht9VBp7WwaQ6GAJKA6r4QXj/0a/QJz5JcvNqWIatU2a9JA06MAgvlQh7oouXvzrDdoBczBzpc3M6LBK7gasWYZ4ht/XzmqSK62/LD5kohxGrPiSwNOFHl99P/9eWO9pp+Rz3yg7/8SU9itU9Q+X6anZIPAW1lC2X8= 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=la2oZcn8; 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.18.1.2/8.18.1.2) with ESMTP id 43PLOkgF006493; Thu, 25 Apr 2024 21:51:47 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=la2oZcn8BtHp/YLK8Ez+iQM/0T/Mn55NQJ8h 2pj/wgdkllNXP557v5x6zvDdKY798lvLUARaWNMfzP7FuIEiCVy0Eq+fqDFRVpwp BcH50h4tufKIkOwNO2h5gApeqj3+Rjuu4rJpzTibvNjYGtwKRlC4ckluTbdK57+w l668MxMGfWk6Pk/gIrlh4nCj0lm8wVBd0umuX/TSjkmu3QeDg0SU96tc1WCIRqeI mGB3O2YS5Y+8n+9TjXSZ+OZzBDS5OjbrZqbu2LbBUQYS4saAykJP3okvZJ6pK39P GXNWiPnwWXi7uMAeAEW4W0Z/XqZcdtkLl5Lolh+79TynYJ0+EA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3xqx03852t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Apr 2024 21:51:47 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 43PLpkIZ024627 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Apr 2024 21:51:46 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.1544.9; Thu, 25 Apr 2024 14:51:45 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v20 32/41] ASoC: qcom: qdsp6: Add PCM ops to track current state Date: Thu, 25 Apr 2024 14:51:16 -0700 Message-ID: <20240425215125.29761-33-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240425215125.29761-1-quic_wcheng@quicinc.com> References: <20240425215125.29761-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: fMxg5XNXS-8TdSI1oSFPskeVazzmzhqg X-Proofpoint-ORIG-GUID: fMxg5XNXS-8TdSI1oSFPskeVazzmzhqg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-25_21,2024-04-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2404250159 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; }