2 * File: sound/soc/blackfin/bf5xx-i2s.c
3 * Author: Cliff Cai <Cliff.Cai@analog.com>
5 * Created: Tue June 06 2008
6 * Description: Blackfin I2S CPU DAI driver
9 * Copyright 2008 Analog Devices Inc.
11 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see the file COPYING, or write
25 * to the Free Software Foundation, Inc.,
26 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <linux/init.h>
30 #include <linux/module.h>
31 #include <linux/device.h>
32 #include <linux/delay.h>
33 #include <sound/core.h>
34 #include <sound/pcm.h>
35 #include <sound/pcm_params.h>
36 #include <sound/initval.h>
37 #include <sound/soc.h>
40 #include <asm/portmux.h>
41 #include <linux/mutex.h>
42 #include <linux/gpio.h>
44 #include "bf5xx-sport.h"
46 struct bf5xx_i2s_port
{
54 static struct bf5xx_i2s_port bf5xx_i2s
;
55 static int sport_num
= CONFIG_SND_BF5XX_SPORT_NUM
;
57 static struct sport_param sport_params
[2] = {
59 .dma_rx_chan
= CH_SPORT0_RX
,
60 .dma_tx_chan
= CH_SPORT0_TX
,
61 .err_irq
= IRQ_SPORT0_ERROR
,
62 .regs
= (struct sport_register
*)SPORT0_TCR1
,
65 .dma_rx_chan
= CH_SPORT1_RX
,
66 .dma_tx_chan
= CH_SPORT1_TX
,
67 .err_irq
= IRQ_SPORT1_ERROR
,
68 .regs
= (struct sport_register
*)SPORT1_TCR1
,
73 * Setting the TFS pin selector for SPORT 0 based on whether the selected
74 * port id F or G. If the port is F then no conflict should exist for the
75 * TFS. When Port G is selected and EMAC then there is a conflict between
76 * the PHY interrupt line and TFS. Current settings prevent the conflict
77 * by ignoring the TFS pin when Port G is selected. This allows both
78 * codecs and EMAC using Port G concurrently.
80 #ifdef CONFIG_BF527_SPORT0_PORTG
81 #define LOCAL_SPORT0_TFS (0)
83 #define LOCAL_SPORT0_TFS (P_SPORT0_TFS)
86 static u16 sport_req
[][7] = { {P_SPORT0_DTPRI
, P_SPORT0_TSCLK
, P_SPORT0_RFS
,
87 P_SPORT0_DRPRI
, P_SPORT0_RSCLK
, LOCAL_SPORT0_TFS
, 0},
88 {P_SPORT1_DTPRI
, P_SPORT1_TSCLK
, P_SPORT1_RFS
, P_SPORT1_DRPRI
,
89 P_SPORT1_RSCLK
, P_SPORT1_TFS
, 0} };
91 static int bf5xx_i2s_set_dai_fmt(struct snd_soc_dai
*cpu_dai
,
96 /* interface format:support I2S,slave mode */
97 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
98 case SND_SOC_DAIFMT_I2S
:
99 bf5xx_i2s
.tcr1
|= TFSR
| TCKFE
;
100 bf5xx_i2s
.rcr1
|= RFSR
| RCKFE
;
101 bf5xx_i2s
.tcr2
|= TSFSE
;
102 bf5xx_i2s
.rcr2
|= RSFSE
;
104 case SND_SOC_DAIFMT_DSP_A
:
105 bf5xx_i2s
.tcr1
|= TFSR
;
106 bf5xx_i2s
.rcr1
|= RFSR
;
108 case SND_SOC_DAIFMT_LEFT_J
:
112 printk(KERN_ERR
"%s: Unknown DAI format type\n", __func__
);
117 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
118 case SND_SOC_DAIFMT_CBM_CFM
:
120 case SND_SOC_DAIFMT_CBS_CFS
:
121 case SND_SOC_DAIFMT_CBM_CFS
:
122 case SND_SOC_DAIFMT_CBS_CFM
:
126 printk(KERN_ERR
"%s: Unknown DAI master type\n", __func__
);
134 static int bf5xx_i2s_hw_params(struct snd_pcm_substream
*substream
,
135 struct snd_pcm_hw_params
*params
,
136 struct snd_soc_dai
*dai
)
140 bf5xx_i2s
.tcr2
&= ~0x1f;
141 bf5xx_i2s
.rcr2
&= ~0x1f;
142 switch (params_format(params
)) {
143 case SNDRV_PCM_FORMAT_S8
:
144 bf5xx_i2s
->tcr2
|= 7;
145 bf5xx_i2s
->rcr2
|= 7;
146 sport_handle
->wdsize
= 1;
147 case SNDRV_PCM_FORMAT_S16_LE
:
148 bf5xx_i2s
.tcr2
|= 15;
149 bf5xx_i2s
.rcr2
|= 15;
150 sport_handle
->wdsize
= 2;
152 case SNDRV_PCM_FORMAT_S24_LE
:
153 bf5xx_i2s
.tcr2
|= 23;
154 bf5xx_i2s
.rcr2
|= 23;
155 sport_handle
->wdsize
= 3;
157 case SNDRV_PCM_FORMAT_S32_LE
:
158 bf5xx_i2s
.tcr2
|= 31;
159 bf5xx_i2s
.rcr2
|= 31;
160 sport_handle
->wdsize
= 4;
164 if (!bf5xx_i2s
.configured
) {
166 * TX and RX are not independent,they are enabled at the
167 * same time, even if only one side is running. So, we
168 * need to configure both of them at the time when the first
171 * CPU DAI:slave mode.
173 bf5xx_i2s
.configured
= 1;
174 ret
= sport_config_rx(sport_handle
, bf5xx_i2s
.rcr1
,
175 bf5xx_i2s
.rcr2
, 0, 0);
177 pr_err("SPORT is busy!\n");
181 ret
= sport_config_tx(sport_handle
, bf5xx_i2s
.tcr1
,
182 bf5xx_i2s
.tcr2
, 0, 0);
184 pr_err("SPORT is busy!\n");
192 static void bf5xx_i2s_shutdown(struct snd_pcm_substream
*substream
,
193 struct snd_soc_dai
*dai
)
195 pr_debug("%s enter\n", __func__
);
196 /* No active stream, SPORT is allowed to be configured again. */
198 bf5xx_i2s
.configured
= 0;
201 static int bf5xx_i2s_probe(struct snd_soc_dai
*dai
)
203 pr_debug("%s enter\n", __func__
);
204 if (peripheral_request_list(&sport_req
[sport_num
][0], "soc-audio")) {
205 pr_err("Requesting Peripherals failed\n");
209 /* request DMA for SPORT */
210 sport_handle
= sport_init(&sport_params
[sport_num
], 4, \
211 2 * sizeof(u32
), NULL
);
213 peripheral_free_list(&sport_req
[sport_num
][0]);
220 static int bf5xx_i2s_remove(struct snd_soc_dai
*dai
)
222 pr_debug("%s enter\n", __func__
);
223 peripheral_free_list(&sport_req
[sport_num
][0]);
228 static int bf5xx_i2s_suspend(struct snd_soc_dai
*dai
)
231 pr_debug("%s : sport %d\n", __func__
, dai
->id
);
233 if (dai
->capture_active
)
234 sport_rx_stop(sport_handle
);
235 if (dai
->playback_active
)
236 sport_tx_stop(sport_handle
);
240 static int bf5xx_i2s_resume(struct snd_soc_dai
*dai
)
244 pr_debug("%s : sport %d\n", __func__
, dai
->id
);
246 ret
= sport_config_rx(sport_handle
, bf5xx_i2s
.rcr1
,
247 bf5xx_i2s
.rcr2
, 0, 0);
249 pr_err("SPORT is busy!\n");
253 ret
= sport_config_tx(sport_handle
, bf5xx_i2s
.tcr1
,
254 bf5xx_i2s
.tcr2
, 0, 0);
256 pr_err("SPORT is busy!\n");
264 #define bf5xx_i2s_suspend NULL
265 #define bf5xx_i2s_resume NULL
268 #define BF5XX_I2S_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
269 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
270 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | \
271 SNDRV_PCM_RATE_96000)
273 #define BF5XX_I2S_FORMATS \
274 (SNDRV_PCM_FMTBIT_S8 | \
275 SNDRV_PCM_FMTBIT_S16_LE | \
276 SNDRV_PCM_FMTBIT_S24_LE | \
277 SNDRV_PCM_FMTBIT_S32_LE)
279 static struct snd_soc_dai_ops bf5xx_i2s_dai_ops
= {
280 .shutdown
= bf5xx_i2s_shutdown
,
281 .hw_params
= bf5xx_i2s_hw_params
,
282 .set_fmt
= bf5xx_i2s_set_dai_fmt
,
285 static struct snd_soc_dai_driver bf5xx_i2s_dai
= {
286 .probe
= bf5xx_i2s_probe
,
287 .remove
= bf5xx_i2s_remove
,
288 .suspend
= bf5xx_i2s_suspend
,
289 .resume
= bf5xx_i2s_resume
,
293 .rates
= BF5XX_I2S_RATES
,
294 .formats
= BF5XX_I2S_FORMATS
,},
298 .rates
= BF5XX_I2S_RATES
,
299 .formats
= BF5XX_I2S_FORMATS
,},
300 .ops
= &bf5xx_i2s_dai_ops
,
303 static int bfin_i2s_drv_probe(struct platform_device
*pdev
)
305 return snd_soc_register_dai(&pdev
->dev
, &bf5xx_i2s_dai
);
308 static int __devexit
bfin_i2s_drv_remove(struct platform_device
*pdev
)
310 snd_soc_unregister_dai(&pdev
->dev
);
314 static struct platform_driver bfin_i2s_driver
= {
315 .probe
= bfin_i2s_drv_probe
,
316 .remove
= __devexit_p(bfin_i2s_drv_remove
),
320 .owner
= THIS_MODULE
,
324 static int __init
bfin_i2s_init(void)
326 return platform_driver_register(&bfin_i2s_driver
);
329 static void __exit
bfin_i2s_exit(void)
331 platform_driver_unregister(&bfin_i2s_driver
);
334 module_init(bfin_i2s_init
);
335 module_exit(bfin_i2s_exit
);
337 /* Module information */
338 MODULE_AUTHOR("Cliff Cai");
339 MODULE_DESCRIPTION("I2S driver for ADI Blackfin");
340 MODULE_LICENSE("GPL");