18 #include <linux/module.h>
19 #include <linux/slab.h>
34 #include <mach/hardware.h>
37 #include "../../arm/pxa2xx-pcm.h"
57 dev_dbg(&ssp->
pdev->dev,
"SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
58 pxa_ssp_read_reg(ssp,
SSCR0), pxa_ssp_read_reg(ssp,
SSCR1),
59 pxa_ssp_read_reg(ssp,
SSTO));
61 dev_dbg(&ssp->
pdev->dev,
"SSPSP 0x%08x SSSR 0x%08x SSACD 0x%08x\n",
62 pxa_ssp_read_reg(ssp,
SSPSP), pxa_ssp_read_reg(ssp,
SSSR),
63 pxa_ssp_read_reg(ssp,
SSACD));
87 static void pxa_ssp_set_dma_params(
struct ssp_device *
ssp,
int width4,
95 width4 ?
"32-bit" :
"16-bit", out ?
"out" :
"in");
108 struct ssp_priv *
priv = snd_soc_dai_get_drvdata(cpu_dai);
115 pxa_ssp_disable(ssp);
121 snd_soc_dai_set_dma_data(cpu_dai, substream, &dma->
params);
129 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
133 pxa_ssp_disable(ssp);
137 kfree(snd_soc_dai_get_dma_data(cpu_dai, substream));
138 snd_soc_dai_set_dma_data(cpu_dai, substream,
NULL);
145 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
156 pxa_ssp_disable(ssp);
163 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
184 #define pxa_ssp_suspend NULL
185 #define pxa_ssp_resume NULL
194 u32 sscr0 = pxa_ssp_read_reg(ssp,
SSCR0);
197 sscr0 &= ~0x0000ff00;
198 sscr0 |= ((div - 2)/2) << 8;
200 sscr0 &= ~0x000fff00;
201 sscr0 |= (div - 1) << 8;
203 pxa_ssp_write_reg(ssp,
SSCR0, sscr0);
211 u32 sscr0 = pxa_ssp_read_reg(ssp,
SSCR0);
215 div = ((sscr0 >> 8) & 0xff) * 2 + 2;
217 div = ((sscr0 >> 8) & 0xfff) + 1;
224 static int pxa_ssp_set_dai_sysclk(
struct snd_soc_dai *cpu_dai,
225 int clk_id,
unsigned int freq,
int dir)
227 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
231 u32 sscr0 = pxa_ssp_read_reg(ssp,
SSCR0) &
235 "pxa_ssp_set_dai_sysclk id: %d, clk_id %d, freq %u\n",
236 cpu_dai->
id, clk_id, freq);
259 pxa_ssp_set_scr(ssp, 1);
270 val = pxa_ssp_read_reg(ssp,
SSCR0) | sscr0;
271 pxa_ssp_write_reg(ssp,
SSCR0, val);
281 static int pxa_ssp_set_dai_clkdiv(
struct snd_soc_dai *cpu_dai,
284 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
291 pxa_ssp_write_reg(ssp,
SSACD, val);
294 val = pxa_ssp_read_reg(ssp,
SSACD);
313 pxa_ssp_write_reg(ssp,
SSACD, val);
316 pxa_ssp_set_scr(ssp, div);
328 static int pxa_ssp_set_dai_pll(
struct snd_soc_dai *cpu_dai,
int pll_id,
329 int source,
unsigned int freq_in,
unsigned int freq_out)
331 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
333 u32 ssacd = pxa_ssp_read_reg(ssp,
SSACD) & ~0x70;
336 pxa_ssp_write_reg(ssp,
SSACDD, 0);
371 val = (val << 16) | 64;
372 pxa_ssp_write_reg(ssp,
SSACDD, val);
377 "Using SSACDD %x to supply %uHz\n",
385 pxa_ssp_write_reg(ssp,
SSACD, ssacd);
393 static int pxa_ssp_set_dai_tdm_slot(
struct snd_soc_dai *cpu_dai,
396 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
400 sscr0 = pxa_ssp_read_reg(ssp,
SSCR0);
417 pxa_ssp_write_reg(ssp,
SSTSA, tx_mask);
418 pxa_ssp_write_reg(ssp,
SSRSA, rx_mask);
420 pxa_ssp_write_reg(ssp,
SSCR0, sscr0);
428 static int pxa_ssp_set_dai_tristate(
struct snd_soc_dai *cpu_dai,
431 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
435 sscr1 = pxa_ssp_read_reg(ssp,
SSCR1);
440 pxa_ssp_write_reg(ssp,
SSCR1, sscr1);
450 static int pxa_ssp_set_dai_fmt(
struct snd_soc_dai *cpu_dai,
453 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
455 u32 sscr0, sscr1, sspsp, scfr;
464 "can't change hardware dai format: stream is in use");
469 sscr0 = pxa_ssp_read_reg(ssp,
SSCR0) &
521 pxa_ssp_write_reg(ssp,
SSCR0, sscr0);
522 pxa_ssp_write_reg(ssp,
SSCR1, sscr1);
523 pxa_ssp_write_reg(ssp,
SSPSP, sspsp);
525 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
529 pxa_ssp_write_reg(ssp,
SSCR1, scfr);
555 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
561 int ttsa = pxa_ssp_read_reg(ssp,
SSTSA) & 0xf;
564 dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream);
570 pxa_ssp_set_dma_params(ssp,
571 ((chn == 2) && (ttsa != 1)) || (width == 32),
575 if (pxa_ssp_read_reg(ssp,
SSCR0) & SSCR0_SSE)
595 pxa_ssp_write_reg(ssp,
SSCR0, sscr0);
597 switch (priv->
dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
599 sspsp = pxa_ssp_read_reg(ssp,
SSPSP);
601 if ((pxa_ssp_get_scr(ssp) == 4) && (width == 16)) {
630 pxa_ssp_write_reg(ssp,
SSPSP, sspsp);
640 dev_err(&ssp->
pdev->dev,
"No TDM timeslot configured\n");
657 if (value && (sscr0 & SSCR0_SSE))
658 pxa_ssp_write_reg(ssp,
SSCR0, sscr0 & ~SSCR0_SSE);
672 pxa_ssp_write_reg(ssp,
SSCR1, sscr1);
675 pxa_ssp_write_reg(ssp,
SSSR, sssr);
676 pxa_ssp_write_reg(ssp,
SSPSP, sspsp);
677 pxa_ssp_write_reg(ssp,
SSCR0, sscr0 | SSCR0_SSE);
685 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
694 pxa_ssp_set_running_bit(substream, ssp, 1);
695 val = pxa_ssp_read_reg(ssp,
SSSR);
696 pxa_ssp_write_reg(ssp,
SSSR, val);
699 pxa_ssp_set_running_bit(substream, ssp, 1);
702 pxa_ssp_set_running_bit(substream, ssp, 0);
705 pxa_ssp_disable(ssp);
708 pxa_ssp_set_running_bit(substream, ssp, 0);
736 snd_soc_dai_set_drvdata(dai, priv);
747 struct ssp_priv *priv = snd_soc_dai_get_drvdata(dai);
754 #define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
755 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
756 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
757 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
758 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
760 #define PXA_SSP_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
761 SNDRV_PCM_FMTBIT_S24_LE | \
762 SNDRV_PCM_FMTBIT_S32_LE)
765 .startup = pxa_ssp_startup,
766 .shutdown = pxa_ssp_shutdown,
767 .trigger = pxa_ssp_trigger,
768 .hw_params = pxa_ssp_hw_params,
769 .set_sysclk = pxa_ssp_set_dai_sysclk,
770 .set_clkdiv = pxa_ssp_set_dai_clkdiv,
771 .set_pll = pxa_ssp_set_dai_pll,
772 .set_fmt = pxa_ssp_set_dai_fmt,
773 .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
774 .set_tristate = pxa_ssp_set_dai_tristate,
778 .probe = pxa_ssp_probe,
779 .remove = pxa_ssp_remove,
794 .ops = &pxa_ssp_dai_ops,
810 .name =
"pxa-ssp-dai",
814 .probe = asoc_ssp_probe,