2 * Copyright (C) ST-Ericsson SA 2012
4 * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
5 * Roger Nilsson <roger.xr.nilsson@stericsson.com>,
6 * Sandeep Kaushik <sandeep.kaushik@st.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as published
13 * by the Free Software Foundation.
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/pinctrl/consumer.h>
19 #include <linux/delay.h>
20 #include <linux/slab.h>
24 #include <mach/hardware.h>
27 #include <sound/soc.h>
29 #include "ux500_msp_i2s.h"
31 /* MSP1/3 Tx/Rx usage protection */
32 static DEFINE_SPINLOCK(msp_rxtx_lock
);
34 /* Protocol desciptors */
35 static const struct msp_protdesc prot_descs
[] = {
39 MSP_PHASE2_START_MODE_IMEDIATE
,
40 MSP_PHASE2_START_MODE_IMEDIATE
,
59 MSP_COMPRESS_MODE_LINEAR
,
60 MSP_EXPAND_MODE_LINEAR
,
68 MSP_PHASE2_START_MODE_FSYNC
,
69 MSP_PHASE2_START_MODE_FSYNC
,
88 MSP_COMPRESS_MODE_LINEAR
,
89 MSP_EXPAND_MODE_LINEAR
,
94 }, { /* Companded PCM */
97 MSP_PHASE2_START_MODE_FSYNC
,
98 MSP_PHASE2_START_MODE_FSYNC
,
100 MSP_BTF_MS_BIT_FIRST
,
113 MSP_FSYNC_POL_ACT_HI
,
114 MSP_FSYNC_POL_ACT_HI
,
117 MSP_COMPRESS_MODE_LINEAR
,
118 MSP_EXPAND_MODE_LINEAR
,
126 static void set_prot_desc_tx(struct ux500_msp
*msp
,
127 struct msp_protdesc
*protdesc
,
128 enum msp_data_size data_size
)
132 temp_reg
|= MSP_P2_ENABLE_BIT(protdesc
->tx_phase_mode
);
133 temp_reg
|= MSP_P2_START_MODE_BIT(protdesc
->tx_phase2_start_mode
);
134 temp_reg
|= MSP_P1_FRAME_LEN_BITS(protdesc
->tx_frame_len_1
);
135 temp_reg
|= MSP_P2_FRAME_LEN_BITS(protdesc
->tx_frame_len_2
);
136 if (msp
->def_elem_len
) {
137 temp_reg
|= MSP_P1_ELEM_LEN_BITS(protdesc
->tx_elem_len_1
);
138 temp_reg
|= MSP_P2_ELEM_LEN_BITS(protdesc
->tx_elem_len_2
);
140 temp_reg
|= MSP_P1_ELEM_LEN_BITS(data_size
);
141 temp_reg
|= MSP_P2_ELEM_LEN_BITS(data_size
);
143 temp_reg
|= MSP_DATA_DELAY_BITS(protdesc
->tx_data_delay
);
144 temp_reg
|= MSP_SET_ENDIANNES_BIT(protdesc
->tx_byte_order
);
145 temp_reg
|= MSP_FSYNC_POL(protdesc
->tx_fsync_pol
);
146 temp_reg
|= MSP_DATA_WORD_SWAP(protdesc
->tx_half_word_swap
);
147 temp_reg
|= MSP_SET_COMPANDING_MODE(protdesc
->compression_mode
);
148 temp_reg
|= MSP_SET_FSYNC_IGNORE(protdesc
->frame_sync_ignore
);
150 writel(temp_reg
, msp
->registers
+ MSP_TCF
);
153 static void set_prot_desc_rx(struct ux500_msp
*msp
,
154 struct msp_protdesc
*protdesc
,
155 enum msp_data_size data_size
)
159 temp_reg
|= MSP_P2_ENABLE_BIT(protdesc
->rx_phase_mode
);
160 temp_reg
|= MSP_P2_START_MODE_BIT(protdesc
->rx_phase2_start_mode
);
161 temp_reg
|= MSP_P1_FRAME_LEN_BITS(protdesc
->rx_frame_len_1
);
162 temp_reg
|= MSP_P2_FRAME_LEN_BITS(protdesc
->rx_frame_len_2
);
163 if (msp
->def_elem_len
) {
164 temp_reg
|= MSP_P1_ELEM_LEN_BITS(protdesc
->rx_elem_len_1
);
165 temp_reg
|= MSP_P2_ELEM_LEN_BITS(protdesc
->rx_elem_len_2
);
167 temp_reg
|= MSP_P1_ELEM_LEN_BITS(data_size
);
168 temp_reg
|= MSP_P2_ELEM_LEN_BITS(data_size
);
171 temp_reg
|= MSP_DATA_DELAY_BITS(protdesc
->rx_data_delay
);
172 temp_reg
|= MSP_SET_ENDIANNES_BIT(protdesc
->rx_byte_order
);
173 temp_reg
|= MSP_FSYNC_POL(protdesc
->rx_fsync_pol
);
174 temp_reg
|= MSP_DATA_WORD_SWAP(protdesc
->rx_half_word_swap
);
175 temp_reg
|= MSP_SET_COMPANDING_MODE(protdesc
->expansion_mode
);
176 temp_reg
|= MSP_SET_FSYNC_IGNORE(protdesc
->frame_sync_ignore
);
178 writel(temp_reg
, msp
->registers
+ MSP_RCF
);
181 static int configure_protocol(struct ux500_msp
*msp
,
182 struct ux500_msp_config
*config
)
184 struct msp_protdesc
*protdesc
;
185 enum msp_data_size data_size
;
188 data_size
= config
->data_size
;
189 msp
->def_elem_len
= config
->def_elem_len
;
190 if (config
->default_protdesc
== 1) {
191 if (config
->protocol
>= MSP_INVALID_PROTOCOL
) {
192 dev_err(msp
->dev
, "%s: ERROR: Invalid protocol!\n",
197 (struct msp_protdesc
*)&prot_descs
[config
->protocol
];
199 protdesc
= (struct msp_protdesc
*)&config
->protdesc
;
202 if (data_size
< MSP_DATA_BITS_DEFAULT
|| data_size
> MSP_DATA_BITS_32
) {
204 "%s: ERROR: Invalid data-size requested (data_size = %d)!\n",
205 __func__
, data_size
);
209 if (config
->direction
& MSP_DIR_TX
)
210 set_prot_desc_tx(msp
, protdesc
, data_size
);
211 if (config
->direction
& MSP_DIR_RX
)
212 set_prot_desc_rx(msp
, protdesc
, data_size
);
214 /* The code below should not be separated. */
215 temp_reg
= readl(msp
->registers
+ MSP_GCR
) & ~TX_CLK_POL_RISING
;
216 temp_reg
|= MSP_TX_CLKPOL_BIT(~protdesc
->tx_clk_pol
);
217 writel(temp_reg
, msp
->registers
+ MSP_GCR
);
218 temp_reg
= readl(msp
->registers
+ MSP_GCR
) & ~RX_CLK_POL_RISING
;
219 temp_reg
|= MSP_RX_CLKPOL_BIT(protdesc
->rx_clk_pol
);
220 writel(temp_reg
, msp
->registers
+ MSP_GCR
);
225 static int setup_bitclk(struct ux500_msp
*msp
, struct ux500_msp_config
*config
)
232 struct msp_protdesc
*protdesc
= NULL
;
234 reg_val_GCR
= readl(msp
->registers
+ MSP_GCR
);
235 writel(reg_val_GCR
& ~SRG_ENABLE
, msp
->registers
+ MSP_GCR
);
237 if (config
->default_protdesc
)
239 (struct msp_protdesc
*)&prot_descs
[config
->protocol
];
241 protdesc
= (struct msp_protdesc
*)&config
->protdesc
;
243 switch (config
->protocol
) {
244 case MSP_PCM_PROTOCOL
:
245 case MSP_PCM_COMPAND_PROTOCOL
:
246 frame_width
= protdesc
->frame_width
;
247 sck_div
= config
->f_inputclk
/ (config
->frame_freq
*
248 (protdesc
->clocks_per_frame
));
249 frame_per
= protdesc
->frame_period
;
251 case MSP_I2S_PROTOCOL
:
252 frame_width
= protdesc
->frame_width
;
253 sck_div
= config
->f_inputclk
/ (config
->frame_freq
*
254 (protdesc
->clocks_per_frame
));
255 frame_per
= protdesc
->frame_period
;
258 dev_err(msp
->dev
, "%s: ERROR: Unknown protocol (%d)!\n",
264 temp_reg
= (sck_div
- 1) & SCK_DIV_MASK
;
265 temp_reg
|= FRAME_WIDTH_BITS(frame_width
);
266 temp_reg
|= FRAME_PERIOD_BITS(frame_per
);
267 writel(temp_reg
, msp
->registers
+ MSP_SRG
);
269 msp
->f_bitclk
= (config
->f_inputclk
)/(sck_div
+ 1);
271 /* Enable bit-clock */
273 reg_val_GCR
= readl(msp
->registers
+ MSP_GCR
);
274 writel(reg_val_GCR
| SRG_ENABLE
, msp
->registers
+ MSP_GCR
);
280 static int configure_multichannel(struct ux500_msp
*msp
,
281 struct ux500_msp_config
*config
)
283 struct msp_protdesc
*protdesc
;
284 struct msp_multichannel_config
*mcfg
;
287 if (config
->default_protdesc
== 1) {
288 if (config
->protocol
>= MSP_INVALID_PROTOCOL
) {
290 "%s: ERROR: Invalid protocol (%d)!\n",
291 __func__
, config
->protocol
);
294 protdesc
= (struct msp_protdesc
*)
295 &prot_descs
[config
->protocol
];
297 protdesc
= (struct msp_protdesc
*)&config
->protdesc
;
300 mcfg
= &config
->multichannel_config
;
301 if (mcfg
->tx_multichannel_enable
) {
302 if (protdesc
->tx_phase_mode
== MSP_SINGLE_PHASE
) {
303 reg_val_MCR
= readl(msp
->registers
+ MSP_MCR
);
304 writel(reg_val_MCR
| (mcfg
->tx_multichannel_enable
?
306 msp
->registers
+ MSP_MCR
);
307 writel(mcfg
->tx_channel_0_enable
,
308 msp
->registers
+ MSP_TCE0
);
309 writel(mcfg
->tx_channel_1_enable
,
310 msp
->registers
+ MSP_TCE1
);
311 writel(mcfg
->tx_channel_2_enable
,
312 msp
->registers
+ MSP_TCE2
);
313 writel(mcfg
->tx_channel_3_enable
,
314 msp
->registers
+ MSP_TCE3
);
317 "%s: ERROR: Only single-phase supported (TX-mode: %d)!\n",
318 __func__
, protdesc
->tx_phase_mode
);
322 if (mcfg
->rx_multichannel_enable
) {
323 if (protdesc
->rx_phase_mode
== MSP_SINGLE_PHASE
) {
324 reg_val_MCR
= readl(msp
->registers
+ MSP_MCR
);
325 writel(reg_val_MCR
| (mcfg
->rx_multichannel_enable
?
327 msp
->registers
+ MSP_MCR
);
328 writel(mcfg
->rx_channel_0_enable
,
329 msp
->registers
+ MSP_RCE0
);
330 writel(mcfg
->rx_channel_1_enable
,
331 msp
->registers
+ MSP_RCE1
);
332 writel(mcfg
->rx_channel_2_enable
,
333 msp
->registers
+ MSP_RCE2
);
334 writel(mcfg
->rx_channel_3_enable
,
335 msp
->registers
+ MSP_RCE3
);
338 "%s: ERROR: Only single-phase supported (RX-mode: %d)!\n",
339 __func__
, protdesc
->rx_phase_mode
);
342 if (mcfg
->rx_comparison_enable_mode
) {
343 reg_val_MCR
= readl(msp
->registers
+ MSP_MCR
);
345 (mcfg
->rx_comparison_enable_mode
<< RCMPM_BIT
),
346 msp
->registers
+ MSP_MCR
);
348 writel(mcfg
->comparison_mask
,
349 msp
->registers
+ MSP_RCM
);
350 writel(mcfg
->comparison_value
,
351 msp
->registers
+ MSP_RCV
);
359 static int enable_msp(struct ux500_msp
*msp
, struct ux500_msp_config
*config
)
361 int status
= 0, retval
= 0;
362 u32 reg_val_DMACR
, reg_val_GCR
;
365 /* Check msp state whether in RUN or CONFIGURED Mode */
366 if (msp
->msp_state
== MSP_STATE_IDLE
) {
367 spin_lock_irqsave(&msp_rxtx_lock
, flags
);
368 if (msp
->pinctrl_rxtx_ref
== 0 &&
369 !(IS_ERR(msp
->pinctrl_p
) || IS_ERR(msp
->pinctrl_def
))) {
370 retval
= pinctrl_select_state(msp
->pinctrl_p
,
373 pr_err("could not set MSP defstate\n");
376 msp
->pinctrl_rxtx_ref
++;
377 spin_unlock_irqrestore(&msp_rxtx_lock
, flags
);
380 /* Configure msp with protocol dependent settings */
381 configure_protocol(msp
, config
);
382 setup_bitclk(msp
, config
);
383 if (config
->multichannel_configured
== 1) {
384 status
= configure_multichannel(msp
, config
);
387 "%s: WARN: configure_multichannel failed (%d)!\n",
391 /* Make sure the correct DMA-directions are configured */
392 if ((config
->direction
& MSP_DIR_RX
) && (!msp
->dma_cfg_rx
)) {
393 dev_err(msp
->dev
, "%s: ERROR: MSP RX-mode is not configured!",
397 if ((config
->direction
== MSP_DIR_TX
) && (!msp
->dma_cfg_tx
)) {
398 dev_err(msp
->dev
, "%s: ERROR: MSP TX-mode is not configured!",
403 reg_val_DMACR
= readl(msp
->registers
+ MSP_DMACR
);
404 if (config
->direction
& MSP_DIR_RX
)
405 reg_val_DMACR
|= RX_DMA_ENABLE
;
406 if (config
->direction
& MSP_DIR_TX
)
407 reg_val_DMACR
|= TX_DMA_ENABLE
;
408 writel(reg_val_DMACR
, msp
->registers
+ MSP_DMACR
);
410 writel(config
->iodelay
, msp
->registers
+ MSP_IODLY
);
412 /* Enable frame generation logic */
413 reg_val_GCR
= readl(msp
->registers
+ MSP_GCR
);
414 writel(reg_val_GCR
| FRAME_GEN_ENABLE
, msp
->registers
+ MSP_GCR
);
419 static void flush_fifo_rx(struct ux500_msp
*msp
)
421 u32 reg_val_DR
, reg_val_GCR
, reg_val_FLR
;
424 reg_val_GCR
= readl(msp
->registers
+ MSP_GCR
);
425 writel(reg_val_GCR
| RX_ENABLE
, msp
->registers
+ MSP_GCR
);
427 reg_val_FLR
= readl(msp
->registers
+ MSP_FLR
);
428 while (!(reg_val_FLR
& RX_FIFO_EMPTY
) && limit
--) {
429 reg_val_DR
= readl(msp
->registers
+ MSP_DR
);
430 reg_val_FLR
= readl(msp
->registers
+ MSP_FLR
);
433 writel(reg_val_GCR
, msp
->registers
+ MSP_GCR
);
436 static void flush_fifo_tx(struct ux500_msp
*msp
)
438 u32 reg_val_TSTDR
, reg_val_GCR
, reg_val_FLR
;
441 reg_val_GCR
= readl(msp
->registers
+ MSP_GCR
);
442 writel(reg_val_GCR
| TX_ENABLE
, msp
->registers
+ MSP_GCR
);
443 writel(MSP_ITCR_ITEN
| MSP_ITCR_TESTFIFO
, msp
->registers
+ MSP_ITCR
);
445 reg_val_FLR
= readl(msp
->registers
+ MSP_FLR
);
446 while (!(reg_val_FLR
& TX_FIFO_EMPTY
) && limit
--) {
447 reg_val_TSTDR
= readl(msp
->registers
+ MSP_TSTDR
);
448 reg_val_FLR
= readl(msp
->registers
+ MSP_FLR
);
450 writel(0x0, msp
->registers
+ MSP_ITCR
);
451 writel(reg_val_GCR
, msp
->registers
+ MSP_GCR
);
454 int ux500_msp_i2s_open(struct ux500_msp
*msp
,
455 struct ux500_msp_config
*config
)
457 u32 old_reg
, new_reg
, mask
;
459 unsigned int tx_sel
, rx_sel
, tx_busy
, rx_busy
;
461 if (in_interrupt()) {
463 "%s: ERROR: Open called in interrupt context!\n",
468 tx_sel
= (config
->direction
& MSP_DIR_TX
) > 0;
469 rx_sel
= (config
->direction
& MSP_DIR_RX
) > 0;
470 if (!tx_sel
&& !rx_sel
) {
471 dev_err(msp
->dev
, "%s: Error: No direction selected!\n",
476 tx_busy
= (msp
->dir_busy
& MSP_DIR_TX
) > 0;
477 rx_busy
= (msp
->dir_busy
& MSP_DIR_RX
) > 0;
478 if (tx_busy
&& tx_sel
) {
479 dev_err(msp
->dev
, "%s: Error: TX is in use!\n", __func__
);
482 if (rx_busy
&& rx_sel
) {
483 dev_err(msp
->dev
, "%s: Error: RX is in use!\n", __func__
);
487 msp
->dir_busy
|= (tx_sel
? MSP_DIR_TX
: 0) | (rx_sel
? MSP_DIR_RX
: 0);
489 /* First do the global config register */
490 mask
= RX_CLK_SEL_MASK
| TX_CLK_SEL_MASK
| RX_FSYNC_MASK
|
491 TX_FSYNC_MASK
| RX_SYNC_SEL_MASK
| TX_SYNC_SEL_MASK
|
492 RX_FIFO_ENABLE_MASK
| TX_FIFO_ENABLE_MASK
| SRG_CLK_SEL_MASK
|
493 LOOPBACK_MASK
| TX_EXTRA_DELAY_MASK
;
495 new_reg
= (config
->tx_clk_sel
| config
->rx_clk_sel
|
496 config
->rx_fsync_pol
| config
->tx_fsync_pol
|
497 config
->rx_fsync_sel
| config
->tx_fsync_sel
|
498 config
->rx_fifo_config
| config
->tx_fifo_config
|
499 config
->srg_clk_sel
| config
->loopback_enable
|
500 config
->tx_data_enable
);
502 old_reg
= readl(msp
->registers
+ MSP_GCR
);
505 writel(new_reg
, msp
->registers
+ MSP_GCR
);
507 res
= enable_msp(msp
, config
);
509 dev_err(msp
->dev
, "%s: ERROR: enable_msp failed (%d)!\n",
513 if (config
->loopback_enable
& 0x80)
514 msp
->loopback_enable
= 1;
520 msp
->msp_state
= MSP_STATE_CONFIGURED
;
524 static void disable_msp_rx(struct ux500_msp
*msp
)
526 u32 reg_val_GCR
, reg_val_DMACR
, reg_val_IMSC
;
528 reg_val_GCR
= readl(msp
->registers
+ MSP_GCR
);
529 writel(reg_val_GCR
& ~RX_ENABLE
, msp
->registers
+ MSP_GCR
);
530 reg_val_DMACR
= readl(msp
->registers
+ MSP_DMACR
);
531 writel(reg_val_DMACR
& ~RX_DMA_ENABLE
, msp
->registers
+ MSP_DMACR
);
532 reg_val_IMSC
= readl(msp
->registers
+ MSP_IMSC
);
533 writel(reg_val_IMSC
&
534 ~(RX_SERVICE_INT
| RX_OVERRUN_ERROR_INT
),
535 msp
->registers
+ MSP_IMSC
);
537 msp
->dir_busy
&= ~MSP_DIR_RX
;
540 static void disable_msp_tx(struct ux500_msp
*msp
)
542 u32 reg_val_GCR
, reg_val_DMACR
, reg_val_IMSC
;
544 reg_val_GCR
= readl(msp
->registers
+ MSP_GCR
);
545 writel(reg_val_GCR
& ~TX_ENABLE
, msp
->registers
+ MSP_GCR
);
546 reg_val_DMACR
= readl(msp
->registers
+ MSP_DMACR
);
547 writel(reg_val_DMACR
& ~TX_DMA_ENABLE
, msp
->registers
+ MSP_DMACR
);
548 reg_val_IMSC
= readl(msp
->registers
+ MSP_IMSC
);
549 writel(reg_val_IMSC
&
550 ~(TX_SERVICE_INT
| TX_UNDERRUN_ERR_INT
),
551 msp
->registers
+ MSP_IMSC
);
553 msp
->dir_busy
&= ~MSP_DIR_TX
;
556 static int disable_msp(struct ux500_msp
*msp
, unsigned int dir
)
560 unsigned int disable_tx
, disable_rx
;
562 reg_val_GCR
= readl(msp
->registers
+ MSP_GCR
);
563 disable_tx
= dir
& MSP_DIR_TX
;
564 disable_rx
= dir
& MSP_DIR_TX
;
565 if (disable_tx
&& disable_rx
) {
566 reg_val_GCR
= readl(msp
->registers
+ MSP_GCR
);
567 writel(reg_val_GCR
| LOOPBACK_MASK
,
568 msp
->registers
+ MSP_GCR
);
573 /* Disable TX-channel */
574 writel((readl(msp
->registers
+ MSP_GCR
) &
575 (~TX_ENABLE
)), msp
->registers
+ MSP_GCR
);
580 /* Disable Loopback and Receive channel */
581 writel((readl(msp
->registers
+ MSP_GCR
) &
582 (~(RX_ENABLE
| LOOPBACK_MASK
))),
583 msp
->registers
+ MSP_GCR
);
587 } else if (disable_tx
)
595 int ux500_msp_i2s_trigger(struct ux500_msp
*msp
, int cmd
, int direction
)
597 u32 reg_val_GCR
, enable_bit
;
599 if (msp
->msp_state
== MSP_STATE_IDLE
) {
600 dev_err(msp
->dev
, "%s: ERROR: MSP is not configured!\n",
606 case SNDRV_PCM_TRIGGER_START
:
607 case SNDRV_PCM_TRIGGER_RESUME
:
608 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
609 if (direction
== SNDRV_PCM_STREAM_PLAYBACK
)
610 enable_bit
= TX_ENABLE
;
612 enable_bit
= RX_ENABLE
;
613 reg_val_GCR
= readl(msp
->registers
+ MSP_GCR
);
614 writel(reg_val_GCR
| enable_bit
, msp
->registers
+ MSP_GCR
);
617 case SNDRV_PCM_TRIGGER_STOP
:
618 case SNDRV_PCM_TRIGGER_SUSPEND
:
619 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
620 if (direction
== SNDRV_PCM_STREAM_PLAYBACK
)
633 int ux500_msp_i2s_close(struct ux500_msp
*msp
, unsigned int dir
)
635 int status
= 0, retval
= 0;
638 dev_dbg(msp
->dev
, "%s: Enter (dir = 0x%01x).\n", __func__
, dir
);
640 status
= disable_msp(msp
, dir
);
641 if (msp
->dir_busy
== 0) {
642 /* disable sample rate and frame generators */
643 msp
->msp_state
= MSP_STATE_IDLE
;
644 writel((readl(msp
->registers
+ MSP_GCR
) &
645 (~(FRAME_GEN_ENABLE
| SRG_ENABLE
))),
646 msp
->registers
+ MSP_GCR
);
648 spin_lock_irqsave(&msp_rxtx_lock
, flags
);
649 WARN_ON(!msp
->pinctrl_rxtx_ref
);
650 msp
->pinctrl_rxtx_ref
--;
651 if (msp
->pinctrl_rxtx_ref
== 0 &&
652 !(IS_ERR(msp
->pinctrl_p
) || IS_ERR(msp
->pinctrl_sleep
))) {
653 retval
= pinctrl_select_state(msp
->pinctrl_p
,
656 pr_err("could not set MSP sleepstate\n");
658 spin_unlock_irqrestore(&msp_rxtx_lock
, flags
);
660 writel(0, msp
->registers
+ MSP_GCR
);
661 writel(0, msp
->registers
+ MSP_TCF
);
662 writel(0, msp
->registers
+ MSP_RCF
);
663 writel(0, msp
->registers
+ MSP_DMACR
);
664 writel(0, msp
->registers
+ MSP_SRG
);
665 writel(0, msp
->registers
+ MSP_MCR
);
666 writel(0, msp
->registers
+ MSP_RCM
);
667 writel(0, msp
->registers
+ MSP_RCV
);
668 writel(0, msp
->registers
+ MSP_TCE0
);
669 writel(0, msp
->registers
+ MSP_TCE1
);
670 writel(0, msp
->registers
+ MSP_TCE2
);
671 writel(0, msp
->registers
+ MSP_TCE3
);
672 writel(0, msp
->registers
+ MSP_RCE0
);
673 writel(0, msp
->registers
+ MSP_RCE1
);
674 writel(0, msp
->registers
+ MSP_RCE2
);
675 writel(0, msp
->registers
+ MSP_RCE3
);
682 int ux500_msp_i2s_init_msp(struct platform_device
*pdev
,
683 struct ux500_msp
**msp_p
,
684 struct msp_i2s_platform_data
*platform_data
)
686 struct resource
*res
= NULL
;
687 struct i2s_controller
*i2s_cont
;
688 struct device_node
*np
= pdev
->dev
.of_node
;
689 struct ux500_msp
*msp
;
691 *msp_p
= devm_kzalloc(&pdev
->dev
, sizeof(struct ux500_msp
), GFP_KERNEL
);
697 if (!platform_data
) {
698 platform_data
= devm_kzalloc(&pdev
->dev
,
699 sizeof(struct msp_i2s_platform_data
), GFP_KERNEL
);
707 dev_dbg(&pdev
->dev
, "%s: Enter (name: %s, id: %d).\n", __func__
,
708 pdev
->name
, platform_data
->id
);
710 msp
->id
= platform_data
->id
;
711 msp
->dev
= &pdev
->dev
;
712 msp
->dma_cfg_rx
= platform_data
->msp_i2s_dma_rx
;
713 msp
->dma_cfg_tx
= platform_data
->msp_i2s_dma_tx
;
715 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
717 dev_err(&pdev
->dev
, "%s: ERROR: Unable to get resource!\n",
722 msp
->registers
= devm_ioremap(&pdev
->dev
, res
->start
,
724 if (msp
->registers
== NULL
) {
725 dev_err(&pdev
->dev
, "%s: ERROR: ioremap failed!\n", __func__
);
729 msp
->msp_state
= MSP_STATE_IDLE
;
730 msp
->loopback_enable
= 0;
732 /* I2S-controller is allocated and added in I2S controller class. */
733 i2s_cont
= devm_kzalloc(&pdev
->dev
, sizeof(*i2s_cont
), GFP_KERNEL
);
736 "%s: ERROR: Failed to allocate I2S-controller!\n",
740 i2s_cont
->dev
.parent
= &pdev
->dev
;
741 i2s_cont
->data
= (void *)msp
;
742 i2s_cont
->id
= (s16
)msp
->id
;
743 snprintf(i2s_cont
->name
, sizeof(i2s_cont
->name
), "ux500-msp-i2s.%04x",
745 dev_dbg(&pdev
->dev
, "I2S device-name: '%s'\n", i2s_cont
->name
);
746 msp
->i2s_cont
= i2s_cont
;
748 msp
->pinctrl_p
= pinctrl_get(msp
->dev
);
749 if (IS_ERR(msp
->pinctrl_p
))
750 dev_err(&pdev
->dev
, "could not get MSP pinctrl\n");
752 msp
->pinctrl_def
= pinctrl_lookup_state(msp
->pinctrl_p
,
753 PINCTRL_STATE_DEFAULT
);
754 if (IS_ERR(msp
->pinctrl_def
)) {
756 "could not get MSP defstate (%li)\n",
757 PTR_ERR(msp
->pinctrl_def
));
759 msp
->pinctrl_sleep
= pinctrl_lookup_state(msp
->pinctrl_p
,
760 PINCTRL_STATE_SLEEP
);
761 if (IS_ERR(msp
->pinctrl_sleep
))
763 "could not get MSP idlestate (%li)\n",
764 PTR_ERR(msp
->pinctrl_def
));
770 void ux500_msp_i2s_cleanup_msp(struct platform_device
*pdev
,
771 struct ux500_msp
*msp
)
773 dev_dbg(msp
->dev
, "%s: Enter (id = %d).\n", __func__
, msp
->id
);
775 device_unregister(&msp
->i2s_cont
->dev
);
778 MODULE_LICENSE("GPL v2");