Blame view

sound/soc/blackfin/bf5xx-ad73311.c 6.1 KB
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  /*
   * File:         sound/soc/blackfin/bf5xx-ad73311.c
   * Author:       Cliff Cai <Cliff.Cai@analog.com>
   *
   * Created:      Thur Sep 25 2008
   * Description:  Board driver for ad73311 sound chip
   *
   * Modified:
   *               Copyright 2008 Analog Devices Inc.
   *
   * Bugs:         Enter bugs at http://blackfin.uclinux.org/
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, see the file COPYING, or write
   * to the Free Software Foundation, Inc.,
   * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   */
  
  #include <linux/module.h>
  #include <linux/moduleparam.h>
  #include <linux/device.h>
  #include <linux/delay.h>
  #include <linux/gpio.h>
  
  #include <sound/core.h>
  #include <sound/pcm.h>
  #include <sound/soc.h>
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
38
39
40
41
42
43
44
45
46
47
48
  #include <sound/pcm_params.h>
  
  #include <asm/blackfin.h>
  #include <asm/cacheflush.h>
  #include <asm/irq.h>
  #include <asm/dma.h>
  #include <asm/portmux.h>
  
  #include "../codecs/ad73311.h"
  #include "bf5xx-sport.h"
  #include "bf5xx-i2s-pcm.h"
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  
  #if CONFIG_SND_BF5XX_SPORT_NUM == 0
  #define bfin_write_SPORT_TCR1	bfin_write_SPORT0_TCR1
  #define bfin_read_SPORT_TCR1	bfin_read_SPORT0_TCR1
  #define bfin_write_SPORT_TCR2	bfin_write_SPORT0_TCR2
  #define bfin_write_SPORT_TX16	bfin_write_SPORT0_TX16
  #define bfin_read_SPORT_STAT	bfin_read_SPORT0_STAT
  #else
  #define bfin_write_SPORT_TCR1	bfin_write_SPORT1_TCR1
  #define bfin_read_SPORT_TCR1	bfin_read_SPORT1_TCR1
  #define bfin_write_SPORT_TCR2	bfin_write_SPORT1_TCR2
  #define bfin_write_SPORT_TX16	bfin_write_SPORT1_TX16
  #define bfin_read_SPORT_STAT	bfin_read_SPORT1_STAT
  #endif
  
  #define GPIO_SE CONFIG_SND_BFIN_AD73311_SE
875065491   Mark Brown   ASoC: Rename snd_...
65
  static struct snd_soc_card bf5xx_ad73311;
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  
  static int snd_ad73311_startup(void)
  {
  	pr_debug("%s enter
  ", __func__);
  
  	/* Pull up SE pin on AD73311L */
  	gpio_set_value(GPIO_SE, 1);
  	return 0;
  }
  
  static int snd_ad73311_configure(void)
  {
  	unsigned short ctrl_regs[6];
  	unsigned short status = 0;
  	int count = 0;
  
  	/* DMCLK = MCLK = 16.384 MHz
  	 * SCLK = DMCLK/8 = 2.048 MHz
  	 * Sample Rate = DMCLK/2048  = 8 KHz
  	 */
  	ctrl_regs[0] = AD_CONTROL | AD_WRITE | CTRL_REG_B | REGB_MCDIV(0) | \
  			REGB_SCDIV(0) | REGB_DIRATE(0);
  	ctrl_regs[1] = AD_CONTROL | AD_WRITE | CTRL_REG_C | REGC_PUDEV | \
  			REGC_PUADC | REGC_PUDAC | REGC_PUREF | REGC_REFUSE ;
  	ctrl_regs[2] = AD_CONTROL | AD_WRITE | CTRL_REG_D | REGD_OGS(2) | \
  			REGD_IGS(2);
  	ctrl_regs[3] = AD_CONTROL | AD_WRITE | CTRL_REG_E | REGE_DA(0x1f);
  	ctrl_regs[4] = AD_CONTROL | AD_WRITE | CTRL_REG_F | REGF_SEEN ;
  	ctrl_regs[5] = AD_CONTROL | AD_WRITE | CTRL_REG_A | REGA_MODE_DATA;
  
  	local_irq_disable();
  	snd_ad73311_startup();
  	udelay(1);
  
  	bfin_write_SPORT_TCR1(TFSR);
  	bfin_write_SPORT_TCR2(0xF);
  	SSYNC();
  
  	/* SPORT Tx Register is a 8 x 16 FIFO, all the data can be put to
  	 * FIFO before enable SPORT to transfer the data
  	 */
  	for (count = 0; count < 6; count++)
  		bfin_write_SPORT_TX16(ctrl_regs[count]);
  	SSYNC();
  	bfin_write_SPORT_TCR1(bfin_read_SPORT_TCR1() | TSPEN);
  	SSYNC();
  
  	/* When TUVF is set, the data is already send out */
67137a5d4   Roel Kluin   ASoC: count reach...
115
  	while (!(status & TUVF) && ++count < 10000) {
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
116
117
118
119
120
121
122
  		udelay(1);
  		status = bfin_read_SPORT_STAT();
  		SSYNC();
  	}
  	bfin_write_SPORT_TCR1(bfin_read_SPORT_TCR1() & ~TSPEN);
  	SSYNC();
  	local_irq_enable();
67137a5d4   Roel Kluin   ASoC: count reach...
123
  	if (count >= 10000) {
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
124
125
126
127
128
129
  		printk(KERN_ERR "ad73311: failed to configure codec
  ");
  		return -1;
  	}
  	return 0;
  }
4f6c7e159   Axel Lin   ASoC: bf5xx-ad733...
130
  static int bf5xx_probe(struct snd_soc_card *card)
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
  {
  	int err;
  	if (gpio_request(GPIO_SE, "AD73311_SE")) {
  		printk(KERN_ERR "%s: Failed ro request GPIO_%d
  ", __func__, GPIO_SE);
  		return -EBUSY;
  	}
  
  	gpio_direction_output(GPIO_SE, 0);
  
  	err = snd_ad73311_configure();
  	if (err < 0)
  		return -EFAULT;
  
  	return 0;
  }
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
147
148
149
150
  static int bf5xx_ad73311_hw_params(struct snd_pcm_substream *substream,
  	struct snd_pcm_hw_params *params)
  {
  	struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
151
  	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
152
153
154
155
156
157
158
  	int ret = 0;
  
  	pr_debug("%s rate %d format %x
  ", __func__, params_rate(params),
  		params_format(params));
  
  	/* set cpu DAI configuration */
9b0db7e7f   Mark Brown   ASoC: Convert bla...
159
  	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
160
161
162
163
164
165
166
167
168
  		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  	if (ret < 0)
  		return ret;
  
  	return 0;
  }
  
  
  static struct snd_soc_ops bf5xx_ad73311_ops = {
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
169
170
  	.hw_params = bf5xx_ad73311_hw_params,
  };
2c66cb99d   Barry Song   ASoC: Blackfin: p...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
  static struct snd_soc_dai_link bf5xx_ad73311_dai[] = {
  	{
  		.name = "ad73311",
  		.stream_name = "AD73311",
  		.cpu_dai_name = "bfin-i2s.0",
  		.codec_dai_name = "ad73311-hifi",
  		.platform_name = "bfin-i2s-pcm-audio",
  		.codec_name = "ad73311",
  		.ops = &bf5xx_ad73311_ops,
  	},
  	{
  		.name = "ad73311",
  		.stream_name = "AD73311",
  		.cpu_dai_name = "bfin-i2s.1",
  		.codec_dai_name = "ad73311-hifi",
  		.platform_name = "bfin-i2s-pcm-audio",
  		.codec_name = "ad73311",
  		.ops = &bf5xx_ad73311_ops,
  	},
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
190
  };
875065491   Mark Brown   ASoC: Rename snd_...
191
  static struct snd_soc_card bf5xx_ad73311 = {
bfe4ee0a9   Mike Frysinger   ASoC: Blackfin: s...
192
  	.name = "bfin-ad73311",
30e495301   Axel Lin   ASoC: blackfin: A...
193
  	.owner = THIS_MODULE,
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
194
  	.probe = bf5xx_probe,
2c66cb99d   Barry Song   ASoC: Blackfin: p...
195
  	.dai_link = &bf5xx_ad73311_dai[CONFIG_SND_BF5XX_SPORT_NUM],
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
196
197
  	.num_links = 1,
  };
f274143f1   Barry Song   ASoC: Blackfin: c...
198
  static struct platform_device *bf5xx_ad73311_snd_device;
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
199
200
201
202
203
204
205
  
  static int __init bf5xx_ad73311_init(void)
  {
  	int ret;
  
  	pr_debug("%s enter
  ", __func__);
f274143f1   Barry Song   ASoC: Blackfin: c...
206
207
  	bf5xx_ad73311_snd_device = platform_device_alloc("soc-audio", -1);
  	if (!bf5xx_ad73311_snd_device)
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
208
  		return -ENOMEM;
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
209
  	platform_set_drvdata(bf5xx_ad73311_snd_device, &bf5xx_ad73311);
f274143f1   Barry Song   ASoC: Blackfin: c...
210
  	ret = platform_device_add(bf5xx_ad73311_snd_device);
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
211
212
  
  	if (ret)
f274143f1   Barry Song   ASoC: Blackfin: c...
213
  		platform_device_put(bf5xx_ad73311_snd_device);
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
214
215
216
217
218
219
220
221
  
  	return ret;
  }
  
  static void __exit bf5xx_ad73311_exit(void)
  {
  	pr_debug("%s enter
  ", __func__);
f274143f1   Barry Song   ASoC: Blackfin: c...
222
  	platform_device_unregister(bf5xx_ad73311_snd_device);
5564b14b8   Cliff Cai   ALSA: ASoC Blackf...
223
224
225
226
227
228
229
230
231
  }
  
  module_init(bf5xx_ad73311_init);
  module_exit(bf5xx_ad73311_exit);
  
  /* Module information */
  MODULE_AUTHOR("Cliff Cai");
  MODULE_DESCRIPTION("ALSA SoC AD73311 Blackfin");
  MODULE_LICENSE("GPL");