Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/sound/sof/ipc4/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ struct sof_ipc4_notify_module_data {
#define SOF_IPC4_NOTIFY_MODULE_EVENTID_ALSA_MAGIC_VAL 0xA15A0000
#define SOF_IPC4_NOTIFY_MODULE_EVENTID_ALSA_PARAMID_MASK GENMASK(15, 0)
#define SOF_IPC4_NOTIFY_MODULE_EVENTID_COMPR_MAGIC_VAL 0xC0C00000
#define SOF_IPC4_NOTIFY_MODULE_EVENTID_GESTURE_MAGIC_VAL 0x6E570000

/*
* Macros for creating struct sof_ipc4_module_init_ext_init payload
Expand Down
85 changes: 85 additions & 0 deletions include/uapi/sound/sof/ultrasound.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
/*
* Sound Open Firmware (SOF) Ultrasonic Gesture & Presence Detection UAPI
*
* Copyright(c) 2026 Intel Corporation.
*/

#ifndef __INCLUDE_UAPI_SOUND_SOF_ULTRASOUND_H__
#define __INCLUDE_UAPI_SOUND_SOF_ULTRASOUND_H__

#include <linux/ioctl.h>
#include <linux/types.h>

#define SOF_ULTRASOUND_UAPI_VERSION 1

/* Lower 16 bits of IPC4 module notification event_id */
#define SOF_US_EVENT_SUBTYPE_GESTURE 1
#define SOF_US_EVENT_SUBTYPE_PRESENCE 2

/**
* enum sof_ultrasound_event_type - Ultrasonic gesture / presence event codes
*/
enum sof_ultrasound_event_type {
SOF_US_EVT_NONE = 0,
SOF_US_EVT_PUSH = 1,
SOF_US_EVT_PULL = 2,
SOF_US_EVT_TAP = 3,
SOF_US_EVT_SWIPE_LEFT = 4,
SOF_US_EVT_SWIPE_RIGHT = 5,
SOF_US_EVT_PRESENCE_DETECTED = 6,
SOF_US_EVT_PRESENCE_LOST = 7,
};

/**
* struct sof_ultrasound_dsp_event - Wire format sent by SOF DSP inside
* struct sof_ipc4_notify_module_data.event_data[]
*/
struct sof_ultrasound_dsp_event {
__u32 version;
__u32 event_type;
__s32 doppler_mhz;
__s32 velocity_mm_s;
__u32 confidence;
__u32 snr_db_q8;
__u32 carrier_hz;
__u32 seq;
__u64 dsp_timestamp_us;
} __attribute__((packed, aligned(4)));

/**
* struct sof_ultrasound_uapi_event - Event record returned by read() on
* /dev/sof-ultrasound<N>
*/
struct sof_ultrasound_uapi_event {
__u32 abi_version; /* SOF_ULTRASOUND_UAPI_VERSION */
__u32 event_type; /* enum sof_ultrasound_event_type */
__u16 module_id; /* IPC4 originator module ID */
__u16 instance_id; /* IPC4 originator instance ID */
__u32 subtype; /* SOF_US_EVENT_SUBTYPE_* */
__s32 doppler_mhz; /* signed peak Doppler shift in millihertz */
__s32 velocity_mm_s; /* estimated radial velocity in mm/s */
__u32 confidence; /* 0..1000 (0.0% .. 100.0%) */
__u32 snr_db_q8; /* peak SNR above noise floor in Q24.8 dB */
__u32 carrier_hz; /* ultrasonic carrier frequency in Hz */
__u32 seq; /* DSP monotonic event sequence number */
__u64 dsp_timestamp_us; /* DSP stream timestamp in microseconds */
__u64 host_ktime_ns; /* Linux CLOCK_MONOTONIC timestamp in ns */
};

/**
* struct sof_ultrasound_stats - Diagnostic counters queried via ioctl
*/
struct sof_ultrasound_stats {
__u64 total_events;
__u64 dropped_events;
__u32 active_readers;
__u32 last_event_type;
};

#define SOF_ULTRASOUND_IOC_MAGIC 'U'
#define SOF_ULTRASOUND_IOC_GET_STATS \
_IOR(SOF_ULTRASOUND_IOC_MAGIC, 1, struct sof_ultrasound_stats)
#define SOF_ULTRASOUND_IOC_FLUSH _IO(SOF_ULTRASOUND_IOC_MAGIC, 2)

#endif /* __INCLUDE_UAPI_SOUND_SOF_ULTRASOUND_H__ */
15 changes: 15 additions & 0 deletions sound/soc/sof/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ config SND_SOC_SOF_CLIENT
This option is not user-selectable but automagically handled by
'select' statements at a higher level.

config SND_SOC_SOF_ULTRASOUND
tristate "SOF ultrasonic gesture and presence sensing client"
depends on SND_SOC_SOF && SND_SOC_SOF_IPC4
depends on INPUT
select SND_SOC_SOF_CLIENT
help
This option enables the SOF IPC4 ultrasonic gesture and presence
sensing client driver (snd-sof-ultrasound). It manages hostless
DSP-autonomous ultrasonic TX/RX streams with zero host audio DMA,
supports D0i3/S0ix low-power sensing, and delivers gesture and
presence events to userspace via /dev/sof-ultrasound<N>, the Linux
input subsystem, and sysfs.
Say Y or M if you want to enable SOF ultrasonic gesture sensing.
If unsure select "N".

config SND_SOC_SOF_DEVELOPER_SUPPORT
bool "SOF developer options support"
depends on EXPERT && SND_SOC_SOF
Expand Down
2 changes: 2 additions & 0 deletions sound/soc/sof/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ifneq ($(CONFIG_SND_SOC_SOF_IPC4),)
snd-sof-probes-y += sof-client-probes-ipc4.o
endif
snd-sof-fw-gdb-objs := sof-client-fw-gdb.o
snd-sof-ultrasound-objs := sof-client-ultrasound.o

snd-sof-nocodec-y := nocodec.o

Expand All @@ -55,6 +56,7 @@ obj-$(CONFIG_SND_SOC_SOF_DEBUG_IPC_MSG_INJECTOR) += snd-sof-ipc-msg-injector.o
obj-$(CONFIG_SND_SOC_SOF_DEBUG_IPC_KERNEL_INJECTOR) += snd-sof-ipc-kernel-injector.o
obj-$(CONFIG_SND_SOC_SOF_DEBUG_PROBES) += snd-sof-probes.o
obj-$(CONFIG_SND_SOC_SOF_DEBUG_FW_GDB) += snd-sof-fw-gdb.o
obj-$(CONFIG_SND_SOC_SOF_ULTRASOUND) += snd-sof-ultrasound.o

obj-$(CONFIG_SND_SOC_SOF_INTEL_TOPLEVEL) += intel/
obj-$(CONFIG_SND_SOC_SOF_IMX_TOPLEVEL) += imx/
Expand Down
2 changes: 2 additions & 0 deletions sound/soc/sof/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,13 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
INIT_LIST_HEAD(&sdev->ipc_client_list);
INIT_LIST_HEAD(&sdev->ipc_rx_handler_list);
INIT_LIST_HEAD(&sdev->fw_state_handler_list);
INIT_LIST_HEAD(&sdev->card_disconnect_handler_list);
spin_lock_init(&sdev->ipc_lock);
spin_lock_init(&sdev->hw_lock);
mutex_init(&sdev->power_state_access);
mutex_init(&sdev->ipc_client_mutex);
mutex_init(&sdev->client_event_handler_mutex);
mutex_init(&sdev->card_disconnect_mutex);
mutex_init(&sdev->dsp_fw_boot_mutex);

/* set default timeouts if none provided */
Expand Down
22 changes: 11 additions & 11 deletions sound/soc/sof/intel/hda-dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,21 @@ static bool hda_dai_has_wov_fe(struct snd_sof_dev *sdev, struct snd_pcm_substrea
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_soc_dpcm *dpcm;
struct snd_sof_pcm *spcm;

if (substream->stream != SNDRV_PCM_STREAM_CAPTURE)
return false;
int dir = substream->stream;

/*
* Only retain the BE for a connected WoV capture FE that is running
* or has already ignored its suspend trigger. An idle WoV FE may
* still be connected to the BE.
* Retain the BE for a connected WoV capture FE or hostless D0i3-compatible
* FE (e.g., ultrasonic sensing TX/RX) that is running or has already
* ignored its suspend trigger.
*/
for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
for_each_dpcm_fe(rtd, dir, dpcm) {
spcm = snd_sof_find_spcm_dai(sdev->component, dpcm->fe);
if (spcm && spcm->stream[SNDRV_PCM_STREAM_CAPTURE].d0i3_compatible &&
spcm->stream[SNDRV_PCM_STREAM_CAPTURE].dsp_max_burst_size_in_ms <= 1 &&
(dpcm->fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].state == SND_SOC_DPCM_STATE_START ||
spcm->stream[SNDRV_PCM_STREAM_CAPTURE].suspend_ignored))
if (spcm &&
(dir == SNDRV_PCM_STREAM_CAPTURE || spcm->stream[dir].hostless) &&
spcm->stream[dir].d0i3_compatible &&
spcm->stream[dir].dsp_max_burst_size_in_ms <= 1 &&
(dpcm->fe->dpcm[dir].state == SND_SOC_DPCM_STATE_START ||
spcm->stream[dir].suspend_ignored))
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions sound/soc/sof/ipc4-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,10 @@ void sof_ipc4_build_time_info(struct snd_sof_dev *sdev, struct snd_sof_pcm_strea
}
}

/* hostless streams have no host copier or host DMA timestamp */
if (sps->hostless)
return;

/* both host and dai copier must be valid for time_info */
if (!host_copier || !dai_copier) {
dev_err(sdev->dev, "host or dai copier are not found\n");
Expand Down
2 changes: 2 additions & 0 deletions sound/soc/sof/ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,8 @@ static void sof_ipc4_rx_msg(struct snd_sof_dev *sdev)
if (handler_func)
handler_func(sdev, ipc4_msg);

sof_client_ipc_rx_dispatcher(sdev, ipc4_msg);

sof_ipc4_log_header(sdev->dev, "ipc rx done ", ipc4_msg, true);

if (data_size) {
Expand Down
Loading
Loading