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/pcm_params.h>
37 
38 #include <asm/dma.h>
39 #include <asm/portmux.h>
40 #include <linux/gpio.h>
41 #include "../codecs/ssm2602.h"
42 #include "bf5xx-sport.h"
43 #include "bf5xx-i2s-pcm.h"
44 
45 static struct snd_soc_card bf5xx_ssm2602;
46 
bf5xx_ssm2602_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)47 static int bf5xx_ssm2602_hw_params(struct snd_pcm_substream *substream,
48 	struct snd_pcm_hw_params *params)
49 {
50 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
51 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
52 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
53 	unsigned int clk = 0;
54 	int ret = 0;
55 
56 	pr_debug("%s rate %d format %x\n", __func__, params_rate(params),
57 		params_format(params));
58 	/*
59 	 * If you are using a crystal source which frequency is not 12MHz
60 	 * then modify the below case statement with frequency of the crystal.
61 	 *
62 	 * If you are using the SPORT to generate clocking then this is
63 	 * where to do it.
64 	 */
65 
66 	switch (params_rate(params)) {
67 	case 8000:
68 	case 16000:
69 	case 48000:
70 	case 96000:
71 	case 11025:
72 	case 22050:
73 	case 44100:
74 		clk = 12000000;
75 		break;
76 	}
77 
78 	/*
79 	 * CODEC is master for BCLK and LRC in this configuration.
80 	 */
81 
82 	/* set codec DAI configuration */
83 	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
84 		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
85 	if (ret < 0)
86 		return ret;
87 	/* set cpu DAI configuration */
88 	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
89 		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
90 	if (ret < 0)
91 		return ret;
92 
93 	ret = snd_soc_dai_set_sysclk(codec_dai, SSM2602_SYSCLK, clk,
94 		SND_SOC_CLOCK_IN);
95 	if (ret < 0)
96 		return ret;
97 
98 	return 0;
99 }
100 
101 static struct snd_soc_ops bf5xx_ssm2602_ops = {
102 	.hw_params = bf5xx_ssm2602_hw_params,
103 };
104 
105 static struct snd_soc_dai_link bf5xx_ssm2602_dai[] = {
106 	{
107 		.name = "ssm2602",
108 		.stream_name = "SSM2602",
109 		.cpu_dai_name = "bfin-i2s.0",
110 		.codec_dai_name = "ssm2602-hifi",
111 		.platform_name = "bfin-i2s-pcm-audio",
112 		.codec_name = "ssm2602.0-001b",
113 		.ops = &bf5xx_ssm2602_ops,
114 	},
115 	{
116 		.name = "ssm2602",
117 		.stream_name = "SSM2602",
118 		.cpu_dai_name = "bfin-i2s.1",
119 		.codec_dai_name = "ssm2602-hifi",
120 		.platform_name = "bfin-i2s-pcm-audio",
121 		.codec_name = "ssm2602.0-001b",
122 		.ops = &bf5xx_ssm2602_ops,
123 	},
124 };
125 
126 static struct snd_soc_card bf5xx_ssm2602 = {
127 	.name = "bfin-ssm2602",
128 	.owner = THIS_MODULE,
129 	.dai_link = &bf5xx_ssm2602_dai[CONFIG_SND_BF5XX_SPORT_NUM],
130 	.num_links = 1,
131 };
132 
133 static struct platform_device *bf5xx_ssm2602_snd_device;
134 
bf5xx_ssm2602_init(void)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 
bf5xx_ssm2602_exit(void)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 
167