GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / sound / soc / davinci / davinci-sffsdr.c
blob40eccfe9e358c2f2bc05574d3cdeb87f6fa7bffc
1 /*
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>
26 #include <asm/dma.h>
27 #include <asm/mach-types.h>
28 #ifdef CONFIG_SFFSDR_FPGA
29 #include <asm/plat-sffsdr/sffsdr-fpga.h>
30 #endif
32 #include <mach/mcbsp.h>
33 #include <mach/edma.h>
35 #include "../codecs/pcm3008.h"
36 #include "davinci-pcm.h"
37 #include "davinci-i2s.h"
40 * CLKX and CLKR are the inputs for the Sample Rate Generator.
41 * FSX and FSR are outputs, driven by the sample Rate Generator.
43 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
44 SND_SOC_DAIFMT_CBM_CFS | \
45 SND_SOC_DAIFMT_IB_NF)
47 static int sffsdr_hw_params(struct snd_pcm_substream *substream,
48 struct snd_pcm_hw_params *params)
50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
51 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
52 int fs;
53 int ret = 0;
55 /* Fsref can be 32000, 44100 or 48000. */
56 fs = params_rate(params);
58 #ifndef CONFIG_SFFSDR_FPGA
59 /* Without the FPGA module, the Fs is fixed at 44100 Hz */
60 if (fs != 44100) {
61 pr_debug("warning: only 44.1 kHz is supported without SFFSDR FPGA module\n");
62 return -EINVAL;
64 #endif
66 /* set cpu DAI configuration */
67 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
68 if (ret < 0)
69 return ret;
71 pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs);
73 #ifndef CONFIG_SFFSDR_FPGA
74 return 0;
75 #else
76 return sffsdr_fpga_set_codec_fs(fs);
77 #endif
80 static struct snd_soc_ops sffsdr_ops = {
81 .hw_params = sffsdr_hw_params,
84 /* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */
85 static struct snd_soc_dai_link sffsdr_dai = {
86 .name = "PCM3008", /* Codec name */
87 .stream_name = "PCM3008 HiFi",
88 .cpu_dai = &davinci_i2s_dai,
89 .codec_dai = &pcm3008_dai,
90 .ops = &sffsdr_ops,
93 /* davinci-sffsdr audio machine driver */
94 static struct snd_soc_card snd_soc_sffsdr = {
95 .name = "DaVinci SFFSDR",
96 .platform = &davinci_soc_platform,
97 .dai_link = &sffsdr_dai,
98 .num_links = 1,
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 /* sffsdr audio subsystem */
110 static struct snd_soc_device sffsdr_snd_devdata = {
111 .card = &snd_soc_sffsdr,
112 .codec_dev = &soc_codec_dev_pcm3008,
113 .codec_data = &sffsdr_pcm3008_setup,
116 static struct resource sffsdr_snd_resources[] = {
118 .start = DAVINCI_MCBSP_BASE,
119 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
120 .flags = IORESOURCE_MEM,
124 static struct evm_snd_platform_data sffsdr_snd_data = {
125 .tx_dma_ch = DAVINCI_DMA_MCBSP_TX,
126 .rx_dma_ch = DAVINCI_DMA_MCBSP_RX,
129 static struct platform_device *sffsdr_snd_device;
131 static int __init sffsdr_init(void)
133 int ret;
135 if (!machine_is_sffsdr())
136 return -EINVAL;
138 sffsdr_snd_device = platform_device_alloc("soc-audio", 0);
139 if (!sffsdr_snd_device) {
140 printk(KERN_ERR "platform device allocation failed\n");
141 return -ENOMEM;
144 platform_set_drvdata(sffsdr_snd_device, &sffsdr_snd_devdata);
145 sffsdr_snd_devdata.dev = &sffsdr_snd_device->dev;
146 platform_device_add_data(sffsdr_snd_device, &sffsdr_snd_data,
147 sizeof(sffsdr_snd_data));
149 ret = platform_device_add_resources(sffsdr_snd_device,
150 sffsdr_snd_resources,
151 ARRAY_SIZE(sffsdr_snd_resources));
152 if (ret) {
153 printk(KERN_ERR "platform device add ressources failed\n");
154 goto error;
157 ret = platform_device_add(sffsdr_snd_device);
158 if (ret)
159 goto error;
161 return ret;
163 error:
164 platform_device_put(sffsdr_snd_device);
165 return ret;
168 static void __exit sffsdr_exit(void)
170 platform_device_unregister(sffsdr_snd_device);
173 module_init(sffsdr_init);
174 module_exit(sffsdr_exit);
176 MODULE_AUTHOR("Hugo Villeneuve");
177 MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver");
178 MODULE_LICENSE("GPL");