]> git.karo-electronics.de Git - mv-sheeva.git/blob - sound/soc/blackfin/bf5xx-ssm2602.c
36f2769eb912b67c04bb08cb60a28681f7977f29
[mv-sheeva.git] / sound / soc / blackfin / bf5xx-ssm2602.c
1 /*
2  * File:         sound/soc/blackfin/bf5xx-ssm2602.c
3  * Author:       Cliff Cai <Cliff.Cai@analog.com>
4  *
5  * Created:      Tue June 06 2008
6  * Description:  board driver for SSM2602 sound chip
7  *
8  * Modified:
9  *               Copyright 2008 Analog Devices Inc.
10  *
11  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
12  *
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.
17  *
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.
22  *
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
27  */
28
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/device.h>
32
33 #include <sound/core.h>
34 #include <sound/pcm.h>
35 #include <sound/soc.h>
36 #include <sound/soc-dapm.h>
37 #include <sound/pcm_params.h>
38
39 #include <asm/dma.h>
40 #include <asm/portmux.h>
41 #include <linux/gpio.h>
42 #include "../codecs/ssm2602.h"
43 #include "bf5xx-sport.h"
44 #include "bf5xx-i2s-pcm.h"
45
46 static struct snd_soc_card bf5xx_ssm2602;
47
48 static int bf5xx_ssm2602_startup(struct snd_pcm_substream *substream)
49 {
50         struct snd_soc_pcm_runtime *rtd = substream->private_data;
51         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
52
53         pr_debug("%s enter\n", __func__);
54         snd_soc_dai_set_drvdata(cpu_dai, sport_handle);
55         return 0;
56 }
57
58 static int bf5xx_ssm2602_hw_params(struct snd_pcm_substream *substream,
59         struct snd_pcm_hw_params *params)
60 {
61         struct snd_soc_pcm_runtime *rtd = substream->private_data;
62         struct snd_soc_dai *codec_dai = rtd->codec_dai;
63         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
64         unsigned int clk = 0;
65         int ret = 0;
66
67         pr_debug("%s rate %d format %x\n", __func__, params_rate(params),
68                 params_format(params));
69         /*
70          * If you are using a crystal source which frequency is not 12MHz
71          * then modify the below case statement with frequency of the crystal.
72          *
73          * If you are using the SPORT to generate clocking then this is
74          * where to do it.
75          */
76
77         switch (params_rate(params)) {
78         case 8000:
79         case 16000:
80         case 48000:
81         case 96000:
82         case 11025:
83         case 22050:
84         case 44100:
85                 clk = 12000000;
86                 break;
87         }
88
89         /*
90          * CODEC is master for BCLK and LRC in this configuration.
91          */
92
93         /* set codec DAI configuration */
94         ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
95                 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
96         if (ret < 0)
97                 return ret;
98         /* set cpu DAI configuration */
99         ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
100                 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
101         if (ret < 0)
102                 return ret;
103
104         ret = snd_soc_dai_set_sysclk(codec_dai, SSM2602_SYSCLK, clk,
105                 SND_SOC_CLOCK_IN);
106         if (ret < 0)
107                 return ret;
108
109         return 0;
110 }
111
112 static struct snd_soc_ops bf5xx_ssm2602_ops = {
113         .startup = bf5xx_ssm2602_startup,
114         .hw_params = bf5xx_ssm2602_hw_params,
115 };
116
117 static struct snd_soc_dai_link bf5xx_ssm2602_dai = {
118         .name = "ssm2602",
119         .stream_name = "SSM2602",
120         .cpu_dai_name = "bf5xx-i2s",
121         .codec_dai_name = "ssm2602-hifi",
122         .platform_name = "bf5xx-pcm-audio",
123         .codec_name = "ssm2602-codec.0-0x1b",
124         .ops = &bf5xx_ssm2602_ops,
125 };
126
127 static struct snd_soc_card bf5xx_ssm2602 = {
128         .name = "bf5xx_ssm2602",
129         .dai_link = &bf5xx_ssm2602_dai,
130         .num_links = 1,
131 };
132
133 static struct platform_device *bf5xx_ssm2602_snd_device;
134
135 static int __init bf5xx_ssm2602_init(void)
136 {
137         int ret;
138
139         pr_debug("%s enter\n", __func__);
140         bf5xx_ssm2602_snd_device = platform_device_alloc("soc-audio", -1);
141         if (!bf5xx_ssm2602_snd_device)
142                 return -ENOMEM;
143
144         platform_set_drvdata(bf5xx_ssm2602_snd_device, &bf5xx_ssm2602);
145         ret = platform_device_add(bf5xx_ssm2602_snd_device);
146
147         if (ret)
148                 platform_device_put(bf5xx_ssm2602_snd_device);
149
150         return ret;
151 }
152
153 static void __exit bf5xx_ssm2602_exit(void)
154 {
155         pr_debug("%s enter\n", __func__);
156         platform_device_unregister(bf5xx_ssm2602_snd_device);
157 }
158
159 module_init(bf5xx_ssm2602_init);
160 module_exit(bf5xx_ssm2602_exit);
161
162 /* Module information */
163 MODULE_AUTHOR("Cliff Cai");
164 MODULE_DESCRIPTION("ALSA SoC SSM2602 BF527-EZKIT");
165 MODULE_LICENSE("GPL");
166