Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 1 | /* |
| 2 | * linux/sound/arm/ep93xx-pcm.c - EP93xx ALSA PCM interface |
| 3 | * |
| 4 | * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org> |
| 5 | * Copyright (C) 2006 Applied Data Systems |
| 6 | * |
| 7 | * Rewritten for the SoC audio subsystem (Based on PXA2xx code): |
Ryan Mallon | 1c5454e | 2011-06-15 14:45:36 +1000 | [diff] [blame] | 8 | * Copyright (c) 2008 Ryan Mallon |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/init.h> |
Lars-Peter Clausen | e27e8a6 | 2013-04-20 19:29:05 +0200 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Mika Westerberg | 51e2cc0 | 2011-05-29 13:10:04 +0300 | [diff] [blame] | 18 | #include <linux/dmaengine.h> |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 19 | |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 20 | #include <sound/pcm.h> |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 21 | #include <sound/soc.h> |
Lars-Peter Clausen | d7a42e1 | 2012-03-05 14:02:15 +0100 | [diff] [blame] | 22 | #include <sound/dmaengine_pcm.h> |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 23 | |
Arnd Bergmann | a3b2924 | 2012-08-24 15:12:11 +0200 | [diff] [blame] | 24 | #include <linux/platform_data/dma-ep93xx.h> |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 25 | |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 26 | static const struct snd_pcm_hardware ep93xx_pcm_hardware = { |
| 27 | .info = (SNDRV_PCM_INFO_MMAP | |
| 28 | SNDRV_PCM_INFO_MMAP_VALID | |
| 29 | SNDRV_PCM_INFO_INTERLEAVED | |
| 30 | SNDRV_PCM_INFO_BLOCK_TRANSFER), |
| 31 | |
Alexander Sverdlin | 4cfeb69 | 2011-03-07 20:30:12 +0300 | [diff] [blame] | 32 | .rates = SNDRV_PCM_RATE_8000_192000, |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 33 | .rate_min = SNDRV_PCM_RATE_8000, |
Alexander Sverdlin | 4cfeb69 | 2011-03-07 20:30:12 +0300 | [diff] [blame] | 34 | .rate_max = SNDRV_PCM_RATE_192000, |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 35 | |
| 36 | .formats = (SNDRV_PCM_FMTBIT_S16_LE | |
| 37 | SNDRV_PCM_FMTBIT_S24_LE | |
| 38 | SNDRV_PCM_FMTBIT_S32_LE), |
| 39 | |
| 40 | .buffer_bytes_max = 131072, |
| 41 | .period_bytes_min = 32, |
| 42 | .period_bytes_max = 32768, |
| 43 | .periods_min = 1, |
| 44 | .periods_max = 32, |
| 45 | .fifo_size = 32, |
| 46 | }; |
| 47 | |
Mika Westerberg | 51e2cc0 | 2011-05-29 13:10:04 +0300 | [diff] [blame] | 48 | static bool ep93xx_pcm_dma_filter(struct dma_chan *chan, void *filter_param) |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 49 | { |
Mika Westerberg | 51e2cc0 | 2011-05-29 13:10:04 +0300 | [diff] [blame] | 50 | struct ep93xx_dma_data *data = filter_param; |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 51 | |
Mika Westerberg | 51e2cc0 | 2011-05-29 13:10:04 +0300 | [diff] [blame] | 52 | if (data->direction == ep93xx_dma_chan_direction(chan)) { |
| 53 | chan->private = data; |
| 54 | return true; |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 55 | } |
Mika Westerberg | 51e2cc0 | 2011-05-29 13:10:04 +0300 | [diff] [blame] | 56 | |
| 57 | return false; |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 58 | } |
| 59 | |
Mark Brown | d7711dc | 2013-10-19 14:13:04 +0100 | [diff] [blame] | 60 | static struct dma_chan *ep93xx_compat_request_channel( |
| 61 | struct snd_soc_pcm_runtime *rtd, |
| 62 | struct snd_pcm_substream *substream) |
| 63 | { |
| 64 | struct snd_dmaengine_dai_dma_data *dma_data; |
| 65 | |
| 66 | dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); |
| 67 | |
| 68 | return snd_dmaengine_pcm_request_channel(ep93xx_pcm_dma_filter, |
| 69 | dma_data); |
| 70 | } |
| 71 | |
Lars-Peter Clausen | e27e8a6 | 2013-04-20 19:29:05 +0200 | [diff] [blame] | 72 | static const struct snd_dmaengine_pcm_config ep93xx_dmaengine_pcm_config = { |
| 73 | .pcm_hardware = &ep93xx_pcm_hardware, |
| 74 | .compat_filter_fn = ep93xx_pcm_dma_filter, |
Mark Brown | d7711dc | 2013-10-19 14:13:04 +0100 | [diff] [blame] | 75 | .compat_request_channel = ep93xx_compat_request_channel, |
Lars-Peter Clausen | e27e8a6 | 2013-04-20 19:29:05 +0200 | [diff] [blame] | 76 | .prealloc_buffer_size = 131072, |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 77 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 78 | |
Bill Pemberton | 145e287 | 2012-12-07 09:26:23 -0500 | [diff] [blame] | 79 | static int ep93xx_soc_platform_probe(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 80 | { |
Lars-Peter Clausen | 237eeb1 | 2013-11-28 08:50:34 +0100 | [diff] [blame^] | 81 | return devm_snd_dmaengine_pcm_register(&pdev->dev, |
Lars-Peter Clausen | e27e8a6 | 2013-04-20 19:29:05 +0200 | [diff] [blame] | 82 | &ep93xx_dmaengine_pcm_config, |
| 83 | SND_DMAENGINE_PCM_FLAG_NO_RESIDUE | |
| 84 | SND_DMAENGINE_PCM_FLAG_NO_DT | |
| 85 | SND_DMAENGINE_PCM_FLAG_COMPAT); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 88 | static struct platform_driver ep93xx_pcm_driver = { |
| 89 | .driver = { |
| 90 | .name = "ep93xx-pcm-audio", |
| 91 | .owner = THIS_MODULE, |
| 92 | }, |
| 93 | |
| 94 | .probe = ep93xx_soc_platform_probe, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 95 | }; |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 96 | |
Axel Lin | ee18f63 | 2011-11-24 12:07:55 +0800 | [diff] [blame] | 97 | module_platform_driver(ep93xx_pcm_driver); |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 98 | |
Ryan Mallon | 1c5454e | 2011-06-15 14:45:36 +1000 | [diff] [blame] | 99 | MODULE_AUTHOR("Ryan Mallon"); |
Ryan Mallon | db5bf41 | 2010-06-04 17:11:24 +1200 | [diff] [blame] | 100 | MODULE_DESCRIPTION("EP93xx ALSA PCM interface"); |
| 101 | MODULE_LICENSE("GPL"); |
Mika Westerberg | 9306816 | 2011-09-11 12:28:49 +0300 | [diff] [blame] | 102 | MODULE_ALIAS("platform:ep93xx-pcm-audio"); |