[RFC PATCH v2 3/3] ASoC: codecs: Initialise PCM hardware tables at boot for page size

From: Eric Curtin

Date: Tue Dec 01 2026 - 22:18:45 EST


From: Ryan Roberts <ryan.roberts@xxxxxxx>

The snd_pcm_hardware tables in cros_ec_codec.c and rt5514-spi.c use
PAGE_SIZE in their initialisers. That is not a constant expression with
arm64 boot-time page size selection, so the tables cannot be static
initialisers.

Define them with DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(), which keeps a
normal const initialiser for a fixed page size and otherwise fills the
table in once the page size is known at boot. In cros_ec_codec.c the
table was local to wov_pcm_open(), so it moves to file scope.

Signed-off-by: Ryan Roberts <ryan.roberts@xxxxxxx>
Signed-off-by: Eric Curtin <eric.curtin@xxxxxxxxxx>
---
sound/soc/codecs/cros_ec_codec.c | 30 +++++++++++++++---------------
sound/soc/codecs/rt5514-spi.c | 5 +++--
2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
index b6f7016a324a..f6e0395d47a1 100644
--- a/sound/soc/codecs/cros_ec_codec.c
+++ b/sound/soc/codecs/cros_ec_codec.c
@@ -874,24 +874,24 @@ static void wov_remove(struct snd_soc_component *component)
&priv->ec_device->event_notifier, &priv->wov_notifier);
}

+static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, hw_param, {
+ .info = SNDRV_PCM_INFO_MMAP |
+ SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_MMAP_VALID,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ .rates = SNDRV_PCM_RATE_16000,
+ .channels_min = 1,
+ .channels_max = 1,
+ .period_bytes_min = PAGE_SIZE,
+ .period_bytes_max = 0x20000 / 8,
+ .periods_min = 8,
+ .periods_max = 8,
+ .buffer_bytes_max = 0x20000,
+});
+
static int wov_pcm_open(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
- static const struct snd_pcm_hardware hw_param = {
- .info = SNDRV_PCM_INFO_MMAP |
- SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_MMAP_VALID,
- .formats = SNDRV_PCM_FMTBIT_S16_LE,
- .rates = SNDRV_PCM_RATE_16000,
- .channels_min = 1,
- .channels_max = 1,
- .period_bytes_min = PAGE_SIZE,
- .period_bytes_max = 0x20000 / 8,
- .periods_min = 8,
- .periods_max = 8,
- .buffer_bytes_max = 0x20000,
- };
-
return snd_soc_set_runtime_hwparams(substream, &hw_param);
}

diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c
index bcc2ff28b125..f619f3475397 100644
--- a/sound/soc/codecs/rt5514-spi.c
+++ b/sound/soc/codecs/rt5514-spi.c
@@ -46,7 +46,8 @@ struct rt5514_dsp {
int irq;
};

-static const struct snd_pcm_hardware rt5514_spi_pcm_hardware = {
+static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware,
+ rt5514_spi_pcm_hardware, {
.info = SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_INTERLEAVED,
@@ -58,7 +59,7 @@ static const struct snd_pcm_hardware rt5514_spi_pcm_hardware = {
.channels_min = 1,
.channels_max = 1,
.buffer_bytes_max = 0x20000,
-};
+});

static struct snd_soc_dai_driver rt5514_spi_dai = {
.name = "rt5514-dsp-cpu-dai",