blob: a1ae3736a5d7a99783b7c1bb62736f475197f1d2 [file] [log] [blame]
Hugo Villeneuve08bd1682008-11-19 01:37:32 -05001/*
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>
David Brownell5cf1c002009-01-05 02:08:30 -080027#include <asm/mach-types.h>
Hugo Villeneuveac373732009-01-15 15:40:35 -050028#ifdef CONFIG_SFFSDR_FPGA
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050029#include <asm/plat-sffsdr/sffsdr-fpga.h>
Hugo Villeneuveac373732009-01-15 15:40:35 -050030#endif
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050031
32#include <mach/mcbsp.h>
33#include <mach/edma.h>
34
35#include "../codecs/pcm3008.h"
36#include "davinci-pcm.h"
37#include "davinci-i2s.h"
38
Hugo Villeneuve14cbba82009-03-09 23:32:07 -040039/*
40 * CLKX and CLKR are the inputs for the Sample Rate Generator.
41 * FSX and FSR are outputs, driven by the sample Rate Generator.
42 */
43#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
44 SND_SOC_DAIFMT_CBM_CFS | \
45 SND_SOC_DAIFMT_IB_NF)
46
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050047static int sffsdr_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +000048 struct snd_pcm_hw_params *params,
49 struct snd_soc_dai *dai)
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050050{
51 struct snd_soc_pcm_runtime *rtd = substream->private_data;
52 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
53 int fs;
54 int ret = 0;
55
Hugo Villeneuveac373732009-01-15 15:40:35 -050056 /* Fsref can be 32000, 44100 or 48000. */
57 fs = params_rate(params);
58
59#ifndef CONFIG_SFFSDR_FPGA
60 /* Without the FPGA module, the Fs is fixed at 44100 Hz */
61 if (fs != 44100) {
62 pr_debug("warning: only 44.1 kHz is supported without SFFSDR FPGA module\n");
63 return -EINVAL;
64 }
65#endif
66
Hugo Villeneuve14cbba82009-03-09 23:32:07 -040067 /* set cpu DAI configuration */
68 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050069 if (ret < 0)
70 return ret;
71
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050072 pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs);
73
Hugo Villeneuveac373732009-01-15 15:40:35 -050074#ifndef CONFIG_SFFSDR_FPGA
75 return 0;
76#else
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050077 return sffsdr_fpga_set_codec_fs(fs);
Hugo Villeneuveac373732009-01-15 15:40:35 -050078#endif
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050079}
80
81static struct snd_soc_ops sffsdr_ops = {
82 .hw_params = sffsdr_hw_params,
83};
84
85/* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */
86static struct snd_soc_dai_link sffsdr_dai = {
87 .name = "PCM3008", /* Codec name */
88 .stream_name = "PCM3008 HiFi",
89 .cpu_dai = &davinci_i2s_dai,
90 .codec_dai = &pcm3008_dai,
91 .ops = &sffsdr_ops,
92};
93
94/* davinci-sffsdr audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +000095static struct snd_soc_card snd_soc_sffsdr = {
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050096 .name = "DaVinci SFFSDR",
Mark Brown87689d52008-12-02 16:01:14 +000097 .platform = &davinci_soc_platform,
Hugo Villeneuve08bd1682008-11-19 01:37:32 -050098 .dai_link = &sffsdr_dai,
99 .num_links = 1,
100};
101
102/* sffsdr audio private data */
103static struct pcm3008_setup_data sffsdr_pcm3008_setup = {
104 .dem0_pin = GPIO(45),
105 .dem1_pin = GPIO(46),
106 .pdad_pin = GPIO(47),
107 .pdda_pin = GPIO(38),
108};
109
110/* sffsdr audio subsystem */
111static struct snd_soc_device sffsdr_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000112 .card = &snd_soc_sffsdr,
Hugo Villeneuve08bd1682008-11-19 01:37:32 -0500113 .codec_dev = &soc_codec_dev_pcm3008,
114 .codec_data = &sffsdr_pcm3008_setup,
115};
116
117static struct resource sffsdr_snd_resources[] = {
118 {
119 .start = DAVINCI_MCBSP_BASE,
120 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
121 .flags = IORESOURCE_MEM,
122 },
123};
124
125static struct evm_snd_platform_data sffsdr_snd_data = {
126 .tx_dma_ch = DAVINCI_DMA_MCBSP_TX,
127 .rx_dma_ch = DAVINCI_DMA_MCBSP_RX,
128};
129
130static struct platform_device *sffsdr_snd_device;
131
132static int __init sffsdr_init(void)
133{
134 int ret;
135
David Brownell5cf1c002009-01-05 02:08:30 -0800136 if (!machine_is_sffsdr())
137 return -EINVAL;
138
Hugo Villeneuve08bd1682008-11-19 01:37:32 -0500139 sffsdr_snd_device = platform_device_alloc("soc-audio", 0);
140 if (!sffsdr_snd_device) {
141 printk(KERN_ERR "platform device allocation failed\n");
142 return -ENOMEM;
143 }
144
145 platform_set_drvdata(sffsdr_snd_device, &sffsdr_snd_devdata);
146 sffsdr_snd_devdata.dev = &sffsdr_snd_device->dev;
Kevin Hilmanbf3dbe52009-02-13 11:36:37 -0800147 platform_device_add_data(sffsdr_snd_device, &sffsdr_snd_data,
148 sizeof(sffsdr_snd_data));
Hugo Villeneuve08bd1682008-11-19 01:37:32 -0500149
150 ret = platform_device_add_resources(sffsdr_snd_device,
151 sffsdr_snd_resources,
152 ARRAY_SIZE(sffsdr_snd_resources));
153 if (ret) {
154 printk(KERN_ERR "platform device add ressources failed\n");
155 goto error;
156 }
157
158 ret = platform_device_add(sffsdr_snd_device);
159 if (ret)
160 goto error;
161
162 return ret;
163
164error:
165 platform_device_put(sffsdr_snd_device);
166 return ret;
167}
168
169static void __exit sffsdr_exit(void)
170{
171 platform_device_unregister(sffsdr_snd_device);
172}
173
174module_init(sffsdr_init);
175module_exit(sffsdr_exit);
176
177MODULE_AUTHOR("Hugo Villeneuve");
178MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver");
179MODULE_LICENSE("GPL");