Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: pxa2xx: Use managed PCM buffer allocation

Now with the recent addition of WC buffer allocation support, we can
use the standard PCM buffer allocation helpers for pxa2xx drivers.
This allows us to remove lots of superfluous code.

Cc: Daniel Mack <daniel@zonque.org>
Cc: Haojian Zhuang <haojian.zhuang@gmail.com>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210802072815.13551-6-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+10 -123
+1 -12
include/sound/pxa2xx-lib.h
··· 14 14 15 15 extern int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream, 16 16 struct snd_pcm_hw_params *params); 17 - extern int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream); 18 17 extern int pxa2xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd); 19 18 extern snd_pcm_uframes_t pxa2xx_pcm_pointer(struct snd_pcm_substream *substream); 20 19 extern int pxa2xx_pcm_prepare(struct snd_pcm_substream *substream); 21 20 extern int pxa2xx_pcm_open(struct snd_pcm_substream *substream); 22 21 extern int pxa2xx_pcm_close(struct snd_pcm_substream *substream); 23 - extern int pxa2xx_pcm_mmap(struct snd_pcm_substream *substream, 24 - struct vm_area_struct *vma); 25 - extern int pxa2xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream); 26 - extern void pxa2xx_pcm_free_dma_buffers(struct snd_pcm *pcm); 27 - extern void pxa2xx_soc_pcm_free(struct snd_soc_component *component, 28 - struct snd_pcm *pcm); 22 + extern int pxa2xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm); 29 23 extern int pxa2xx_soc_pcm_new(struct snd_soc_component *component, 30 24 struct snd_soc_pcm_runtime *rtd); 31 25 extern int pxa2xx_soc_pcm_open(struct snd_soc_component *component, ··· 29 35 extern int pxa2xx_soc_pcm_hw_params(struct snd_soc_component *component, 30 36 struct snd_pcm_substream *substream, 31 37 struct snd_pcm_hw_params *params); 32 - extern int pxa2xx_soc_pcm_hw_free(struct snd_soc_component *component, 33 - struct snd_pcm_substream *substream); 34 38 extern int pxa2xx_soc_pcm_prepare(struct snd_soc_component *component, 35 39 struct snd_pcm_substream *substream); 36 40 extern int pxa2xx_soc_pcm_trigger(struct snd_soc_component *component, ··· 36 44 extern snd_pcm_uframes_t 37 45 pxa2xx_soc_pcm_pointer(struct snd_soc_component *component, 38 46 struct snd_pcm_substream *substream); 39 - extern int pxa2xx_soc_pcm_mmap(struct snd_soc_component *component, 40 - struct snd_pcm_substream *substream, 41 - struct vm_area_struct *vma); 42 47 43 48 /* AC97 */ 44 49
+4 -14
sound/arm/pxa2xx-ac97.c
··· 172 172 .open = pxa2xx_ac97_pcm_open, 173 173 .close = pxa2xx_ac97_pcm_close, 174 174 .hw_params = pxa2xx_pcm_hw_params, 175 - .hw_free = pxa2xx_pcm_hw_free, 176 175 .prepare = pxa2xx_ac97_pcm_prepare, 177 176 .trigger = pxa2xx_pcm_trigger, 178 177 .pointer = pxa2xx_pcm_pointer, 179 - .mmap = pxa2xx_pcm_mmap, 180 178 }; 181 179 182 180 183 181 static int pxa2xx_ac97_pcm_new(struct snd_card *card) 184 182 { 185 183 struct snd_pcm *pcm; 186 - int stream, ret; 184 + int ret; 187 185 188 186 ret = snd_pcm_new(card, "PXA2xx-PCM", 0, 1, 1, &pcm); 189 187 if (ret) 190 188 goto out; 191 189 192 - pcm->private_free = pxa2xx_pcm_free_dma_buffers; 193 - 194 190 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32)); 195 191 if (ret) 196 192 goto out; 197 193 198 - stream = SNDRV_PCM_STREAM_PLAYBACK; 199 - snd_pcm_set_ops(pcm, stream, &pxa2xx_ac97_pcm_ops); 200 - ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream); 201 - if (ret) 202 - goto out; 203 - 204 - stream = SNDRV_PCM_STREAM_CAPTURE; 205 - snd_pcm_set_ops(pcm, stream, &pxa2xx_ac97_pcm_ops); 206 - ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream); 194 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &pxa2xx_ac97_pcm_ops); 195 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pxa2xx_ac97_pcm_ops); 196 + ret = pxa2xx_pcm_preallocate_dma_buffer(pcm); 207 197 if (ret) 208 198 goto out; 209 199
+5 -85
sound/arm/pxa2xx-pcm-lib.c
··· 54 54 if (ret) 55 55 return ret; 56 56 57 - snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); 58 - 59 57 return 0; 60 58 } 61 59 EXPORT_SYMBOL(pxa2xx_pcm_hw_params); 62 - 63 - int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream) 64 - { 65 - snd_pcm_set_runtime_buffer(substream, NULL); 66 - return 0; 67 - } 68 - EXPORT_SYMBOL(pxa2xx_pcm_hw_free); 69 60 70 61 int pxa2xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 71 62 { ··· 122 131 } 123 132 EXPORT_SYMBOL(pxa2xx_pcm_close); 124 133 125 - int pxa2xx_pcm_mmap(struct snd_pcm_substream *substream, 126 - struct vm_area_struct *vma) 134 + int pxa2xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm) 127 135 { 128 - struct snd_pcm_runtime *runtime = substream->runtime; 129 - return dma_mmap_wc(substream->pcm->card->dev, vma, runtime->dma_area, 130 - runtime->dma_addr, runtime->dma_bytes); 131 - } 132 - EXPORT_SYMBOL(pxa2xx_pcm_mmap); 133 - 134 - int pxa2xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream) 135 - { 136 - struct snd_pcm_substream *substream = pcm->streams[stream].substream; 137 - struct snd_dma_buffer *buf = &substream->dma_buffer; 138 136 size_t size = pxa2xx_pcm_hardware.buffer_bytes_max; 139 - buf->dev.type = SNDRV_DMA_TYPE_DEV; 140 - buf->dev.dev = pcm->card->dev; 141 - buf->private_data = NULL; 142 - buf->area = dma_alloc_wc(pcm->card->dev, size, &buf->addr, GFP_KERNEL); 143 - if (!buf->area) 144 - return -ENOMEM; 145 - buf->bytes = size; 146 - return 0; 137 + 138 + return snd_pcm_set_fixed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_WC, 139 + pcm->card->dev, size); 147 140 } 148 141 EXPORT_SYMBOL(pxa2xx_pcm_preallocate_dma_buffer); 149 - 150 - void pxa2xx_pcm_free_dma_buffers(struct snd_pcm *pcm) 151 - { 152 - struct snd_pcm_substream *substream; 153 - struct snd_dma_buffer *buf; 154 - int stream; 155 - 156 - for (stream = 0; stream < 2; stream++) { 157 - substream = pcm->streams[stream].substream; 158 - if (!substream) 159 - continue; 160 - buf = &substream->dma_buffer; 161 - if (!buf->area) 162 - continue; 163 - dma_free_wc(pcm->card->dev, buf->bytes, buf->area, buf->addr); 164 - buf->area = NULL; 165 - } 166 - } 167 - EXPORT_SYMBOL(pxa2xx_pcm_free_dma_buffers); 168 - 169 - void pxa2xx_soc_pcm_free(struct snd_soc_component *component, 170 - struct snd_pcm *pcm) 171 - { 172 - pxa2xx_pcm_free_dma_buffers(pcm); 173 - } 174 - EXPORT_SYMBOL(pxa2xx_soc_pcm_free); 175 142 176 143 int pxa2xx_soc_pcm_new(struct snd_soc_component *component, 177 144 struct snd_soc_pcm_runtime *rtd) ··· 142 193 if (ret) 143 194 return ret; 144 195 145 - if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 146 - ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, 147 - SNDRV_PCM_STREAM_PLAYBACK); 148 - if (ret) 149 - goto out; 150 - } 151 - 152 - if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { 153 - ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, 154 - SNDRV_PCM_STREAM_CAPTURE); 155 - if (ret) 156 - goto out; 157 - } 158 - out: 159 - return ret; 196 + return pxa2xx_pcm_preallocate_dma_buffer(pcm); 160 197 } 161 198 EXPORT_SYMBOL(pxa2xx_soc_pcm_new); 162 199 ··· 168 233 } 169 234 EXPORT_SYMBOL(pxa2xx_soc_pcm_hw_params); 170 235 171 - int pxa2xx_soc_pcm_hw_free(struct snd_soc_component *component, 172 - struct snd_pcm_substream *substream) 173 - { 174 - return pxa2xx_pcm_hw_free(substream); 175 - } 176 - EXPORT_SYMBOL(pxa2xx_soc_pcm_hw_free); 177 - 178 236 int pxa2xx_soc_pcm_prepare(struct snd_soc_component *component, 179 237 struct snd_pcm_substream *substream) 180 238 { ··· 189 261 return pxa2xx_pcm_pointer(substream); 190 262 } 191 263 EXPORT_SYMBOL(pxa2xx_soc_pcm_pointer); 192 - 193 - int pxa2xx_soc_pcm_mmap(struct snd_soc_component *component, 194 - struct snd_pcm_substream *substream, 195 - struct vm_area_struct *vma) 196 - { 197 - return pxa2xx_pcm_mmap(substream, vma); 198 - } 199 - EXPORT_SYMBOL(pxa2xx_soc_pcm_mmap); 200 264 201 265 MODULE_AUTHOR("Nicolas Pitre"); 202 266 MODULE_DESCRIPTION("Intel PXA2xx sound library");
-3
sound/soc/pxa/pxa-ssp.c
··· 850 850 static const struct snd_soc_component_driver pxa_ssp_component = { 851 851 .name = "pxa-ssp", 852 852 .pcm_construct = pxa2xx_soc_pcm_new, 853 - .pcm_destruct = pxa2xx_soc_pcm_free, 854 853 .open = pxa2xx_soc_pcm_open, 855 854 .close = pxa2xx_soc_pcm_close, 856 855 .hw_params = pxa2xx_soc_pcm_hw_params, 857 - .hw_free = pxa2xx_soc_pcm_hw_free, 858 856 .prepare = pxa2xx_soc_pcm_prepare, 859 857 .trigger = pxa2xx_soc_pcm_trigger, 860 858 .pointer = pxa2xx_soc_pcm_pointer, 861 - .mmap = pxa2xx_soc_pcm_mmap, 862 859 .suspend = pxa_ssp_suspend, 863 860 .resume = pxa_ssp_resume, 864 861 };
-3
sound/soc/pxa/pxa2xx-ac97.c
··· 202 202 static const struct snd_soc_component_driver pxa_ac97_component = { 203 203 .name = "pxa-ac97", 204 204 .pcm_construct = pxa2xx_soc_pcm_new, 205 - .pcm_destruct = pxa2xx_soc_pcm_free, 206 205 .open = pxa2xx_soc_pcm_open, 207 206 .close = pxa2xx_soc_pcm_close, 208 207 .hw_params = pxa2xx_soc_pcm_hw_params, 209 - .hw_free = pxa2xx_soc_pcm_hw_free, 210 208 .prepare = pxa2xx_soc_pcm_prepare, 211 209 .trigger = pxa2xx_soc_pcm_trigger, 212 210 .pointer = pxa2xx_soc_pcm_pointer, 213 - .mmap = pxa2xx_soc_pcm_mmap, 214 211 }; 215 212 216 213 #ifdef CONFIG_OF
-3
sound/soc/pxa/pxa2xx-i2s.c
··· 359 359 static const struct snd_soc_component_driver pxa_i2s_component = { 360 360 .name = "pxa-i2s", 361 361 .pcm_construct = pxa2xx_soc_pcm_new, 362 - .pcm_destruct = pxa2xx_soc_pcm_free, 363 362 .open = pxa2xx_soc_pcm_open, 364 363 .close = pxa2xx_soc_pcm_close, 365 364 .hw_params = pxa2xx_soc_pcm_hw_params, 366 - .hw_free = pxa2xx_soc_pcm_hw_free, 367 365 .prepare = pxa2xx_soc_pcm_prepare, 368 366 .trigger = pxa2xx_soc_pcm_trigger, 369 367 .pointer = pxa2xx_soc_pcm_pointer, 370 - .mmap = pxa2xx_soc_pcm_mmap, 371 368 .suspend = pxa2xx_soc_pcm_suspend, 372 369 .resume = pxa2xx_soc_pcm_resume, 373 370 };
-3
sound/soc/pxa/pxa2xx-pcm.c
··· 19 19 20 20 static const struct snd_soc_component_driver pxa2xx_soc_platform = { 21 21 .pcm_construct = pxa2xx_soc_pcm_new, 22 - .pcm_destruct = pxa2xx_soc_pcm_free, 23 22 .open = pxa2xx_soc_pcm_open, 24 23 .close = pxa2xx_soc_pcm_close, 25 24 .hw_params = pxa2xx_soc_pcm_hw_params, 26 - .hw_free = pxa2xx_soc_pcm_hw_free, 27 25 .prepare = pxa2xx_soc_pcm_prepare, 28 26 .trigger = pxa2xx_soc_pcm_trigger, 29 27 .pointer = pxa2xx_soc_pcm_pointer, 30 - .mmap = pxa2xx_soc_pcm_mmap, 31 28 }; 32 29 33 30 static int pxa2xx_soc_platform_probe(struct platform_device *pdev)