2 * ASoC driver for Lyrtech SFFSDR board.
4 * Author: Hugo Villeneuve
5 * Copyright (C) 2008 Lyrtech inc
7 * Based on ASoC driver for TI DAVINCI EVM platform, original copyright follow:
8 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.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
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/timer.h>
18 #include <linux/interrupt.h>
19 #include <linux/platform_device.h>
20 #include <linux/gpio.h>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/soc.h>
24 #include <sound/soc-dapm.h>
27 #include <asm/mach-types.h>
28 #ifdef CONFIG_SFFSDR_FPGA
29 #include <asm/plat-sffsdr/sffsdr-fpga.h>
32 #include <mach/edma.h>
34 #include "../codecs/pcm3008.h"
35 #include "davinci-pcm.h"
36 #include "davinci-i2s.h"
39 * CLKX and CLKR are the inputs for the Sample Rate Generator.
40 * FSX and FSR are outputs, driven by the sample Rate Generator.
42 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
43 SND_SOC_DAIFMT_CBM_CFS | \
46 static int sffsdr_hw_params(struct snd_pcm_substream
*substream
,
47 struct snd_pcm_hw_params
*params
)
49 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
50 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
54 /* Fsref can be 32000, 44100 or 48000. */
55 fs
= params_rate(params
);
57 #ifndef CONFIG_SFFSDR_FPGA
58 /* Without the FPGA module, the Fs is fixed at 44100 Hz */
60 pr_debug("warning: only 44.1 kHz is supported without SFFSDR FPGA module\n");
65 /* set cpu DAI configuration */
66 ret
= snd_soc_dai_set_fmt(cpu_dai
, AUDIO_FORMAT
);
70 pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs
);
72 #ifndef CONFIG_SFFSDR_FPGA
75 return sffsdr_fpga_set_codec_fs(fs
);
79 static struct snd_soc_ops sffsdr_ops
= {
80 .hw_params
= sffsdr_hw_params
,
83 /* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */
84 static struct snd_soc_dai_link sffsdr_dai
= {
85 .name
= "PCM3008", /* Codec name */
86 .stream_name
= "PCM3008 HiFi",
87 .cpu_dai_name
= "davinci-asp.0",
88 .codec_dai_name
= "pcm3008-hifi",
89 .codec_name
= "pcm3008-codec",
90 .platform_name
= "davinci-pcm-audio",
94 /* davinci-sffsdr audio machine driver */
95 static struct snd_soc_card snd_soc_sffsdr
= {
96 .name
= "DaVinci SFFSDR",
97 .dai_link
= &sffsdr_dai
,
101 /* sffsdr audio private data */
102 static struct pcm3008_setup_data sffsdr_pcm3008_setup
= {
103 .dem0_pin
= GPIO(45),
104 .dem1_pin
= GPIO(46),
105 .pdad_pin
= GPIO(47),
106 .pdda_pin
= GPIO(38),
109 struct platform_device pcm3008_codec
= {
110 .name
= "pcm3008-codec",
113 .platform_data
= &sffsdr_pcm3008_setup
,
117 static struct resource sffsdr_snd_resources
[] = {
119 .start
= DAVINCI_MCBSP_BASE
,
120 .end
= DAVINCI_MCBSP_BASE
+ SZ_8K
- 1,
121 .flags
= IORESOURCE_MEM
,
125 static struct evm_snd_platform_data sffsdr_snd_data
= {
126 .tx_dma_ch
= DAVINCI_DMA_MCBSP_TX
,
127 .rx_dma_ch
= DAVINCI_DMA_MCBSP_RX
,
130 static struct platform_device
*sffsdr_snd_device
;
132 static int __init
sffsdr_init(void)
136 if (!machine_is_sffsdr())
139 platform_device_register(&pcm3008_codec
);
141 sffsdr_snd_device
= platform_device_alloc("soc-audio", 0);
142 if (!sffsdr_snd_device
) {
143 printk(KERN_ERR
"platform device allocation failed\n");
147 platform_set_drvdata(sffsdr_snd_device
, &snd_soc_sffsdr
);
148 platform_device_add_data(sffsdr_snd_device
, &sffsdr_snd_data
,
149 sizeof(sffsdr_snd_data
));
151 ret
= platform_device_add_resources(sffsdr_snd_device
,
152 sffsdr_snd_resources
,
153 ARRAY_SIZE(sffsdr_snd_resources
));
155 printk(KERN_ERR
"platform device add resources failed\n");
159 ret
= platform_device_add(sffsdr_snd_device
);
166 platform_device_put(sffsdr_snd_device
);
170 static void __exit
sffsdr_exit(void)
172 platform_device_unregister(sffsdr_snd_device
);
173 platform_device_unregister(&pcm3008_codec
);
176 module_init(sffsdr_init
);
177 module_exit(sffsdr_exit
);
179 MODULE_AUTHOR("Hugo Villeneuve");
180 MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver");
181 MODULE_LICENSE("GPL");