2 * Copyright (C) ST-Ericsson SA 2012
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
5 * Roger Nilsson <roger.xr.nilsson@stericsson.com>
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.
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/bitops.h>
18 #include <linux/platform_device.h>
19 #include <linux/clk.h>
21 #include <linux/regulator/consumer.h>
22 #include <linux/mfd/dbx500-prcmu.h>
23 #include <linux/platform_data/asoc-ux500-msp.h>
25 #include <sound/soc.h>
26 #include <sound/soc-dai.h>
27 #include <sound/dmaengine_pcm.h>
29 #include "ux500_msp_i2s.h"
30 #include "ux500_msp_dai.h"
31 #include "ux500_pcm.h"
33 static int setup_pcm_multichan(struct snd_soc_dai
*dai
,
34 struct ux500_msp_config
*msp_config
)
36 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
37 struct msp_multichannel_config
*multi
=
38 &msp_config
->multichannel_config
;
40 if (drvdata
->slots
> 1) {
41 msp_config
->multichannel_configured
= 1;
43 multi
->tx_multichannel_enable
= true;
44 multi
->rx_multichannel_enable
= true;
45 multi
->rx_comparison_enable_mode
= MSP_COMPARISON_DISABLED
;
47 multi
->tx_channel_0_enable
= drvdata
->tx_mask
;
48 multi
->tx_channel_1_enable
= 0;
49 multi
->tx_channel_2_enable
= 0;
50 multi
->tx_channel_3_enable
= 0;
52 multi
->rx_channel_0_enable
= drvdata
->rx_mask
;
53 multi
->rx_channel_1_enable
= 0;
54 multi
->rx_channel_2_enable
= 0;
55 multi
->rx_channel_3_enable
= 0;
58 "%s: Multichannel enabled. Slots: %d, TX: %u, RX: %u\n",
59 __func__
, drvdata
->slots
, multi
->tx_channel_0_enable
,
60 multi
->rx_channel_0_enable
);
66 static int setup_frameper(struct snd_soc_dai
*dai
, unsigned int rate
,
67 struct msp_protdesc
*prot_desc
)
69 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
71 switch (drvdata
->slots
) {
75 prot_desc
->frame_period
=
76 FRAME_PER_SINGLE_SLOT_8_KHZ
;
80 prot_desc
->frame_period
=
81 FRAME_PER_SINGLE_SLOT_16_KHZ
;
85 prot_desc
->frame_period
=
86 FRAME_PER_SINGLE_SLOT_44_1_KHZ
;
90 prot_desc
->frame_period
=
91 FRAME_PER_SINGLE_SLOT_48_KHZ
;
96 "%s: Error: Unsupported sample-rate (freq = %d)!\n",
103 prot_desc
->frame_period
= FRAME_PER_2_SLOTS
;
107 prot_desc
->frame_period
= FRAME_PER_8_SLOTS
;
111 prot_desc
->frame_period
= FRAME_PER_16_SLOTS
;
115 "%s: Error: Unsupported slot-count (slots = %d)!\n",
116 __func__
, drvdata
->slots
);
120 prot_desc
->clocks_per_frame
=
121 prot_desc
->frame_period
+1;
123 dev_dbg(dai
->dev
, "%s: Clocks per frame: %u\n",
125 prot_desc
->clocks_per_frame
);
130 static int setup_pcm_framing(struct snd_soc_dai
*dai
, unsigned int rate
,
131 struct msp_protdesc
*prot_desc
)
133 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
135 u32 frame_length
= MSP_FRAME_LEN_1
;
137 prot_desc
->frame_width
= 0;
139 switch (drvdata
->slots
) {
141 frame_length
= MSP_FRAME_LEN_1
;
145 frame_length
= MSP_FRAME_LEN_2
;
149 frame_length
= MSP_FRAME_LEN_8
;
153 frame_length
= MSP_FRAME_LEN_16
;
157 "%s: Error: Unsupported slot-count (slots = %d)!\n",
158 __func__
, drvdata
->slots
);
162 prot_desc
->tx_frame_len_1
= frame_length
;
163 prot_desc
->rx_frame_len_1
= frame_length
;
164 prot_desc
->tx_frame_len_2
= frame_length
;
165 prot_desc
->rx_frame_len_2
= frame_length
;
167 prot_desc
->tx_elem_len_1
= MSP_ELEM_LEN_16
;
168 prot_desc
->rx_elem_len_1
= MSP_ELEM_LEN_16
;
169 prot_desc
->tx_elem_len_2
= MSP_ELEM_LEN_16
;
170 prot_desc
->rx_elem_len_2
= MSP_ELEM_LEN_16
;
172 return setup_frameper(dai
, rate
, prot_desc
);
175 static int setup_clocking(struct snd_soc_dai
*dai
,
177 struct ux500_msp_config
*msp_config
)
179 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
180 case SND_SOC_DAIFMT_NB_NF
:
183 case SND_SOC_DAIFMT_NB_IF
:
184 msp_config
->tx_fsync_pol
^= 1 << TFSPOL_SHIFT
;
185 msp_config
->rx_fsync_pol
^= 1 << RFSPOL_SHIFT
;
191 "%s: Error: Unsupported inversion (fmt = 0x%x)!\n",
197 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
198 case SND_SOC_DAIFMT_CBM_CFM
:
199 dev_dbg(dai
->dev
, "%s: Codec is master.\n", __func__
);
201 msp_config
->iodelay
= 0x20;
202 msp_config
->rx_fsync_sel
= 0;
203 msp_config
->tx_fsync_sel
= 1 << TFSSEL_SHIFT
;
204 msp_config
->tx_clk_sel
= 0;
205 msp_config
->rx_clk_sel
= 0;
206 msp_config
->srg_clk_sel
= 0x2 << SCKSEL_SHIFT
;
210 case SND_SOC_DAIFMT_CBS_CFS
:
211 dev_dbg(dai
->dev
, "%s: Codec is slave.\n", __func__
);
213 msp_config
->tx_clk_sel
= TX_CLK_SEL_SRG
;
214 msp_config
->tx_fsync_sel
= TX_SYNC_SRG_PROG
;
215 msp_config
->rx_clk_sel
= RX_CLK_SEL_SRG
;
216 msp_config
->rx_fsync_sel
= RX_SYNC_SRG
;
217 msp_config
->srg_clk_sel
= 1 << SCKSEL_SHIFT
;
222 dev_err(dai
->dev
, "%s: Error: Unsupported master (fmt = 0x%x)!\n",
231 static int setup_pcm_protdesc(struct snd_soc_dai
*dai
,
233 struct msp_protdesc
*prot_desc
)
235 prot_desc
->rx_phase_mode
= MSP_SINGLE_PHASE
;
236 prot_desc
->tx_phase_mode
= MSP_SINGLE_PHASE
;
237 prot_desc
->rx_phase2_start_mode
= MSP_PHASE2_START_MODE_IMEDIATE
;
238 prot_desc
->tx_phase2_start_mode
= MSP_PHASE2_START_MODE_IMEDIATE
;
239 prot_desc
->rx_byte_order
= MSP_BTF_MS_BIT_FIRST
;
240 prot_desc
->tx_byte_order
= MSP_BTF_MS_BIT_FIRST
;
241 prot_desc
->tx_fsync_pol
= MSP_FSYNC_POL(MSP_FSYNC_POL_ACT_HI
);
242 prot_desc
->rx_fsync_pol
= MSP_FSYNC_POL_ACT_HI
<< RFSPOL_SHIFT
;
244 if ((fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) == SND_SOC_DAIFMT_DSP_A
) {
245 dev_dbg(dai
->dev
, "%s: DSP_A.\n", __func__
);
246 prot_desc
->rx_clk_pol
= MSP_RISING_EDGE
;
247 prot_desc
->tx_clk_pol
= MSP_FALLING_EDGE
;
249 prot_desc
->rx_data_delay
= MSP_DELAY_1
;
250 prot_desc
->tx_data_delay
= MSP_DELAY_1
;
252 dev_dbg(dai
->dev
, "%s: DSP_B.\n", __func__
);
253 prot_desc
->rx_clk_pol
= MSP_FALLING_EDGE
;
254 prot_desc
->tx_clk_pol
= MSP_RISING_EDGE
;
256 prot_desc
->rx_data_delay
= MSP_DELAY_0
;
257 prot_desc
->tx_data_delay
= MSP_DELAY_0
;
260 prot_desc
->rx_half_word_swap
= MSP_SWAP_NONE
;
261 prot_desc
->tx_half_word_swap
= MSP_SWAP_NONE
;
262 prot_desc
->compression_mode
= MSP_COMPRESS_MODE_LINEAR
;
263 prot_desc
->expansion_mode
= MSP_EXPAND_MODE_LINEAR
;
264 prot_desc
->frame_sync_ignore
= MSP_FSYNC_IGNORE
;
269 static int setup_i2s_protdesc(struct msp_protdesc
*prot_desc
)
271 prot_desc
->rx_phase_mode
= MSP_DUAL_PHASE
;
272 prot_desc
->tx_phase_mode
= MSP_DUAL_PHASE
;
273 prot_desc
->rx_phase2_start_mode
= MSP_PHASE2_START_MODE_FSYNC
;
274 prot_desc
->tx_phase2_start_mode
= MSP_PHASE2_START_MODE_FSYNC
;
275 prot_desc
->rx_byte_order
= MSP_BTF_MS_BIT_FIRST
;
276 prot_desc
->tx_byte_order
= MSP_BTF_MS_BIT_FIRST
;
277 prot_desc
->tx_fsync_pol
= MSP_FSYNC_POL(MSP_FSYNC_POL_ACT_LO
);
278 prot_desc
->rx_fsync_pol
= MSP_FSYNC_POL_ACT_LO
<< RFSPOL_SHIFT
;
280 prot_desc
->rx_frame_len_1
= MSP_FRAME_LEN_1
;
281 prot_desc
->rx_frame_len_2
= MSP_FRAME_LEN_1
;
282 prot_desc
->tx_frame_len_1
= MSP_FRAME_LEN_1
;
283 prot_desc
->tx_frame_len_2
= MSP_FRAME_LEN_1
;
284 prot_desc
->rx_elem_len_1
= MSP_ELEM_LEN_16
;
285 prot_desc
->rx_elem_len_2
= MSP_ELEM_LEN_16
;
286 prot_desc
->tx_elem_len_1
= MSP_ELEM_LEN_16
;
287 prot_desc
->tx_elem_len_2
= MSP_ELEM_LEN_16
;
289 prot_desc
->rx_clk_pol
= MSP_RISING_EDGE
;
290 prot_desc
->tx_clk_pol
= MSP_FALLING_EDGE
;
292 prot_desc
->rx_data_delay
= MSP_DELAY_0
;
293 prot_desc
->tx_data_delay
= MSP_DELAY_0
;
295 prot_desc
->tx_half_word_swap
= MSP_SWAP_NONE
;
296 prot_desc
->rx_half_word_swap
= MSP_SWAP_NONE
;
297 prot_desc
->compression_mode
= MSP_COMPRESS_MODE_LINEAR
;
298 prot_desc
->expansion_mode
= MSP_EXPAND_MODE_LINEAR
;
299 prot_desc
->frame_sync_ignore
= MSP_FSYNC_IGNORE
;
304 static int setup_msp_config(struct snd_pcm_substream
*substream
,
305 struct snd_soc_dai
*dai
,
306 struct ux500_msp_config
*msp_config
)
308 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
309 struct msp_protdesc
*prot_desc
= &msp_config
->protdesc
;
310 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
311 unsigned int fmt
= drvdata
->fmt
;
314 memset(msp_config
, 0, sizeof(*msp_config
));
316 msp_config
->f_inputclk
= drvdata
->master_clk
;
318 msp_config
->tx_fifo_config
= TX_FIFO_ENABLE
;
319 msp_config
->rx_fifo_config
= RX_FIFO_ENABLE
;
320 msp_config
->def_elem_len
= 1;
321 msp_config
->direction
= substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
?
322 MSP_DIR_TX
: MSP_DIR_RX
;
323 msp_config
->data_size
= MSP_DATA_BITS_32
;
324 msp_config
->frame_freq
= runtime
->rate
;
326 dev_dbg(dai
->dev
, "%s: f_inputclk = %u, frame_freq = %u.\n",
327 __func__
, msp_config
->f_inputclk
, msp_config
->frame_freq
);
328 /* To avoid division by zero */
329 prot_desc
->clocks_per_frame
= 1;
331 dev_dbg(dai
->dev
, "%s: rate: %u, channels: %d.\n", __func__
,
332 runtime
->rate
, runtime
->channels
);
334 (SND_SOC_DAIFMT_FORMAT_MASK
| SND_SOC_DAIFMT_MASTER_MASK
)) {
335 case SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_CBS_CFS
:
336 dev_dbg(dai
->dev
, "%s: SND_SOC_DAIFMT_I2S.\n", __func__
);
338 msp_config
->default_protdesc
= 1;
339 msp_config
->protocol
= MSP_I2S_PROTOCOL
;
342 case SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_CBM_CFM
:
343 dev_dbg(dai
->dev
, "%s: SND_SOC_DAIFMT_I2S.\n", __func__
);
345 msp_config
->data_size
= MSP_DATA_BITS_16
;
346 msp_config
->protocol
= MSP_I2S_PROTOCOL
;
348 ret
= setup_i2s_protdesc(prot_desc
);
354 case SND_SOC_DAIFMT_DSP_A
| SND_SOC_DAIFMT_CBS_CFS
:
355 case SND_SOC_DAIFMT_DSP_A
| SND_SOC_DAIFMT_CBM_CFM
:
356 case SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBS_CFS
:
357 case SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
:
358 dev_dbg(dai
->dev
, "%s: PCM format.\n", __func__
);
360 msp_config
->data_size
= MSP_DATA_BITS_16
;
361 msp_config
->protocol
= MSP_PCM_PROTOCOL
;
363 ret
= setup_pcm_protdesc(dai
, fmt
, prot_desc
);
367 ret
= setup_pcm_multichan(dai
, msp_config
);
371 ret
= setup_pcm_framing(dai
, runtime
->rate
, prot_desc
);
378 dev_err(dai
->dev
, "%s: Error: Unsupported format (%d)!\n",
383 return setup_clocking(dai
, fmt
, msp_config
);
386 static int ux500_msp_dai_startup(struct snd_pcm_substream
*substream
,
387 struct snd_soc_dai
*dai
)
390 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
392 dev_dbg(dai
->dev
, "%s: MSP %d (%s): Enter.\n", __func__
, dai
->id
,
393 snd_pcm_stream_str(substream
));
395 /* Enable regulator */
396 ret
= regulator_enable(drvdata
->reg_vape
);
398 dev_err(drvdata
->msp
->dev
,
399 "%s: Failed to enable regulator!\n", __func__
);
403 /* Prepare and enable clocks */
404 dev_dbg(dai
->dev
, "%s: Enabling MSP-clocks.\n", __func__
);
405 ret
= clk_prepare_enable(drvdata
->pclk
);
407 dev_err(drvdata
->msp
->dev
,
408 "%s: Failed to prepare/enable pclk!\n", __func__
);
412 ret
= clk_prepare_enable(drvdata
->clk
);
414 dev_err(drvdata
->msp
->dev
,
415 "%s: Failed to prepare/enable clk!\n", __func__
);
421 clk_disable_unprepare(drvdata
->pclk
);
423 regulator_disable(drvdata
->reg_vape
);
427 static void ux500_msp_dai_shutdown(struct snd_pcm_substream
*substream
,
428 struct snd_soc_dai
*dai
)
431 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
432 bool is_playback
= (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
);
434 dev_dbg(dai
->dev
, "%s: MSP %d (%s): Enter.\n", __func__
, dai
->id
,
435 snd_pcm_stream_str(substream
));
437 if (drvdata
->vape_opp_constraint
== 1) {
438 prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP
,
439 "ux500_msp_i2s", 50);
440 drvdata
->vape_opp_constraint
= 0;
443 if (ux500_msp_i2s_close(drvdata
->msp
,
444 is_playback
? MSP_DIR_TX
: MSP_DIR_RX
)) {
446 "%s: Error: MSP %d (%s): Unable to close i2s.\n",
447 __func__
, dai
->id
, snd_pcm_stream_str(substream
));
450 /* Disable and unprepare clocks */
451 clk_disable_unprepare(drvdata
->clk
);
452 clk_disable_unprepare(drvdata
->pclk
);
454 /* Disable regulator */
455 ret
= regulator_disable(drvdata
->reg_vape
);
458 "%s: ERROR: Failed to disable regulator (%d)!\n",
462 static int ux500_msp_dai_prepare(struct snd_pcm_substream
*substream
,
463 struct snd_soc_dai
*dai
)
466 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
467 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
468 struct ux500_msp_config msp_config
;
470 dev_dbg(dai
->dev
, "%s: MSP %d (%s): Enter (rate = %d).\n", __func__
,
471 dai
->id
, snd_pcm_stream_str(substream
), runtime
->rate
);
473 setup_msp_config(substream
, dai
, &msp_config
);
475 ret
= ux500_msp_i2s_open(drvdata
->msp
, &msp_config
);
477 dev_err(dai
->dev
, "%s: Error: msp_setup failed (ret = %d)!\n",
483 if ((drvdata
->fmt
& SND_SOC_DAIFMT_MASTER_MASK
) &&
484 (drvdata
->msp
->f_bitclk
> 19200000)) {
485 /* If the bit-clock is higher than 19.2MHz, Vape should be
486 * run in 100% OPP. Only when bit-clock is used (MSP master)
488 prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP
,
489 "ux500-msp-i2s", 100);
490 drvdata
->vape_opp_constraint
= 1;
492 prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP
,
493 "ux500-msp-i2s", 50);
494 drvdata
->vape_opp_constraint
= 0;
500 static int ux500_msp_dai_hw_params(struct snd_pcm_substream
*substream
,
501 struct snd_pcm_hw_params
*params
,
502 struct snd_soc_dai
*dai
)
504 unsigned int mask
, slots_active
;
505 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
506 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
508 dev_dbg(dai
->dev
, "%s: MSP %d (%s): Enter.\n",
509 __func__
, dai
->id
, snd_pcm_stream_str(substream
));
511 switch (drvdata
->fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
512 case SND_SOC_DAIFMT_I2S
:
513 snd_pcm_hw_constraint_minmax(runtime
,
514 SNDRV_PCM_HW_PARAM_CHANNELS
,
518 case SND_SOC_DAIFMT_DSP_B
:
519 case SND_SOC_DAIFMT_DSP_A
:
520 mask
= substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
?
524 slots_active
= hweight32(mask
);
525 dev_dbg(dai
->dev
, "TDM-slots active: %d", slots_active
);
527 snd_pcm_hw_constraint_single(runtime
,
528 SNDRV_PCM_HW_PARAM_CHANNELS
,
534 "%s: Error: Unsupported protocol (fmt = 0x%x)!\n",
535 __func__
, drvdata
->fmt
);
542 static int ux500_msp_dai_set_dai_fmt(struct snd_soc_dai
*dai
,
545 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
547 dev_dbg(dai
->dev
, "%s: MSP %d: Enter.\n", __func__
, dai
->id
);
549 switch (fmt
& (SND_SOC_DAIFMT_FORMAT_MASK
|
550 SND_SOC_DAIFMT_MASTER_MASK
)) {
551 case SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_CBS_CFS
:
552 case SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_CBM_CFM
:
553 case SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBS_CFS
:
554 case SND_SOC_DAIFMT_DSP_B
| SND_SOC_DAIFMT_CBM_CFM
:
555 case SND_SOC_DAIFMT_DSP_A
| SND_SOC_DAIFMT_CBS_CFS
:
556 case SND_SOC_DAIFMT_DSP_A
| SND_SOC_DAIFMT_CBM_CFM
:
561 "%s: Error: Unsupported protocol/master (fmt = 0x%x)!\n",
562 __func__
, drvdata
->fmt
);
566 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
567 case SND_SOC_DAIFMT_NB_NF
:
568 case SND_SOC_DAIFMT_NB_IF
:
569 case SND_SOC_DAIFMT_IB_IF
:
574 "%s: Error: Unsupported inversion (fmt = 0x%x)!\n",
575 __func__
, drvdata
->fmt
);
583 static int ux500_msp_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
584 unsigned int tx_mask
,
585 unsigned int rx_mask
,
586 int slots
, int slot_width
)
588 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
605 dev_err(dai
->dev
, "%s: Error: Unsupported slot-count (%d)!\n",
609 drvdata
->slots
= slots
;
611 if (!(slot_width
== 16)) {
612 dev_err(dai
->dev
, "%s: Error: Unsupported slot-width (%d)!\n",
613 __func__
, slot_width
);
616 drvdata
->slot_width
= slot_width
;
618 drvdata
->tx_mask
= tx_mask
& cap
;
619 drvdata
->rx_mask
= rx_mask
& cap
;
624 static int ux500_msp_dai_set_dai_sysclk(struct snd_soc_dai
*dai
,
625 int clk_id
, unsigned int freq
, int dir
)
627 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
629 dev_dbg(dai
->dev
, "%s: MSP %d: Enter. clk-id: %d, freq: %u.\n",
630 __func__
, dai
->id
, clk_id
, freq
);
633 case UX500_MSP_MASTER_CLOCK
:
634 drvdata
->master_clk
= freq
;
638 dev_err(dai
->dev
, "%s: MSP %d: Invalid clk-id (%d)!\n",
639 __func__
, dai
->id
, clk_id
);
646 static int ux500_msp_dai_trigger(struct snd_pcm_substream
*substream
,
647 int cmd
, struct snd_soc_dai
*dai
)
650 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
652 dev_dbg(dai
->dev
, "%s: MSP %d (%s): Enter (msp->id = %d, cmd = %d).\n",
653 __func__
, dai
->id
, snd_pcm_stream_str(substream
),
654 (int)drvdata
->msp
->id
, cmd
);
656 ret
= ux500_msp_i2s_trigger(drvdata
->msp
, cmd
, substream
->stream
);
661 static int ux500_msp_dai_of_probe(struct snd_soc_dai
*dai
)
663 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
664 struct snd_dmaengine_dai_dma_data
*playback_dma_data
;
665 struct snd_dmaengine_dai_dma_data
*capture_dma_data
;
667 playback_dma_data
= devm_kzalloc(dai
->dev
,
668 sizeof(*playback_dma_data
),
670 if (!playback_dma_data
)
673 capture_dma_data
= devm_kzalloc(dai
->dev
,
674 sizeof(*capture_dma_data
),
676 if (!capture_dma_data
)
679 playback_dma_data
->addr
= drvdata
->msp
->playback_dma_data
.tx_rx_addr
;
680 capture_dma_data
->addr
= drvdata
->msp
->capture_dma_data
.tx_rx_addr
;
682 playback_dma_data
->maxburst
= 4;
683 capture_dma_data
->maxburst
= 4;
685 snd_soc_dai_init_dma_data(dai
, playback_dma_data
, capture_dma_data
);
690 static int ux500_msp_dai_probe(struct snd_soc_dai
*dai
)
692 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(dai
->dev
);
693 struct msp_i2s_platform_data
*pdata
= dai
->dev
->platform_data
;
697 ret
= ux500_msp_dai_of_probe(dai
);
701 drvdata
->msp
->playback_dma_data
.data_size
= drvdata
->slot_width
;
702 drvdata
->msp
->capture_dma_data
.data_size
= drvdata
->slot_width
;
704 snd_soc_dai_init_dma_data(dai
,
705 &drvdata
->msp
->playback_dma_data
,
706 &drvdata
->msp
->capture_dma_data
);
710 static const struct snd_soc_dai_ops ux500_msp_dai_ops
[] = {
712 .set_sysclk
= ux500_msp_dai_set_dai_sysclk
,
713 .set_fmt
= ux500_msp_dai_set_dai_fmt
,
714 .set_tdm_slot
= ux500_msp_dai_set_tdm_slot
,
715 .startup
= ux500_msp_dai_startup
,
716 .shutdown
= ux500_msp_dai_shutdown
,
717 .prepare
= ux500_msp_dai_prepare
,
718 .trigger
= ux500_msp_dai_trigger
,
719 .hw_params
= ux500_msp_dai_hw_params
,
723 static struct snd_soc_dai_driver ux500_msp_dai_drv
= {
724 .probe
= ux500_msp_dai_probe
,
727 .playback
.channels_min
= UX500_MSP_MIN_CHANNELS
,
728 .playback
.channels_max
= UX500_MSP_MAX_CHANNELS
,
729 .playback
.rates
= UX500_I2S_RATES
,
730 .playback
.formats
= UX500_I2S_FORMATS
,
731 .capture
.channels_min
= UX500_MSP_MIN_CHANNELS
,
732 .capture
.channels_max
= UX500_MSP_MAX_CHANNELS
,
733 .capture
.rates
= UX500_I2S_RATES
,
734 .capture
.formats
= UX500_I2S_FORMATS
,
735 .ops
= ux500_msp_dai_ops
,
738 static const struct snd_soc_component_driver ux500_msp_component
= {
743 static int ux500_msp_drv_probe(struct platform_device
*pdev
)
745 struct ux500_msp_i2s_drvdata
*drvdata
;
746 struct msp_i2s_platform_data
*pdata
= pdev
->dev
.platform_data
;
747 struct device_node
*np
= pdev
->dev
.of_node
;
751 dev_err(&pdev
->dev
, "No platform data or Device Tree found\n");
755 drvdata
= devm_kzalloc(&pdev
->dev
,
756 sizeof(struct ux500_msp_i2s_drvdata
),
763 drvdata
->tx_mask
= 0x01;
764 drvdata
->rx_mask
= 0x01;
765 drvdata
->slot_width
= 16;
766 drvdata
->master_clk
= MSP_INPUT_FREQ_APB
;
768 drvdata
->reg_vape
= devm_regulator_get(&pdev
->dev
, "v-ape");
769 if (IS_ERR(drvdata
->reg_vape
)) {
770 ret
= (int)PTR_ERR(drvdata
->reg_vape
);
772 "%s: ERROR: Failed to get Vape supply (%d)!\n",
776 prcmu_qos_add_requirement(PRCMU_QOS_APE_OPP
, (char *)pdev
->name
, 50);
778 drvdata
->pclk
= devm_clk_get(&pdev
->dev
, "apb_pclk");
779 if (IS_ERR(drvdata
->pclk
)) {
780 ret
= (int)PTR_ERR(drvdata
->pclk
);
782 "%s: ERROR: devm_clk_get of pclk failed (%d)!\n",
787 drvdata
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
788 if (IS_ERR(drvdata
->clk
)) {
789 ret
= (int)PTR_ERR(drvdata
->clk
);
791 "%s: ERROR: devm_clk_get failed (%d)!\n",
796 ret
= ux500_msp_i2s_init_msp(pdev
, &drvdata
->msp
,
797 pdev
->dev
.platform_data
);
800 "%s: ERROR: Failed to init MSP-struct (%d)!",
804 dev_set_drvdata(&pdev
->dev
, drvdata
);
806 ret
= snd_soc_register_component(&pdev
->dev
, &ux500_msp_component
,
807 &ux500_msp_dai_drv
, 1);
809 dev_err(&pdev
->dev
, "Error: %s: Failed to register MSP%d!\n",
810 __func__
, drvdata
->msp
->id
);
814 ret
= ux500_pcm_register_platform(pdev
);
817 "Error: %s: Failed to register PCM platform device!\n",
825 snd_soc_unregister_component(&pdev
->dev
);
829 static int ux500_msp_drv_remove(struct platform_device
*pdev
)
831 struct ux500_msp_i2s_drvdata
*drvdata
= dev_get_drvdata(&pdev
->dev
);
833 ux500_pcm_unregister_platform(pdev
);
835 snd_soc_unregister_component(&pdev
->dev
);
837 prcmu_qos_remove_requirement(PRCMU_QOS_APE_OPP
, "ux500_msp_i2s");
839 ux500_msp_i2s_cleanup_msp(pdev
, drvdata
->msp
);
844 static const struct of_device_id ux500_msp_i2s_match
[] = {
845 { .compatible
= "stericsson,ux500-msp-i2s", },
848 MODULE_DEVICE_TABLE(of
, ux500_msp_i2s_match
);
850 static struct platform_driver msp_i2s_driver
= {
852 .name
= "ux500-msp-i2s",
853 .of_match_table
= ux500_msp_i2s_match
,
855 .probe
= ux500_msp_drv_probe
,
856 .remove
= ux500_msp_drv_remove
,
858 module_platform_driver(msp_i2s_driver
);
860 MODULE_LICENSE("GPL v2");