aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/ux500
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/ux500')
-rw-r--r--sound/soc/ux500/Kconfig18
-rw-r--r--sound/soc/ux500/Makefile6
-rw-r--r--sound/soc/ux500/mop500.c113
-rw-r--r--sound/soc/ux500/mop500_ab8500.c431
-rw-r--r--sound/soc/ux500/mop500_ab8500.h22
-rw-r--r--sound/soc/ux500/ux500_msp_dai.c2
-rw-r--r--sound/soc/ux500/ux500_msp_i2s.c2
-rw-r--r--sound/soc/ux500/ux500_pcm.c318
-rw-r--r--sound/soc/ux500/ux500_pcm.h35
9 files changed, 945 insertions, 2 deletions
diff --git a/sound/soc/ux500/Kconfig b/sound/soc/ux500/Kconfig
index 44cf43404cd9..069330d82be5 100644
--- a/sound/soc/ux500/Kconfig
+++ b/sound/soc/ux500/Kconfig
@@ -12,3 +12,21 @@ menuconfig SND_SOC_UX500
12config SND_SOC_UX500_PLAT_MSP_I2S 12config SND_SOC_UX500_PLAT_MSP_I2S
13 tristate 13 tristate
14 depends on SND_SOC_UX500 14 depends on SND_SOC_UX500
15
16config SND_SOC_UX500_PLAT_DMA
17 tristate "Platform - DB8500 (DMA)"
18 depends on SND_SOC_UX500
19 select SND_SOC_DMAENGINE_PCM
20 help
21 Say Y if you want to enable the Ux500 platform-driver.
22
23+config SND_SOC_UX500_MACH_MOP500
24+ tristate "Machine - MOP500 (Ux500 + AB8500)"
25 depends on AB8500_CORE && AB8500_GPADC && SND_SOC_UX500
26 select SND_SOC_AB8500_CODEC
27 select SND_SOC_UX500_PLAT_MSP_I2S
28 select SND_SOC_UX500_PLAT_DMA
29 help
30 Select this to enable the MOP500 machine-driver.
31 This will enable platform-drivers for: Ux500
32 This will enable codec-drivers for: AB8500
diff --git a/sound/soc/ux500/Makefile b/sound/soc/ux500/Makefile
index 19974c5a2ea1..cce0c11a4d86 100644
--- a/sound/soc/ux500/Makefile
+++ b/sound/soc/ux500/Makefile
@@ -2,3 +2,9 @@
2 2
3snd-soc-ux500-plat-msp-i2s-objs := ux500_msp_dai.o ux500_msp_i2s.o 3snd-soc-ux500-plat-msp-i2s-objs := ux500_msp_dai.o ux500_msp_i2s.o
4obj-$(CONFIG_SND_SOC_UX500_PLAT_MSP_I2S) += snd-soc-ux500-plat-msp-i2s.o 4obj-$(CONFIG_SND_SOC_UX500_PLAT_MSP_I2S) += snd-soc-ux500-plat-msp-i2s.o
5
6snd-soc-ux500-plat-dma-objs := ux500_pcm.o
7obj-$(CONFIG_SND_SOC_UX500_PLAT_DMA) += snd-soc-ux500-plat-dma.o
8
9snd-soc-ux500-mach-mop500-objs := mop500.o mop500_ab8500.o
10obj-$(CONFIG_SND_SOC_UX500_MACH_MOP500) += snd-soc-ux500-mach-mop500.o
diff --git a/sound/soc/ux500/mop500.c b/sound/soc/ux500/mop500.c
new file mode 100644
index 000000000000..31c4d26d0359
--- /dev/null
+++ b/sound/soc/ux500/mop500.c
@@ -0,0 +1,113 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2012
3 *
4 * Author: Ola Lilja (ola.o.lilja@stericsson.com)
5 * for ST-Ericsson.
6 *
7 * License terms:
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 */
13
14#include <asm/mach-types.h>
15
16#include <linux/module.h>
17#include <linux/io.h>
18#include <linux/spi/spi.h>
19
20#include <sound/soc.h>
21#include <sound/initval.h>
22
23#include "ux500_pcm.h"
24#include "ux500_msp_dai.h"
25
26#include <mop500_ab8500.h>
27
28/* Define the whole MOP500 soundcard, linking platform to the codec-drivers */
29struct snd_soc_dai_link mop500_dai_links[] = {
30 {
31 .name = "ab8500_0",
32 .stream_name = "ab8500_0",
33 .cpu_dai_name = "ux500-msp-i2s.1",
34 .codec_dai_name = "ab8500-codec-dai.0",
35 .platform_name = "ux500-pcm.0",
36 .codec_name = "ab8500-codec.0",
37 .init = mop500_ab8500_machine_init,
38 .ops = mop500_ab8500_ops,
39 },
40 {
41 .name = "ab8500_1",
42 .stream_name = "ab8500_1",
43 .cpu_dai_name = "ux500-msp-i2s.3",
44 .codec_dai_name = "ab8500-codec-dai.1",
45 .platform_name = "ux500-pcm.0",
46 .codec_name = "ab8500-codec.0",
47 .init = NULL,
48 .ops = mop500_ab8500_ops,
49 },
50};
51
52static struct snd_soc_card mop500_card = {
53 .name = "MOP500-card",
54 .probe = NULL,
55 .dai_link = mop500_dai_links,
56 .num_links = ARRAY_SIZE(mop500_dai_links),
57};
58
59static int __devinit mop500_probe(struct platform_device *pdev)
60{
61 int ret;
62
63 pr_debug("%s: Enter.\n", __func__);
64
65 dev_dbg(&pdev->dev, "%s: Enter.\n", __func__);
66
67 mop500_card.dev = &pdev->dev;
68
69 dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n",
70 __func__, mop500_card.name);
71 platform_set_drvdata(pdev, &mop500_card);
72
73 snd_soc_card_set_drvdata(&mop500_card, NULL);
74
75 dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n",
76 __func__, mop500_card.name, mop500_card.num_links);
77 dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n",
78 __func__, mop500_card.name, mop500_card.dai_link[0].name);
79 dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n",
80 __func__, mop500_card.name,
81 mop500_card.dai_link[0].stream_name);
82
83 ret = snd_soc_register_card(&mop500_card);
84 if (ret)
85 dev_err(&pdev->dev,
86 "Error: snd_soc_register_card failed (%d)!\n",
87 ret);
88
89 return ret;
90}
91
92static int __devexit mop500_remove(struct platform_device *pdev)
93{
94 struct snd_soc_card *mop500_card = platform_get_drvdata(pdev);
95
96 pr_debug("%s: Enter.\n", __func__);
97
98 snd_soc_unregister_card(mop500_card);
99 mop500_ab8500_remove(mop500_card);
100
101 return 0;
102}
103
104static struct platform_driver snd_soc_mop500_driver = {
105 .driver = {
106 .owner = THIS_MODULE,
107 .name = "snd-soc-mop500",
108 },
109 .probe = mop500_probe,
110 .remove = __devexit_p(mop500_remove),
111};
112
113module_platform_driver(snd_soc_mop500_driver);
diff --git a/sound/soc/ux500/mop500_ab8500.c b/sound/soc/ux500/mop500_ab8500.c
new file mode 100644
index 000000000000..78cce236693e
--- /dev/null
+++ b/sound/soc/ux500/mop500_ab8500.c
@@ -0,0 +1,431 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2012
3 *
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
5 * Kristoffer Karlsson <kristoffer.karlsson@stericsson.com>
6 * for ST-Ericsson.
7 *
8 * License terms:
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 published
12 * by the Free Software Foundation.
13 */
14
15#include <linux/module.h>
16#include <linux/device.h>
17#include <linux/io.h>
18#include <linux/clk.h>
19
20#include <mach/hardware.h>
21
22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26
27#include "ux500_pcm.h"
28#include "ux500_msp_dai.h"
29#include "../codecs/ab8500-codec.h"
30
31#define TX_SLOT_MONO 0x0008
32#define TX_SLOT_STEREO 0x000a
33#define RX_SLOT_MONO 0x0001
34#define RX_SLOT_STEREO 0x0003
35#define TX_SLOT_8CH 0x00FF
36#define RX_SLOT_8CH 0x00FF
37
38#define DEF_TX_SLOTS TX_SLOT_STEREO
39#define DEF_RX_SLOTS RX_SLOT_MONO
40
41#define DRIVERMODE_NORMAL 0
42#define DRIVERMODE_CODEC_ONLY 1
43
44/* Slot configuration */
45static unsigned int tx_slots = DEF_TX_SLOTS;
46static unsigned int rx_slots = DEF_RX_SLOTS;
47
48/* Clocks */
49static const char * const enum_mclk[] = {
50 "SYSCLK",
51 "ULPCLK"
52};
53enum mclk {
54 MCLK_SYSCLK,
55 MCLK_ULPCLK,
56};
57
58static SOC_ENUM_SINGLE_EXT_DECL(soc_enum_mclk, enum_mclk);
59
60/* Private data for machine-part MOP500<->AB8500 */
61struct mop500_ab8500_drvdata {
62 /* Clocks */
63 enum mclk mclk_sel;
64 struct clk *clk_ptr_intclk;
65 struct clk *clk_ptr_sysclk;
66 struct clk *clk_ptr_ulpclk;
67};
68
69static inline const char *get_mclk_str(enum mclk mclk_sel)
70{
71 switch (mclk_sel) {
72 case MCLK_SYSCLK:
73 return "SYSCLK";
74 case MCLK_ULPCLK:
75 return "ULPCLK";
76 default:
77 return "Unknown";
78 }
79}
80
81static int mop500_ab8500_set_mclk(struct device *dev,
82 struct mop500_ab8500_drvdata *drvdata)
83{
84 int status;
85 struct clk *clk_ptr;
86
87 if (IS_ERR(drvdata->clk_ptr_intclk)) {
88 dev_err(dev,
89 "%s: ERROR: intclk not initialized!\n", __func__);
90 return -EIO;
91 }
92
93 switch (drvdata->mclk_sel) {
94 case MCLK_SYSCLK:
95 clk_ptr = drvdata->clk_ptr_sysclk;
96 break;
97 case MCLK_ULPCLK:
98 clk_ptr = drvdata->clk_ptr_ulpclk;
99 break;
100 default:
101 return -EINVAL;
102 }
103
104 if (IS_ERR(clk_ptr)) {
105 dev_err(dev, "%s: ERROR: %s not initialized!\n", __func__,
106 get_mclk_str(drvdata->mclk_sel));
107 return -EIO;
108 }
109
110 status = clk_set_parent(drvdata->clk_ptr_intclk, clk_ptr);
111 if (status)
112 dev_err(dev,
113 "%s: ERROR: Setting intclk parent to %s failed (ret = %d)!",
114 __func__, get_mclk_str(drvdata->mclk_sel), status);
115 else
116 dev_dbg(dev,
117 "%s: intclk parent changed to %s.\n",
118 __func__, get_mclk_str(drvdata->mclk_sel));
119
120 return status;
121}
122
123/*
124 * Control-events
125 */
126
127static int mclk_input_control_get(struct snd_kcontrol *kcontrol,
128 struct snd_ctl_elem_value *ucontrol)
129{
130 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
131 struct mop500_ab8500_drvdata *drvdata =
132 snd_soc_card_get_drvdata(codec->card);
133
134 ucontrol->value.enumerated.item[0] = drvdata->mclk_sel;
135
136 return 0;
137}
138
139static int mclk_input_control_put(struct snd_kcontrol *kcontrol,
140 struct snd_ctl_elem_value *ucontrol)
141{
142 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
143 struct mop500_ab8500_drvdata *drvdata =
144 snd_soc_card_get_drvdata(codec->card);
145 unsigned int val = ucontrol->value.enumerated.item[0];
146
147 if (val > (unsigned int)MCLK_ULPCLK)
148 return -EINVAL;
149 if (drvdata->mclk_sel == val)
150 return 0;
151
152 drvdata->mclk_sel = val;
153
154 return 1;
155}
156
157/*
158 * Controls
159 */
160
161static struct snd_kcontrol_new mop500_ab8500_ctrls[] = {
162 SOC_ENUM_EXT("Master Clock Select",
163 soc_enum_mclk,
164 mclk_input_control_get, mclk_input_control_put),
165 /* Digital interface - Clocks */
166 SOC_SINGLE("Digital Interface Master Generator Switch",
167 AB8500_DIGIFCONF1, AB8500_DIGIFCONF1_ENMASTGEN,
168 1, 0),
169 SOC_SINGLE("Digital Interface 0 Bit-clock Switch",
170 AB8500_DIGIFCONF1, AB8500_DIGIFCONF1_ENFSBITCLK0,
171 1, 0),
172 SOC_SINGLE("Digital Interface 1 Bit-clock Switch",
173 AB8500_DIGIFCONF1, AB8500_DIGIFCONF1_ENFSBITCLK1,
174 1, 0),
175 SOC_DAPM_PIN_SWITCH("Headset Left"),
176 SOC_DAPM_PIN_SWITCH("Headset Right"),
177 SOC_DAPM_PIN_SWITCH("Earpiece"),
178 SOC_DAPM_PIN_SWITCH("Speaker Left"),
179 SOC_DAPM_PIN_SWITCH("Speaker Right"),
180 SOC_DAPM_PIN_SWITCH("LineOut Left"),
181 SOC_DAPM_PIN_SWITCH("LineOut Right"),
182 SOC_DAPM_PIN_SWITCH("Vibra 1"),
183 SOC_DAPM_PIN_SWITCH("Vibra 2"),
184 SOC_DAPM_PIN_SWITCH("Mic 1"),
185 SOC_DAPM_PIN_SWITCH("Mic 2"),
186 SOC_DAPM_PIN_SWITCH("LineIn Left"),
187 SOC_DAPM_PIN_SWITCH("LineIn Right"),
188 SOC_DAPM_PIN_SWITCH("DMic 1"),
189 SOC_DAPM_PIN_SWITCH("DMic 2"),
190 SOC_DAPM_PIN_SWITCH("DMic 3"),
191 SOC_DAPM_PIN_SWITCH("DMic 4"),
192 SOC_DAPM_PIN_SWITCH("DMic 5"),
193 SOC_DAPM_PIN_SWITCH("DMic 6"),
194};
195
196/* ASoC */
197
198int mop500_ab8500_startup(struct snd_pcm_substream *substream)
199{
200 struct snd_soc_pcm_runtime *rtd = substream->private_data;
201
202 /* Set audio-clock source */
203 return mop500_ab8500_set_mclk(rtd->card->dev,
204 snd_soc_card_get_drvdata(rtd->card));
205}
206
207void mop500_ab8500_shutdown(struct snd_pcm_substream *substream)
208{
209 struct snd_soc_pcm_runtime *rtd = substream->private_data;
210 struct device *dev = rtd->card->dev;
211
212 dev_dbg(dev, "%s: Enter\n", __func__);
213
214 /* Reset slots configuration to default(s) */
215 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
216 tx_slots = DEF_TX_SLOTS;
217 else
218 rx_slots = DEF_RX_SLOTS;
219}
220
221int mop500_ab8500_hw_params(struct snd_pcm_substream *substream,
222 struct snd_pcm_hw_params *params)
223{
224 struct snd_soc_pcm_runtime *rtd = substream->private_data;
225 struct snd_soc_dai *codec_dai = rtd->codec_dai;
226 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
227 struct device *dev = rtd->card->dev;
228 unsigned int fmt;
229 int channels, ret = 0, driver_mode, slots;
230 unsigned int sw_codec, sw_cpu;
231 bool is_playback;
232
233 dev_dbg(dev, "%s: Enter\n", __func__);
234
235 dev_dbg(dev, "%s: substream->pcm->name = %s\n"
236 "substream->pcm->id = %s.\n"
237 "substream->name = %s.\n"
238 "substream->number = %d.\n",
239 __func__,
240 substream->pcm->name,
241 substream->pcm->id,
242 substream->name,
243 substream->number);
244
245 channels = params_channels(params);
246
247 switch (params_format(params)) {
248 case SNDRV_PCM_FORMAT_S32_LE:
249 sw_cpu = 32;
250 break;
251
252 case SNDRV_PCM_FORMAT_S16_LE:
253 sw_cpu = 16;
254 break;
255
256 default:
257 return -EINVAL;
258 }
259
260 /* Setup codec depending on driver-mode */
261 if (channels == 8)
262 driver_mode = DRIVERMODE_CODEC_ONLY;
263 else
264 driver_mode = DRIVERMODE_NORMAL;
265 dev_dbg(dev, "%s: Driver-mode: %s.\n", __func__,
266 (driver_mode == DRIVERMODE_NORMAL) ? "NORMAL" : "CODEC_ONLY");
267
268 /* Setup format */
269
270 if (driver_mode == DRIVERMODE_NORMAL) {
271 fmt = SND_SOC_DAIFMT_DSP_A |
272 SND_SOC_DAIFMT_CBM_CFM |
273 SND_SOC_DAIFMT_NB_NF |
274 SND_SOC_DAIFMT_CONT;
275 } else {
276 fmt = SND_SOC_DAIFMT_DSP_A |
277 SND_SOC_DAIFMT_CBM_CFM |
278 SND_SOC_DAIFMT_NB_NF |
279 SND_SOC_DAIFMT_GATED;
280 }
281
282 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
283 if (ret < 0) {
284 dev_err(dev,
285 "%s: ERROR: snd_soc_dai_set_fmt failed for codec_dai (ret = %d)!\n",
286 __func__, ret);
287 return ret;
288 }
289
290 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
291 if (ret < 0) {
292 dev_err(dev,
293 "%s: ERROR: snd_soc_dai_set_fmt failed for cpu_dai (ret = %d)!\n",
294 __func__, ret);
295 return ret;
296 }
297
298 /* Setup TDM-slots */
299
300 is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
301 switch (channels) {
302 case 1:
303 slots = 16;
304 tx_slots = (is_playback) ? TX_SLOT_MONO : 0;
305 rx_slots = (is_playback) ? 0 : RX_SLOT_MONO;
306 break;
307 case 2:
308 slots = 16;
309 tx_slots = (is_playback) ? TX_SLOT_STEREO : 0;
310 rx_slots = (is_playback) ? 0 : RX_SLOT_STEREO;
311 break;
312 case 8:
313 slots = 16;
314 tx_slots = (is_playback) ? TX_SLOT_8CH : 0;
315 rx_slots = (is_playback) ? 0 : RX_SLOT_8CH;
316 break;
317 default:
318 return -EINVAL;
319 }
320
321 if (driver_mode == DRIVERMODE_NORMAL)
322 sw_codec = sw_cpu;
323 else
324 sw_codec = 20;
325
326 dev_dbg(dev, "%s: CPU-DAI TDM: TX=0x%04X RX=0x%04x\n", __func__,
327 tx_slots, rx_slots);
328 ret = snd_soc_dai_set_tdm_slot(cpu_dai, tx_slots, rx_slots, slots,
329 sw_cpu);
330 if (ret)
331 return ret;
332
333 dev_dbg(dev, "%s: CODEC-DAI TDM: TX=0x%04X RX=0x%04x\n", __func__,
334 tx_slots, rx_slots);
335 ret = snd_soc_dai_set_tdm_slot(codec_dai, tx_slots, rx_slots, slots,
336 sw_codec);
337 if (ret)
338 return ret;
339
340 return 0;
341}
342
343struct snd_soc_ops mop500_ab8500_ops[] = {
344 {
345 .hw_params = mop500_ab8500_hw_params,
346 .startup = mop500_ab8500_startup,
347 .shutdown = mop500_ab8500_shutdown,
348 }
349};
350
351int mop500_ab8500_machine_init(struct snd_soc_pcm_runtime *rtd)
352{
353 struct snd_soc_codec *codec = rtd->codec;
354 struct device *dev = rtd->card->dev;
355 struct mop500_ab8500_drvdata *drvdata;
356 int ret;
357
358 dev_dbg(dev, "%s Enter.\n", __func__);
359
360 /* Create driver private-data struct */
361 drvdata = devm_kzalloc(dev, sizeof(struct mop500_ab8500_drvdata),
362 GFP_KERNEL);
363 snd_soc_card_set_drvdata(rtd->card, drvdata);
364
365 /* Setup clocks */
366
367 drvdata->clk_ptr_sysclk = clk_get(dev, "sysclk");
368 if (IS_ERR(drvdata->clk_ptr_sysclk))
369 dev_warn(dev, "%s: WARNING: clk_get failed for 'sysclk'!\n",
370 __func__);
371 drvdata->clk_ptr_ulpclk = clk_get(dev, "ulpclk");
372 if (IS_ERR(drvdata->clk_ptr_ulpclk))
373 dev_warn(dev, "%s: WARNING: clk_get failed for 'ulpclk'!\n",
374 __func__);
375 drvdata->clk_ptr_intclk = clk_get(dev, "intclk");
376 if (IS_ERR(drvdata->clk_ptr_intclk))
377 dev_warn(dev, "%s: WARNING: clk_get failed for 'intclk'!\n",
378 __func__);
379
380 /* Set intclk default parent to ulpclk */
381 drvdata->mclk_sel = MCLK_ULPCLK;
382 ret = mop500_ab8500_set_mclk(dev, drvdata);
383 if (ret < 0)
384 dev_warn(dev, "%s: WARNING: mop500_ab8500_set_mclk!\n",
385 __func__);
386
387 drvdata->mclk_sel = MCLK_ULPCLK;
388
389 /* Add controls */
390 ret = snd_soc_add_codec_controls(codec, mop500_ab8500_ctrls,
391 ARRAY_SIZE(mop500_ab8500_ctrls));
392 if (ret < 0) {
393 pr_err("%s: Failed to add machine-controls (%d)!\n",
394 __func__, ret);
395 return ret;
396 }
397
398 ret = snd_soc_dapm_disable_pin(&codec->dapm, "Earpiece");
399 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Speaker Left");
400 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Speaker Right");
401 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "LineOut Left");
402 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "LineOut Right");
403 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Vibra 1");
404 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Vibra 2");
405 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Mic 1");
406 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "Mic 2");
407 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "LineIn Left");
408 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "LineIn Right");
409 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 1");
410 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 2");
411 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 3");
412 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 4");
413 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 5");
414 ret |= snd_soc_dapm_disable_pin(&codec->dapm, "DMic 6");
415
416 return ret;
417}
418
419void mop500_ab8500_remove(struct snd_soc_card *card)
420{
421 struct mop500_ab8500_drvdata *drvdata = snd_soc_card_get_drvdata(card);
422
423 if (drvdata->clk_ptr_sysclk != NULL)
424 clk_put(drvdata->clk_ptr_sysclk);
425 if (drvdata->clk_ptr_ulpclk != NULL)
426 clk_put(drvdata->clk_ptr_ulpclk);
427 if (drvdata->clk_ptr_intclk != NULL)
428 clk_put(drvdata->clk_ptr_intclk);
429
430 snd_soc_card_set_drvdata(card, drvdata);
431}
diff --git a/sound/soc/ux500/mop500_ab8500.h b/sound/soc/ux500/mop500_ab8500.h
new file mode 100644
index 000000000000..cca5b33964b6
--- /dev/null
+++ b/sound/soc/ux500/mop500_ab8500.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2012
3 *
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>
5 * for ST-Ericsson.
6 *
7 * License terms:
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 */
13
14#ifndef MOP500_AB8500_H
15#define MOP500_AB8500_H
16
17extern struct snd_soc_ops mop500_ab8500_ops[];
18
19int mop500_ab8500_machine_init(struct snd_soc_pcm_runtime *runtime);
20void mop500_ab8500_remove(struct snd_soc_card *card);
21
22#endif
diff --git a/sound/soc/ux500/ux500_msp_dai.c b/sound/soc/ux500/ux500_msp_dai.c
index 93c6c40e724c..62ac0285bfaf 100644
--- a/sound/soc/ux500/ux500_msp_dai.c
+++ b/sound/soc/ux500/ux500_msp_dai.c
@@ -840,4 +840,4 @@ static struct platform_driver msp_i2s_driver = {
840}; 840};
841module_platform_driver(msp_i2s_driver); 841module_platform_driver(msp_i2s_driver);
842 842
843MODULE_LICENSE("GPLv2"); 843MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/ux500/ux500_msp_i2s.c b/sound/soc/ux500/ux500_msp_i2s.c
index 496dec10c96e..ee14d2dac2f5 100644
--- a/sound/soc/ux500/ux500_msp_i2s.c
+++ b/sound/soc/ux500/ux500_msp_i2s.c
@@ -739,4 +739,4 @@ void ux500_msp_i2s_cleanup_msp(struct platform_device *pdev,
739 devm_kfree(&pdev->dev, msp); 739 devm_kfree(&pdev->dev, msp);
740} 740}
741 741
742MODULE_LICENSE("GPLv2"); 742MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/ux500/ux500_pcm.c b/sound/soc/ux500/ux500_pcm.c
new file mode 100644
index 000000000000..1a04e248453c
--- /dev/null
+++ b/sound/soc/ux500/ux500_pcm.c
@@ -0,0 +1,318 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2012
3 *
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
5 * Roger Nilsson <roger.xr.nilsson@stericsson.com>
6 * for ST-Ericsson.
7 *
8 * License terms:
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 published
12 * by the Free Software Foundation.
13 */
14
15#include <asm/page.h>
16
17#include <linux/module.h>
18#include <linux/dma-mapping.h>
19#include <linux/dmaengine.h>
20#include <linux/slab.h>
21
22#include <plat/ste_dma40.h>
23
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/soc.h>
27#include <sound/dmaengine_pcm.h>
28
29#include "ux500_msp_i2s.h"
30#include "ux500_pcm.h"
31
32static struct snd_pcm_hardware ux500_pcm_hw_playback = {
33 .info = SNDRV_PCM_INFO_INTERLEAVED |
34 SNDRV_PCM_INFO_MMAP |
35 SNDRV_PCM_INFO_RESUME |
36 SNDRV_PCM_INFO_PAUSE,
37 .formats = SNDRV_PCM_FMTBIT_S16_LE |
38 SNDRV_PCM_FMTBIT_U16_LE |
39 SNDRV_PCM_FMTBIT_S16_BE |
40 SNDRV_PCM_FMTBIT_U16_BE,
41 .rates = SNDRV_PCM_RATE_KNOT,
42 .rate_min = UX500_PLATFORM_MIN_RATE_PLAYBACK,
43 .rate_max = UX500_PLATFORM_MAX_RATE_PLAYBACK,
44 .channels_min = UX500_PLATFORM_MIN_CHANNELS,
45 .channels_max = UX500_PLATFORM_MAX_CHANNELS,
46 .buffer_bytes_max = UX500_PLATFORM_BUFFER_BYTES_MAX,
47 .period_bytes_min = UX500_PLATFORM_PERIODS_BYTES_MIN,
48 .period_bytes_max = UX500_PLATFORM_PERIODS_BYTES_MAX,
49 .periods_min = UX500_PLATFORM_PERIODS_MIN,
50 .periods_max = UX500_PLATFORM_PERIODS_MAX,
51};
52
53static struct snd_pcm_hardware ux500_pcm_hw_capture = {
54 .info = SNDRV_PCM_INFO_INTERLEAVED |
55 SNDRV_PCM_INFO_MMAP |
56 SNDRV_PCM_INFO_RESUME |
57 SNDRV_PCM_INFO_PAUSE,
58 .formats = SNDRV_PCM_FMTBIT_S16_LE |
59 SNDRV_PCM_FMTBIT_U16_LE |
60 SNDRV_PCM_FMTBIT_S16_BE |
61 SNDRV_PCM_FMTBIT_U16_BE,
62 .rates = SNDRV_PCM_RATE_KNOT,
63 .rate_min = UX500_PLATFORM_MIN_RATE_CAPTURE,
64 .rate_max = UX500_PLATFORM_MAX_RATE_CAPTURE,
65 .channels_min = UX500_PLATFORM_MIN_CHANNELS,
66 .channels_max = UX500_PLATFORM_MAX_CHANNELS,
67 .buffer_bytes_max = UX500_PLATFORM_BUFFER_BYTES_MAX,
68 .period_bytes_min = UX500_PLATFORM_PERIODS_BYTES_MIN,
69 .period_bytes_max = UX500_PLATFORM_PERIODS_BYTES_MAX,
70 .periods_min = UX500_PLATFORM_PERIODS_MIN,
71 .periods_max = UX500_PLATFORM_PERIODS_MAX,
72};
73
74static void ux500_pcm_dma_hw_free(struct device *dev,
75 struct snd_pcm_substream *substream)
76{
77 struct snd_pcm_runtime *runtime = substream->runtime;
78 struct snd_dma_buffer *buf = runtime->dma_buffer_p;
79
80 if (runtime->dma_area == NULL)
81 return;
82
83 if (buf != &substream->dma_buffer) {
84 dma_free_coherent(buf->dev.dev, buf->bytes, buf->area,
85 buf->addr);
86 kfree(runtime->dma_buffer_p);
87 }
88
89 snd_pcm_set_runtime_buffer(substream, NULL);
90}
91
92static int ux500_pcm_open(struct snd_pcm_substream *substream)
93{
94 int stream_id = substream->pstr->stream;
95 struct snd_pcm_runtime *runtime = substream->runtime;
96 struct snd_soc_pcm_runtime *rtd = substream->private_data;
97 struct snd_soc_dai *dai = rtd->cpu_dai;
98 struct device *dev = dai->dev;
99 int ret;
100 struct ux500_msp_dma_params *dma_params;
101 u16 per_data_width, mem_data_width;
102 struct stedma40_chan_cfg *dma_cfg;
103
104 dev_dbg(dev, "%s: MSP %d (%s): Enter.\n", __func__, dai->id,
105 snd_pcm_stream_str(substream));
106
107 dev_dbg(dev, "%s: Set runtime hwparams.\n", __func__);
108 if (stream_id == SNDRV_PCM_STREAM_PLAYBACK)
109 snd_soc_set_runtime_hwparams(substream,
110 &ux500_pcm_hw_playback);
111 else
112 snd_soc_set_runtime_hwparams(substream,
113 &ux500_pcm_hw_capture);
114
115 /* ensure that buffer size is a multiple of period size */
116 ret = snd_pcm_hw_constraint_integer(runtime,
117 SNDRV_PCM_HW_PARAM_PERIODS);
118 if (ret < 0) {
119 dev_err(dev, "%s: Error: snd_pcm_hw_constraints failed (%d)\n",
120 __func__, ret);
121 return ret;
122 }
123
124 dev_dbg(dev, "%s: Set hw-struct for %s.\n", __func__,
125 snd_pcm_stream_str(substream));
126 runtime->hw = (stream_id == SNDRV_PCM_STREAM_PLAYBACK) ?
127 ux500_pcm_hw_playback : ux500_pcm_hw_capture;
128
129 mem_data_width = STEDMA40_HALFWORD_WIDTH;
130
131 dma_params = snd_soc_dai_get_dma_data(dai, substream);
132 switch (dma_params->data_size) {
133 case 32:
134 per_data_width = STEDMA40_WORD_WIDTH;
135 break;
136 case 16:
137 per_data_width = STEDMA40_HALFWORD_WIDTH;
138 break;
139 case 8:
140 per_data_width = STEDMA40_BYTE_WIDTH;
141 break;
142 default:
143 per_data_width = STEDMA40_WORD_WIDTH;
144 dev_warn(rtd->platform->dev,
145 "%s: Unknown data-size (%d)! Assuming 32 bits.\n",
146 __func__, dma_params->data_size);
147 }
148
149 dma_cfg = dma_params->dma_cfg;
150
151 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
152 dma_cfg->src_info.data_width = mem_data_width;
153 dma_cfg->dst_info.data_width = per_data_width;
154 } else {
155 dma_cfg->src_info.data_width = per_data_width;
156 dma_cfg->dst_info.data_width = mem_data_width;
157 }
158
159
160 ret = snd_dmaengine_pcm_open(substream, stedma40_filter, dma_cfg);
161 if (ret) {
162 dev_dbg(dai->dev,
163 "%s: ERROR: snd_dmaengine_pcm_open failed (%d)!\n",
164 __func__, ret);
165 return ret;
166 }
167
168 snd_dmaengine_pcm_set_data(substream, dma_cfg);
169
170 return 0;
171}
172
173static int ux500_pcm_close(struct snd_pcm_substream *substream)
174{
175 struct snd_soc_pcm_runtime *rtd = substream->private_data;
176 struct snd_soc_dai *dai = rtd->cpu_dai;
177
178 dev_dbg(dai->dev, "%s: Enter\n", __func__);
179
180 snd_dmaengine_pcm_close(substream);
181
182 return 0;
183}
184
185static int ux500_pcm_hw_params(struct snd_pcm_substream *substream,
186 struct snd_pcm_hw_params *hw_params)
187{
188 struct snd_pcm_runtime *runtime = substream->runtime;
189 struct snd_dma_buffer *buf = runtime->dma_buffer_p;
190 struct snd_soc_pcm_runtime *rtd = substream->private_data;
191 int ret = 0;
192 int size;
193
194 dev_dbg(rtd->platform->dev, "%s: Enter\n", __func__);
195
196 size = params_buffer_bytes(hw_params);
197
198 if (buf) {
199 if (buf->bytes >= size)
200 goto out;
201 ux500_pcm_dma_hw_free(NULL, substream);
202 }
203
204 if (substream->dma_buffer.area != NULL &&
205 substream->dma_buffer.bytes >= size) {
206 buf = &substream->dma_buffer;
207 } else {
208 buf = kmalloc(sizeof(struct snd_dma_buffer), GFP_KERNEL);
209 if (!buf)
210 goto nomem;
211
212 buf->dev.type = SNDRV_DMA_TYPE_DEV;
213 buf->dev.dev = NULL;
214 buf->area = dma_alloc_coherent(NULL, size, &buf->addr,
215 GFP_KERNEL);
216 buf->bytes = size;
217 buf->private_data = NULL;
218
219 if (!buf->area)
220 goto free;
221 }
222 snd_pcm_set_runtime_buffer(substream, buf);
223 ret = 1;
224 out:
225 runtime->dma_bytes = size;
226 return ret;
227
228 free:
229 kfree(buf);
230 nomem:
231 return -ENOMEM;
232}
233
234static int ux500_pcm_hw_free(struct snd_pcm_substream *substream)
235{
236 struct snd_soc_pcm_runtime *rtd = substream->private_data;
237
238 dev_dbg(rtd->platform->dev, "%s: Enter\n", __func__);
239
240 ux500_pcm_dma_hw_free(NULL, substream);
241
242 return 0;
243}
244
245static int ux500_pcm_mmap(struct snd_pcm_substream *substream,
246 struct vm_area_struct *vma)
247{
248 struct snd_pcm_runtime *runtime = substream->runtime;
249 struct snd_soc_pcm_runtime *rtd = substream->private_data;
250
251 dev_dbg(rtd->platform->dev, "%s: Enter.\n", __func__);
252
253 return dma_mmap_coherent(NULL, vma, runtime->dma_area,
254 runtime->dma_addr, runtime->dma_bytes);
255}
256
257static struct snd_pcm_ops ux500_pcm_ops = {
258 .open = ux500_pcm_open,
259 .close = ux500_pcm_close,
260 .ioctl = snd_pcm_lib_ioctl,
261 .hw_params = ux500_pcm_hw_params,
262 .hw_free = ux500_pcm_hw_free,
263 .trigger = snd_dmaengine_pcm_trigger,
264 .pointer = snd_dmaengine_pcm_pointer_no_residue,
265 .mmap = ux500_pcm_mmap
266};
267
268int ux500_pcm_new(struct snd_soc_pcm_runtime *rtd)
269{
270 struct snd_pcm *pcm = rtd->pcm;
271
272 dev_dbg(rtd->platform->dev, "%s: Enter (id = '%s').\n", __func__,
273 pcm->id);
274
275 pcm->info_flags = 0;
276
277 return 0;
278}
279
280static struct snd_soc_platform_driver ux500_pcm_soc_drv = {
281 .ops = &ux500_pcm_ops,
282 .pcm_new = ux500_pcm_new,
283};
284
285static int __devexit ux500_pcm_drv_probe(struct platform_device *pdev)
286{
287 int ret;
288
289 ret = snd_soc_register_platform(&pdev->dev, &ux500_pcm_soc_drv);
290 if (ret < 0) {
291 dev_err(&pdev->dev,
292 "%s: ERROR: Failed to register platform '%s' (%d)!\n",
293 __func__, pdev->name, ret);
294 return ret;
295 }
296
297 return 0;
298}
299
300static int __devinit ux500_pcm_drv_remove(struct platform_device *pdev)
301{
302 snd_soc_unregister_platform(&pdev->dev);
303
304 return 0;
305}
306
307static struct platform_driver ux500_pcm_driver = {
308 .driver = {
309 .name = "ux500-pcm",
310 .owner = THIS_MODULE,
311 },
312
313 .probe = ux500_pcm_drv_probe,
314 .remove = __devexit_p(ux500_pcm_drv_remove),
315};
316module_platform_driver(ux500_pcm_driver);
317
318MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/ux500/ux500_pcm.h b/sound/soc/ux500/ux500_pcm.h
new file mode 100644
index 000000000000..77ed44d371e9
--- /dev/null
+++ b/sound/soc/ux500/ux500_pcm.h
@@ -0,0 +1,35 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2012
3 *
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
5 * Roger Nilsson <roger.xr.nilsson@stericsson.com>
6 * for ST-Ericsson.
7 *
8 * License terms:
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 published
12 * by the Free Software Foundation.
13 */
14#ifndef UX500_PCM_H
15#define UX500_PCM_H
16
17#include <asm/page.h>
18
19#include <linux/workqueue.h>
20
21#define UX500_PLATFORM_MIN_RATE_PLAYBACK 8000
22#define UX500_PLATFORM_MAX_RATE_PLAYBACK 48000
23#define UX500_PLATFORM_MIN_RATE_CAPTURE 8000
24#define UX500_PLATFORM_MAX_RATE_CAPTURE 48000
25
26#define UX500_PLATFORM_MIN_CHANNELS 1
27#define UX500_PLATFORM_MAX_CHANNELS 8
28
29#define UX500_PLATFORM_PERIODS_BYTES_MIN 128
30#define UX500_PLATFORM_PERIODS_BYTES_MAX (64 * PAGE_SIZE)
31#define UX500_PLATFORM_PERIODS_MIN 2
32#define UX500_PLATFORM_PERIODS_MAX 48
33#define UX500_PLATFORM_BUFFER_BYTES_MAX (2048 * PAGE_SIZE)
34
35#endif