diff options
author | Mark Brown <broonie@linaro.org> | 2013-08-22 09:28:28 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-08-22 09:28:28 -0400 |
commit | 04877397afbdfeda4e073be710ce3f79f2912f16 (patch) | |
tree | e97db44d25953bf8626e106006caf6f7873b3cbe /sound/soc/atmel | |
parent | 0b1107b29b1c7c96ce5b2cae4115e336dbdfe8e7 (diff) | |
parent | f813175aa54367f455d8bb96f8f5ac2cec924528 (diff) |
Merge remote-tracking branch 'asoc/topic/atmel' into asoc-next
Diffstat (limited to 'sound/soc/atmel')
-rw-r--r-- | sound/soc/atmel/Kconfig | 21 | ||||
-rw-r--r-- | sound/soc/atmel/Makefile | 4 | ||||
-rw-r--r-- | sound/soc/atmel/atmel-pcm-dma.c | 118 | ||||
-rw-r--r-- | sound/soc/atmel/atmel_ssc_dai.c | 36 | ||||
-rw-r--r-- | sound/soc/atmel/atmel_wm8904.c | 254 | ||||
-rw-r--r-- | sound/soc/atmel/sam9x5_wm8731.c | 208 |
6 files changed, 522 insertions, 119 deletions
diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig index 3fdd87fa18a9..e48d38a1b95c 100644 --- a/sound/soc/atmel/Kconfig +++ b/sound/soc/atmel/Kconfig | |||
@@ -13,6 +13,7 @@ config SND_ATMEL_SOC_PDC | |||
13 | config SND_ATMEL_SOC_DMA | 13 | config SND_ATMEL_SOC_DMA |
14 | tristate | 14 | tristate |
15 | depends on SND_ATMEL_SOC | 15 | depends on SND_ATMEL_SOC |
16 | select SND_SOC_GENERIC_DMAENGINE_PCM | ||
16 | 17 | ||
17 | config SND_ATMEL_SOC_SSC | 18 | config SND_ATMEL_SOC_SSC |
18 | tristate | 19 | tristate |
@@ -32,6 +33,26 @@ config SND_AT91_SOC_SAM9G20_WM8731 | |||
32 | Say Y if you want to add support for SoC audio on WM8731-based | 33 | Say Y if you want to add support for SoC audio on WM8731-based |
33 | AT91sam9g20 evaluation board. | 34 | AT91sam9g20 evaluation board. |
34 | 35 | ||
36 | config SND_ATMEL_SOC_WM8904 | ||
37 | tristate "Atmel ASoC driver for boards using WM8904 codec" | ||
38 | depends on ARCH_AT91 && ATMEL_SSC && SND_ATMEL_SOC | ||
39 | select SND_ATMEL_SOC_SSC | ||
40 | select SND_ATMEL_SOC_DMA | ||
41 | select SND_SOC_WM8904 | ||
42 | help | ||
43 | Say Y if you want to add support for Atmel ASoC driver for boards using | ||
44 | WM8904 codec. | ||
45 | |||
46 | config SND_AT91_SOC_SAM9X5_WM8731 | ||
47 | tristate "SoC Audio support for WM8731-based at91sam9x5 board" | ||
48 | depends on ATMEL_SSC && SND_ATMEL_SOC && SOC_AT91SAM9X5 | ||
49 | select SND_ATMEL_SOC_SSC | ||
50 | select SND_ATMEL_SOC_DMA | ||
51 | select SND_SOC_WM8731 | ||
52 | help | ||
53 | Say Y if you want to add support for audio SoC on an | ||
54 | at91sam9x5 based board that is using WM8731 codec. | ||
55 | |||
35 | config SND_AT91_SOC_AFEB9260 | 56 | config SND_AT91_SOC_AFEB9260 |
36 | tristate "SoC Audio support for AFEB9260 board" | 57 | tristate "SoC Audio support for AFEB9260 board" |
37 | depends on ARCH_AT91 && ATMEL_SSC && ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC | 58 | depends on ARCH_AT91 && ATMEL_SSC && ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC |
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile index 41967ccb6f41..5baabc8bde3a 100644 --- a/sound/soc/atmel/Makefile +++ b/sound/soc/atmel/Makefile | |||
@@ -11,6 +11,10 @@ obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o | |||
11 | 11 | ||
12 | # AT91 Machine Support | 12 | # AT91 Machine Support |
13 | snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o | 13 | snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o |
14 | snd-atmel-soc-wm8904-objs := atmel_wm8904.o | ||
15 | snd-soc-sam9x5-wm8731-objs := sam9x5_wm8731.o | ||
14 | 16 | ||
15 | obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o | 17 | obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o |
18 | obj-$(CONFIG_SND_ATMEL_SOC_WM8904) += snd-atmel-soc-wm8904.o | ||
19 | obj-$(CONFIG_SND_AT91_SOC_SAM9X5_WM8731) += snd-soc-sam9x5-wm8731.o | ||
16 | obj-$(CONFIG_SND_AT91_SOC_AFEB9260) += snd-soc-afeb9260.o | 20 | obj-$(CONFIG_SND_AT91_SOC_AFEB9260) += snd-soc-afeb9260.o |
diff --git a/sound/soc/atmel/atmel-pcm-dma.c b/sound/soc/atmel/atmel-pcm-dma.c index d12826526798..06082e5e5dcb 100644 --- a/sound/soc/atmel/atmel-pcm-dma.c +++ b/sound/soc/atmel/atmel-pcm-dma.c | |||
@@ -91,138 +91,52 @@ static void atmel_pcm_dma_irq(u32 ssc_sr, | |||
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | /*--------------------------------------------------------------------------*\ | ||
95 | * DMAENGINE operations | ||
96 | \*--------------------------------------------------------------------------*/ | ||
97 | static bool filter(struct dma_chan *chan, void *slave) | ||
98 | { | ||
99 | struct at_dma_slave *sl = slave; | ||
100 | |||
101 | if (sl->dma_dev == chan->device->dev) { | ||
102 | chan->private = sl; | ||
103 | return true; | ||
104 | } else { | ||
105 | return false; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | static int atmel_pcm_configure_dma(struct snd_pcm_substream *substream, | 94 | static int atmel_pcm_configure_dma(struct snd_pcm_substream *substream, |
110 | struct snd_pcm_hw_params *params, struct atmel_pcm_dma_params *prtd) | 95 | struct snd_pcm_hw_params *params, struct dma_slave_config *slave_config) |
111 | { | 96 | { |
97 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
98 | struct atmel_pcm_dma_params *prtd; | ||
112 | struct ssc_device *ssc; | 99 | struct ssc_device *ssc; |
113 | struct dma_chan *dma_chan; | ||
114 | struct dma_slave_config slave_config; | ||
115 | int ret; | 100 | int ret; |
116 | 101 | ||
102 | prtd = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); | ||
117 | ssc = prtd->ssc; | 103 | ssc = prtd->ssc; |
118 | 104 | ||
119 | ret = snd_hwparams_to_dma_slave_config(substream, params, | 105 | ret = snd_hwparams_to_dma_slave_config(substream, params, slave_config); |
120 | &slave_config); | ||
121 | if (ret) { | 106 | if (ret) { |
122 | pr_err("atmel-pcm: hwparams to dma slave configure failed\n"); | 107 | pr_err("atmel-pcm: hwparams to dma slave configure failed\n"); |
123 | return ret; | 108 | return ret; |
124 | } | 109 | } |
125 | 110 | ||
126 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 111 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
127 | slave_config.dst_addr = (dma_addr_t)ssc->phybase + SSC_THR; | 112 | slave_config->dst_addr = ssc->phybase + SSC_THR; |
128 | slave_config.dst_maxburst = 1; | 113 | slave_config->dst_maxburst = 1; |
129 | } else { | 114 | } else { |
130 | slave_config.src_addr = (dma_addr_t)ssc->phybase + SSC_RHR; | 115 | slave_config->src_addr = ssc->phybase + SSC_RHR; |
131 | slave_config.src_maxburst = 1; | 116 | slave_config->src_maxburst = 1; |
132 | } | ||
133 | |||
134 | dma_chan = snd_dmaengine_pcm_get_chan(substream); | ||
135 | if (dmaengine_slave_config(dma_chan, &slave_config)) { | ||
136 | pr_err("atmel-pcm: failed to configure dma channel\n"); | ||
137 | ret = -EBUSY; | ||
138 | return ret; | ||
139 | } | ||
140 | |||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | static int atmel_pcm_hw_params(struct snd_pcm_substream *substream, | ||
145 | struct snd_pcm_hw_params *params) | ||
146 | { | ||
147 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
148 | struct atmel_pcm_dma_params *prtd; | ||
149 | struct ssc_device *ssc; | ||
150 | struct at_dma_slave *sdata = NULL; | ||
151 | int ret; | ||
152 | |||
153 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); | ||
154 | |||
155 | prtd = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); | ||
156 | ssc = prtd->ssc; | ||
157 | if (ssc->pdev) | ||
158 | sdata = ssc->pdev->dev.platform_data; | ||
159 | |||
160 | ret = snd_dmaengine_pcm_open_request_chan(substream, filter, sdata); | ||
161 | if (ret) { | ||
162 | pr_err("atmel-pcm: dmaengine pcm open failed\n"); | ||
163 | return -EINVAL; | ||
164 | } | ||
165 | |||
166 | ret = atmel_pcm_configure_dma(substream, params, prtd); | ||
167 | if (ret) { | ||
168 | pr_err("atmel-pcm: failed to configure dmai\n"); | ||
169 | goto err; | ||
170 | } | 117 | } |
171 | 118 | ||
172 | prtd->dma_intr_handler = atmel_pcm_dma_irq; | 119 | prtd->dma_intr_handler = atmel_pcm_dma_irq; |
173 | 120 | ||
174 | return 0; | 121 | return 0; |
175 | err: | ||
176 | snd_dmaengine_pcm_close_release_chan(substream); | ||
177 | return ret; | ||
178 | } | 122 | } |
179 | 123 | ||
180 | static int atmel_pcm_dma_prepare(struct snd_pcm_substream *substream) | 124 | static const struct snd_dmaengine_pcm_config atmel_dmaengine_pcm_config = { |
181 | { | 125 | .prepare_slave_config = atmel_pcm_configure_dma, |
182 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 126 | .pcm_hardware = &atmel_pcm_dma_hardware, |
183 | struct atmel_pcm_dma_params *prtd; | 127 | .prealloc_buffer_size = ATMEL_SSC_DMABUF_SIZE, |
184 | |||
185 | prtd = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); | ||
186 | |||
187 | ssc_writex(prtd->ssc->regs, SSC_IER, prtd->mask->ssc_error); | ||
188 | ssc_writex(prtd->ssc->regs, SSC_CR, prtd->mask->ssc_enable); | ||
189 | |||
190 | return 0; | ||
191 | } | ||
192 | |||
193 | static int atmel_pcm_open(struct snd_pcm_substream *substream) | ||
194 | { | ||
195 | snd_soc_set_runtime_hwparams(substream, &atmel_pcm_dma_hardware); | ||
196 | |||
197 | return 0; | ||
198 | } | ||
199 | |||
200 | static struct snd_pcm_ops atmel_pcm_ops = { | ||
201 | .open = atmel_pcm_open, | ||
202 | .close = snd_dmaengine_pcm_close_release_chan, | ||
203 | .ioctl = snd_pcm_lib_ioctl, | ||
204 | .hw_params = atmel_pcm_hw_params, | ||
205 | .prepare = atmel_pcm_dma_prepare, | ||
206 | .trigger = snd_dmaengine_pcm_trigger, | ||
207 | .pointer = snd_dmaengine_pcm_pointer_no_residue, | ||
208 | .mmap = atmel_pcm_mmap, | ||
209 | }; | ||
210 | |||
211 | static struct snd_soc_platform_driver atmel_soc_platform = { | ||
212 | .ops = &atmel_pcm_ops, | ||
213 | .pcm_new = atmel_pcm_new, | ||
214 | .pcm_free = atmel_pcm_free, | ||
215 | }; | 128 | }; |
216 | 129 | ||
217 | int atmel_pcm_dma_platform_register(struct device *dev) | 130 | int atmel_pcm_dma_platform_register(struct device *dev) |
218 | { | 131 | { |
219 | return snd_soc_register_platform(dev, &atmel_soc_platform); | 132 | return snd_dmaengine_pcm_register(dev, &atmel_dmaengine_pcm_config, |
133 | SND_DMAENGINE_PCM_FLAG_NO_RESIDUE); | ||
220 | } | 134 | } |
221 | EXPORT_SYMBOL(atmel_pcm_dma_platform_register); | 135 | EXPORT_SYMBOL(atmel_pcm_dma_platform_register); |
222 | 136 | ||
223 | void atmel_pcm_dma_platform_unregister(struct device *dev) | 137 | void atmel_pcm_dma_platform_unregister(struct device *dev) |
224 | { | 138 | { |
225 | snd_soc_unregister_platform(dev); | 139 | snd_dmaengine_pcm_unregister(dev); |
226 | } | 140 | } |
227 | EXPORT_SYMBOL(atmel_pcm_dma_platform_unregister); | 141 | EXPORT_SYMBOL(atmel_pcm_dma_platform_unregister); |
228 | 142 | ||
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c index f3fdfa07fcb9..0ecf356027f6 100644 --- a/sound/soc/atmel/atmel_ssc_dai.c +++ b/sound/soc/atmel/atmel_ssc_dai.c | |||
@@ -73,6 +73,7 @@ static struct atmel_ssc_mask ssc_tx_mask = { | |||
73 | .ssc_disable = SSC_BIT(CR_TXDIS), | 73 | .ssc_disable = SSC_BIT(CR_TXDIS), |
74 | .ssc_endx = SSC_BIT(SR_ENDTX), | 74 | .ssc_endx = SSC_BIT(SR_ENDTX), |
75 | .ssc_endbuf = SSC_BIT(SR_TXBUFE), | 75 | .ssc_endbuf = SSC_BIT(SR_TXBUFE), |
76 | .ssc_error = SSC_BIT(SR_OVRUN), | ||
76 | .pdc_enable = ATMEL_PDC_TXTEN, | 77 | .pdc_enable = ATMEL_PDC_TXTEN, |
77 | .pdc_disable = ATMEL_PDC_TXTDIS, | 78 | .pdc_disable = ATMEL_PDC_TXTDIS, |
78 | }; | 79 | }; |
@@ -82,6 +83,7 @@ static struct atmel_ssc_mask ssc_rx_mask = { | |||
82 | .ssc_disable = SSC_BIT(CR_RXDIS), | 83 | .ssc_disable = SSC_BIT(CR_RXDIS), |
83 | .ssc_endx = SSC_BIT(SR_ENDRX), | 84 | .ssc_endx = SSC_BIT(SR_ENDRX), |
84 | .ssc_endbuf = SSC_BIT(SR_RXBUFF), | 85 | .ssc_endbuf = SSC_BIT(SR_RXBUFF), |
86 | .ssc_error = SSC_BIT(SR_OVRUN), | ||
85 | .pdc_enable = ATMEL_PDC_RXTEN, | 87 | .pdc_enable = ATMEL_PDC_RXTEN, |
86 | .pdc_disable = ATMEL_PDC_RXTDIS, | 88 | .pdc_disable = ATMEL_PDC_RXTDIS, |
87 | }; | 89 | }; |
@@ -196,15 +198,27 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream, | |||
196 | struct snd_soc_dai *dai) | 198 | struct snd_soc_dai *dai) |
197 | { | 199 | { |
198 | struct atmel_ssc_info *ssc_p = &ssc_info[dai->id]; | 200 | struct atmel_ssc_info *ssc_p = &ssc_info[dai->id]; |
199 | int dir_mask; | 201 | struct atmel_pcm_dma_params *dma_params; |
202 | int dir, dir_mask; | ||
200 | 203 | ||
201 | pr_debug("atmel_ssc_startup: SSC_SR=0x%u\n", | 204 | pr_debug("atmel_ssc_startup: SSC_SR=0x%u\n", |
202 | ssc_readl(ssc_p->ssc->regs, SR)); | 205 | ssc_readl(ssc_p->ssc->regs, SR)); |
203 | 206 | ||
204 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | 207 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
208 | dir = 0; | ||
205 | dir_mask = SSC_DIR_MASK_PLAYBACK; | 209 | dir_mask = SSC_DIR_MASK_PLAYBACK; |
206 | else | 210 | } else { |
211 | dir = 1; | ||
207 | dir_mask = SSC_DIR_MASK_CAPTURE; | 212 | dir_mask = SSC_DIR_MASK_CAPTURE; |
213 | } | ||
214 | |||
215 | dma_params = &ssc_dma_params[dai->id][dir]; | ||
216 | dma_params->ssc = ssc_p->ssc; | ||
217 | dma_params->substream = substream; | ||
218 | |||
219 | ssc_p->dma_params[dir] = dma_params; | ||
220 | |||
221 | snd_soc_dai_set_dma_data(dai, substream, dma_params); | ||
208 | 222 | ||
209 | spin_lock_irq(&ssc_p->lock); | 223 | spin_lock_irq(&ssc_p->lock); |
210 | if (ssc_p->dir_mask & dir_mask) { | 224 | if (ssc_p->dir_mask & dir_mask) { |
@@ -325,7 +339,6 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream, | |||
325 | struct snd_pcm_hw_params *params, | 339 | struct snd_pcm_hw_params *params, |
326 | struct snd_soc_dai *dai) | 340 | struct snd_soc_dai *dai) |
327 | { | 341 | { |
328 | struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream); | ||
329 | int id = dai->id; | 342 | int id = dai->id; |
330 | struct atmel_ssc_info *ssc_p = &ssc_info[id]; | 343 | struct atmel_ssc_info *ssc_p = &ssc_info[id]; |
331 | struct atmel_pcm_dma_params *dma_params; | 344 | struct atmel_pcm_dma_params *dma_params; |
@@ -344,19 +357,7 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream, | |||
344 | else | 357 | else |
345 | dir = 1; | 358 | dir = 1; |
346 | 359 | ||
347 | dma_params = &ssc_dma_params[id][dir]; | 360 | dma_params = ssc_p->dma_params[dir]; |
348 | dma_params->ssc = ssc_p->ssc; | ||
349 | dma_params->substream = substream; | ||
350 | |||
351 | ssc_p->dma_params[dir] = dma_params; | ||
352 | |||
353 | /* | ||
354 | * The snd_soc_pcm_stream->dma_data field is only used to communicate | ||
355 | * the appropriate DMA parameters to the pcm driver hw_params() | ||
356 | * function. It should not be used for other purposes | ||
357 | * as it is common to all substreams. | ||
358 | */ | ||
359 | snd_soc_dai_set_dma_data(rtd->cpu_dai, substream, dma_params); | ||
360 | 361 | ||
361 | channels = params_channels(params); | 362 | channels = params_channels(params); |
362 | 363 | ||
@@ -648,6 +649,7 @@ static int atmel_ssc_prepare(struct snd_pcm_substream *substream, | |||
648 | dma_params = ssc_p->dma_params[dir]; | 649 | dma_params = ssc_p->dma_params[dir]; |
649 | 650 | ||
650 | ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_enable); | 651 | ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_enable); |
652 | ssc_writel(ssc_p->ssc->regs, IER, dma_params->mask->ssc_error); | ||
651 | 653 | ||
652 | pr_debug("%s enabled SSC_SR=0x%08x\n", | 654 | pr_debug("%s enabled SSC_SR=0x%08x\n", |
653 | dir ? "receive" : "transmit", | 655 | dir ? "receive" : "transmit", |
diff --git a/sound/soc/atmel/atmel_wm8904.c b/sound/soc/atmel/atmel_wm8904.c new file mode 100644 index 000000000000..7222380131ea --- /dev/null +++ b/sound/soc/atmel/atmel_wm8904.c | |||
@@ -0,0 +1,254 @@ | |||
1 | /* | ||
2 | * atmel_wm8904 - Atmel ASoC driver for boards with WM8904 codec. | ||
3 | * | ||
4 | * Copyright (C) 2012 Atmel | ||
5 | * | ||
6 | * Author: Bo Shen <voice.shen@atmel.com> | ||
7 | * | ||
8 | * GPLv2 or later | ||
9 | */ | ||
10 | |||
11 | #include <linux/clk.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/of.h> | ||
14 | #include <linux/of_device.h> | ||
15 | #include <linux/pinctrl/consumer.h> | ||
16 | |||
17 | #include <sound/soc.h> | ||
18 | |||
19 | #include "../codecs/wm8904.h" | ||
20 | #include "atmel_ssc_dai.h" | ||
21 | |||
22 | #define MCLK_RATE 32768 | ||
23 | |||
24 | static struct clk *mclk; | ||
25 | |||
26 | static const struct snd_soc_dapm_widget atmel_asoc_wm8904_dapm_widgets[] = { | ||
27 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | ||
28 | SND_SOC_DAPM_MIC("Mic", NULL), | ||
29 | SND_SOC_DAPM_LINE("Line In Jack", NULL), | ||
30 | }; | ||
31 | |||
32 | static int atmel_asoc_wm8904_hw_params(struct snd_pcm_substream *substream, | ||
33 | struct snd_pcm_hw_params *params) | ||
34 | { | ||
35 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
36 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
37 | int ret; | ||
38 | |||
39 | ret = snd_soc_dai_set_pll(codec_dai, WM8904_FLL_MCLK, WM8904_FLL_MCLK, | ||
40 | 32768, params_rate(params) * 256); | ||
41 | if (ret < 0) { | ||
42 | pr_err("%s - failed to set wm8904 codec PLL.", __func__); | ||
43 | return ret; | ||
44 | } | ||
45 | |||
46 | /* | ||
47 | * As here wm8904 use FLL output as its system clock | ||
48 | * so calling set_sysclk won't care freq parameter | ||
49 | * then we pass 0 | ||
50 | */ | ||
51 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8904_CLK_FLL, | ||
52 | 0, SND_SOC_CLOCK_IN); | ||
53 | if (ret < 0) { | ||
54 | pr_err("%s -failed to set wm8904 SYSCLK\n", __func__); | ||
55 | return ret; | ||
56 | } | ||
57 | |||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | static struct snd_soc_ops atmel_asoc_wm8904_ops = { | ||
62 | .hw_params = atmel_asoc_wm8904_hw_params, | ||
63 | }; | ||
64 | |||
65 | static int atmel_set_bias_level(struct snd_soc_card *card, | ||
66 | struct snd_soc_dapm_context *dapm, | ||
67 | enum snd_soc_bias_level level) | ||
68 | { | ||
69 | if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { | ||
70 | switch (level) { | ||
71 | case SND_SOC_BIAS_PREPARE: | ||
72 | clk_prepare_enable(mclk); | ||
73 | break; | ||
74 | case SND_SOC_BIAS_OFF: | ||
75 | clk_disable_unprepare(mclk); | ||
76 | break; | ||
77 | default: | ||
78 | break; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | return 0; | ||
83 | }; | ||
84 | |||
85 | static struct snd_soc_dai_link atmel_asoc_wm8904_dailink = { | ||
86 | .name = "WM8904", | ||
87 | .stream_name = "WM8904 PCM", | ||
88 | .codec_dai_name = "wm8904-hifi", | ||
89 | .dai_fmt = SND_SOC_DAIFMT_I2S | ||
90 | | SND_SOC_DAIFMT_NB_NF | ||
91 | | SND_SOC_DAIFMT_CBM_CFM, | ||
92 | .ops = &atmel_asoc_wm8904_ops, | ||
93 | }; | ||
94 | |||
95 | static struct snd_soc_card atmel_asoc_wm8904_card = { | ||
96 | .name = "atmel_asoc_wm8904", | ||
97 | .owner = THIS_MODULE, | ||
98 | .set_bias_level = atmel_set_bias_level, | ||
99 | .dai_link = &atmel_asoc_wm8904_dailink, | ||
100 | .num_links = 1, | ||
101 | .dapm_widgets = atmel_asoc_wm8904_dapm_widgets, | ||
102 | .num_dapm_widgets = ARRAY_SIZE(atmel_asoc_wm8904_dapm_widgets), | ||
103 | .fully_routed = true, | ||
104 | }; | ||
105 | |||
106 | static int atmel_asoc_wm8904_dt_init(struct platform_device *pdev) | ||
107 | { | ||
108 | struct device_node *np = pdev->dev.of_node; | ||
109 | struct device_node *codec_np, *cpu_np; | ||
110 | struct snd_soc_card *card = &atmel_asoc_wm8904_card; | ||
111 | struct snd_soc_dai_link *dailink = &atmel_asoc_wm8904_dailink; | ||
112 | int ret; | ||
113 | |||
114 | if (!np) { | ||
115 | dev_err(&pdev->dev, "only device tree supported\n"); | ||
116 | return -EINVAL; | ||
117 | } | ||
118 | |||
119 | ret = snd_soc_of_parse_card_name(card, "atmel,model"); | ||
120 | if (ret) { | ||
121 | dev_err(&pdev->dev, "failed to parse card name\n"); | ||
122 | return ret; | ||
123 | } | ||
124 | |||
125 | ret = snd_soc_of_parse_audio_routing(card, "atmel,audio-routing"); | ||
126 | if (ret) { | ||
127 | dev_err(&pdev->dev, "failed to parse audio routing\n"); | ||
128 | return ret; | ||
129 | } | ||
130 | |||
131 | cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0); | ||
132 | if (!cpu_np) { | ||
133 | dev_err(&pdev->dev, "failed to get dai and pcm info\n"); | ||
134 | ret = -EINVAL; | ||
135 | return ret; | ||
136 | } | ||
137 | dailink->cpu_of_node = cpu_np; | ||
138 | dailink->platform_of_node = cpu_np; | ||
139 | of_node_put(cpu_np); | ||
140 | |||
141 | codec_np = of_parse_phandle(np, "atmel,audio-codec", 0); | ||
142 | if (!codec_np) { | ||
143 | dev_err(&pdev->dev, "failed to get codec info\n"); | ||
144 | ret = -EINVAL; | ||
145 | return ret; | ||
146 | } | ||
147 | dailink->codec_of_node = codec_np; | ||
148 | of_node_put(codec_np); | ||
149 | |||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | static int atmel_asoc_wm8904_probe(struct platform_device *pdev) | ||
154 | { | ||
155 | struct snd_soc_card *card = &atmel_asoc_wm8904_card; | ||
156 | struct snd_soc_dai_link *dailink = &atmel_asoc_wm8904_dailink; | ||
157 | struct clk *clk_src; | ||
158 | struct pinctrl *pinctrl; | ||
159 | int id, ret; | ||
160 | |||
161 | pinctrl = devm_pinctrl_get_select_default(&pdev->dev); | ||
162 | if (IS_ERR(pinctrl)) { | ||
163 | dev_err(&pdev->dev, "failed to request pinctrl\n"); | ||
164 | return PTR_ERR(pinctrl); | ||
165 | } | ||
166 | |||
167 | card->dev = &pdev->dev; | ||
168 | ret = atmel_asoc_wm8904_dt_init(pdev); | ||
169 | if (ret) { | ||
170 | dev_err(&pdev->dev, "failed to init dt info\n"); | ||
171 | return ret; | ||
172 | } | ||
173 | |||
174 | id = of_alias_get_id((struct device_node *)dailink->cpu_of_node, "ssc"); | ||
175 | ret = atmel_ssc_set_audio(id); | ||
176 | if (ret != 0) { | ||
177 | dev_err(&pdev->dev, "failed to set SSC %d for audio\n", id); | ||
178 | return ret; | ||
179 | } | ||
180 | |||
181 | mclk = clk_get(NULL, "pck0"); | ||
182 | if (IS_ERR(mclk)) { | ||
183 | dev_err(&pdev->dev, "failed to get pck0\n"); | ||
184 | ret = PTR_ERR(mclk); | ||
185 | goto err_set_audio; | ||
186 | } | ||
187 | |||
188 | clk_src = clk_get(NULL, "clk32k"); | ||
189 | if (IS_ERR(clk_src)) { | ||
190 | dev_err(&pdev->dev, "failed to get clk32k\n"); | ||
191 | ret = PTR_ERR(clk_src); | ||
192 | goto err_set_audio; | ||
193 | } | ||
194 | |||
195 | ret = clk_set_parent(mclk, clk_src); | ||
196 | clk_put(clk_src); | ||
197 | if (ret != 0) { | ||
198 | dev_err(&pdev->dev, "failed to set MCLK parent\n"); | ||
199 | goto err_set_audio; | ||
200 | } | ||
201 | |||
202 | dev_info(&pdev->dev, "setting pck0 to %dHz\n", MCLK_RATE); | ||
203 | clk_set_rate(mclk, MCLK_RATE); | ||
204 | |||
205 | ret = snd_soc_register_card(card); | ||
206 | if (ret) { | ||
207 | dev_err(&pdev->dev, "snd_soc_register_card failed\n"); | ||
208 | goto err_set_audio; | ||
209 | } | ||
210 | |||
211 | return 0; | ||
212 | |||
213 | err_set_audio: | ||
214 | atmel_ssc_put_audio(id); | ||
215 | return ret; | ||
216 | } | ||
217 | |||
218 | static int atmel_asoc_wm8904_remove(struct platform_device *pdev) | ||
219 | { | ||
220 | struct snd_soc_card *card = platform_get_drvdata(pdev); | ||
221 | struct snd_soc_dai_link *dailink = &atmel_asoc_wm8904_dailink; | ||
222 | int id; | ||
223 | |||
224 | id = of_alias_get_id((struct device_node *)dailink->cpu_of_node, "ssc"); | ||
225 | |||
226 | snd_soc_unregister_card(card); | ||
227 | atmel_ssc_put_audio(id); | ||
228 | |||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | #ifdef CONFIG_OF | ||
233 | static const struct of_device_id atmel_asoc_wm8904_dt_ids[] = { | ||
234 | { .compatible = "atmel,asoc-wm8904", }, | ||
235 | { } | ||
236 | }; | ||
237 | #endif | ||
238 | |||
239 | static struct platform_driver atmel_asoc_wm8904_driver = { | ||
240 | .driver = { | ||
241 | .name = "atmel-wm8904-audio", | ||
242 | .owner = THIS_MODULE, | ||
243 | .of_match_table = of_match_ptr(atmel_asoc_wm8904_dt_ids), | ||
244 | }, | ||
245 | .probe = atmel_asoc_wm8904_probe, | ||
246 | .remove = atmel_asoc_wm8904_remove, | ||
247 | }; | ||
248 | |||
249 | module_platform_driver(atmel_asoc_wm8904_driver); | ||
250 | |||
251 | /* Module information */ | ||
252 | MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>"); | ||
253 | MODULE_DESCRIPTION("ALSA SoC machine driver for Atmel EK with WM8904 codec"); | ||
254 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/atmel/sam9x5_wm8731.c b/sound/soc/atmel/sam9x5_wm8731.c new file mode 100644 index 000000000000..992ae38d5a15 --- /dev/null +++ b/sound/soc/atmel/sam9x5_wm8731.c | |||
@@ -0,0 +1,208 @@ | |||
1 | /* | ||
2 | * sam9x5_wm8731 -- SoC audio for AT91SAM9X5-based boards | ||
3 | * that are using WM8731 as codec. | ||
4 | * | ||
5 | * Copyright (C) 2011 Atmel, | ||
6 | * Nicolas Ferre <nicolas.ferre@atmel.com> | ||
7 | * | ||
8 | * Copyright (C) 2013 Paratronic, | ||
9 | * Richard Genoud <richard.genoud@gmail.com> | ||
10 | * | ||
11 | * Based on sam9g20_wm8731.c by: | ||
12 | * Sedji Gaouaou <sedji.gaouaou@atmel.com> | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify it | ||
15 | * under the terms of the GNU General Public License as published by the | ||
16 | * Free Software Foundation; either version 2 of the License, or (at your | ||
17 | * option) any later version. | ||
18 | * | ||
19 | */ | ||
20 | #include <linux/of.h> | ||
21 | #include <linux/export.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/mod_devicetable.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | #include <linux/device.h> | ||
26 | |||
27 | #include <sound/soc.h> | ||
28 | #include <sound/soc-dai.h> | ||
29 | #include <sound/soc-dapm.h> | ||
30 | |||
31 | #include "../codecs/wm8731.h" | ||
32 | #include "atmel_ssc_dai.h" | ||
33 | |||
34 | |||
35 | #define MCLK_RATE 12288000 | ||
36 | |||
37 | #define DRV_NAME "sam9x5-snd-wm8731" | ||
38 | |||
39 | struct sam9x5_drvdata { | ||
40 | int ssc_id; | ||
41 | }; | ||
42 | |||
43 | /* | ||
44 | * Logic for a wm8731 as connected on a at91sam9x5ek based board. | ||
45 | */ | ||
46 | static int sam9x5_wm8731_init(struct snd_soc_pcm_runtime *rtd) | ||
47 | { | ||
48 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
49 | struct device *dev = rtd->dev; | ||
50 | int ret; | ||
51 | |||
52 | dev_dbg(dev, "ASoC: %s called\n", __func__); | ||
53 | |||
54 | /* set the codec system clock for DAC and ADC */ | ||
55 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL, | ||
56 | MCLK_RATE, SND_SOC_CLOCK_IN); | ||
57 | if (ret < 0) { | ||
58 | dev_err(dev, "ASoC: Failed to set WM8731 SYSCLK: %d\n", ret); | ||
59 | return ret; | ||
60 | } | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * Audio paths on at91sam9x5ek board: | ||
67 | * | ||
68 | * |A| ------------> | | ---R----> Headphone Jack | ||
69 | * |T| <----\ | WM | ---L--/ | ||
70 | * |9| ---> CLK <--> | 8731 | <--R----- Line In Jack | ||
71 | * |1| <------------ | | <--L--/ | ||
72 | */ | ||
73 | static const struct snd_soc_dapm_widget sam9x5_dapm_widgets[] = { | ||
74 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | ||
75 | SND_SOC_DAPM_LINE("Line In Jack", NULL), | ||
76 | }; | ||
77 | |||
78 | static int sam9x5_wm8731_driver_probe(struct platform_device *pdev) | ||
79 | { | ||
80 | struct device_node *np = pdev->dev.of_node; | ||
81 | struct device_node *codec_np, *cpu_np; | ||
82 | struct snd_soc_card *card; | ||
83 | struct snd_soc_dai_link *dai; | ||
84 | struct sam9x5_drvdata *priv; | ||
85 | int ret; | ||
86 | |||
87 | if (!np) { | ||
88 | dev_err(&pdev->dev, "No device node supplied\n"); | ||
89 | return -EINVAL; | ||
90 | } | ||
91 | |||
92 | card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL); | ||
93 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); | ||
94 | dai = devm_kzalloc(&pdev->dev, sizeof(*dai), GFP_KERNEL); | ||
95 | if (!dai || !card || !priv) { | ||
96 | ret = -ENOMEM; | ||
97 | goto out; | ||
98 | } | ||
99 | |||
100 | card->dev = &pdev->dev; | ||
101 | card->owner = THIS_MODULE; | ||
102 | card->dai_link = dai; | ||
103 | card->num_links = 1; | ||
104 | card->dapm_widgets = sam9x5_dapm_widgets; | ||
105 | card->num_dapm_widgets = ARRAY_SIZE(sam9x5_dapm_widgets); | ||
106 | dai->name = "WM8731"; | ||
107 | dai->stream_name = "WM8731 PCM"; | ||
108 | dai->codec_dai_name = "wm8731-hifi"; | ||
109 | dai->init = sam9x5_wm8731_init; | ||
110 | dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | ||
111 | | SND_SOC_DAIFMT_CBM_CFM; | ||
112 | |||
113 | ret = snd_soc_of_parse_card_name(card, "atmel,model"); | ||
114 | if (ret) { | ||
115 | dev_err(&pdev->dev, "atmel,model node missing\n"); | ||
116 | goto out; | ||
117 | } | ||
118 | |||
119 | ret = snd_soc_of_parse_audio_routing(card, "atmel,audio-routing"); | ||
120 | if (ret) { | ||
121 | dev_err(&pdev->dev, "atmel,audio-routing node missing\n"); | ||
122 | goto out; | ||
123 | } | ||
124 | |||
125 | codec_np = of_parse_phandle(np, "atmel,audio-codec", 0); | ||
126 | if (!codec_np) { | ||
127 | dev_err(&pdev->dev, "atmel,audio-codec node missing\n"); | ||
128 | ret = -EINVAL; | ||
129 | goto out; | ||
130 | } | ||
131 | |||
132 | dai->codec_of_node = codec_np; | ||
133 | |||
134 | cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0); | ||
135 | if (!cpu_np) { | ||
136 | dev_err(&pdev->dev, "atmel,ssc-controller node missing\n"); | ||
137 | ret = -EINVAL; | ||
138 | goto out; | ||
139 | } | ||
140 | dai->cpu_of_node = cpu_np; | ||
141 | dai->platform_of_node = cpu_np; | ||
142 | |||
143 | priv->ssc_id = of_alias_get_id(cpu_np, "ssc"); | ||
144 | |||
145 | ret = atmel_ssc_set_audio(priv->ssc_id); | ||
146 | if (ret != 0) { | ||
147 | dev_err(&pdev->dev, | ||
148 | "ASoC: Failed to set SSC %d for audio: %d\n", | ||
149 | ret, priv->ssc_id); | ||
150 | goto out; | ||
151 | } | ||
152 | |||
153 | of_node_put(codec_np); | ||
154 | of_node_put(cpu_np); | ||
155 | |||
156 | platform_set_drvdata(pdev, card); | ||
157 | |||
158 | ret = snd_soc_register_card(card); | ||
159 | if (ret) { | ||
160 | dev_err(&pdev->dev, | ||
161 | "ASoC: Platform device allocation failed\n"); | ||
162 | goto out_put_audio; | ||
163 | } | ||
164 | |||
165 | dev_dbg(&pdev->dev, "ASoC: %s ok\n", __func__); | ||
166 | |||
167 | return ret; | ||
168 | |||
169 | out_put_audio: | ||
170 | atmel_ssc_put_audio(priv->ssc_id); | ||
171 | out: | ||
172 | return ret; | ||
173 | } | ||
174 | |||
175 | static int sam9x5_wm8731_driver_remove(struct platform_device *pdev) | ||
176 | { | ||
177 | struct snd_soc_card *card = platform_get_drvdata(pdev); | ||
178 | struct sam9x5_drvdata *priv = card->drvdata; | ||
179 | |||
180 | snd_soc_unregister_card(card); | ||
181 | atmel_ssc_put_audio(priv->ssc_id); | ||
182 | |||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | static const struct of_device_id sam9x5_wm8731_of_match[] = { | ||
187 | { .compatible = "atmel,sam9x5-wm8731-audio", }, | ||
188 | {}, | ||
189 | }; | ||
190 | MODULE_DEVICE_TABLE(of, sam9x5_wm8731_of_match); | ||
191 | |||
192 | static struct platform_driver sam9x5_wm8731_driver = { | ||
193 | .driver = { | ||
194 | .name = DRV_NAME, | ||
195 | .owner = THIS_MODULE, | ||
196 | .of_match_table = of_match_ptr(sam9x5_wm8731_of_match), | ||
197 | }, | ||
198 | .probe = sam9x5_wm8731_driver_probe, | ||
199 | .remove = sam9x5_wm8731_driver_remove, | ||
200 | }; | ||
201 | module_platform_driver(sam9x5_wm8731_driver); | ||
202 | |||
203 | /* Module information */ | ||
204 | MODULE_AUTHOR("Nicolas Ferre <nicolas.ferre@atmel.com>"); | ||
205 | MODULE_AUTHOR("Richard Genoud <richard.genoud@gmail.com>"); | ||
206 | MODULE_DESCRIPTION("ALSA SoC machine driver for AT91SAM9x5 - WM8731"); | ||
207 | MODULE_LICENSE("GPL"); | ||
208 | MODULE_ALIAS("platform:" DRV_NAME); | ||