From 7695d5e6e4827761b86beb3dde1f2a0409c5d3d2 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Mon, 6 Jul 2026 23:06:35 +0200 Subject: [PATCH] ASoC: qdsp6: q6apm: add voice-call blob-player prototype (FP6 bring-up) Replay pre-generated APM command sequences (GRAPH_OPEN/SET_CFG/PREPARE/ START, mined from the stock FP6 ACDB by utilities/mkvoiceblobs.py) through the q6apm GPR channel via /sys/kernel/debug/q6apm-voice-proto/play. Bring-up prototype for cellular voice-call audio: the replayed graphs contain the VCPM voice config; the modem and the ADSP VCPM service attach the vocoder to them once a call is active. Local carry only, NOT for upstream (the upstreamable form will be topology-driven). Assisted-by: Claude:claude-fable-5 --- sound/soc/qcom/qdsp6/Makefile | 2 +- sound/soc/qcom/qdsp6/q6apm-voice-proto.c | 156 +++++++++++++++++++++++ sound/soc/qcom/qdsp6/q6apm.c | 3 + sound/soc/qcom/qdsp6/q6apm.h | 4 + 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 sound/soc/qcom/qdsp6/q6apm-voice-proto.c diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile index 67267304e7e9..d650e0b0ba5b 100644 --- a/sound/soc/qcom/qdsp6/Makefile +++ b/sound/soc/qcom/qdsp6/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only snd-q6dsp-common-y := q6dsp-common.o q6dsp-lpass-ports.o q6dsp-lpass-clocks.o -snd-q6apm-y := q6apm.o audioreach.o topology.o +snd-q6apm-y := q6apm.o audioreach.o topology.o q6apm-voice-proto.o obj-$(CONFIG_SND_SOC_QDSP6_COMMON) += snd-q6dsp-common.o obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o diff --git a/sound/soc/qcom/qdsp6/q6apm-voice-proto.c b/sound/soc/qcom/qdsp6/q6apm-voice-proto.c new file mode 100644 index 000000000000..e3c6587dde93 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6apm-voice-proto.c @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Voice-call bring-up prototype for the Fairphone (Gen. 6): replay + * pre-generated APM command sequences through the q6apm GPR channel. + * + * The blobs reproduce, byte for byte, the GRAPH_OPEN/SET_CFG/PREPARE/START + * sequence the stock Android PAL/AGM/GSL stack sends to set up the + * handset voice-call graphs (mined from the device ACDB; generated by + * utilities/mkvoiceblobs.py in the bring-up repo). The modem's voice + * engine and the ADSP VCPM service wire up the vocoder themselves once + * these graphs are running. + * + * Local prototype only, NOT for upstream. Interface: + * echo > /sys/kernel/debug/q6apm-voice-proto/play + * where is relative to /lib/firmware. Playback aborts on the + * first command the DSP rejects. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "audioreach.h" +#include "q6apm.h" + +#define Q6VP_MAGIC 0x50563651 /* "Q6VP" little-endian */ +#define Q6VP_VERSION 1 + +struct q6vp_hdr { + __le32 magic; + __le32 version; + __le32 num_records; +} __packed; + +struct q6vp_rec { + __le32 opcode; + __le32 size; +} __packed; + +static struct q6apm *q6vp_apm; +static struct dentry *q6vp_dir; + +static int q6vp_send(uint32_t opcode, const void *payload, uint32_t size) +{ + struct gpr_pkt *pkt; + int ret; + + pkt = audioreach_alloc_apm_cmd_pkt(size, opcode, 0); + if (IS_ERR(pkt)) + return PTR_ERR(pkt); + + memcpy((void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE, payload, size); + + ret = q6apm_send_cmd_sync(q6vp_apm, pkt, 0); + kfree(pkt); + + return ret; +} + +static int q6vp_play(const char *name) +{ + const struct firmware *fw; + const struct q6vp_hdr *hdr; + const struct q6vp_rec *rec; + struct device *dev = q6vp_apm->dev; + size_t off; + uint32_t i, num, opcode, size; + int ret; + + ret = request_firmware(&fw, name, dev); + if (ret) { + dev_err(dev, "voice-proto: cannot load %s (%d)\n", name, ret); + return ret; + } + + hdr = (const struct q6vp_hdr *)fw->data; + if (fw->size < sizeof(*hdr) || + le32_to_cpu(hdr->magic) != Q6VP_MAGIC || + le32_to_cpu(hdr->version) != Q6VP_VERSION) { + dev_err(dev, "voice-proto: %s: bad header\n", name); + ret = -EINVAL; + goto out; + } + + num = le32_to_cpu(hdr->num_records); + off = sizeof(*hdr); + for (i = 0; i < num; i++) { + if (off + sizeof(*rec) > fw->size) { + ret = -EINVAL; + goto out; + } + rec = (const struct q6vp_rec *)(fw->data + off); + opcode = le32_to_cpu(rec->opcode); + size = le32_to_cpu(rec->size); + off += sizeof(*rec); + if (off + size > fw->size) { + ret = -EINVAL; + goto out; + } + + ret = q6vp_send(opcode, fw->data + off, size); + dev_info(dev, "voice-proto: %s[%u] opcode 0x%08x size %u -> %d\n", + name, i, opcode, size, ret); + if (ret) + goto out; + + off += ALIGN(size, 4); + } + +out: + release_firmware(fw); + return ret; +} + +static ssize_t q6vp_play_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + char name[128]; + int ret; + + if (!q6vp_apm) + return -ENODEV; + if (count >= sizeof(name)) + return -EINVAL; + if (copy_from_user(name, ubuf, count)) + return -EFAULT; + name[count] = '\0'; + strim(name); + + ret = q6vp_play(name); + + return ret ? ret : count; +} + +static const struct file_operations q6vp_play_fops = { + .open = simple_open, + .write = q6vp_play_write, + .llseek = default_llseek, +}; + +void q6apm_voice_proto_init(struct q6apm *apm) +{ + q6vp_apm = apm; + q6vp_dir = debugfs_create_dir("q6apm-voice-proto", NULL); + debugfs_create_file("play", 0200, q6vp_dir, NULL, &q6vp_play_fops); +} + +void q6apm_voice_proto_exit(void) +{ + debugfs_remove_recursive(q6vp_dir); + q6vp_dir = NULL; + q6vp_apm = NULL; +} diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c index 2ab378fb5032..cd7a9a1e0b9b 100644 --- a/sound/soc/qcom/qdsp6/q6apm.c +++ b/sound/soc/qcom/qdsp6/q6apm.c @@ -764,6 +764,8 @@ static int apm_probe(gpr_device_t *gdev) g_apm = apm; + q6apm_voice_proto_init(apm); + q6apm_get_apm_state(apm); ret = snd_soc_register_component(dev, &q6apm_audio_component, NULL, 0); @@ -781,6 +783,7 @@ static int apm_probe(gpr_device_t *gdev) static void apm_remove(gpr_device_t *gdev) { + q6apm_voice_proto_exit(); of_platform_depopulate(&gdev->dev); snd_soc_unregister_component(&gdev->dev); } diff --git a/sound/soc/qcom/qdsp6/q6apm.h b/sound/soc/qcom/qdsp6/q6apm.h index 376a36700c53..736a2b53f303 100644 --- a/sound/soc/qcom/qdsp6/q6apm.h +++ b/sound/soc/qcom/qdsp6/q6apm.h @@ -157,4 +157,8 @@ int q6apm_remove_initial_silence(struct device *dev, struct q6apm_graph *graph, int q6apm_remove_trailing_silence(struct device *dev, struct q6apm_graph *graph, uint32_t samples); int q6apm_set_real_module_id(struct device *dev, struct q6apm_graph *graph, uint32_t codec_id); int q6apm_get_hw_pointer(struct q6apm_graph *graph, int dir); + +/* FP6 voice-call bring-up prototype (q6apm-voice-proto.c) */ +void q6apm_voice_proto_init(struct q6apm *apm); +void q6apm_voice_proto_exit(void); #endif /* __APM_GRAPH_ */