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