Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // soc-util.c  --  ALSA SoC Audio Layer utility functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) // Copyright 2009 Wolfson Microelectronics PLC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) // Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) //         Liam Girdwood <lrg@slimlogic.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	return sample_size * channels * tdm_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) EXPORT_SYMBOL_GPL(snd_soc_calc_frame_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int sample_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	sample_size = snd_pcm_format_width(params_format(params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	if (sample_size < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		return sample_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	return snd_soc_calc_frame_size(sample_size, params_channels(params),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 				       1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) EXPORT_SYMBOL_GPL(snd_soc_params_to_frame_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	return fs * snd_soc_calc_frame_size(sample_size, channels, tdm_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) EXPORT_SYMBOL_GPL(snd_soc_calc_bclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) int snd_soc_params_to_bclk(struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	ret = snd_soc_params_to_frame_size(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return ret * params_rate(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) EXPORT_SYMBOL_GPL(snd_soc_params_to_bclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static const struct snd_pcm_hardware dummy_dma_hardware = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/* Random values to keep userspace happy when checking constraints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.info			= SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 				  SNDRV_PCM_INFO_BLOCK_TRANSFER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	.buffer_bytes_max	= 128*1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.period_bytes_min	= PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	.period_bytes_max	= PAGE_SIZE*2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.periods_min		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.periods_max		= 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int dummy_dma_open(struct snd_soc_component *component,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			  struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	/* BE's dont need dummy params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (!rtd->dai_link->no_pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		snd_soc_set_runtime_hwparams(substream, &dummy_dma_hardware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static const struct snd_soc_component_driver dummy_platform = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	.open		= dummy_dma_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static const struct snd_soc_component_driver dummy_codec = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	.idle_bias_on		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	.use_pmdown_time	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	.endianness		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	.non_legacy_dai_naming	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #define STUB_RATES	SNDRV_PCM_RATE_8000_384000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #define STUB_FORMATS	(SNDRV_PCM_FMTBIT_S8 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			SNDRV_PCM_FMTBIT_U8 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			SNDRV_PCM_FMTBIT_S16_LE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			SNDRV_PCM_FMTBIT_U16_LE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			SNDRV_PCM_FMTBIT_S24_LE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			SNDRV_PCM_FMTBIT_S24_3LE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			SNDRV_PCM_FMTBIT_U24_LE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			SNDRV_PCM_FMTBIT_S32_LE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			SNDRV_PCM_FMTBIT_U32_LE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * The dummy CODEC is only meant to be used in situations where there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * actual hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * If there is actual hardware even if it does not have a control bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * the hardware will still have constraints like supported samplerates, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * which should be modelled. And the data flow graph also should be modelled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * using DAPM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static struct snd_soc_dai_driver dummy_dai = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	.name = "snd-soc-dummy-dai",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	.playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		.stream_name	= "Playback",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		.channels_min	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		.channels_max	= 384,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		.rates		= STUB_RATES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		.formats	= STUB_FORMATS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		.stream_name	= "Capture",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		.channels_min	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		.channels_max	= 384,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		.rates = STUB_RATES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		.formats = STUB_FORMATS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int snd_soc_dai_is_dummy(struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (dai->driver == &dummy_dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int snd_soc_dummy_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	ret = devm_snd_soc_register_component(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 					      &dummy_codec, &dummy_dai, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	ret = devm_snd_soc_register_component(&pdev->dev, &dummy_platform,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 					      NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static struct platform_driver soc_dummy_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		.name = "snd-soc-dummy",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	.probe = snd_soc_dummy_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static struct platform_device *soc_dummy_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int __init snd_soc_util_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	soc_dummy_dev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		platform_device_register_simple("snd-soc-dummy", -1, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (IS_ERR(soc_dummy_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		return PTR_ERR(soc_dummy_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	ret = platform_driver_register(&soc_dummy_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		platform_device_unregister(soc_dummy_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) void __exit snd_soc_util_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	platform_driver_unregister(&soc_dummy_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	platform_device_unregister(soc_dummy_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }