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
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
78 changes: 52 additions & 26 deletions sound/soc/sof/pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
}

platform_params = &spcm->platform_params[substream->stream];
ret = snd_sof_pcm_platform_hw_params(sdev, substream, params, platform_params);
if (ret < 0) {
spcm_err(spcm, substream->stream, "platform hw params failed\n");
return ret;
if (!spcm->stream[substream->stream].hostless) {
ret = snd_sof_pcm_platform_hw_params(sdev, substream, params, platform_params);
if (ret < 0) {
spcm_err(spcm, substream->stream, "platform hw params failed\n");
return ret;
}
}

/* if this is a repeated hw_params without hw_free, skip setting up widgets */
Expand All @@ -174,7 +176,7 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
return ret;
}

if (!sdev->dspless_mode_selected) {
if (!sdev->dspless_mode_selected && !spcm->stream[substream->stream].hostless) {
int host_comp_id = spcm->stream[substream->stream].comp_id;

host_widget = snd_sof_find_swidget_by_comp_id(sdev, host_comp_id);
Expand All @@ -190,7 +192,7 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
}

/* create compressed page table for audio firmware */
if (runtime->buffer_changed) {
if (!spcm->stream[substream->stream].hostless && runtime->buffer_changed) {
struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream);

ret = snd_sof_create_page_table(component->dev, dmab,
Expand All @@ -217,7 +219,8 @@ static int sof_pcm_stream_free(struct snd_sof_dev *sdev,

if (spcm->prepared[substream->stream]) {
/* stop DMA first if needed */
if (pcm_ops && pcm_ops->platform_stop_during_hw_free)
if (!spcm->stream[substream->stream].hostless &&
pcm_ops && pcm_ops->platform_stop_during_hw_free)
snd_sof_pcm_platform_trigger(sdev, substream,
SNDRV_PCM_TRIGGER_STOP);

Expand All @@ -237,12 +240,14 @@ static int sof_pcm_stream_free(struct snd_sof_dev *sdev,
}

/* reset the DMA */
ret = snd_sof_pcm_platform_hw_free(sdev, substream);
if (ret < 0) {
spcm_err(spcm, substream->stream,
"platform hw free failed %d\n", ret);
if (!err)
err = ret;
if (!spcm->stream[substream->stream].hostless) {
ret = snd_sof_pcm_platform_hw_free(sdev, substream);
if (ret < 0) {
spcm_err(spcm, substream->stream,
"platform hw free failed %d\n", ret);
if (!err)
err = ret;
}
}

/* free widget list */
Expand Down Expand Up @@ -445,7 +450,8 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
* They don't use Deep Buffer
*/
if (sdev->system_suspend_target == SOF_SUSPEND_S0IX &&
substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
(substream->stream == SNDRV_PCM_STREAM_CAPTURE ||
spcm->stream[substream->stream].hostless) &&
spcm->stream[substream->stream].d0i3_compatible &&
spcm->stream[substream->stream].dsp_max_burst_size_in_ms <= 1) {
spcm->stream[substream->stream].suspend_ignored = true;
Expand All @@ -466,7 +472,7 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
return -EINVAL;
}

if (!ipc_first)
if (!ipc_first && !spcm->stream[substream->stream].hostless)
snd_sof_pcm_platform_trigger(sdev, substream, cmd);

if (pcm_ops && pcm_ops->trigger)
Expand All @@ -476,14 +482,15 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
case SNDRV_PCM_TRIGGER_START:
/* invoke platform trigger to start DMA only if pcm_ops is successful */
if (ipc_first && !ret)
if (ipc_first && !ret && !spcm->stream[substream->stream].hostless)
snd_sof_pcm_platform_trigger(sdev, substream, cmd);
break;
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
case SNDRV_PCM_TRIGGER_STOP:
/* invoke platform trigger to stop DMA even if pcm_ops isn't set or if it failed */
if (!pcm_ops || !pcm_ops->platform_stop_during_hw_free)
if (!spcm->stream[substream->stream].hostless &&
(!pcm_ops || !pcm_ops->platform_stop_during_hw_free))
snd_sof_pcm_platform_trigger(sdev, substream, cmd);

/*
Expand Down Expand Up @@ -520,6 +527,10 @@ static snd_pcm_uframes_t sof_pcm_pointer(struct snd_soc_component *component,
if (rtd->dai_link->no_pcm)
return 0;

spcm = snd_sof_find_spcm_dai(component, rtd);
if (spcm && spcm->stream[substream->stream].hostless)
return 0;

if (pcm_ops && pcm_ops->pointer)
ret = pcm_ops->pointer(component, substream, &host);

Expand All @@ -530,7 +541,6 @@ static snd_pcm_uframes_t sof_pcm_pointer(struct snd_soc_component *component,
if (sof_ops(sdev)->pcm_pointer)
return sof_ops(sdev)->pcm_pointer(sdev, substream);

spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm)
return -EINVAL;

Expand Down Expand Up @@ -592,6 +602,12 @@ static int sof_pcm_open(struct snd_soc_component *component,
spcm->stream[substream->stream].substream = substream;
spcm->prepared[substream->stream] = false;

if (spcm->stream[substream->stream].hostless) {
if (spcm->stream[substream->stream].d0i3_compatible)
runtime->hw.info |= SNDRV_PCM_INFO_RESUME;
return 0;
}

ret = snd_sof_pcm_platform_open(sdev, substream);
if (ret < 0) {
spcm_err(spcm, substream->stream,
Expand Down Expand Up @@ -626,14 +642,16 @@ static int sof_pcm_close(struct snd_soc_component *component,

spcm_dbg(spcm, substream->stream, "Entry: close\n");

err = snd_sof_pcm_platform_close(sdev, substream);
if (err < 0) {
spcm_err(spcm, substream->stream,
"platform pcm close failed %d\n", err);
/*
* keep going, no point in preventing the close
* from happening
*/
if (!spcm->stream[substream->stream].hostless) {
err = snd_sof_pcm_platform_close(sdev, substream);
if (err < 0) {
spcm_err(spcm, substream->stream,
"platform pcm close failed %d\n", err);
/*
* keep going, no point in preventing the close
* from happening
*/
}
}

spcm->stream[substream->stream].substream = NULL;
Expand Down Expand Up @@ -815,7 +833,15 @@ static void sof_pcm_remove(struct snd_soc_component *component)
static int sof_pcm_ack(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
struct snd_sof_pcm *spcm;

if (!rtd->dai_link->no_pcm) {
spcm = snd_sof_find_spcm_dai(component, rtd);
if (spcm && spcm->stream[substream->stream].hostless)
return 0;
}

return snd_sof_pcm_platform_ack(sdev, substream);
}
Expand Down
Loading
Loading