Chrome platform driver development
 help / color / mirror / Atom feed
* [RFC PATCH v2 3/3] ASoC: codecs: Initialise PCM hardware tables at boot for page size
       [not found] <20261202031733.1704898-1-ericcurtin17@gmail.com>
@ 2026-12-02  3:17 ` Eric Curtin
  2026-12-02  4:56   ` Tzung-Bi Shih
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Curtin @ 2026-12-02  3:17 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ryan Roberts, Cheng-Yi Chiang, Tzung-Bi Shih, Guenter Roeck,
	Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Benson Leung, Oder Chiou, chrome-platform, linux-sound

From: Ryan Roberts <ryan.roberts@arm.com>

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@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 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",

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RFC PATCH v2 3/3] ASoC: codecs: Initialise PCM hardware tables at boot for page size
  2026-12-02  3:17 ` [RFC PATCH v2 3/3] ASoC: codecs: Initialise PCM hardware tables at boot for page size Eric Curtin
@ 2026-12-02  4:56   ` Tzung-Bi Shih
  0 siblings, 0 replies; 2+ messages in thread
From: Tzung-Bi Shih @ 2026-12-02  4:56 UTC (permalink / raw)
  To: Eric Curtin
  Cc: linux-kernel, Ryan Roberts, Cheng-Yi Chiang, Guenter Roeck,
	Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Benson Leung, Oder Chiou, chrome-platform, linux-sound

On Wed, Dec 02, 2026 at 03:17:29AM +0000, Eric Curtin wrote:
> From: Ryan Roberts <ryan.roberts@arm.com>
> 
> 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.

The cover letter [1] should be sent to the recipients of the patch as well,
so the context is easier to find.

[1] https://lore.kernel.org/all/20261202031733.1704898-1-ericcurtin17@gmail.com

> 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,
> +});

If keeping it this way, hw_param is moved from function scope to file scope
and needs a prefix, e.g., wov_hw_param.

> +
>  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,
> -	};
> -

Overall, I think this is overkill.  Replacing PAGE_SIZE here with SZ_4K
would be the simplest fix.  At least cros_ec_codec was written and tested
assuming PAGE_SIZE is 4K.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02  4:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261202031733.1704898-1-ericcurtin17@gmail.com>
2026-12-02  3:17 ` [RFC PATCH v2 3/3] ASoC: codecs: Initialise PCM hardware tables at boot for page size Eric Curtin
2026-12-02  4:56   ` Tzung-Bi Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox