]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - sound/soc/davinci/davinci-sffsdr.c
Merge branch 'linus' into cpus4096
[linux-2.6-omap-h63xx.git] / sound / soc / davinci / davinci-sffsdr.c
1 /*
2  * ASoC driver for Lyrtech SFFSDR board.
3  *
4  * Author:      Hugo Villeneuve
5  * Copyright (C) 2008 Lyrtech inc
6  *
7  * Based on ASoC driver for TI DAVINCI EVM platform, original copyright follow:
8  * Copyright:   (C) 2007 MontaVista Software, Inc., <source@mvista.com>
9  *
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.
13  */
14
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>
25
26 #include <asm/dma.h>
27 #include <asm/mach-types.h>
28 #include <asm/plat-sffsdr/sffsdr-fpga.h>
29
30 #include <mach/mcbsp.h>
31 #include <mach/edma.h>
32
33 #include "../codecs/pcm3008.h"
34 #include "davinci-pcm.h"
35 #include "davinci-i2s.h"
36
37 static int sffsdr_hw_params(struct snd_pcm_substream *substream,
38                             struct snd_pcm_hw_params *params,
39                             struct snd_soc_dai *dai)
40 {
41         struct snd_soc_pcm_runtime *rtd = substream->private_data;
42         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
43         int fs;
44         int ret = 0;
45
46         /* Set cpu DAI configuration:
47          * CLKX and CLKR are the inputs for the Sample Rate Generator.
48          * FSX and FSR are outputs, driven by the sample Rate Generator. */
49         ret = snd_soc_dai_set_fmt(cpu_dai,
50                                   SND_SOC_DAIFMT_RIGHT_J |
51                                   SND_SOC_DAIFMT_CBM_CFS |
52                                   SND_SOC_DAIFMT_IB_NF);
53         if (ret < 0)
54                 return ret;
55
56         /* Fsref can be 32000, 44100 or 48000. */
57         fs = params_rate(params);
58
59         pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs);
60
61         return sffsdr_fpga_set_codec_fs(fs);
62 }
63
64 static struct snd_soc_ops sffsdr_ops = {
65         .hw_params = sffsdr_hw_params,
66 };
67
68 /* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */
69 static struct snd_soc_dai_link sffsdr_dai = {
70         .name = "PCM3008", /* Codec name */
71         .stream_name = "PCM3008 HiFi",
72         .cpu_dai = &davinci_i2s_dai,
73         .codec_dai = &pcm3008_dai,
74         .ops = &sffsdr_ops,
75 };
76
77 /* davinci-sffsdr audio machine driver */
78 static struct snd_soc_card snd_soc_sffsdr = {
79         .name = "DaVinci SFFSDR",
80         .platform = &davinci_soc_platform,
81         .dai_link = &sffsdr_dai,
82         .num_links = 1,
83 };
84
85 /* sffsdr audio private data */
86 static struct pcm3008_setup_data sffsdr_pcm3008_setup = {
87         .dem0_pin = GPIO(45),
88         .dem1_pin = GPIO(46),
89         .pdad_pin = GPIO(47),
90         .pdda_pin = GPIO(38),
91 };
92
93 /* sffsdr audio subsystem */
94 static struct snd_soc_device sffsdr_snd_devdata = {
95         .card = &snd_soc_sffsdr,
96         .codec_dev = &soc_codec_dev_pcm3008,
97         .codec_data = &sffsdr_pcm3008_setup,
98 };
99
100 static struct resource sffsdr_snd_resources[] = {
101         {
102                 .start = DAVINCI_MCBSP_BASE,
103                 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
104                 .flags = IORESOURCE_MEM,
105         },
106 };
107
108 static struct evm_snd_platform_data sffsdr_snd_data = {
109         .tx_dma_ch      = DAVINCI_DMA_MCBSP_TX,
110         .rx_dma_ch      = DAVINCI_DMA_MCBSP_RX,
111 };
112
113 static struct platform_device *sffsdr_snd_device;
114
115 static int __init sffsdr_init(void)
116 {
117         int ret;
118
119         if (!machine_is_sffsdr())
120                 return -EINVAL;
121
122         sffsdr_snd_device = platform_device_alloc("soc-audio", 0);
123         if (!sffsdr_snd_device) {
124                 printk(KERN_ERR "platform device allocation failed\n");
125                 return -ENOMEM;
126         }
127
128         platform_set_drvdata(sffsdr_snd_device, &sffsdr_snd_devdata);
129         sffsdr_snd_devdata.dev = &sffsdr_snd_device->dev;
130         sffsdr_snd_device->dev.platform_data = &sffsdr_snd_data;
131
132         ret = platform_device_add_resources(sffsdr_snd_device,
133                                             sffsdr_snd_resources,
134                                             ARRAY_SIZE(sffsdr_snd_resources));
135         if (ret) {
136                 printk(KERN_ERR "platform device add ressources failed\n");
137                 goto error;
138         }
139
140         ret = platform_device_add(sffsdr_snd_device);
141         if (ret)
142                 goto error;
143
144         return ret;
145
146 error:
147         platform_device_put(sffsdr_snd_device);
148         return ret;
149 }
150
151 static void __exit sffsdr_exit(void)
152 {
153         platform_device_unregister(sffsdr_snd_device);
154 }
155
156 module_init(sffsdr_init);
157 module_exit(sffsdr_exit);
158
159 MODULE_AUTHOR("Hugo Villeneuve");
160 MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver");
161 MODULE_LICENSE("GPL");