[PATCH v2 15/19] ASoC: qcom: lpass: allocate LPM buffer memory to DAIs

From: Neil Armstrong

Date: Tue Nov 24 2026 - 12:33:21 EST


When using MI2S on non-core LPAIFs, the hardware can only
fetch data from the LPM buffers and not from DDR memory,
allocate the DMA buffers in each LPM memory for all users
and drop the static allocation.

Signed-off-by: Neil Armstrong <neil.armstrong@xxxxxxxxxx>
---
sound/soc/qcom/lpass-cpu.c | 41 ++++++----
sound/soc/qcom/lpass-platform.c | 160 +++++++++++++++++++++++++++++++++++++---
sound/soc/qcom/lpass.h | 10 +++
3 files changed, 183 insertions(+), 28 deletions(-)

diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
index a83507c2cd55..8b005a87d408 100644
--- a/sound/soc/qcom/lpass-cpu.c
+++ b/sound/soc/qcom/lpass-cpu.c
@@ -1169,6 +1169,8 @@ static void of_lpass_cpu_parse_dai_data(struct device *dev,
data->codec_dma_enable = 1;
if (is_wsa_cdc_dma_port(id))
data->wsa_enable = 1;
+ else if (!is_rxtx_cdc_dma_port(id))
+ data->va_enable = 1;
} else if (is_mi2s_port_id(id)) {
unsigned int port_id = mi2s_port_id(id);

@@ -1351,22 +1353,6 @@ int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev)
if (IS_ERR(drvdata->wsa_lpaif_map))
return PTR_ERR(drvdata->wsa_lpaif_map);
}
-
- ret = of_lpass_cdc_dma_clks_parse(dev, drvdata);
- if (ret) {
- dev_err(dev, "failed to get cdc dma clocks %d\n", ret);
- return ret;
- }
-
- res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpass-rxtx-cdc-dma-lpm");
- if (!res)
- return -EINVAL;
- drvdata->rxtx_cdc_dma_lpm_buf = res->start;
-
- res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpass-va-cdc-dma-lpm");
- if (!res)
- return -EINVAL;
- drvdata->va_cdc_dma_lpm_buf = res->start;
}

if (variant->mi2s_desc) {
@@ -1380,6 +1366,9 @@ int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev)
variant->mi2s_desc[i].reg_name);
if (ret)
return ret;
+
+ if (variant->mi2s_desc[i].lpm_type != LPASS_LPM_NONE)
+ drvdata->mi2s_lpm_enable = true;
}
} else {
drvdata->num_lpaif = 1;
@@ -1389,6 +1378,26 @@ int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev)
return ret;
}

+ if (drvdata->codec_dma_enable || drvdata->mi2s_lpm_enable) {
+ ret = of_lpass_cdc_dma_clks_parse(dev, drvdata);
+ if (ret) {
+ dev_err(dev, "failed to get cdc dma clocks %d\n", ret);
+ return ret;
+ }
+
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpass-rxtx-cdc-dma-lpm");
+ if (!res)
+ return -EINVAL;
+ drvdata->rxtx_cdc_dma_lpm_buf = res->start;
+ drvdata->rxtx_cdc_dma_lpm_size = resource_size(res);
+
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpass-va-cdc-dma-lpm");
+ if (!res)
+ return -EINVAL;
+ drvdata->va_cdc_dma_lpm_buf = res->start;
+ drvdata->va_cdc_dma_lpm_size = resource_size(res);
+ }
+
if (drvdata->hdmi_port_enable) {
drvdata->hdmiif = devm_platform_ioremap_resource_byname(pdev, "lpass-hdmiif");
if (IS_ERR(drvdata->hdmiif))
diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c
index 16a964e1aec1..855f1ee19394 100644
--- a/sound/soc/qcom/lpass-platform.c
+++ b/sound/soc/qcom/lpass-platform.c
@@ -49,6 +49,31 @@ static const struct snd_pcm_hardware lpass_platform_pcm_hardware = {
.fifo_size = 0,
};

+/* MI2S ports with their DMA buffer in a LPM block */
+static const struct snd_pcm_hardware lpass_platform_lpm_mi2s_hardware = {
+ .info = SNDRV_PCM_INFO_MMAP |
+ SNDRV_PCM_INFO_MMAP_VALID |
+ SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_PAUSE |
+ SNDRV_PCM_INFO_RESUME,
+ .formats = SNDRV_PCM_FMTBIT_S16 |
+ SNDRV_PCM_FMTBIT_S24 |
+ SNDRV_PCM_FMTBIT_S32,
+ .rates = SNDRV_PCM_RATE_8000_192000,
+ .rate_min = 8000,
+ .rate_max = 192000,
+ .channels_min = 1,
+ .channels_max = 8,
+ .buffer_bytes_max = LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE,
+ .period_bytes_max = LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE /
+ LPASS_PLATFORM_PERIODS,
+ .period_bytes_min = LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE /
+ LPASS_PLATFORM_PERIODS,
+ .periods_min = LPASS_PLATFORM_PERIODS,
+ .periods_max = LPASS_PLATFORM_PERIODS,
+ .fifo_size = 0,
+};
+
static const struct snd_pcm_hardware lpass_platform_rxtx_hardware = {
.info = SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID |
@@ -312,6 +337,13 @@ static int lpass_platform_pcmops_open(struct snd_soc_component *component,
dev_err(soc_runtime->dev, "error writing to rdmactl reg: %d\n", ret);
return ret;
}
+ if (is_lpm_mi2s_port(drvdata, dai_id)) {
+ snd_soc_set_runtime_hwparams(substream,
+ &lpass_platform_lpm_mi2s_hardware);
+ runtime->dma_bytes = lpass_platform_lpm_mi2s_hardware.buffer_bytes_max;
+ snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
+ break;
+ }
snd_soc_set_runtime_hwparams(substream, &lpass_platform_pcm_hardware);
runtime->dma_bytes = lpass_platform_pcm_hardware.buffer_bytes_max;
break;
@@ -1038,9 +1070,10 @@ static int lpass_platform_pcmops_mmap(struct snd_soc_component *component,
{
struct snd_soc_pcm_runtime *soc_runtime = snd_soc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(soc_runtime, 0);
+ struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
unsigned int dai_id = cpu_dai->driver->id;

- if (is_cdc_dma_port(dai_id))
+ if (is_cdc_dma_port(dai_id) || is_lpm_mi2s_port(drvdata, dai_id))
return lpass_platform_cdc_dma_mmap(substream, vma);

return snd_pcm_lib_default_mmap(substream, vma);
@@ -1288,6 +1321,41 @@ static irqreturn_t lpass_platform_wsaif_irq(int irq, void *data)
return IRQ_HANDLED;
}

+static int lpass_platform_prealloc_lpm_mi2s_buffer(struct snd_soc_component *component,
+ struct snd_pcm *pcm, int dai_id)
+{
+ struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
+ unsigned int port_id = mi2s_port_id(dai_id);
+ struct snd_pcm_substream *substream;
+ struct snd_dma_buffer *buf;
+ u32 addr;
+ int dir;
+
+ if (drvdata->mi2s_lpm[port_id] == LPASS_VA_CDC_LPM)
+ addr = drvdata->va_cdc_dma_lpm_buf;
+ else
+ addr = drvdata->rxtx_cdc_dma_lpm_buf;
+ addr += drvdata->mi2s_lpm_offset[port_id];
+
+ /* Playback and capture buffers are allocated one after the other */
+ for (dir = SNDRV_PCM_STREAM_PLAYBACK; dir <= SNDRV_PCM_STREAM_CAPTURE; dir++) {
+ substream = pcm->streams[dir].substream;
+ if (!substream)
+ continue;
+
+ buf = &substream->dma_buffer;
+ buf->dev.dev = pcm->card->dev;
+ buf->dev.type = SNDRV_DMA_TYPE_CONTINUOUS;
+ buf->private_data = NULL;
+ buf->bytes = lpass_platform_lpm_mi2s_hardware.buffer_bytes_max;
+ buf->addr = addr + dir * LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE;
+ buf->area = (unsigned char * __force)memremap(buf->addr, buf->bytes,
+ MEMREMAP_WC);
+ }
+
+ return 0;
+}
+
static int lpass_platform_prealloc_cdc_dma_buffer(struct snd_soc_component *component,
struct snd_pcm *pcm, int dai_id)
{
@@ -1310,23 +1378,25 @@ static int lpass_platform_prealloc_cdc_dma_buffer(struct snd_soc_component *comp
switch (dai_id) {
case LPASS_CDC_DMA_RX0 ... LPASS_CDC_DMA_RX9:
buf->bytes = lpass_platform_rxtx_hardware.buffer_bytes_max;
- buf->addr = drvdata->rxtx_cdc_dma_lpm_buf;
+ buf->addr = drvdata->rxtx_cdc_dma_lpm_buf + drvdata->rxtx_lpm_offset;
break;
case LPASS_CDC_DMA_TX0 ... LPASS_CDC_DMA_TX8:
buf->bytes = lpass_platform_rxtx_hardware.buffer_bytes_max;
- buf->addr = drvdata->rxtx_cdc_dma_lpm_buf + LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE;
+ buf->addr = drvdata->rxtx_cdc_dma_lpm_buf +
+ drvdata->rxtx_lpm_offset + LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE;
break;
case LPASS_CDC_DMA_VA_TX0 ... LPASS_CDC_DMA_VA_TX8:
buf->bytes = lpass_platform_va_hardware.buffer_bytes_max;
- buf->addr = drvdata->va_cdc_dma_lpm_buf;
+ buf->addr = drvdata->va_cdc_dma_lpm_buf + drvdata->va_lpm_offset;
break;
case LPASS_CDC_DMA_WSA_RX0 ... LPASS_CDC_DMA_WSA_RX9:
buf->bytes = lpass_platform_wsa_hardware.buffer_bytes_max;
- buf->addr = drvdata->rxtx_cdc_dma_lpm_buf + LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
+ buf->addr = drvdata->rxtx_cdc_dma_lpm_buf + drvdata->wsa_lpm_offset;
break;
case LPASS_CDC_DMA_WSA_TX0 ... LPASS_CDC_DMA_WSA_TX8:
buf->bytes = lpass_platform_wsa_hardware.buffer_bytes_max;
- buf->addr = drvdata->rxtx_cdc_dma_lpm_buf + LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 3;
+ buf->addr = drvdata->rxtx_cdc_dma_lpm_buf +
+ drvdata->wsa_lpm_offset + LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE;
break;
default:
break;
@@ -1342,14 +1412,14 @@ static int lpass_platform_pcm_new(struct snd_soc_component *component,
{
struct snd_pcm *pcm = soc_runtime->pcm;
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(soc_runtime, 0);
+ struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
unsigned int dai_id = cpu_dai->driver->id;

size_t size = lpass_platform_pcm_hardware.buffer_bytes_max;

- /*
- * Lpass codec dma can access only lpass lpm hardware memory.
- * ioremap is for HLOS to access hardware memory.
- */
+ if (is_lpm_mi2s_port(drvdata, dai_id))
+ return lpass_platform_prealloc_lpm_mi2s_buffer(component, pcm, dai_id);
+
if (is_cdc_dma_port(dai_id))
return lpass_platform_prealloc_cdc_dma_buffer(component, pcm, dai_id);

@@ -1412,6 +1482,7 @@ static int lpass_platform_copy(struct snd_soc_component *component,
unsigned long pos, struct iov_iter *buf,
unsigned long bytes)
{
+ struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
struct snd_pcm_runtime *rt = substream->runtime;
struct snd_soc_pcm_runtime *soc_runtime = snd_soc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(soc_runtime, 0);
@@ -1422,7 +1493,7 @@ static int lpass_platform_copy(struct snd_soc_component *component,
channel * (rt->dma_bytes / rt->channels));

if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
- if (is_cdc_dma_port(dai_id)) {
+ if (is_cdc_dma_port(dai_id) || is_lpm_mi2s_port(drvdata, dai_id)) {
if (copy_from_iter_toio(dma_buf, bytes, buf) != bytes)
ret = -EFAULT;
} else {
@@ -1430,7 +1501,7 @@ static int lpass_platform_copy(struct snd_soc_component *component,
ret = -EFAULT;
}
} else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
- if (is_cdc_dma_port(dai_id)) {
+ if (is_cdc_dma_port(dai_id) || is_lpm_mi2s_port(drvdata, dai_id)) {
if (copy_to_iter_fromio(dma_buf, bytes, buf) != bytes)
ret = -EFAULT;
} else {
@@ -1459,6 +1530,66 @@ static const struct snd_soc_component_driver lpass_component_driver = {

};

+static int lpass_platform_allocate_lpm(struct lpass_data *drvdata)
+{
+ u32 rxtx_cdc_dma_lpm_remain = drvdata->rxtx_cdc_dma_lpm_size;
+ u32 va_cdc_dma_lpm_remain = drvdata->va_cdc_dma_lpm_size;
+ u32 rxtx_cdc_dma_lpm_offset = 0;
+ u32 va_cdc_dma_lpm_offset = 0;
+ int port_id;
+
+ if (drvdata->codec_dma_enable) {
+ drvdata->rxtx_lpm_offset = rxtx_cdc_dma_lpm_offset;
+ rxtx_cdc_dma_lpm_offset += LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
+ rxtx_cdc_dma_lpm_remain -= LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
+
+ if (drvdata->va_enable) {
+ drvdata->va_lpm_offset = va_cdc_dma_lpm_offset;
+ va_cdc_dma_lpm_offset += LPASS_VA_CDC_DMA_LPM_BUFF_SIZE;
+ va_cdc_dma_lpm_remain -= LPASS_VA_CDC_DMA_LPM_BUFF_SIZE;
+ }
+
+ if (drvdata->wsa_enable) {
+ drvdata->wsa_lpm_offset = rxtx_cdc_dma_lpm_offset;
+ rxtx_cdc_dma_lpm_offset += LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
+ rxtx_cdc_dma_lpm_remain -= LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
+ }
+ }
+
+ if (!drvdata->mi2s_lpm_enable)
+ return 0;
+
+ for (port_id = 0; port_id < LPASS_MAX_MI2S_PORTS; port_id++) {
+ if (!test_bit(port_id, &drvdata->lpaif_port_enable))
+ continue;
+
+ switch (drvdata->mi2s_lpm[port_id]) {
+ case LPASS_RXTX_CDC_LPM:
+ if (rxtx_cdc_dma_lpm_remain < LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2)
+ return -EINVAL;
+ drvdata->mi2s_lpm_offset[port_id] = rxtx_cdc_dma_lpm_offset;
+ rxtx_cdc_dma_lpm_offset += LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
+ rxtx_cdc_dma_lpm_remain -= LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
+ break;
+ case LPASS_VA_CDC_LPM:
+ /*
+ * VA Codec uses 12KiB, but MI2S uses 2x8KiB for playback
+ * and capture, so it must be large enough to fit
+ */
+ if (va_cdc_dma_lpm_remain < LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2)
+ return -EINVAL;
+ drvdata->mi2s_lpm_offset[port_id] = va_cdc_dma_lpm_offset;
+ va_cdc_dma_lpm_offset += LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
+ va_cdc_dma_lpm_remain -= LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
+ break;
+ default:
+ break;
+ }
+ }
+
+ return 0;
+}
+
static int lpass_platform_init_lpaif(struct platform_device *pdev, int idx,
const char *irq_name, unsigned long irqflags)
{
@@ -1624,6 +1755,11 @@ int asoc_qcom_lpass_platform_register(struct platform_device *pdev)
return ret;
}
}
+
+ ret = lpass_platform_allocate_lpm(drvdata);
+ if (ret)
+ return ret;
+
return devm_snd_soc_register_component(&pdev->dev,
&lpass_component_driver, NULL, 0);
}
diff --git a/sound/soc/qcom/lpass.h b/sound/soc/qcom/lpass.h
index 71f1274dfa89..3a37bf992645 100644
--- a/sound/soc/qcom/lpass.h
+++ b/sound/soc/qcom/lpass.h
@@ -196,6 +196,8 @@ struct lpass_data {
int hdmi_port_enable;
int codec_dma_enable;
int wsa_enable;
+ int va_enable;
+ int mi2s_lpm_enable;

/* LPAIF instances, 0 is the core "lpass-lpaif" one */
struct lpass_lpaif lpaif[LPASS_MAX_LPAIF];
@@ -214,7 +216,15 @@ struct lpass_data {
void __iomem *wsa_lpaif;

u32 rxtx_cdc_dma_lpm_buf;
+ u32 rxtx_cdc_dma_lpm_size;
u32 va_cdc_dma_lpm_buf;
+ u32 va_cdc_dma_lpm_size;
+
+ /* LPM buffer assignment */
+ u32 rxtx_lpm_offset;
+ u32 va_lpm_offset;
+ u32 wsa_lpm_offset;
+ u32 mi2s_lpm_offset[LPASS_MAX_MI2S_PORTS];

/* regmap backed by the low-power audio interface (LPAIF) registers */
struct regmap *hdmiif_map;

--
2.34.1