From patchwork Wed Oct 16 13:02:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= X-Patchwork-Id: 13838452 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 72550208D60 for ; Wed, 16 Oct 2024 13:01:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729083705; cv=none; b=dcJ9cus4rmesFC9A6DsGZNc7Jkz1f1kdguGLdlJ1/+6+mTFJvl7GehUnZGjomxdLZNNAWfj8UaDjyf0m1kJX1tq3eLGok3ymhFwLvYq6TnFRlZF9MCeOqxCeK+s9MnfBp5s1h1/JvH6jBY75h03vOEUcP2yoGmf0op05G7LJHtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729083705; c=relaxed/simple; bh=9+IjvcaJFjx7VKTRltojtYicutSkSZlKX5Vijk9d2o8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ndpfIQV31i01MJHi+MRt/XjMGLsVSQACKdF/iloVeVu8P9GwmJ/vHh6ntAj6WZlFwCb0N2h7t98alFyyBh1CqX85GcwD+eRWGONuVbzN+iV4qvMjcQgNCr07JcgK8a/dn6s7EIcPfml8e8BK07QLbWd6lR09gQ7jjYlzWcrXM8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=g8gHmI9z; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="g8gHmI9z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729083704; x=1760619704; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9+IjvcaJFjx7VKTRltojtYicutSkSZlKX5Vijk9d2o8=; b=g8gHmI9zbkfEtg6NeuGWKVfni0xWSM6QfIuccRl1sObiGk/21qpQfOgL mPM4pDVXj4feNKYhSAG90ehVGeNGEqrd+aTo7fb+LFdiXROc/6676jYIK FrtgcEJoKAmED/ZleRhXEw52CUnSto1pwM0e0n03IQjpCJPhq53RL16Fz KE+6vCxmP3su+aI4ccZhujYtsAfQtVzev/WSeFO88uR/HchvdG9aMu2Fk MidxlW6SJKJgD6iplRLvOHbwwXKr3QNbukCSlNnTqyPcBOxhcxosWxlPL /v0xHsOYg+sDY1QS7tROWncUMRmR7dFwvcJ1Fwy/UHrPtvI/ga11iTX1f w==; X-CSE-ConnectionGUID: uot798ltSpqBGdYo8jmdDQ== X-CSE-MsgGUID: /hE/RFwHTOyuCUEuv6fZtQ== X-IronPort-AV: E=McAfee;i="6700,10204,11226"; a="32450301" X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="32450301" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 06:01:43 -0700 X-CSE-ConnectionGUID: Du/KoUrARz6qjjWmpEm/Bg== X-CSE-MsgGUID: NWmIUrE6T2mkOsfxJpzPqg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="78566098" Received: from dev2.igk.intel.com ([10.237.148.94]) by fmviesa010.fm.intel.com with ESMTP; 16 Oct 2024 06:01:41 -0700 From: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= To: Jaroslav Kysela , Takashi Iwai , Mark Brown Cc: Cezary Rojewski , linux-sound@vger.kernel.org, =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= Subject: [RFC PATCH 1/4] ALSA: core: Add support for running detect on capture stream Date: Wed, 16 Oct 2024 15:02:25 +0200 Message-Id: <20241016130228.1013227-2-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016130228.1013227-1-amadeuszx.slawinski@linux.intel.com> References: <20241016130228.1013227-1-amadeuszx.slawinski@linux.intel.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-State: RFC In order to save power when running detection on capture streams, there is need for additional state which allows stream to be in "half" running state. Goal is to allow for DSP to perform detection and then tell userspace that it detected something and to trigger transfer to running mode where capture will be performed for further analysis. Signed-off-by: Amadeusz Sławiński --- include/sound/pcm.h | 2 + include/uapi/sound/asound.h | 4 +- sound/core/pcm_native.c | 77 ++++++++++++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 3 deletions(-) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 0bf7d25434d7f..f06ef7c718733 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -102,6 +102,8 @@ struct snd_pcm_ops { #define SNDRV_PCM_TRIGGER_SUSPEND 5 #define SNDRV_PCM_TRIGGER_RESUME 6 #define SNDRV_PCM_TRIGGER_DRAIN 7 +#define SNDRV_PCM_TRIGGER_DETECT_STOP 8 +#define SNDRV_PCM_TRIGGER_DETECT_START 9 #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1) diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index 4cd513215bcd8..c9f53d79638be 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -313,7 +313,8 @@ typedef int __bitwise snd_pcm_state_t; #define SNDRV_PCM_STATE_PAUSED ((__force snd_pcm_state_t) 6) /* stream is paused */ #define SNDRV_PCM_STATE_SUSPENDED ((__force snd_pcm_state_t) 7) /* hardware is suspended */ #define SNDRV_PCM_STATE_DISCONNECTED ((__force snd_pcm_state_t) 8) /* hardware is disconnected */ -#define SNDRV_PCM_STATE_LAST SNDRV_PCM_STATE_DISCONNECTED +#define SNDRV_PCM_STATE_DETECTING ((__force snd_pcm_state_t) 9) /* stream is detecting (e.g. voice detection) */ +#define SNDRV_PCM_STATE_LAST SNDRV_PCM_STATE_DETECTING enum { SNDRV_PCM_MMAP_OFFSET_DATA = 0x00000000, @@ -703,6 +704,7 @@ enum { #define SNDRV_PCM_IOCTL_READI_FRAMES _IOR('A', 0x51, struct snd_xferi) #define SNDRV_PCM_IOCTL_WRITEN_FRAMES _IOW('A', 0x52, struct snd_xfern) #define SNDRV_PCM_IOCTL_READN_FRAMES _IOR('A', 0x53, struct snd_xfern) +#define SNDRV_PCM_IOCTL_DETECT _IO('A', 0x54) #define SNDRV_PCM_IOCTL_LINK _IOW('A', 0x60, int) #define SNDRV_PCM_IOCTL_UNLINK _IO('A', 0x61) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index b465fb6e1f5f0..4fe1d2f41149c 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1410,6 +1410,72 @@ static int snd_pcm_action_nonatomic(const struct action_ops *ops, return res; } +/* + * detection callbacks + */ + +static int snd_pcm_pre_detect(struct snd_pcm_substream *substream, + snd_pcm_state_t state) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + + if (runtime->status->state != SNDRV_PCM_STATE_PREPARED) + return -EBADFD; + /* Detection only makes sense on capture stream */ + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + return -EINVAL; + runtime->trigger_tstamp_latched = false; + runtime->trigger_master = substream; + return 0; +} + +static int snd_pcm_do_detect(struct snd_pcm_substream *substream, + snd_pcm_state_t state) +{ + if (substream->runtime->trigger_master != substream) + return 0; + return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_DETECT_START); +} + +static void snd_pcm_undo_detect(struct snd_pcm_substream *substream, + snd_pcm_state_t state) +{ + if (substream->runtime->trigger_master == substream) + substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_DETECT_STOP); +} + +static void snd_pcm_post_detect(struct snd_pcm_substream *substream, + snd_pcm_state_t state) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + + snd_pcm_trigger_tstamp(substream); + runtime->hw_ptr_jiffies = jiffies; + runtime->hw_ptr_buffer_jiffies = (runtime->buffer_size * HZ) / runtime->rate; + runtime->status->state = state; + snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSTART); +} + +static const struct action_ops snd_pcm_action_detect = { + .pre_action = snd_pcm_pre_detect, + .do_action = snd_pcm_do_detect, + .undo_action = snd_pcm_undo_detect, + .post_action = snd_pcm_post_detect, +}; + +/** + * snd_pcm_detect - start all detection streams + * @substream: the PCM substream instance + * + * Return: Zero if successful, or a negative error code. + * The stream lock must be acquired before calling this function. + */ +int snd_pcm_detect(struct snd_pcm_substream *substream) +{ + return snd_pcm_action_lock_irq(&snd_pcm_action_detect, substream, + SNDRV_PCM_STATE_DETECTING); +} + /* * start callbacks */ @@ -1417,7 +1483,8 @@ static int snd_pcm_pre_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; - if (runtime->state != SNDRV_PCM_STATE_PREPARED) + if (runtime->state != SNDRV_PCM_STATE_PREPARED && + runtime->state != SNDRV_PCM_STATE_DETECTING) return -EBADFD; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !snd_pcm_playback_data(substream)) @@ -2919,10 +2986,14 @@ static int snd_pcm_release(struct inode *inode, struct file *file) static int do_pcm_hwsync(struct snd_pcm_substream *substream) { switch (substream->runtime->state) { + case SNDRV_PCM_STATE_DETECTING: + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + return -EBADFD; + return snd_pcm_update_hw_ptr(substream); case SNDRV_PCM_STATE_DRAINING: if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) return -EBADFD; - fallthrough; + return snd_pcm_update_hw_ptr(substream); case SNDRV_PCM_STATE_RUNNING: return snd_pcm_update_hw_ptr(substream); case SNDRV_PCM_STATE_PREPARED: @@ -3342,6 +3413,8 @@ static int snd_pcm_common_ioctl(struct file *file, return snd_pcm_prepare(substream, file); case SNDRV_PCM_IOCTL_RESET: return snd_pcm_reset(substream); + case SNDRV_PCM_IOCTL_DETECT: + return snd_pcm_detect(substream); case SNDRV_PCM_IOCTL_START: return snd_pcm_start_lock_irq(substream); case SNDRV_PCM_IOCTL_LINK: From patchwork Wed Oct 16 13:02:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= X-Patchwork-Id: 13838453 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 C19EB206E91 for ; Wed, 16 Oct 2024 13:01:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729083706; cv=none; b=UAW664QJIG0MUASTYEYFNuaBy1LSdq06fe5TUNfX5zNacMlDBUu4sndk06KuVnK4BWqVEXJY0RiHzCJfDsZRnRI7jVZACit0aH3f4XzSroUC/KXjNF2ZhKpDzjqRZaoyG64ipysEgDcvyAmhDM1mTyODv8j/eE9zhHFjq9tyTmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729083706; c=relaxed/simple; bh=YTucvGuqGqjSae/gXpF94kINnM6erhOXr9w7b7IsIu4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=azH6ANnxJoXdhWZ9KpCsNv+lt/prY6LoAXXxtrNROatXpfKxXmAVtaZUputOnaTysjgqTbzjoMfWu7BaXgbx/gyBIfObYygupsWzjSsutHzlq2bWeJs8mWmZVzi8cA08MA0odwvR9Yv2lS/rYk/FtZVU8hPJEabjyTli7qCl0I4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bZcdLKqq; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bZcdLKqq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729083705; x=1760619705; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YTucvGuqGqjSae/gXpF94kINnM6erhOXr9w7b7IsIu4=; b=bZcdLKqq7ybrB4OW8z/2C7lFKmtU3TXBeupX81NZZIqn4a0+YB+ng/72 HGX7kLA3IdXDBpc+lSz6EGbiZno2VPmfFKBzTh7ym2DLYZIIQ1nTFn6ZU pBMKgNbTaV+DIQfLpdwP++mvN8ARXksZT99kIIsH+Q4k+d6782UqN0ztW MVzkfuh9fTOTOQVRjVHc5JtlN7b/UPMHmWp76pVM05v6AYAnR3vMDnHEW gpmkEfVpKPcYsgQe8pe+rE8CG16dZ58NELgvsCEP1mNN0JA/P0mJ3BOwZ IEldNBSqgFlgLOT+mDsCcwkG4s5iRVxYbIwdfSWo03dRlmGu5bMrWpYzl g==; X-CSE-ConnectionGUID: 1xiPZTvESLuQpor1FOTtGg== X-CSE-MsgGUID: EvODLzklQ+OVOPMFG9ERIQ== X-IronPort-AV: E=McAfee;i="6700,10204,11226"; a="32450315" X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="32450315" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 06:01:45 -0700 X-CSE-ConnectionGUID: QWvBA436SratdYa1OROiGA== X-CSE-MsgGUID: BmkSvju7T8O/2fWPDECi3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="78566118" Received: from dev2.igk.intel.com ([10.237.148.94]) by fmviesa010.fm.intel.com with ESMTP; 16 Oct 2024 06:01:43 -0700 From: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= To: Jaroslav Kysela , Takashi Iwai , Mark Brown Cc: Cezary Rojewski , linux-sound@vger.kernel.org, =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= Subject: [RFC PATCH 2/4] ALSA: core: Allow polling for detection Date: Wed, 16 Oct 2024 15:02:26 +0200 Message-Id: <20241016130228.1013227-3-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016130228.1013227-1-amadeuszx.slawinski@linux.intel.com> References: <20241016130228.1013227-1-amadeuszx.slawinski@linux.intel.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-State: RFC In order for userspace to wait for detection event to happen, there needs to be possibility to wait in some way. Add API allowing to poll for event when stream is in detection state. Signed-off-by: Amadeusz Sławiński --- include/sound/pcm.h | 4 ++++ sound/core/pcm_native.c | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index f06ef7c718733..28df5bc5c131c 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -448,6 +448,9 @@ struct snd_pcm_runtime { struct snd_pcm_audio_tstamp_report audio_tstamp_report; struct timespec64 driver_tstamp; + /* -- detection -- */ + unsigned int detected:1; /* detection was triggered */ + #if IS_ENABLED(CONFIG_SND_PCM_OSS) /* -- OSS things -- */ struct snd_pcm_oss_runtime oss; @@ -592,6 +595,7 @@ int snd_pcm_start(struct snd_pcm_substream *substream); int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status); int snd_pcm_drain_done(struct snd_pcm_substream *substream); int snd_pcm_stop_xrun(struct snd_pcm_substream *substream); +void snd_pcm_detected(struct snd_pcm_substream *substream); #ifdef CONFIG_PM int snd_pcm_suspend_all(struct snd_pcm *pcm); #else diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 4fe1d2f41149c..c024eb0ed74ff 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -3662,6 +3662,14 @@ static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from) return result; } +void snd_pcm_detected(struct snd_pcm_substream *substream) +{ + substream->runtime->detected = 1; + + wake_up(&substream->runtime->sleep); +} +EXPORT_SYMBOL_GPL(snd_pcm_detected); + static __poll_t snd_pcm_poll(struct file *file, poll_table *wait) { struct snd_pcm_file *pcm_file; @@ -3690,6 +3698,10 @@ static __poll_t snd_pcm_poll(struct file *file, poll_table *wait) guard(pcm_stream_lock_irq)(substream); avail = snd_pcm_avail(substream); switch (runtime->state) { + case SNDRV_PCM_STATE_DETECTING: + if (runtime->detected) + mask = ok; + break; case SNDRV_PCM_STATE_RUNNING: case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PAUSED: From patchwork Wed Oct 16 13:02:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= X-Patchwork-Id: 13838454 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 167911C2325 for ; Wed, 16 Oct 2024 13:01:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729083708; cv=none; b=KEWoLfiMqJSmYyOkZKjRBsGjYhZ4rXB5XxkQy1MSW9p3hKuYtX6Iq9GSPcjJA+A63GE8PaamWw0lTTGR6agFycDI1B9wfRY0s9eIVgdtAgJIPRQALEJfZVbsRdiOIbzGBBqfLqqeYdIs4qn0K4y/T3aCgzdvPtJhyHq/SJkuJZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729083708; c=relaxed/simple; bh=zDmtgweDuOLg46Y8hyTZlkdExXCrOLa6FqIUvt3aulQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=U/v0qA0cDzpIiiP9cY3cZUC7IeyMhBdIzlDHrpAP2Pv8seJyej4r2gIehfAF2aZ9JJfwEDoIUH+rIxc7Oib3FknZH3DUvk5/pVCVmdsJzzO3hHEzIIi8OR6OzPXR4E3ShaR6wluejJ8VDwt149OhNy+nVyBISV58ScRWpX+uuHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=l8J67jOU; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="l8J67jOU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729083707; x=1760619707; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zDmtgweDuOLg46Y8hyTZlkdExXCrOLa6FqIUvt3aulQ=; b=l8J67jOUzpW/TpRIYbyBGVaux0842n55sE6yHR6iTaICh0OrKpsZsXFs +qDeukgyUWUtHl6cQ9c++UZxapBNvudBh81PydSZEXEhdaTmFWSju4O0s vKFPdWN3Tgu3XIJYHMxERtLDWGgaP/7ZxAzVv2Z/qxoyUktP3sIZr4WTa 2WdTWlIcXY1kLVIC+5IlXDAacE7rlqy8jqWlGq1eKW9o9NuGbfE3ybv3j Mt+1qB4OmA/Z7owx5PFqq964vgoKIFqWhSZ4cU6n6YDZnEBGYlJwMg67X Z6J4tCCQM3OH9nfbx8adhtzRbPSBOj/8ArbbZXlTWe600JoXjLcfTxodu A==; X-CSE-ConnectionGUID: XiUoo4YDSUSxpJJ7Z9oZ6g== X-CSE-MsgGUID: taK/YQpQR8aBExaWcpUzVQ== X-IronPort-AV: E=McAfee;i="6700,10204,11226"; a="32450324" X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="32450324" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 06:01:46 -0700 X-CSE-ConnectionGUID: IM9fvkH9RDKZnyQ221Dz4A== X-CSE-MsgGUID: TyAbngOdSJKZeatVqy4QSA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="78566138" Received: from dev2.igk.intel.com ([10.237.148.94]) by fmviesa010.fm.intel.com with ESMTP; 16 Oct 2024 06:01:45 -0700 From: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= To: Jaroslav Kysela , Takashi Iwai , Mark Brown Cc: Cezary Rojewski , linux-sound@vger.kernel.org, =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= Subject: [RFC PATCH 3/4] ASoC: pcm: Add support for running detect on capture stream Date: Wed, 16 Oct 2024 15:02:27 +0200 Message-Id: <20241016130228.1013227-4-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016130228.1013227-1-amadeuszx.slawinski@linux.intel.com> References: <20241016130228.1013227-1-amadeuszx.slawinski@linux.intel.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-State: RFC In order to be able to run detection on capture streams, DPCM state machine needs to be expanded to recognize "detect" state. Signed-off-by: Amadeusz Sławiński --- include/sound/soc-dpcm.h | 2 ++ sound/core/pcm_native.c | 2 +- sound/soc/soc-pcm.c | 56 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/include/sound/soc-dpcm.h b/include/sound/soc-dpcm.h index c6fb350b4b062..7062f77528edd 100644 --- a/include/sound/soc-dpcm.h +++ b/include/sound/soc-dpcm.h @@ -40,6 +40,7 @@ enum snd_soc_dpcm_state { SND_SOC_DPCM_STATE_OPEN, SND_SOC_DPCM_STATE_HW_PARAMS, SND_SOC_DPCM_STATE_PREPARE, + SND_SOC_DPCM_STATE_DETECT, SND_SOC_DPCM_STATE_START, SND_SOC_DPCM_STATE_STOP, SND_SOC_DPCM_STATE_PAUSED, @@ -98,6 +99,7 @@ struct snd_soc_dpcm_runtime { int trigger_pending; /* trigger cmd + 1 if pending, 0 if not */ + int be_detect; /* detection runinng on BE */ int be_start; /* refcount protected by BE stream pcm lock */ int be_pause; /* refcount protected by BE stream pcm lock */ bool fe_pause; /* used to track STOP after PAUSE */ diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index c024eb0ed74ff..5370797801132 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1470,7 +1470,7 @@ static const struct action_ops snd_pcm_action_detect = { * Return: Zero if successful, or a negative error code. * The stream lock must be acquired before calling this function. */ -int snd_pcm_detect(struct snd_pcm_substream *substream) +static int snd_pcm_detect(struct snd_pcm_substream *substream) { return snd_pcm_action_lock_irq(&snd_pcm_action_detect, substream, SNDRV_PCM_STATE_DETECTING); diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 7a59121fc323c..2d65008ec7a2b 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -110,6 +110,7 @@ static int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe, SND_SOC_DPCM_STATE_START, SND_SOC_DPCM_STATE_PAUSED, SND_SOC_DPCM_STATE_SUSPEND, + SND_SOC_DPCM_STATE_DETECT, }; return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state)); @@ -127,6 +128,7 @@ static int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe, SND_SOC_DPCM_STATE_PAUSED, SND_SOC_DPCM_STATE_SUSPEND, SND_SOC_DPCM_STATE_PREPARE, + SND_SOC_DPCM_STATE_DETECT, }; return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state)); @@ -171,6 +173,8 @@ static const char *dpcm_state_string(enum snd_soc_dpcm_state state) return "hw_params"; case SND_SOC_DPCM_STATE_PREPARE: return "prepare"; + case SND_SOC_DPCM_STATE_DETECT: + return "detect"; case SND_SOC_DPCM_STATE_START: return "start"; case SND_SOC_DPCM_STATE_STOP: @@ -1250,6 +1254,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + case SNDRV_PCM_TRIGGER_DETECT_START: for (i = 0; i < TRIGGER_MAX; i++) { r = trigger[start][i](substream, cmd, 0); if (r < 0) @@ -1274,6 +1279,9 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: cmd = SNDRV_PCM_TRIGGER_PAUSE_PUSH; break; + case SNDRV_PCM_TRIGGER_DETECT_START: + cmd = SNDRV_PCM_TRIGGER_DETECT_STOP; + break; } } @@ -1284,6 +1292,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + case SNDRV_PCM_TRIGGER_DETECT_STOP: for (i = TRIGGER_MAX; i > 0; i--) { r = trigger[stop][i - 1](substream, cmd, rollback); if (r < 0) @@ -2247,6 +2256,25 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, be->dai_link->name, cmd); switch (cmd) { + case SNDRV_PCM_TRIGGER_DETECT_START: + if (!be->dpcm[stream].be_start && + (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) && + (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP)) + goto next; + + be->dpcm[stream].be_detect++; + if (be->dpcm[stream].be_detect != 1) + goto next; + + ret = soc_pcm_trigger(be_substream, + SNDRV_PCM_TRIGGER_DETECT_START); + if (ret) { + be->dpcm[stream].be_detect--; + goto next; + } + + be->dpcm[stream].state = SND_SOC_DPCM_STATE_DETECT; + break; case SNDRV_PCM_TRIGGER_START: if (!be->dpcm[stream].be_start && (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) && @@ -2254,6 +2282,8 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED)) goto next; + if (be->dpcm[stream].be_detect > 0) + be->dpcm[stream].be_detect = 0; be->dpcm[stream].be_start++; if (be->dpcm[stream].be_start != 1) goto next; @@ -2308,6 +2338,23 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; break; + case SNDRV_PCM_TRIGGER_DETECT_STOP: + if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_DETECT) + goto next; + + be->dpcm[stream].be_detect--; + + if (be->dpcm[stream].be_detect != 0) + goto next; + + ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_DETECT_STOP); + if (ret) { + be->dpcm[stream].be_detect++; + goto next; + } + + be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; + break; case SNDRV_PCM_TRIGGER_STOP: if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) && (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED)) @@ -2440,11 +2487,13 @@ static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd) case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_DRAIN: + case SNDRV_PCM_TRIGGER_DETECT_START: ret = dpcm_dai_trigger_fe_be(substream, cmd, true); break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + case SNDRV_PCM_TRIGGER_DETECT_STOP: ret = dpcm_dai_trigger_fe_be(substream, cmd, false); break; default: @@ -2458,11 +2507,13 @@ static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd) case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_DRAIN: + case SNDRV_PCM_TRIGGER_DETECT_START: ret = dpcm_dai_trigger_fe_be(substream, cmd, false); break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + case SNDRV_PCM_TRIGGER_DETECT_STOP: ret = dpcm_dai_trigger_fe_be(substream, cmd, true); break; default: @@ -2484,6 +2535,10 @@ static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd) } switch (cmd) { + case SNDRV_PCM_TRIGGER_DETECT_START: + // return -EINVAL;? as FE is not running when detect happens? + fe->dpcm[stream].state = SND_SOC_DPCM_STATE_DETECT; + break; case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: @@ -2491,6 +2546,7 @@ static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd) break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_DETECT_STOP: fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: From patchwork Wed Oct 16 13:02:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= X-Patchwork-Id: 13838455 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 0B9531C2325 for ; Wed, 16 Oct 2024 13:01:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729083710; cv=none; b=WsJ47V1hLzsaaK3K5ARnWJP7s8R1o2iLrvPEvUzh2IroVEcjsrcZy+hmfwlFxHEsCSLc8zovfQnrfSm79qHMoyRIfoVTkrc3nYIHlLSofEgx7/63sReEzSuSMa0n/7LwlvnCFNfnw2NRNuRGwuMy1uUbe60hbBu+WcA08ly9PmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729083710; c=relaxed/simple; bh=PRZHQ+AHptGUSm+fntC4dYprPdUah1lZ1vJxzlzL6l8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=k9Ii2io+Fiua0YZkeFN1I+bzxKKYK2k6qRRHMn2NgqbUTPeeHF5eH+x1j8pvv6hMdDRmkMaMY1VFOf4yXPyiHMXBmYVFc8tCWCEDC4/PyyY46MYRGaAr7axXfnLWKX/qFP3yBGWJfmdhsUfOJLT/14WHrruhkBegQhwML68uLYg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=CKVV9YkR; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CKVV9YkR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729083709; x=1760619709; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PRZHQ+AHptGUSm+fntC4dYprPdUah1lZ1vJxzlzL6l8=; b=CKVV9YkRf5Jr0TUvEAxZlUHDRjsIAMww9zmqm9hupLbj8nU7pLjJFrmp r05fkwG+UMZ6gRvVhfkELVEZSuzXN5puyWjqKsrTGG6o75F0k+sY8DBcF 1cL2UnEWdMBuwtDFmWWX42104dFrjCoqBbPQjqMtNhH6SCQyLWzyVj42A /sRJbX8FSR9TzomwjnUcolnvQ/Z3SvzkMvit3kxkXlQKDaaT3SCZL2plq cyj0nh6rqhGervj0acEc8ByVxpLIFvplYhpoUH/f1CiQqUeIdfKfThoBl eYIsB/yukMAXgSH8J7P5/1XC2ugfam4kQmTV38f3Dk6R97FtR3L4TwnAr Q==; X-CSE-ConnectionGUID: FcLPSDDHS1KClGlx/ltLlQ== X-CSE-MsgGUID: 5afLzoCMRyGaUghIR216mg== X-IronPort-AV: E=McAfee;i="6700,10204,11226"; a="32450334" X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="32450334" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 06:01:48 -0700 X-CSE-ConnectionGUID: OyuqZPZATFWrliql3kGJ6g== X-CSE-MsgGUID: NByL8VQyQRWDr4ELQvxi+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="78566158" Received: from dev2.igk.intel.com ([10.237.148.94]) by fmviesa010.fm.intel.com with ESMTP; 16 Oct 2024 06:01:47 -0700 From: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= To: Jaroslav Kysela , Takashi Iwai , Mark Brown Cc: Cezary Rojewski , linux-sound@vger.kernel.org, =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= Subject: [RFC PATCH 4/4] ASoC: Propagate DETECT trigger Date: Wed, 16 Oct 2024 15:02:28 +0200 Message-Id: <20241016130228.1013227-5-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016130228.1013227-1-amadeuszx.slawinski@linux.intel.com> References: <20241016130228.1013227-1-amadeuszx.slawinski@linux.intel.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-State: RFC Adds support for DETECT trigger in ASoC API, so it can be propagated to ALSA core. Signed-off-by: Amadeusz Sławiński --- sound/soc/soc-component.c | 2 ++ sound/soc/soc-dai.c | 2 ++ sound/soc/soc-link.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index b67ef78f405c3..1ac8acb326623 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -1237,6 +1237,7 @@ int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream, case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + case SNDRV_PCM_TRIGGER_DETECT_START: for_each_rtd_components(rtd, i, component) { ret = soc_component_trigger(component, substream, cmd); if (ret < 0) @@ -1247,6 +1248,7 @@ int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream, case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + case SNDRV_PCM_TRIGGER_DETECT_STOP: for_each_rtd_components(rtd, i, component) { if (rollback && !soc_component_mark_match(component, substream, trigger)) continue; diff --git a/sound/soc/soc-dai.c b/sound/soc/soc-dai.c index 4a1c85ad5a8d6..41fc4ce682a63 100644 --- a/sound/soc/soc-dai.c +++ b/sound/soc/soc-dai.c @@ -616,6 +616,7 @@ int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream, case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + case SNDRV_PCM_TRIGGER_DETECT_START: for_each_rtd_dais(rtd, i, dai) { ret = soc_dai_trigger(dai, substream, cmd); if (ret < 0) @@ -630,6 +631,7 @@ int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream, case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + case SNDRV_PCM_TRIGGER_DETECT_STOP: for_each_rtd_dais(rtd, i, dai) { if (rollback && !soc_dai_mark_match(dai, substream, trigger)) continue; diff --git a/sound/soc/soc-link.c b/sound/soc/soc-link.c index 7f1f1bc717e2c..30d283062baee 100644 --- a/sound/soc/soc-link.c +++ b/sound/soc/soc-link.c @@ -163,6 +163,7 @@ int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd, case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + case SNDRV_PCM_TRIGGER_DETECT_START: ret = soc_link_trigger(substream, cmd); if (ret < 0) break; @@ -171,6 +172,7 @@ int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd, case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + case SNDRV_PCM_TRIGGER_DETECT_STOP: if (rollback && !soc_link_mark_match(rtd, substream, trigger)) break;