Skip to content

ASoC: SOF: add hostless FE PCM support and ultrasonic gesture sensing client - #6074

Draft
lgirdwood wants to merge 3 commits into
thesofproject:topic/sof-devfrom
lgirdwood:topic/ultrasound-gesture
Draft

lgirdwood wants to merge 3 commits into
thesofproject:topic/sof-devfrom
lgirdwood:topic/ultrasound-gesture

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Summary

Companion Linux kernel PR for SOF DSP-autonomous ultrasonic Doppler gesture and presence sensing:

Commits

  1. ASoC: SOF: core: support hostless DSP-autonomous FE PCM streams
    • Recognizes virtual aif_in/aif_out topology widgets with priv.size == 0 as swidget->hostless / spcm->stream[dir].hostless.
    • Skips DSP host-copier creation, virtual AIF MOD_BIND, and all Host HDA DMA operations (open/hw_params/trigger/hw_free/close/page-table/time_info) while keeping connected DSP and BE pipelines active.
    • Extends S0ix suspend_ignored and hda_dai_has_wov_fe() so hostless D0i3-compatible playback and capture streams (including ignore_suspend=1 links) retain DSP pipelines and BE links in D0I3 across s2idle.
  2. ASoC: SOF: ipc4: dispatch IPC4 RX notifications to SOF client drivers
    • Calls sof_client_ipc_rx_dispatcher() from sof_ipc4_rx_msg().
    • Fixes the IPC4 notification type bounds check in sof_client_register_ipc_rx_handler() (ipc_msg_type >= SOF_IPC4_NOTIFY_TYPE_LAST), defines SOF_IPC4_NOTIFY_MODULE_EVENTID_GESTURE_MAGIC_VAL, and exports sof_client_get_component().
  3. ASoC: SOF: client: add ultrasonic gesture and presence sensing driver
    • Adds CONFIG_SND_SOC_SOF_ULTRASOUND (snd-sof-ultrasound, depends on SND_SOC_SOF && SND_SOC_SOF_IPC4 && INPUT) and UAPI header include/uapi/sound/sof/ultrasound.h.
    • Manages hostless Ultrasound TX / Ultrasound RX PCMs directly in kernel space (auto-enabled on /dev/sof-ultrasound<N> open or via sysfs enable) with dynamic ignore_suspend save/restore.
    • Exposes /dev/sof-ultrasound<N> (multi-reader kfifo, read/poll/ioctl), Linux input device ("SOF Ultrasound Gesture", EV_MSC/MSC_GESTURE & EV_SW/SW_FRONT_PROXIMITY), and sysfs telemetry.

Verification (Wildcat Lake / ACE 3.0 + RT722 + 4-ch Intel PDM DMIC)

  • scripts/checkpatch.pl: 0 errors, 0 warnings across all 3 patches.
  • make M=sound/soc/sof W=1: 0 warnings with both CONFIG_SND_SOC_SOF_ULTRASOUND=m and =n.
  • Hardware-verified on Ladybird: hostless bring-up via sysfs and auto-enable on /dev/sof-ultrasound0 open, clean D3 teardown on close, zero host DMA period IRQs, simultaneous speaker playback & DMIC capture coexistence, 7/7 gesture & presence events with dropped=0, automatic D0I3 entry, and clean rtcwake -m freeze -s 4 (s2idle) retention without FW reload.

Enable front-end PCM streams that are driven autonomously inside the DSP
without allocating or triggering a Host HDA DMA channel or instantiating a
DSP host-copier module (e.g. always-on ultrasonic TX tone generation and
terminal RX Doppler gesture detection).

When an aif_in/aif_out topology widget carries zero private token payload
(tw->priv.size == 0), mark swidget->hostless and propagate it to
spcm->stream[dir].hostless:
- Skip DSP copier creation and IPC4 MOD_BIND on the virtual AIF widget
  while still traversing connected DSP processing and BE pipelines.
- Skip Host DMA open, hw_params, trigger, hw_free, close, page-table
  setup, and host/DAI time_info registration; advertise
  SNDRV_PCM_INFO_RESUME for seamless S0ix retention.
- Allow hostless D0i3-compatible playback and capture streams (including
  those with ignore_suspend=1 on their FE DAI link) to keep both DSP
  pipelines and their connected BE DAI links running in D0i3 across S0ix
  suspend/resume.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Wire sof_client_ipc_rx_dispatcher() into sof_ipc4_rx_msg() so auxiliary
SOF client drivers can subscribe to IPC4 firmware notifications (such as
SOF_IPC4_NOTIFY_MODULE_NOTIFICATION).

Also fix the IPC4 notification type bounds check in
sof_client_register_ipc_rx_handler() (ipc_msg_type is a shifted enum
value, not a pre-shifted header mask, so validate against
SOF_IPC4_NOTIFY_TYPE_LAST), define the gesture module notification magic
prefix SOF_IPC4_NOTIFY_MODULE_EVENTID_GESTURE_MAGIC_VAL, and export
sof_client_get_component() so client drivers can access the ASoC card.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add the snd-sof-ultrasound auxiliary client driver
(CONFIG_SND_SOC_SOF_ULTRASOUND) and UAPI header
(include/uapi/sound/sof/ultrasound.h) for DSP-autonomous ultrasonic
Doppler gesture and presence sensing on IPC4 platforms:

- Kernel-managed hostless stream lifecycle: opens, configures (48 kHz
  S32_LE, NO_PERIOD_WAKEUP, zero host DMA), and starts the hostless
  "Ultrasound TX" and "Ultrasound RX" DPCM streams either automatically
  when a userspace reader opens /dev/sof-ultrasound<N> (auto_enable=1) or
  explicitly via /sys/class/misc/sof-ultrasound<N>/enable.
- S0ix low-power support: dynamically sets and restores ignore_suspend on
  the hostless FE and sensing BE DAI links while active so the DSP stays
  in D0i3 across s2idle suspend/resume without tearing down sensing.
- Userspace event interfaces:
  1. /dev/sof-ultrasound<N> multi-reader kfifo supporting read(), poll(),
     SOF_ULTRASOUND_IOC_GET_STATS, and SOF_ULTRASOUND_IOC_FLUSH.
  2. Linux input device ("SOF Ultrasound Gesture") emitting EV_MSC /
     MSC_GESTURE and EV_SW / SW_FRONT_PROXIMITY events.
  3. Sysfs controls and telemetry (enable, active, auto_enable, stats,
     last_event).

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical error-path and PCM lifetime bugs can crash the kernel, while missing suspend/resume handling can leave sensing streams unable to recover after S3 or hibernation.

5 open issues
What changed in this PR

Adds Linux SOF support for DSP-autonomous ultrasonic gesture and presence sensing, complementing the linked firmware/topology PR.

Changes:

  • Supports hostless frontend PCM streams without host DMA, including S0ix pipeline retention.
  • Routes IPC4 notifications to SOF clients.
  • Adds an ultrasound client with stream control, event delivery, input reporting, and sysfs telemetry.
File Description
sound/​soc/​sof/​topology.c Identifies hostless AIF widgets and skips their DSP setup.
sound/​soc/​sof/​sof-client.h Declares the component-access helper.
sound/​soc/​sof/​sof-client.c Registers the ultrasound client and corrects notification validation.
sound/​soc/​sof/​sof-client-ultrasound.c Implements sensing lifecycle and userspace interfaces.
sound/​soc/​sof/​sof-audio.h Adds hostless stream and widget flags.
sound/​soc/​sof/​sof-audio.c Handles hostless widget traversal and suspend retention.
sound/​soc/​sof/​pcm.c Bypasses host DMA operations for hostless streams.
sound/​soc/​sof/​Makefile Adds the ultrasound module build target.
sound/​soc/​sof/​Kconfig Adds the ultrasound configuration option.
sound/​soc/​sof/​ipc4.c Dispatches received notifications to clients.
sound/​soc/​sof/​ipc4-pcm.c Skips host timestamp setup for hostless streams.
sound/​soc/​sof/​intel/​hda-dai.c Extends backend retention to compatible hostless streams.
include/​uapi/​sound/​sof/​ultrasound.h Defines event records and ioctl interfaces.
include/​sound/​sof/​ipc4/​header.h Defines the gesture notification identifier.

Review effort: Balanced

Comment thread sound/soc/sof/sof-audio.c
Comment on lines +495 to 496
if (!swidget || swidget->hostless)
goto sink_prepare;
Comment on lines +186 to +188
mutex_lock(&pcm->open_mutex);
err = snd_pcm_open_substream(pcm, dir, &priv->dummy_file, &substream);
mutex_unlock(&pcm->open_mutex);
Comment on lines +355 to +357
/* Approach B: mark FE and BE links ignore_suspend while hostless sensing is active */
sof_ultrasound_save_ignore_suspend(priv, tx_rtd->dai_link);
sof_ultrasound_save_ignore_suspend(priv, rx_rtd->dai_link);
Comment on lines +691 to +693
mutex_lock(&priv->ctrl_mutex);
if (!priv->sysfs_enabled && priv->sensing_active)
sof_ultrasound_stop_sensing_locked(priv);
priv->miscdev.groups = sof_ultrasound_groups;
priv->miscdev.parent = &auxdev->dev;

ret = misc_register(&priv->miscdev);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants