aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/adi
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/adi')
-rw-r--r--sound/soc/adi/Kconfig21
-rw-r--r--sound/soc/adi/Makefile5
-rw-r--r--sound/soc/adi/axi-i2s.c277
-rw-r--r--sound/soc/adi/axi-spdif.c272
4 files changed, 575 insertions, 0 deletions
diff --git a/sound/soc/adi/Kconfig b/sound/soc/adi/Kconfig
new file mode 100644
index 000000000000..dd763f55edac
--- /dev/null
+++ b/sound/soc/adi/Kconfig
@@ -0,0 +1,21 @@
1config SND_SOC_ADI
2 tristate "Audio support for Analog Devices reference designs"
3 depends on MICROBLAZE || ARCH_ZYNQ || COMPILE_TEST
4 help
5 Audio support for various reference designs by Analog Devices.
6
7config SND_SOC_ADI_AXI_I2S
8 tristate "AXI-I2S support"
9 depends on SND_SOC_ADI
10 select SND_SOC_GENERIC_DMAENGINE_PCM
11 select REGMAP_MMIO
12 help
13 ASoC driver for the Analog Devices AXI-I2S softcore peripheral.
14
15config SND_SOC_ADI_AXI_SPDIF
16 tristate "AXI-SPDIF support"
17 depends on SND_SOC_ADI
18 select SND_SOC_GENERIC_DMAENGINE_PCM
19 select REGMAP_MMIO
20 help
21 ASoC driver for the Analog Devices AXI-SPDIF softcore peripheral.
diff --git a/sound/soc/adi/Makefile b/sound/soc/adi/Makefile
new file mode 100644
index 000000000000..64456c1e5347
--- /dev/null
+++ b/sound/soc/adi/Makefile
@@ -0,0 +1,5 @@
1snd-soc-adi-axi-i2s-objs := axi-i2s.o
2snd-soc-adi-axi-spdif-objs := axi-spdif.o
3
4obj-$(CONFIG_SND_SOC_ADI_AXI_I2S) += snd-soc-adi-axi-i2s.o
5obj-$(CONFIG_SND_SOC_ADI_AXI_SPDIF) += snd-soc-adi-axi-spdif.o
diff --git a/sound/soc/adi/axi-i2s.c b/sound/soc/adi/axi-i2s.c
new file mode 100644
index 000000000000..7f91a86dd734
--- /dev/null
+++ b/sound/soc/adi/axi-i2s.c
@@ -0,0 +1,277 @@
1/*
2 * Copyright (C) 2012-2013, Analog Devices Inc.
3 * Author: Lars-Peter Clausen <lars@metafoo.de>
4 *
5 * Licensed under the GPL-2.
6 */
7
8#include <linux/clk.h>
9#include <linux/init.h>
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/of.h>
13#include <linux/platform_device.h>
14#include <linux/regmap.h>
15#include <linux/slab.h>
16
17#include <sound/core.h>
18#include <sound/pcm.h>
19#include <sound/pcm_params.h>
20#include <sound/soc.h>
21#include <sound/dmaengine_pcm.h>
22
23#define AXI_I2S_REG_RESET 0x00
24#define AXI_I2S_REG_CTRL 0x04
25#define AXI_I2S_REG_CLK_CTRL 0x08
26#define AXI_I2S_REG_STATUS 0x10
27
28#define AXI_I2S_REG_RX_FIFO 0x28
29#define AXI_I2S_REG_TX_FIFO 0x2C
30
31#define AXI_I2S_RESET_GLOBAL BIT(0)
32#define AXI_I2S_RESET_TX_FIFO BIT(1)
33#define AXI_I2S_RESET_RX_FIFO BIT(2)
34
35#define AXI_I2S_CTRL_TX_EN BIT(0)
36#define AXI_I2S_CTRL_RX_EN BIT(1)
37
38/* The frame size is configurable, but for now we always set it 64 bit */
39#define AXI_I2S_BITS_PER_FRAME 64
40
41struct axi_i2s {
42 struct regmap *regmap;
43 struct clk *clk;
44 struct clk *clk_ref;
45
46 struct snd_soc_dai_driver dai_driver;
47
48 struct snd_dmaengine_dai_dma_data capture_dma_data;
49 struct snd_dmaengine_dai_dma_data playback_dma_data;
50
51 struct snd_ratnum ratnum;
52 struct snd_pcm_hw_constraint_ratnums rate_constraints;
53};
54
55static int axi_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
56 struct snd_soc_dai *dai)
57{
58 struct axi_i2s *i2s = snd_soc_dai_get_drvdata(dai);
59 unsigned int mask, val;
60
61 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
62 mask = AXI_I2S_CTRL_RX_EN;
63 else
64 mask = AXI_I2S_CTRL_TX_EN;
65
66 switch (cmd) {
67 case SNDRV_PCM_TRIGGER_START:
68 case SNDRV_PCM_TRIGGER_RESUME:
69 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
70 val = mask;
71 break;
72 case SNDRV_PCM_TRIGGER_STOP:
73 case SNDRV_PCM_TRIGGER_SUSPEND:
74 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
75 val = 0;
76 break;
77 default:
78 return -EINVAL;
79 }
80
81 regmap_update_bits(i2s->regmap, AXI_I2S_REG_CTRL, mask, val);
82
83 return 0;
84}
85
86static int axi_i2s_hw_params(struct snd_pcm_substream *substream,
87 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
88{
89 struct axi_i2s *i2s = snd_soc_dai_get_drvdata(dai);
90 unsigned int bclk_div, word_size;
91 unsigned int bclk_rate;
92
93 bclk_rate = params_rate(params) * AXI_I2S_BITS_PER_FRAME;
94
95 word_size = AXI_I2S_BITS_PER_FRAME / 2 - 1;
96 bclk_div = DIV_ROUND_UP(clk_get_rate(i2s->clk_ref), bclk_rate) / 2 - 1;
97
98 regmap_write(i2s->regmap, AXI_I2S_REG_CLK_CTRL, (word_size << 16) |
99 bclk_div);
100
101 return 0;
102}
103
104static int axi_i2s_startup(struct snd_pcm_substream *substream,
105 struct snd_soc_dai *dai)
106{
107 struct axi_i2s *i2s = snd_soc_dai_get_drvdata(dai);
108 uint32_t mask;
109 int ret;
110
111 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
112 mask = AXI_I2S_RESET_RX_FIFO;
113 else
114 mask = AXI_I2S_RESET_TX_FIFO;
115
116 regmap_write(i2s->regmap, AXI_I2S_REG_RESET, mask);
117
118 ret = snd_pcm_hw_constraint_ratnums(substream->runtime, 0,
119 SNDRV_PCM_HW_PARAM_RATE,
120 &i2s->rate_constraints);
121 if (ret)
122 return ret;
123
124 return clk_prepare_enable(i2s->clk_ref);
125}
126
127static void axi_i2s_shutdown(struct snd_pcm_substream *substream,
128 struct snd_soc_dai *dai)
129{
130 struct axi_i2s *i2s = snd_soc_dai_get_drvdata(dai);
131
132 clk_disable_unprepare(i2s->clk_ref);
133}
134
135static int axi_i2s_dai_probe(struct snd_soc_dai *dai)
136{
137 struct axi_i2s *i2s = snd_soc_dai_get_drvdata(dai);
138
139 snd_soc_dai_init_dma_data(dai, &i2s->playback_dma_data,
140 &i2s->capture_dma_data);
141
142 return 0;
143}
144
145static const struct snd_soc_dai_ops axi_i2s_dai_ops = {
146 .startup = axi_i2s_startup,
147 .shutdown = axi_i2s_shutdown,
148 .trigger = axi_i2s_trigger,
149 .hw_params = axi_i2s_hw_params,
150};
151
152static struct snd_soc_dai_driver axi_i2s_dai = {
153 .probe = axi_i2s_dai_probe,
154 .playback = {
155 .channels_min = 2,
156 .channels_max = 2,
157 .rates = SNDRV_PCM_RATE_KNOT,
158 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_U32_LE,
159 },
160 .capture = {
161 .channels_min = 2,
162 .channels_max = 2,
163 .rates = SNDRV_PCM_RATE_KNOT,
164 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_U32_LE,
165 },
166 .ops = &axi_i2s_dai_ops,
167 .symmetric_rates = 1,
168};
169
170static const struct snd_soc_component_driver axi_i2s_component = {
171 .name = "axi-i2s",
172};
173
174static const struct regmap_config axi_i2s_regmap_config = {
175 .reg_bits = 32,
176 .reg_stride = 4,
177 .val_bits = 32,
178 .max_register = AXI_I2S_REG_STATUS,
179};
180
181static int axi_i2s_probe(struct platform_device *pdev)
182{
183 struct resource *res;
184 struct axi_i2s *i2s;
185 void __iomem *base;
186 int ret;
187
188 i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL);
189 if (!i2s)
190 return -ENOMEM;
191
192 platform_set_drvdata(pdev, i2s);
193
194 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
195 base = devm_ioremap_resource(&pdev->dev, res);
196 if (IS_ERR(base))
197 return PTR_ERR(base);
198
199 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, base,
200 &axi_i2s_regmap_config);
201 if (IS_ERR(i2s->regmap))
202 return PTR_ERR(i2s->regmap);
203
204 i2s->clk = devm_clk_get(&pdev->dev, "axi");
205 if (IS_ERR(i2s->clk))
206 return PTR_ERR(i2s->clk);
207
208 i2s->clk_ref = devm_clk_get(&pdev->dev, "ref");
209 if (IS_ERR(i2s->clk_ref))
210 return PTR_ERR(i2s->clk_ref);
211
212 ret = clk_prepare_enable(i2s->clk);
213 if (ret)
214 return ret;
215
216 i2s->playback_dma_data.addr = res->start + AXI_I2S_REG_TX_FIFO;
217 i2s->playback_dma_data.addr_width = 4;
218 i2s->playback_dma_data.maxburst = 1;
219
220 i2s->capture_dma_data.addr = res->start + AXI_I2S_REG_RX_FIFO;
221 i2s->capture_dma_data.addr_width = 4;
222 i2s->capture_dma_data.maxburst = 1;
223
224 i2s->ratnum.num = clk_get_rate(i2s->clk_ref) / 2 / AXI_I2S_BITS_PER_FRAME;
225 i2s->ratnum.den_step = 1;
226 i2s->ratnum.den_min = 1;
227 i2s->ratnum.den_max = 64;
228
229 i2s->rate_constraints.rats = &i2s->ratnum;
230 i2s->rate_constraints.nrats = 1;
231
232 regmap_write(i2s->regmap, AXI_I2S_REG_RESET, AXI_I2S_RESET_GLOBAL);
233
234 ret = devm_snd_soc_register_component(&pdev->dev, &axi_i2s_component,
235 &axi_i2s_dai, 1);
236 if (ret)
237 goto err_clk_disable;
238
239 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL,
240 SND_DMAENGINE_PCM_FLAG_NO_RESIDUE);
241 if (ret)
242 goto err_clk_disable;
243
244err_clk_disable:
245 clk_disable_unprepare(i2s->clk);
246 return ret;
247}
248
249static int axi_i2s_dev_remove(struct platform_device *pdev)
250{
251 struct axi_i2s *i2s = platform_get_drvdata(pdev);
252
253 clk_disable_unprepare(i2s->clk);
254
255 return 0;
256}
257
258static const struct of_device_id axi_i2s_of_match[] = {
259 { .compatible = "adi,axi-i2s-1.00.a", },
260 {},
261};
262MODULE_DEVICE_TABLE(of, axi_i2s_of_match);
263
264static struct platform_driver axi_i2s_driver = {
265 .driver = {
266 .name = "axi-i2s",
267 .owner = THIS_MODULE,
268 .of_match_table = axi_i2s_of_match,
269 },
270 .probe = axi_i2s_probe,
271 .remove = axi_i2s_dev_remove,
272};
273module_platform_driver(axi_i2s_driver);
274
275MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
276MODULE_DESCRIPTION("AXI I2S driver");
277MODULE_LICENSE("GPL");
diff --git a/sound/soc/adi/axi-spdif.c b/sound/soc/adi/axi-spdif.c
new file mode 100644
index 000000000000..8db7a9920695
--- /dev/null
+++ b/sound/soc/adi/axi-spdif.c
@@ -0,0 +1,272 @@
1/*
2 * Copyright (C) 2012-2013, Analog Devices Inc.
3 * Author: Lars-Peter Clausen <lars@metafoo.de>
4 *
5 * Licensed under the GPL-2.
6 */
7
8#include <linux/init.h>
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/platform_device.h>
12#include <linux/slab.h>
13#include <linux/of.h>
14#include <linux/clk.h>
15#include <linux/regmap.h>
16
17#include <sound/core.h>
18#include <sound/pcm.h>
19#include <sound/pcm_params.h>
20#include <sound/soc.h>
21#include <sound/initval.h>
22#include <sound/dmaengine_pcm.h>
23
24#define AXI_SPDIF_REG_CTRL 0x0
25#define AXI_SPDIF_REG_STAT 0x4
26#define AXI_SPDIF_REG_TX_FIFO 0xc
27
28#define AXI_SPDIF_CTRL_TXDATA BIT(1)
29#define AXI_SPDIF_CTRL_TXEN BIT(0)
30#define AXI_SPDIF_CTRL_CLKDIV_OFFSET 8
31#define AXI_SPDIF_CTRL_CLKDIV_MASK (0xff << 8)
32
33#define AXI_SPDIF_FREQ_44100 (0x0 << 6)
34#define AXI_SPDIF_FREQ_48000 (0x1 << 6)
35#define AXI_SPDIF_FREQ_32000 (0x2 << 6)
36#define AXI_SPDIF_FREQ_NA (0x3 << 6)
37
38struct axi_spdif {
39 struct regmap *regmap;
40 struct clk *clk;
41 struct clk *clk_ref;
42
43 struct snd_dmaengine_dai_dma_data dma_data;
44
45 struct snd_ratnum ratnum;
46 struct snd_pcm_hw_constraint_ratnums rate_constraints;
47};
48
49static int axi_spdif_trigger(struct snd_pcm_substream *substream, int cmd,
50 struct snd_soc_dai *dai)
51{
52 struct axi_spdif *spdif = snd_soc_dai_get_drvdata(dai);
53 unsigned int val;
54
55 switch (cmd) {
56 case SNDRV_PCM_TRIGGER_START:
57 case SNDRV_PCM_TRIGGER_RESUME:
58 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
59 val = AXI_SPDIF_CTRL_TXDATA;
60 break;
61 case SNDRV_PCM_TRIGGER_STOP:
62 case SNDRV_PCM_TRIGGER_SUSPEND:
63 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
64 val = 0;
65 break;
66 default:
67 return -EINVAL;
68 }
69
70 regmap_update_bits(spdif->regmap, AXI_SPDIF_REG_CTRL,
71 AXI_SPDIF_CTRL_TXDATA, val);
72
73 return 0;
74}
75
76static int axi_spdif_hw_params(struct snd_pcm_substream *substream,
77 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
78{
79 struct axi_spdif *spdif = snd_soc_dai_get_drvdata(dai);
80 unsigned int rate = params_rate(params);
81 unsigned int clkdiv, stat;
82
83 switch (params_rate(params)) {
84 case 32000:
85 stat = AXI_SPDIF_FREQ_32000;
86 break;
87 case 44100:
88 stat = AXI_SPDIF_FREQ_44100;
89 break;
90 case 48000:
91 stat = AXI_SPDIF_FREQ_48000;
92 break;
93 default:
94 stat = AXI_SPDIF_FREQ_NA;
95 break;
96 }
97
98 clkdiv = DIV_ROUND_CLOSEST(clk_get_rate(spdif->clk_ref),
99 rate * 64 * 2) - 1;
100 clkdiv <<= AXI_SPDIF_CTRL_CLKDIV_OFFSET;
101
102 regmap_write(spdif->regmap, AXI_SPDIF_REG_STAT, stat);
103 regmap_update_bits(spdif->regmap, AXI_SPDIF_REG_CTRL,
104 AXI_SPDIF_CTRL_CLKDIV_MASK, clkdiv);
105
106 return 0;
107}
108
109static int axi_spdif_dai_probe(struct snd_soc_dai *dai)
110{
111 struct axi_spdif *spdif = snd_soc_dai_get_drvdata(dai);
112
113 snd_soc_dai_init_dma_data(dai, &spdif->dma_data, NULL);
114
115 return 0;
116}
117
118static int axi_spdif_startup(struct snd_pcm_substream *substream,
119 struct snd_soc_dai *dai)
120{
121 struct axi_spdif *spdif = snd_soc_dai_get_drvdata(dai);
122 int ret;
123
124 ret = snd_pcm_hw_constraint_ratnums(substream->runtime, 0,
125 SNDRV_PCM_HW_PARAM_RATE,
126 &spdif->rate_constraints);
127 if (ret)
128 return ret;
129
130 ret = clk_prepare_enable(spdif->clk_ref);
131 if (ret)
132 return ret;
133
134 regmap_update_bits(spdif->regmap, AXI_SPDIF_REG_CTRL,
135 AXI_SPDIF_CTRL_TXEN, AXI_SPDIF_CTRL_TXEN);
136
137 return 0;
138}
139
140static void axi_spdif_shutdown(struct snd_pcm_substream *substream,
141 struct snd_soc_dai *dai)
142{
143 struct axi_spdif *spdif = snd_soc_dai_get_drvdata(dai);
144
145 regmap_update_bits(spdif->regmap, AXI_SPDIF_REG_CTRL,
146 AXI_SPDIF_CTRL_TXEN, 0);
147
148 clk_disable_unprepare(spdif->clk_ref);
149}
150
151static const struct snd_soc_dai_ops axi_spdif_dai_ops = {
152 .startup = axi_spdif_startup,
153 .shutdown = axi_spdif_shutdown,
154 .trigger = axi_spdif_trigger,
155 .hw_params = axi_spdif_hw_params,
156};
157
158static struct snd_soc_dai_driver axi_spdif_dai = {
159 .probe = axi_spdif_dai_probe,
160 .playback = {
161 .channels_min = 2,
162 .channels_max = 2,
163 .rates = SNDRV_PCM_RATE_KNOT,
164 .formats = SNDRV_PCM_FMTBIT_S16_LE,
165 },
166 .ops = &axi_spdif_dai_ops,
167};
168
169static const struct snd_soc_component_driver axi_spdif_component = {
170 .name = "axi-spdif",
171};
172
173static const struct regmap_config axi_spdif_regmap_config = {
174 .reg_bits = 32,
175 .reg_stride = 4,
176 .val_bits = 32,
177 .max_register = AXI_SPDIF_REG_STAT,
178};
179
180static int axi_spdif_probe(struct platform_device *pdev)
181{
182 struct axi_spdif *spdif;
183 struct resource *res;
184 void __iomem *base;
185 int ret;
186
187 spdif = devm_kzalloc(&pdev->dev, sizeof(*spdif), GFP_KERNEL);
188 if (!spdif)
189 return -ENOMEM;
190
191 platform_set_drvdata(pdev, spdif);
192
193 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
194 base = devm_ioremap_resource(&pdev->dev, res);
195 if (IS_ERR(base))
196 return PTR_ERR(base);
197
198 spdif->regmap = devm_regmap_init_mmio(&pdev->dev, base,
199 &axi_spdif_regmap_config);
200 if (IS_ERR(spdif->regmap))
201 return PTR_ERR(spdif->regmap);
202
203 spdif->clk = devm_clk_get(&pdev->dev, "axi");
204 if (IS_ERR(spdif->clk))
205 return PTR_ERR(spdif->clk);
206
207 spdif->clk_ref = devm_clk_get(&pdev->dev, "ref");
208 if (IS_ERR(spdif->clk_ref))
209 return PTR_ERR(spdif->clk_ref);
210
211 ret = clk_prepare_enable(spdif->clk);
212 if (ret)
213 return ret;
214
215 spdif->dma_data.addr = res->start + AXI_SPDIF_REG_TX_FIFO;
216 spdif->dma_data.addr_width = 4;
217 spdif->dma_data.maxburst = 1;
218
219 spdif->ratnum.num = clk_get_rate(spdif->clk_ref) / 128;
220 spdif->ratnum.den_step = 1;
221 spdif->ratnum.den_min = 1;
222 spdif->ratnum.den_max = 64;
223
224 spdif->rate_constraints.rats = &spdif->ratnum;
225 spdif->rate_constraints.nrats = 1;
226
227 ret = devm_snd_soc_register_component(&pdev->dev, &axi_spdif_component,
228 &axi_spdif_dai, 1);
229 if (ret)
230 goto err_clk_disable;
231
232 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL,
233 SND_DMAENGINE_PCM_FLAG_NO_RESIDUE);
234 if (ret)
235 goto err_clk_disable;
236
237 return 0;
238
239err_clk_disable:
240 clk_disable_unprepare(spdif->clk);
241 return ret;
242}
243
244static int axi_spdif_dev_remove(struct platform_device *pdev)
245{
246 struct axi_spdif *spdif = platform_get_drvdata(pdev);
247
248 clk_disable_unprepare(spdif->clk);
249
250 return 0;
251}
252
253static const struct of_device_id axi_spdif_of_match[] = {
254 { .compatible = "adi,axi-spdif-tx-1.00.a", },
255 {},
256};
257MODULE_DEVICE_TABLE(of, axi_spdif_of_match);
258
259static struct platform_driver axi_spdif_driver = {
260 .driver = {
261 .name = "axi-spdif",
262 .owner = THIS_MODULE,
263 .of_match_table = axi_spdif_of_match,
264 },
265 .probe = axi_spdif_probe,
266 .remove = axi_spdif_dev_remove,
267};
268module_platform_driver(axi_spdif_driver);
269
270MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
271MODULE_DESCRIPTION("AXI SPDIF driver");
272MODULE_LICENSE("GPL");